From b2baeec62c088f9147bf53eb4d348d5ac99e30fd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 15:21:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductLists.php | 1 + .../StoreBranchProductLogic.php | 23 +++++- .../WarehouseProductLogic.php | 22 +++++- app/api/controller/IndexController.php | 6 ++ app/api/controller/order/CartController.php | 12 ++- app/api/lists/cate/CateLists.php | 18 ++--- app/api/lists/order/CartList.php | 8 +- app/api/lists/order/OrderList.php | 3 - app/api/lists/product/ProductLists.php | 15 ++-- app/api/lists/product/StoreProductLists.php | 16 ++-- app/api/logic/order/OrderLogic.php | 12 ++- app/common/logic/CommissionProductLogic.php | 7 +- app/common/logic/PayNotifyLogic.php | 46 ++++++++--- .../StoreBranchProduct.php | 2 - .../model/store_product/StoreProduct.php | 4 +- .../WarehouseProductStorege.php | 10 ++- app/functions.php | 19 ++++- app/store/controller/cart/CartController.php | 18 ++++- app/store/lists/cart/CartList.php | 5 +- config/log.php | 76 ++++++++++++++++++- 20 files changed, 239 insertions(+), 84 deletions(-) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 7681a721..6b2f1624 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -12,6 +12,7 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\lists\ListsExcelInterface; use app\common\lists\ListsSortInterface; +use app\common\model\store_product\StoreProduct; /** * 门店商品辅助表 diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index cf365b69..0b19ba48 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -81,19 +81,38 @@ class StoreBranchProductLogic extends BaseLogic { Db::startTrans(); try { - $find = StoreProduct::where('id', $params['product_id'])->find(); - $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find(); + $find = StoreProduct::where('id', $params['product_id'])->find()->toArray(); + $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray(); if ($type == 1) { $stock = bcadd($find['stock'], $params['nums'], 2); $branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2); + onBeforeUpdate($storeBranchProduct,'branch_product'); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); + $storeBranchProduct['stock']=$branchStock; + $storeBranchProduct['total_price']=bcmul($branchStock, $find['purchase'], 2); + onAfterUpdate($storeBranchProduct,'branch_product'); + + onBeforeUpdate($find,'product'); StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); + $find['stock']=$stock; + $find['total_price']=bcmul($stock, $find['purchase'], 2); + onAfterUpdate($find,'product'); } else { $branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2); $stock = bcsub($find['stock'], $params['nums'], 2); + + onBeforeUpdate($storeBranchProduct,'branch_product'); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); + $storeBranchProduct['stock']=$branchStock; + $storeBranchProduct['total_price']=bcmul($branchStock, $find['purchase'], 2); + onAfterUpdate($storeBranchProduct,'branch_product'); + + onBeforeUpdate($find,'product'); StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); + $find['stock']=$stock; + $find['total_price']=bcmul($stock, $find['purchase'], 2); + onAfterUpdate($find,'product'); } Db::commit(); return true; diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 8dc2575a..2134c513 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -42,11 +42,23 @@ class WarehouseProductLogic extends BaseLogic $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); if ($storege) { if ($params['financial_pm'] == 0) { + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + if (!$storeProduct) { + throw new BusinessException('商品不存在'); + } $after_nums = $storege['nums'] - $params['nums']; + $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); + // if ($after_nums < 0) { // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // } - WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update(); + onBeforeUpdate($storege->toArray(),'product_storege'); + WarehouseProductStorege::where('id', $storege['id'])->update(['nums'=>$after_nums, 'total_price' => $total_price]); + $storege=$storege->toArray(); + $storege['nums']=$after_nums; + $storege['total_price']=$total_price; + onAfterUpdate($storege,'product_storege'); + //门店加库存 $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); if (!$storeBranchProduct) { @@ -67,7 +79,12 @@ class WarehouseProductLogic extends BaseLogic throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); + onBeforeUpdate($storege->toArray(),'product_storege'); WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]); + $storege=$storege->toArray(); + $storege['nums']=$after_nums; + $storege['total_price']=$total_price; + onAfterUpdate($storege,'product_storege'); } } $before_nums = $storege['nums']; @@ -78,12 +95,13 @@ class WarehouseProductLogic extends BaseLogic throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - WarehouseProductStorege::create([ + $storege=WarehouseProductStorege::create([ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], 'nums' => $params['nums'], 'total_price'=>$total_price ]); + onAfterUpdate($storege->toArray(),'product_storege'); } $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $data = [ diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index dbe09f34..2a090cd5 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,9 +44,15 @@ class IndexController extends BaseApiController public function index() { + $a=StoreProduct::where('is_show',1)->select(); + foreach($a as $k=>$v){ + $find=StoreBranchProduct::where('product_id',$v['id'])->find(); + StoreProduct::where('id',$v['id'])->update(['top_cate_id'=>$find['top_cate_id'],'two_cate_id'=>$find['two_cate_id'],'cate_id'=>$find['cate_id']]); + } return json([1]); } + /** * @notes 下载文件 */ diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index 90a35cd7..5810409f 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -7,7 +7,7 @@ use app\api\validate\CartValidate; use app\api\controller\BaseApiController; use app\api\lists\order\CartList; use app\common\model\order\Cart; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; class CartController extends BaseApiController @@ -27,10 +27,9 @@ class CartController extends BaseApiController $result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find(); $params['cart_num']=bcadd($params['cart_num'],0,2); //判断起批发价 - $branchProduct = StoreBranchProduct::where( + $branchProduct = StoreProduct::where( [ - 'product_id' => $params['product_id'], - 'store_id' => $params['store_id'] + 'id' => $params['product_id'], ] )->find(); if (!$branchProduct) { @@ -86,10 +85,9 @@ class CartController extends BaseApiController $params['uid'] = $this->request->userId; $params['cart_num']=bcadd($params['cart_num'],0,2); if (convertNumber($params['cart_num']) === false) { - $branchProduct = StoreBranchProduct::where( + $branchProduct = StoreProduct::where( [ - 'product_id' => $params['product_id'], - 'store_id' => $params['store_id'] + 'id' => $params['product_id'], ] )->find(); $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index 8157169f..21c52e4b 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -6,7 +6,7 @@ namespace app\api\lists\cate; use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; use app\common\lists\ListsSearchInterface; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\Request; use think\facade\Db; @@ -28,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'data', 'store_id', 'sort'], + '=' => ['name', 'data', 'sort'], ]; } @@ -47,17 +47,17 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface $level = Request()->get('level', 1); $pid = $this->request->get('pid',0); // $this->searchWhere[] = ['stock', '>', 0]; - $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['is_show', '=', 1]; if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } $lists = []; @@ -85,14 +85,14 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface $pid = $this->request->get('pid',0); if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('two_cate_id'); }elseif($pid && $level ==3){ $this->searchWhere[] = ['two_cate_id','=',$pid]; - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('cate_id'); }else{ - $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + $cate_arr = StoreProduct::where($this->searchWhere)->distinct() ->column('top_cate_id'); } return Cate::where('id', 'in', $cate_arr)->count(); diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index 5b6c770c..e734eb10 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -9,7 +9,7 @@ use app\common\model\order\Cart; use app\common\lists\ListsExtendInterface; use app\common\model\Config; use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; @@ -65,14 +65,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists ->toArray(); $off_activity = Config::where('name', 'off_activity')->value('value'); $user_ship = User::where('id', $userId)->value('user_ship'); - $field = 'product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; + $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; if (in_array($user_ship, [4, 6, 7])) { - $field = 'product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; + $field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; } $this->user_ship = $user_ship; $this->off_activity = $off_activity; foreach ($list as $key => &$item) { - $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) + $find = StoreProduct::where(['id' => $item['product_id']]) ->field($field) ->find(); if ($find) { diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index a08142f7..5e665265 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -5,11 +5,8 @@ namespace app\api\lists\order; use app\admin\lists\BaseAdminDataLists; use app\common\lists\ListsSearchInterface; -use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; -use app\common\model\store_product\StoreProduct; -use app\common\model\store_product_unit\StoreProductUnit; use Picqer\Barcode\BarcodeGeneratorPNG; /** diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index d15d822f..ac126989 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -6,11 +6,8 @@ namespace app\api\lists\product; use app\api\lists\BaseApiDataLists; use app\common\lists\ListsExtendInterface; use app\common\lists\ListsSortInterface; -use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; -use app\common\model\cate\Cate; use app\common\model\Config; use app\common\model\user\User; //use app\common\model\goods\GoodsLabel; @@ -35,7 +32,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis public function setSearch(): array { return [ - '=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'], + '=' => [ 'cate_id', 'top_cate_id', 'two_cate_id'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'], ]; } @@ -79,7 +76,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis } else { $order = [$field => $order]; } - $fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $off_activity = Config::where('name', 'off_activity')->value('value'); if ($off_activity == 1) { $tag = '赠10%品牌礼品券'; @@ -96,13 +93,13 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis if ($uid > 0) { $user_ship = User::where('id', $uid)->value('user_ship'); if (in_array($user_ship, [4, 6, 7])) { - $fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; } } $this->off_activity = $off_activity; - $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['is_show', '=', 1]; // $this->searchWhere[] = ['stock', '>', 0]; - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) @@ -126,7 +123,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function count(): int { - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->count(); } public function extend() diff --git a/app/api/lists/product/StoreProductLists.php b/app/api/lists/product/StoreProductLists.php index f9c4b2d0..ee66cd1c 100644 --- a/app/api/lists/product/StoreProductLists.php +++ b/app/api/lists/product/StoreProductLists.php @@ -7,7 +7,6 @@ use app\api\lists\BaseApiDataLists; use app\common\lists\ListsExtendInterface; use app\common\lists\ListsSortInterface; use app\common\model\dict\DictType; -use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; use app\common\model\cate\Cate; @@ -72,22 +71,17 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface */ public function lists(): array { - $store_id= $this->request->__get('store_id'); - if($store_id){ - $this->searchWhere[] = ['store_id', '=', $store_id]; - } - - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $type=$this->request->get('type',0); if($type==1){ - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; }elseif($type==2){ - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; + $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; } $this->searchWhere[] = ['status', '=', 1]; // $this->searchWhere[] = ['stock', '>', 0]; - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) @@ -105,7 +99,7 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface */ public function count(): int { - return StoreBranchProduct::where($this->searchWhere) + return StoreProduct::where($this->searchWhere) ->count(); } } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 19f9e74a..1dda5e8c 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -87,9 +87,9 @@ class OrderLogic extends BaseLogic self::$fresh_price = 0; //生鲜金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); - $field = 'product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; + $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); + $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); if (!$find) { throw new BusinessException('商品不存在'); } @@ -452,7 +452,7 @@ class OrderLogic extends BaseLogic return []; } $goods_arr = array_unique($goods_id); - $select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); + $select = StoreProduct::where('id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); return $select->toArray(); } catch (\Throwable $e) { throw new BusinessException($e->getMessage()); @@ -495,10 +495,8 @@ class OrderLogic extends BaseLogic $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { - $find = StoreBranchProduct::where('product_id', $item['product_id'])->where('store_id', $find['store_id'])->find(); - if (empty($find)) { - $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); - } + $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); + $item['store_name'] = $find['store_name']; $item['nums'] = floatval($item['nums']); $item['image'] = $find['image']; diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index b2ceaef7..54f53d86 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -22,17 +22,14 @@ class CommissionProductLogic extends BaseLogic */ function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0) { - $product = StoreBranchProduct::where('product_id', $find['product_id'])->where('store_id', $order['store_id'])->find(); - if (!$product) { - $product = StoreProduct::where('id', $find['product_id'])->find(); - } + $product = StoreProduct::where('id', $find['product_id'])->find(); if ($product) { if ($product['product_type'] == 4) { $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product); return true; } else { if ($user_ship == 5) { - $top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); + $top_cate_id = $product['top_cate_id']; if ($top_cate_id == 15189) { $this->b($find, $order, $product,$user_ship); return true; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 1bdacd40..efa80f52 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -574,20 +574,42 @@ class PayNotifyLogic extends BaseLogic { StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); - foreach ($arr as $k => $v) { - $branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); - if($branchProduct){ - $stock=bcsub($branchProduct['stock'],$v['cart_num'],2); - StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2), - 'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]); - } - $storeProduct=StoreProduct::where('id', $v['product_id'])->find(); - if($storeProduct){ - $stock=bcsub($storeProduct['stock'],$v['cart_num'],2); - StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), - 'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]); + try{ + foreach ($arr as $k => $v) { + $branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); + if($branchProduct){ + $stock=bcsub($branchProduct['stock'],$v['cart_num'],2); + onBeforeUpdate($branchProduct->toArray(),'branch_product'); + + StoreBranchProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2), + 'sales'=>bcadd($branchProduct['sales'],$v['cart_num'],2)]); + + $branchProduct=$branchProduct->toArray(); + $branchProduct['stock']=$stock; + $branchProduct['total_price']=bcmul($stock,$branchProduct['purchase'],2); + $branchProduct['sales']=bcadd($branchProduct['sales'],$v['cart_num'],2); + onAfterUpdate($branchProduct,'branch_product'); + } + $storeProduct=StoreProduct::where('id', $v['product_id'])->find(); + if($storeProduct){ + $stock=bcsub($storeProduct['stock'],$v['cart_num'],2); + onBeforeUpdate($storeProduct->toArray(),'product'); + + StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), + 'sales'=>bcadd($storeProduct['sales'],$v['cart_num'],2)]); + + $storeProduct=$storeProduct->toArray(); + $storeProduct['stock']=$stock; + $storeProduct['total_price']=bcmul($stock,$storeProduct['purchase'],2); + $storeProduct['sales']=bcadd($storeProduct['sales'],$v['cart_num'],2); + onAfterUpdate($storeProduct,'product'); + } } + }catch (\Throwable $e) { + Log::error('订单库存更新失败:' . $e->getMessage()); + // 异常处理代码,例如记录日志或发送通知等。 } + $financeLogic = new StoreFinanceFlowLogic(); $off_activity = Config::where('name', 'off_activity')->value('value'); $village_uid = 0; diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index 124eb223..c74b0bcd 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -36,10 +36,8 @@ class StoreBranchProduct extends BaseModel } - public function store() { return $this->hasOne(StoreProduct::class,'id','product_id'); } - } \ No newline at end of file diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index dc810fdd..7f8b6fbb 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -6,6 +6,7 @@ namespace app\common\model\store_product; use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_unit\StoreProductUnit; +use support\Log; use think\model\concern\SoftDelete; @@ -31,8 +32,5 @@ class StoreProduct extends BaseModel { return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); - } - - } \ No newline at end of file diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 074aa2d0..b8c71cf6 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -4,6 +4,7 @@ namespace app\common\model\warehouse_product_storege; use app\common\model\BaseModel; +use support\Log; use think\model\concern\SoftDelete; @@ -18,5 +19,12 @@ class WarehouseProductStorege extends BaseModel protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; - + public function onBeforeUpdate($product){ + $log = Log::channel('product_storege'); + $log->info('更新前:'.json_encode($product)); + } + public function onAfterUpdate($product){ + $log = Log::channel('product_storege'); + $log->info('更新后:'.json_encode($product)); + } } \ No newline at end of file diff --git a/app/functions.php b/app/functions.php index e2b12800..7087f197 100644 --- a/app/functions.php +++ b/app/functions.php @@ -5,7 +5,7 @@ */ use app\common\service\FileService; - +use support\Log; if (!function_exists('substr_symbol_behind')) { /** @@ -500,3 +500,20 @@ if (!function_exists('convertNumber')) { } } } + +/** + * 日志记录 + * @param product + * @param branch_product + * @param product_storege + */ +function onBeforeUpdate($data, $type) +{ + $log = Log::channel($type); + $log->info('更新前:',$data); +} +function onAfterUpdate($data, $type) +{ + $log = Log::channel($type); + $log->info('更新后:' ,$data); +} diff --git a/app/store/controller/cart/CartController.php b/app/store/controller/cart/CartController.php index 29d3cf93..3674f732 100644 --- a/app/store/controller/cart/CartController.php +++ b/app/store/controller/cart/CartController.php @@ -7,6 +7,7 @@ use app\api\validate\CartValidate; use app\common\model\store_branch_product\StoreBranchProduct; use app\store\lists\cart\CartList; use app\common\model\order\Cart; +use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\store\controller\BaseAdminController; @@ -30,10 +31,9 @@ class CartController extends BaseAdminController $params['store_id'] = $adminInfo['store_id']; $result = Cart::where(['uid' => 0, 'staff_id' => $adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find(); //判断起批发价 - $branchProduct = StoreBranchProduct::where( + $branchProduct = StoreProduct::where( [ - 'product_id' => $params['product_id'], - 'store_id' => $adminInfo['store_id'] + 'id' => $params['product_id'], ] )->find(); if ($params['cart_num'] < $branchProduct['batch']) { @@ -76,6 +76,18 @@ class CartController extends BaseAdminController { $params = (new CartValidate())->post()->goCheck('StoreChange'); $adminInfo = $this->adminInfo; + $params['cart_num']=bcadd($params['cart_num'],0,2); + if (convertNumber($params['cart_num']) === false) { + $branchProduct = StoreProduct::where( + [ + 'id' => $params['product_id'], + ] + )->find(); + $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); + if ($is_bulk == 0) { + return $this->fail('非计量商品,不能有小数,请编辑购物车'); + } + } $params['uid'] = 0; $params['staff_id'] = $adminInfo['admin_id']; $params['store_id'] = $adminInfo['store_id']; diff --git a/app/store/lists/cart/CartList.php b/app/store/lists/cart/CartList.php index 27ca4ecf..bfa55e9d 100644 --- a/app/store/lists/cart/CartList.php +++ b/app/store/lists/cart/CartList.php @@ -12,6 +12,7 @@ use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; use app\common\lists\ListsExtendInterface; +use app\common\model\store_product\StoreProduct; /** * 购物车列表 @@ -70,8 +71,8 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists } } foreach ($list as $key => &$item) { - $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) - ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id') + $find = StoreProduct::where(['id' => $item['product_id']]) + ->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id') ->find(); if ($find) { if ($off_activity == 1) { diff --git a/config/log.php b/config/log.php index ee8448c4..7db7057d 100644 --- a/config/log.php +++ b/config/log.php @@ -1,4 +1,5 @@ [ 'class' => Monolog\Formatter\LineFormatter::class, - 'constructor' => [null, 'Y-m-d H:i:s', true,true], + 'constructor' => [null, 'Y-m-d H:i:s', true, true], + ], + ] + ], + ], + // log2通道 + 'product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/product/'.date('Ym').'/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'branch_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/branch_product/'.date('Ym').'/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'product_storege' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/product_storege/'.date('Ym').'/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], ], ] ],