diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index ff127b729..ea5239d8a 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -63,7 +63,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI } return StoreBranchProduct::where($this->searchWhere)->where($where) - ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price']) + ->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price','manufacturer_information']) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 8d2d6969b..12c737412 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -46,7 +46,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function lists(): array { return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name','swap', 'cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code']) + ->field(['id', 'image', 'store_name','swap', 'cate_id','batch', 'price','vip_price','sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','bar_code','manufacturer_information']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 6aee0d22b..df8425a58 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -49,6 +49,7 @@ class StoreProductLogic extends BaseLogic 'purchase' => $params['purchase'], 'rose' => $params['rose'], 'is_return' => $params['is_return'], + 'manufacturer_information' => $params['manufacturer_information']??'', 'swap' => $params['swap'] ?? 0, 'batch' => $params['batch'] ?? 0, ]; @@ -149,6 +150,7 @@ class StoreProductLogic extends BaseLogic 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'batch' => $params['batch'], + 'manufacturer_information' => $params['manufacturer_information']??'', 'swap' => $params['swap'] ?? 0, ]; @@ -177,7 +179,8 @@ class StoreProductLogic extends BaseLogic StoreBranchProduct::where('product_id', $params['id'])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], - 'batch'=>$params['batch'],'store_name'=>$params['store_name'] + 'batch'=>$params['batch'],'store_name'=>$params['store_name'], + 'manufacturer_information' => $params['manufacturer_information']??'', ]); Db::commit(); @@ -290,6 +293,7 @@ class StoreProductLogic extends BaseLogic 'store_id' => $store_id, 'sales' => 0, 'stock' => $stock, + 'manufacturer_information' => $find['manufacturer_information']??'', ]; StoreBranchProduct::create($product); $arr = [ diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index 2b449a454..f8e219939 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -63,7 +63,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L */ public function setDefaultOrder(): array { - return ['sales' => 'desc', 'price' => 'asc']; + return [ 'price' => 'asc','id' => 'desc']; } /** @@ -107,10 +107,12 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L $this->searchWhere[] = ['stock', '>', 0]; return StoreBranchProduct::where($this->searchWhere) ->field(['id', 'product_id', 'cate_id', 'store_name', 'cost', 'store_id','vip_price','purchase', 'price', 'bar_code', 'image', 'sales', 'store_info', 'delete_time', 'unit', 'batch']) - ->limit($this->limitOffset, $this->limitLength) ->with(['className', 'unitName']) + ->limit($this->limitOffset, $this->limitLength) ->order($this->sortOrder) - ->select()?->toArray(); +// ->page($this->limitOffset +1,$this->limitLength) + ->select()->toArray(); + } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 23cd86736..2cc365e5b 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -224,24 +224,17 @@ class OrderLogic extends BaseLogic try { $order = StoreOrder::create($_order); $goods_list = $orderInfo['cart_list']; - $updateData = []; foreach ($goods_list as $k => $v) { $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $user['id']; $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id $StoreBranchProduct = StoreBranchProduct::where('id',$v['branch_product_id'])->withTrashed()->find(); - $updateData[] = [ - 'id' => $v['branch_product_id'], - 'stock' => $StoreBranchProduct['stock']-$v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; if($StoreBranchProduct['stock']-$v['cart_num']<=0){ Db::name('store_product_cate')->where(['cate_id'=>$StoreBranchProduct['cate_id'],'store_id'=>$params['store_id']])->update(['count'=>0]); } } (new StoreOrderCartInfo())->saveAll($goods_list); - (new StoreBranchProduct())->saveAll($updateData); $where = ['is_pay' => 0]; Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); Db::commit(); @@ -447,6 +440,7 @@ class OrderLogic extends BaseLogic // } $order=StoreOrder::where('id',$data['id'])->find(); PayNotifyLogic::afterPay($order); + PayNotifyLogic::descStock($order['id']); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 689234048..6fa47d13c 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -9,6 +9,7 @@ use app\common\enum\user\UserShipEnum; use app\common\model\dict\DictType; use app\common\model\finance\PayNotifyLog; use app\common\model\pay\PayNotify; +use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; @@ -89,6 +90,9 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'],'',0,$order['store_id']); self::dealProductLog($order); + if($order['shipping_type'] == 3){ + self::descStock($order['id']); + } // self::afterPay($order); // Redis::send('push-platform-print', ['id' => $order['id']], 60); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); @@ -136,6 +140,9 @@ class PayNotifyLogic extends BaseLogic OrderLogic::writeOff($params); } self::dealProductLog($order); + if($order['shipping_type'] == 3){ + self::descStock($order['id']); + } // self::afterPay($order); // Redis::send('push-platform-print', ['id' => $order['id']], 60); @@ -175,6 +182,9 @@ class PayNotifyLogic extends BaseLogic } self::dealProductLog($order); + if($order['shipping_type'] == 3){ + self::descStock($order['id']); + } // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; @@ -273,6 +283,9 @@ class PayNotifyLogic extends BaseLogic $cashFlowLogic = new CashFlowLogic(); $cashFlowLogic->insert($order['store_id'], $order['pay_price']); self::dealProductLog($order); + if($order['shipping_type'] == 3){ + self::descStock($order['id']); + } // Redis::send('push-platform-print', ['id' => $order['id']]); } @@ -304,6 +317,9 @@ class PayNotifyLogic extends BaseLogic self::afterPay($order); } self::dealProductLog($order); + if($order['shipping_type'] == 3){ + self::descStock($order['id']); + } // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; @@ -621,4 +637,38 @@ class PayNotifyLogic extends BaseLogic } + + /** + * 扣库存 + * @param $oid + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function descStock($oid) + { + $updateData = []; + $goods_list = StoreOrderCartInfo::where('oid',$oid)->select()->toArray(); + foreach ($goods_list as $v) { + $StoreBranchProduct =StoreBranchProduct::where( + [ + 'store_id'=>$v['store_id'], + 'product_id'=>$v['product_id'], + ] + )->withTrashed()->find(); + $updateData[] = [ + 'id' => $StoreBranchProduct['id'], + 'stock' => $StoreBranchProduct['stock']-$v['cart_num'], + 'sales' => ['inc', $v['cart_num']] + ]; + + } + + (new StoreBranchProduct())->saveAll($updateData); + + } + + + } diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index d2cb8e0e4..33b263814 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -59,6 +59,7 @@ class StoreStorageSend implements Consumer 'cost' => $find['cost'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'], + 'manufacturer_information' => $find['manufacturer_information']??'', 'unit' => $find['unit'], 'batch' => $find['batch'], 'store_id' => $store_id,