字段和店铺商品的逻辑修改

This commit is contained in:
liu 2024-06-17 15:27:43 +08:00
parent 00ebf84f8e
commit bc881d8e09
4 changed files with 22 additions and 12 deletions

View File

@ -58,7 +58,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
} }
} }
return StoreBranchProduct::where($this->searchWhere)->where($where) return StoreBranchProduct::where($this->searchWhere)->where($where)
->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'status']) ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status'])
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
}) })

View File

@ -66,30 +66,33 @@ class OrderLogic extends BaseLogic
try { try {
self::$total_price = 0; self::$total_price = 0;
self::$pay_price = 0; self::$pay_price = 0;
self::$cost = 0; //成本 self::$cost = 0; //成本由采购价替代原成本为门店零售价
self::$profit = 0; //利润 self::$profit = 0; //利润
self::$activity_price = 0; //活动减少 self::$activity_price = 0; //活动减少
/** 计算价格 */ /** 计算价格 */
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,product_id')->withTrashed()->find(); $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id')->withTrashed()->find();
if (!$find) { if (!$find) {
continue; continue;
} }
unset($cart_select[$k]['id']); unset($cart_select[$k]['id']);
if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){
$find['price'] = $find['cost'];
}
$cart_select[$k]['price'] = $find['price']; $cart_select[$k]['price'] = $find['price'];
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
if ($user && $user['user_ship'] == 4) { if ($user && $user['user_ship'] == 4) {
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); $deduction_price_count=bcmul(bcsub($find['price'], $find['purchase'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count; $cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
} }
//利润 //利润
// $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本 $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['product_id'] = $find['product_id']; $cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['old_cart_id'] = $v['id'];
@ -110,7 +113,7 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
} }
$pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 $pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
@ -141,7 +144,7 @@ class OrderLogic extends BaseLogic
if ($params['store_id']) { if ($params['store_id']) {
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
} }
if($user['user_ship']>=1 &&$user['user_ship']<=3){ if($user && $user['user_ship']>=1 &&$user['user_ship']<=3){
$order['is_vip'] = 1; $order['is_vip'] = 1;
} }

View File

@ -8,9 +8,14 @@ class UserShipEnum
* 会员等级 * 会员等级
*/ */
const VIP1 = 1; const VIP1 = 1;
const VIP2 = 7; const VIP2 = 2;
const VIP3 = 8; const VIP3 = 3;
const VIP4 = 9; const VIP4 = 4;
const VIP5 = 10; const VIP5 = 5;
/**
* 切换折扣价
*/
const DISCOUNT_ARRAY = [4,5,6];
} }

View File

@ -56,7 +56,8 @@ class StoreStorageSend implements Consumer
'cate_id' => $find['cate_id'], 'cate_id' => $find['cate_id'],
'price' => $find['price'], 'price' => $find['price'],
// 'cost' => $find['cost'], //v1.0 // 'cost' => $find['cost'], //v1.0
'cost' => $find['purchase'], 'cost' => $find['cost'],
'purchase' => $find['purchase'],
'vip_price' => $find['vip_price'], 'vip_price' => $find['vip_price'],
'unit' => $find['unit'], 'unit' => $find['unit'],
'batch' => $find['batch'], 'batch' => $find['batch'],
@ -117,6 +118,7 @@ class StoreStorageSend implements Consumer
'cate_id' => $find['cate_id'], 'cate_id' => $find['cate_id'],
'price' => $find['price'], 'price' => $find['price'],
'cost' => $find['cost'], 'cost' => $find['cost'],
'purchase' => $find['purchase'],
'vip_price' => $find['vip_price'], 'vip_price' => $find['vip_price'],
'unit' => $find['unit'], 'unit' => $find['unit'],
'store_id' => $store_id, 'store_id' => $store_id,