From 1648d48c15459f8aee10714ea46e9488de93b80c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 12 Sep 2024 17:25:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=95=86=E5=93=81=E3=80=81=E7=BC=96=E8=BE=91=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=92=8C=E5=88=A0=E9=99=A4=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoController.php | 30 ++++ .../StoreOrderCartInfoLists.php | 2 +- .../StoreOrderCartInfoLogic.php | 146 ++++++++++++++++-- app/common/logic/PayNotifyLogic.php | 17 +- 4 files changed, 180 insertions(+), 15 deletions(-) diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index a6aabe21..955f37fa 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -54,7 +54,37 @@ class StoreOrderCartInfoController extends BaseAdminController $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); return $this->data($res); } + /** + * @notes 追加订单商品 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function add() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::add($params); + return $this->success('添加成功', [], 1, 1); + } + /** + * @notes 编辑订单商品 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function edit() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::edit($params); + return $this->success('编辑成功', [], 1, 1); + } + public function del() + { + $params = $this->request->post(); + $result = StoreOrderCartInfoLogic::del($params); + return $this->success('删除成功', [], 1, 1); + } /** * 导出配送表格 */ diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index 859a8987..2c712c04 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -51,7 +51,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) + ->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); if($find){ diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php index 84c9a84f..02bb8269 100644 --- a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -4,7 +4,12 @@ namespace app\admin\logic\store_order_cart_info; use app\admin\logic\statistic\TradeStatisticLogic; use app\common\logic\BaseLogic; +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 support\exception\BusinessException; +use think\facade\Db; /** * 订单购物详情表逻辑 @@ -13,6 +18,129 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; */ class StoreOrderCartInfoLogic extends BaseLogic { + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + $cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find(); + if($cart_info['is_pay']==1){ + throw new BusinessException('已支付订单无法追加'); + } + foreach($params['product_arr'] as $k=>$v){ + $find=StoreProduct::where('id',$v['product_id'])->find(); + + $cart_select['total_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单总价 + + $cart_select['price'] = $v['price']; + $cart_select['cost'] = $v['price']; + $cart_select['vip'] = 0; + $cart_select['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称 + + $cart_select['purchase'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //成本 + $cart_select['pay_price'] = bcmul($v['cart_num'], $v['price'], 2); //订单支付金额 + $cart_select['store_price'] = bcmul($v['cart_num'], $v['price'], 2) ?? 0; //商户价 + $cart_select['vip_price'] = 0; //vip售价 + + $cart_select['product_id'] = $find['id']; + $cart_select['old_cart_id'] = 0; + $cart_select['cart_num'] = $v['cart_num']; + $cart_select['verify_code'] =$cart_info['verify_code']; + $cart_select['vip_frozen_price'] = 0; + $cart_select['store_info'] = $find['store_info']; + $cart_select['rose'] = $find['rose']; + + $cart_select['name'] = $find['store_name']; + $cart_select['image'] = $find['image']; + $aa[$k]['cart_info'] = json_encode($cart_select); + $aa[$k]['oid'] = $cart_info['oid']; + $aa[$k]['uid']=$cart_info['uid']; + $aa[$k]['product_id']=$find['id']; + $aa[$k]['verify_code']=$cart_info['verify_code']; + $aa[$k]['price']=$v['price']; + $aa[$k]['cart_num']=$v['cart_num']; + $aa[$k]['total_price']=$cart_select['pay_price']; + } + (new StoreOrderCartInfo())->saveAll($aa); + $total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count(); + + StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + d($e); + throw new BusinessException('编辑商品失败' . $e->getMessage()); + } + } + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $find = StoreOrderCartInfo::where('id', $params['id'])->find(); + if ($find) { + if($find['is_pay']==1){ + throw new BusinessException('已支付订单无法编辑'); + } + $find->cart_num = $params['cart_num']; + $find->total_price = bcmul($params['cart_num'], $find->price, 2); + $find->save(); + $total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count(); + StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException('编辑商品失败' . $e->getMessage()); + } + } + + /** + * @notes 删除商品 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function del(array $params): bool + { + Db::startTrans(); + try { + $find = StoreOrderCartInfo::where('id', $params['id'])->find(); + if ($find) { + if($find['is_pay']==1){ + throw new BusinessException('已支付订单无法删除'); + } + $find->delete_time=time(); + $find->save(); + $total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price'); + $total_count = StoreOrderCartInfo::where('oid', $find['oid'])->count(); + StoreOrder::where('id', $find['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException('删除商品失败' . $e->getMessage()); + } + } public function curve($product_id, $start_time, $end_time) { $store_order_cart_info = new StoreOrderCartInfo(); @@ -29,13 +157,13 @@ class StoreOrderCartInfoLogic extends BaseLogic $totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)'); $totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey); - $value1=[]; - $value2=[]; - foreach($totalCartNum1['y'] as $k=>$v){ - $value1[]=$v; + $value1 = []; + $value2 = []; + foreach ($totalCartNum1['y'] as $k => $v) { + $value1[] = $v; } - foreach($totalCartNum2['y'] as $k=>$v){ - $value2[]=$v; + foreach ($totalCartNum2['y'] as $k => $v) { + $value2[] = $v; } $data = []; $data['xAxis'] = $totalCartNum1['x'] ?? []; @@ -45,9 +173,9 @@ class StoreOrderCartInfoLogic extends BaseLogic 'smooth' => 'true', 'type' => 'line', 'yAxisIndex' => 1, - 'value' =>$value1 - ] - ,[ + 'value' => $value1 + ], + [ 'name' => '金额', 'smooth' => 'true', 'type' => 'line', diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index f90a6dbd..0092c941 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -2,6 +2,7 @@ namespace app\common\logic; +use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\user_ship\UserShipLogic; use app\api\logic\order\OrderLogic; use app\common\enum\OrderEnum; @@ -54,7 +55,6 @@ class PayNotifyLogic extends BaseLogic Db::rollback(); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); throw new BusinessException($e->getMessage()); - } } @@ -599,22 +599,29 @@ class PayNotifyLogic extends BaseLogic try { foreach ($arr as $k => $v) { $branchProduct = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $v['store_id'])->find(); + $storeProduct = StoreProduct::where('id', $v['product_id'])->find(); + if ($branchProduct) { $stock = bcsub($branchProduct['stock'], $v['cart_num'], 2); StoreBranchProduct::update([ 'stock' => $stock, 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2) - ],['id'=>$branchProduct['id']]); + ], ['id' => $branchProduct['id']]); + } else { + StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct); + StoreBranchProduct::update([ + 'stock' => -$v['cart_num'], + 'sales' => $v['cart_num'] + ], ['product_id' => $v['product_id'],'store_id'=>$v['store_id']]); } - $storeProduct = StoreProduct::where('id', $v['product_id'])->find(); if ($storeProduct) { $stock = bcsub($storeProduct['stock'], $v['cart_num'], 2); StoreProduct::update([ 'stock' => $stock, 'total_price' => bcmul($stock, $storeProduct['purchase'], 2), 'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2) - ],['id'=>$v['product_id']]); + ], ['id' => $v['product_id']]); } } } catch (\Throwable $e) { @@ -657,7 +664,7 @@ class PayNotifyLogic extends BaseLogic return false; } - if($order['uid']>0){ + if ($order['uid'] > 0) { $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); if ($address) { $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');