From df9ed597fc7e21a6d0c2f0c07b7739deafa26e75 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 26 Aug 2024 23:05:01 +0800 Subject: [PATCH 01/72] =?UTF-8?q?feat(commission):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=95=86=E5=93=81=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=92=8C=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CommissionProductLogic.php | 151 ++++++++++++++++---- app/common/logic/PayNotifyLogic.php | 14 ++ 2 files changed, 139 insertions(+), 26 deletions(-) diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 71dcbd310..b2ceaef7a 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -8,6 +8,7 @@ use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use PDO; +use support\Log; /** * 产品佣金计算 @@ -21,20 +22,30 @@ 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('id', $find['product_id'])->where('store_id', $order['store_id'])->find(); + $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(); } if ($product) { - if ($user_ship == 5) { - $top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); - if ($top_cate_id == 15189) { - $this->b($find, $order, $product); - return true; - } + if ($product['product_type'] == 4) { + $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + return true; } else { - $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + if ($user_ship == 5) { + $top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); + if ($top_cate_id == 15189) { + $this->b($find, $order, $product,$user_ship); + return true; + } + } elseif($user_ship==0) { + $this->b($find, $order, $product,$user_ship); + return true; + }else{ + $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); + + } } + return true; } } @@ -45,7 +56,11 @@ class CommissionProductLogic extends BaseLogic public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['price'], $find['cart_num']); + if($user_ship==4){ + $total_price = bcmul($product['cost'], $find['cart_num']); + }else{ + $total_price = bcmul($product['price'], $find['cart_num']); + } // $Distribution = Distribution::where('rate', $rose)->find(); //门店 $data[] = [ @@ -88,11 +103,11 @@ class CommissionProductLogic extends BaseLogic 'status' => 1, ]; //会员 - if ($user_ship == 1) { - $uid = $order['spread_uid']; - } else { - $uid = 0; - } + // if ($user_ship == 1) { + // $uid = $order['spread_uid']; + // } else { + // $uid = 0; + // } // $data[] = [ // 'store_id' => $order['store_id'], // 'product_id' => $find['product_id'], @@ -103,17 +118,29 @@ class CommissionProductLogic extends BaseLogic // 'status' => 1, // ]; - //个人店铺 + //会员 if ($order['spread_uid'] > 0) { - $data[] = [ - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $order['spread_uid'], - 'number' => bcmul($total_price, 0.07, 2), - 'oid' => $order['id'], - 'type' => 5, - 'status' => 1, - ]; + if (in_array($user_ship, [2, 3])) { + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $order['spread_uid'], + 'number' => bcmul($total_price, 0.05, 2), + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + } else { + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $order['spread_uid'], + 'number' => bcmul($total_price, 0.07, 2), + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + } } $data[] = [ 'store_id' => $order['store_id'], @@ -130,10 +157,10 @@ class CommissionProductLogic extends BaseLogic /** * 商户价结算 */ - public function b($find, $order, $product) + public function b($find, $order, $product,$user_ship) { // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['cost'], $find['cart_num']); //门店 $data[] = [ 'store_id' => $order['store_id'], @@ -154,6 +181,78 @@ class CommissionProductLogic extends BaseLogic 'type' => 2, 'status' => 1, ]; + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'number' => bcmul($total_price, 0.01, 2), + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + ]; + (new StoreFinanceFlowProduct())->saveAll($data); + } + + //活动商品结算 + public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product) + { + // $rose = bcdiv($product['rose'], 100, 2); + $total_price = bcmul($product['price'], $find['cart_num']); + $purchase_price = bcmul($product['purchase'], $find['cart_num']); + + $brigade_number = bcmul($total_price, 0.02, 2); + $village_number = bcmul($brigade_number, 0.1, 2); + $platform_number = bcmul($total_price, 0.02, 2); + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + //门店利润 + $store_number = bcsub($number3, $number2, 2); + + //队长 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $brigade_uid, + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + ]; + //村长 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $village_uid, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + ]; + //门店 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + ]; + //平台 + $data[] = [ + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + ]; (new StoreFinanceFlowProduct())->saveAll($data); } } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 45122cc5c..9aac367fd 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -675,6 +675,13 @@ class PayNotifyLogic extends BaseLogic } } } + $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); + $comm = new CommissionProductLogic(); + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); + } + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + return true; if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { try { $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); @@ -709,6 +716,13 @@ class PayNotifyLogic extends BaseLogic break; } } else { + $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); + $comm = new CommissionProductLogic(); + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); + } + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + return true; if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { try { $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); From 63c90c8bbf77d3aa57d1eeb049185fcd7b470211 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 26 Aug 2024 23:09:35 +0800 Subject: [PATCH 02/72] =?UTF-8?q?feat(commission):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=86=E6=B6=A6=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 73 +++++++---------------------- 1 file changed, 17 insertions(+), 56 deletions(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 9aac367fd..1bdacd40c 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -677,67 +677,28 @@ class PayNotifyLogic extends BaseLogic } $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $comm = new CommissionProductLogic(); - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { - try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); - $comm = new CommissionProductLogic(); - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - } catch (\Exception $e) { - Log::error('活动分润报错' . $e->getMessage()); - return false; + try { + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } - } - switch ($user_ship) { - case 1: // 厨师 - //case 4: // 商户 - //case 5: // 种养殖 - // case 6: // 酒店 - // case 7: // 食堂 - case 8: // 一条龙 - CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id); - break; - case 2: // 村长 - CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id); - break; - case 3: // 队长 - CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id); - break; - default: - CommissionLogic::setStore($order, $transaction_id); - break; + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + } catch (\Throwable $e) { + Log::error('分润报错' . $e->getMessage()); + return false; } } else { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); - $comm = new CommissionProductLogic(); - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) { - try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); - $comm = new CommissionProductLogic(); - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - return true; - } catch (\Exception $e) { - Log::error('活动分润报错' . $e->getMessage()); - return false; + try { + $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); + $comm = new CommissionProductLogic(); + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + } catch (\Throwable $e) { + Log::error('分润报错' . $e->getMessage()); + return false; } - CommissionLogic::setStore($order, $transaction_id); + return true; } } From 42b19ff90037101beb61cd9b64c7ff8303c6a3a2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 27 Aug 2024 11:00:26 +0800 Subject: [PATCH 03/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=97=A8=E5=BA=97=E5=92=8C=E4=BB=93=E5=BA=93=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system_store/SystemStoreController.php | 29 ------------------- .../WarehouseOrderController.php | 1 - .../logic/store_product/StoreProductLogic.php | 19 +++++++----- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php index e327dc7ec..748652db1 100644 --- a/app/admin/controller/system_store/SystemStoreController.php +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -40,35 +40,6 @@ class SystemStoreController extends BaseAdminController { return $this->dataLists(new SystemStoreSourceLists()); } - /** - * @notes 根据商品源获取门店列表 - * @return \think\response\Json - * @author admin - * @date 2024/05/31 17:45 - */ - public function source_product_update_store() - { - $addList=$this->request->post('addList'); - $product_id=$this->request->post('product_id'); - if($addList){ - foreach ($addList as $key=>$value){ - StoreProductLogic::copy($product_id,$value); - if(StoreProductLogic::hasError()){ - return $this->fail(StoreProductLogic::getError()); - } - } - } - $removeList=$this->request->post('removeList'); - if($removeList){ - foreach ($removeList as $key=>$value){ - StoreProductLogic::store_del($product_id,$value); - if(StoreProductLogic::hasError()){ - return $this->fail(StoreProductLogic::getError()); - } - } - } - return $this->success('设置成功', [], 1, 1); - } /** * @notes 添加门店列表 diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 5c2876fb4..bb75e99da 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -125,7 +125,6 @@ class WarehouseOrderController extends BaseAdminController Db::commit(); } catch (\Throwable $e) { Db::rollback(); - d($e); throw new BusinessException($e->getMessage()); } return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 55614093c..83f64333f 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -14,6 +14,7 @@ use app\common\model\store_product_cate\StoreProductCate; use app\common\model\system_store\SystemStore; use app\common\model\system_store_storage\SystemStoreStorage; use Illuminate\Support\Facades\Log; +use support\exception\BusinessException; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -101,8 +102,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('添加商品失败'.$e->getMessage()); } } @@ -220,8 +220,8 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('编辑商品失败'.$e->getMessage()); + } } @@ -280,8 +280,8 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('删除失败'.$e->getMessage()); + } } @@ -289,6 +289,10 @@ class StoreProductLogic extends BaseLogic /**普通 */ public static function ordinary($product_arr, $store_id, $admin_id, $find) { + $res=StoreBranchProduct::where('store_id',$store_id)->where('product_id',$find['id'])->find(); + if($res){ + return $res; + } $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], @@ -357,8 +361,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; + throw new BusinessException('添加兑换商品失败'.$e->getMessage()); } } // else { From 40ec3e5ee050dc53bc43f0149fa04e4579dff5cb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 27 Aug 2024 11:56:48 +0800 Subject: [PATCH 04/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=9B=B8=E5=85=B3=E7=9A=84API=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E6=94=AF=E4=BB=98=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=9B=20fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=9C=B0=E5=9D=80=E3=80=81=E5=95=86=E5=93=81=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=AD=89=E9=94=99=E8=AF=AF=EF=BC=9B=20refactor:=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BA=86=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E9=AB=98=E4=BA=86=E4=BB=A3=E7=A0=81=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=80=A7=EF=BC=9B=20style:=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BA=86=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E5=85=B6=E6=9B=B4=E5=8A=A0=E8=A7=84=E8=8C=83=EF=BC=9B=20test:?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=AE=A2=E5=8D=95=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=9B?= =?UTF-8?q?=20docs:=20=E6=9B=B4=E6=96=B0=E4=BA=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=87=E6=A1=A3=EF=BC=9B=20build:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BA=86=E4=BE=9D=E8=B5=96=EF=BC=9B=20ops:=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=80=A7=E8=83=BD?= =?UTF-8?q?=EF=BC=9B=20chore:=20=E6=9B=B4=E6=96=B0=E4=BA=86.gitignore?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductController.php | 12 +-- .../store_product/StoreProductController.php | 11 +-- .../WarehouseOrderController.php | 5 -- .../WarehouseProductController.php | 15 +--- .../StoreBranchProductLogic.php | 11 +-- .../logic/store_product/StoreProductLogic.php | 2 +- app/admin/logic/user/UserLogic.php | 24 ++--- app/admin/logic/user_ship/UserShipLogic.php | 13 ++- .../warehouse_order/WarehouseOrderLogic.php | 12 ++- .../WarehouseProductLogic.php | 5 +- app/api/controller/LoginController.php | 12 --- app/api/controller/order/CartController.php | 4 +- app/api/controller/order/OrderController.php | 36 +------- app/api/controller/store/StoreController.php | 15 ---- app/api/controller/user/AddressController.php | 10 +-- app/api/controller/user/UserController.php | 7 +- .../user/UserFeedbackController.php | 2 +- .../controller/user/UserVisitController.php | 3 - .../UserProductStorageController.php | 3 - .../user_ship/UserShipController.php | 7 +- app/api/logic/LoginLogic.php | 24 +++-- app/api/logic/order/CartLogic.php | 14 ++- app/api/logic/order/OrderLogic.php | 64 +++++-------- app/api/logic/user/AddressLogic.php | 11 ++- app/api/logic/user/UserFeedbackLogic.php | 9 +- app/api/logic/user/UserLogic.php | 10 +-- app/api/logic/user/UserVisitLogic.php | 13 ++- app/common/logic/PaymentLogic.php | 89 +++++++++---------- .../UserProductStorageLogic.php | 14 ++- 29 files changed, 156 insertions(+), 301 deletions(-) diff --git a/app/admin/controller/store_branch_product/StoreBranchProductController.php b/app/admin/controller/store_branch_product/StoreBranchProductController.php index 2d3b59dd5..efd9f862e 100644 --- a/app/admin/controller/store_branch_product/StoreBranchProductController.php +++ b/app/admin/controller/store_branch_product/StoreBranchProductController.php @@ -46,18 +46,13 @@ class StoreBranchProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('add'); $result = StoreProductLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(StoreProductLogic::getError()); + return $this->success('添加成功', [], 1, 1); + } public function update() { $params = $this->request->post(); StoreBranchProductLogic::edit($params); - if (StoreBranchProductLogic::hasError()) { - return $this->fail(StoreBranchProductLogic::getError()); - } return $this->success('更新成功', [], 1, 1); } @@ -110,9 +105,6 @@ class StoreBranchProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('delete'); StoreBranchProductLogic::delete($params); - if(StoreBranchProductLogic::hasError()){ - return $this->fail(StoreBranchProductLogic::getError()); - } return $this->success('删除成功', [], 1, 1); } diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index f39f949c7..50cc68465 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -44,10 +44,7 @@ class StoreProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('add'); $result = StoreProductLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(StoreProductLogic::getError()); + return $this->success('添加成功', [], 1, 1); } @@ -61,10 +58,8 @@ class StoreProductController extends BaseAdminController { $params = (new StoreProductValidate())->post()->goCheck('edit'); $result = StoreProductLogic::edit($params); - if (true === $result) { - return $this->success('编辑成功', [], 1, 1); - } - return $this->fail(StoreProductLogic::getError()); + return $this->success('编辑成功', [], 1, 1); + } diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index bb75e99da..a4dabf8e8 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -58,7 +58,6 @@ class WarehouseOrderController extends BaseAdminController if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(WarehouseOrderLogic::getError()); } /** * @notes 添加出库单 @@ -145,7 +144,6 @@ class WarehouseOrderController extends BaseAdminController if (true === $result) { return $this->success('编辑成功', [], 1, 1); } - return $this->fail(WarehouseOrderLogic::getError()); } /** @@ -173,9 +171,6 @@ class WarehouseOrderController extends BaseAdminController { $params = (new WarehouseOrderValidate())->post()->goCheck('delete'); WarehouseOrderLogic::delete($params); - if(WarehouseOrderLogic::hasError()){ - return $this->fail(WarehouseOrderLogic::getError()); - } return $this->success('删除成功', [], 1, 1); } diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index e723cf2a9..35f2971d9 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -61,12 +61,8 @@ class WarehouseProductController extends BaseAdminController } WarehouseProductLogic::add($data); } - - if (WarehouseProductLogic::hasError()) { - return $this->fail(WarehouseProductLogic::getError()); - } else { - return $this->success('添加成功', [], 1, 1); - } + return $this->success('添加成功', [], 1, 1); + } @@ -95,11 +91,8 @@ class WarehouseProductController extends BaseAdminController { $params = (new WarehouseProductValidate())->post()->goCheck('delete'); WarehouseProductLogic::delete($params); - if (WarehouseProductLogic::hasError()) { - return $this->fail(WarehouseProductLogic::getError()); - } else { - return $this->success('删除成功', [], 1, 1); - } + return $this->success('删除成功', [], 1, 1); + } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index 47fb6eda8..f76a43d5f 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -52,8 +52,7 @@ class StoreBranchProductLogic extends BaseLogic { $StoreProduct = StoreBranchProduct::where('id', $params['id'])->find(); if ($params['status'] == 1 && $StoreProduct['price'] == 0) { - self::setError('商品价格不能为0,无法上架'); - return false; + throw new BusinessException('商品价格不能为0,无法上架'); } Db::startTrans(); try { @@ -67,10 +66,9 @@ class StoreBranchProductLogic extends BaseLogic StoreBranchProduct::where('id', $params['id'])->update($data); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException('商品编辑失败:',$e->getMessage()); } } /** @@ -116,8 +114,7 @@ class StoreBranchProductLogic extends BaseLogic { $stock = StoreBranchProduct::where('id', $params['id'])->value('stock'); if ($stock > 0) { - self::setError('商品库存不为0,无法删除'); - return false; + throw new BusinessException('商品库存不为0,无法删除'); } StoreBranchProduct::destroy($params['id']); return true; diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 83f64333f..875b9cc96 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -218,7 +218,7 @@ class StoreProductLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException('编辑商品失败'.$e->getMessage()); diff --git a/app/admin/logic/user/UserLogic.php b/app/admin/logic/user/UserLogic.php index 309d4ddc1..f28c21255 100644 --- a/app/admin/logic/user/UserLogic.php +++ b/app/admin/logic/user/UserLogic.php @@ -31,6 +31,7 @@ use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use think\facade\Db; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; /** @@ -69,10 +70,9 @@ class UserLogic extends BaseLogic Db::commit(); return $res; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -81,23 +81,19 @@ class UserLogic extends BaseLogic $user_ship=$params['user_ship']??0; if($user_ship==2){ if(!isset($params['village'])){ - self::setError('请设置村参数'); - return false; + throw new BusinessException('请设置村参数'); } $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'])->find(); if ($arr) { - self::setError('该区域已有村长请重新选择'); - return false; + throw new BusinessException('该区域已有村长请重新选择'); } }elseif($user_ship==3){ if(!isset($params['brigade'])){ - self::setError('请设置队参数'); - return false; + throw new BusinessException('请设置队参数'); } $arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'] .' and brigade='.$params['brigade'])->find(); if($arr){ - self::setError('该区域已有队长请重新选择'); - return false; + throw new BusinessException('该区域已有队长请重新选择'); } } return true; @@ -148,8 +144,7 @@ class UserLogic extends BaseLogic return $res; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } /** @@ -179,8 +174,7 @@ class UserLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user_ship/UserShipLogic.php b/app/admin/logic/user_ship/UserShipLogic.php index cf804069d..6075c5cb8 100644 --- a/app/admin/logic/user_ship/UserShipLogic.php +++ b/app/admin/logic/user_ship/UserShipLogic.php @@ -7,6 +7,7 @@ use app\common\model\user_ship\UserShip; use app\common\logic\BaseLogic; use app\common\model\user\User; use app\common\model\user\UserAddress; +use support\exception\BusinessException; use think\facade\Db; @@ -106,8 +107,7 @@ class UserShipLogic extends BaseLogic $user_ship=$params['user_ship']??0; if($user_ship==2){ if(!isset($params['village'])){ - self::setError('请设置村参数'); - return false; + throw new BusinessException('请设置村参数'); } $arr=User::where('user_ship',$user_ship)->column('id'); if($arr){ @@ -116,14 +116,12 @@ class UserShipLogic extends BaseLogic if($params['uid']==$find['uid']){ return true; } - self::setError('该区域已有村长请重新选择'); - return false; + throw new BusinessException('该区域已有村长请重新选择'); } } }elseif($user_ship==3){ if(!isset($params['brigade'])){ - self::setError('请设置队参数'); - return false; + throw new BusinessException('请设置队参数'); } $arr=User::where('user_ship',$user_ship)->column('id'); if($arr){ @@ -132,8 +130,7 @@ class UserShipLogic extends BaseLogic if($params['uid']==$find['uid']){ return true; } - self::setError('该区域已有队长请重新选择'); - return false; + throw new BusinessException('该区域已有队长请重新选择'); } } } diff --git a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php index 65539f214..441d57aab 100644 --- a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php +++ b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php @@ -6,6 +6,7 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\warehouse_order\WarehouseOrder; use app\common\logic\BaseLogic; use app\common\model\warehouse_product\WarehouseProduct; +use support\exception\BusinessException; use think\facade\Db; /** @@ -69,10 +70,9 @@ class WarehouseOrderLogic extends BaseLogic } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -128,8 +128,7 @@ class WarehouseOrderLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -145,8 +144,7 @@ class WarehouseOrderLogic extends BaseLogic { $count = WarehouseProduct::where('oid', $params['id'])->count(); if ($count >= 1) { - self::setError('该订单下还有商品没有删除,请先删除商品'); - return false; + throw new BusinessException('该订单下还有商品没有删除,请先删除商品'); } WarehouseOrder::destroy($params['id']); $find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index dc84e99bc..8dc2575af 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -208,8 +208,7 @@ class WarehouseProductLogic extends BaseLogic } elseif ($res['financial_pm'] == 0) { $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); if ($stock < $res['nums']) { - self::setError('商品库存不足,无法退回'); - return false; + throw new BusinessException('商品库存不足,无法退回'); } StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update(); @@ -223,7 +222,7 @@ class WarehouseProductLogic extends BaseLogic } return true; } - return false; + throw new BusinessException('没有查到出入库信息'); } /** diff --git a/app/api/controller/LoginController.php b/app/api/controller/LoginController.php index a2e35b993..ece536175 100644 --- a/app/api/controller/LoginController.php +++ b/app/api/controller/LoginController.php @@ -19,9 +19,6 @@ class LoginController extends BaseApiController { $params = (new LoginAccountValidate())->post()->goCheck(); $result = LoginLogic::login($params); - if (false === $result) { - return $this->fail(LoginLogic::getError()); - } return $this->success('', $result); } /** @@ -44,9 +41,6 @@ class LoginController extends BaseApiController { $params = (new WechatLoginValidate())->post()->goCheck('mnpLogin'); $res = LoginLogic::mnpLogin($params); - if (false === $res) { - return $this->fail(LoginLogic::getError()); - } $res = LoginLogic::dealStaff($res); return $this->success('', $res); } @@ -63,9 +57,6 @@ class LoginController extends BaseApiController $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth"); $params['user_id'] = $this->userId; $result = LoginLogic::mnpAuthLogin($params); - if ($result === false) { - return $this->fail(LoginLogic::getError()); - } return $this->success('绑定成功', [], 1, 1); } @@ -79,9 +70,6 @@ class LoginController extends BaseApiController { $params = $this->request->post(); $result = LoginLogic::updateUser($params, $this->userId); - if ($result === false) { - return $this->fail(LoginLogic::getError()); - } return $this->success('操作成功', [], 1, 0); } diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index c5f070326..03fea3e5b 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -90,7 +90,7 @@ class CartController extends BaseApiController if ($res) { return $this->success('修改成功'); } else { - return $this->fail(CartLogic::getError()); + return $this->fail('修改失败'); } } @@ -105,7 +105,7 @@ class CartController extends BaseApiController if ($res) { return $this->success('删除成功'); } else { - return $this->fail(CartLogic::getError()); + return $this->fail('删除失败'); } } } diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 76b788483..b50eaa188 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -105,13 +105,6 @@ class OrderController extends BaseApiController $params = $this->request->post(); $user = User::where('id', $this->userId)->find(); $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params); - if ($res == false) { - $msg = OrderLogic::getError(); - if ($msg == '购物车为空') { - return $this->data([]); - } - return $this->fail(OrderLogic::getError()); - } return $this->data($res); } @@ -119,13 +112,6 @@ class OrderController extends BaseApiController { $params = (new OrderValidate())->post()->goCheck('cart'); $res = OrderLogic::checkLeft($params, $this->userId); - if (!$res) { - $msg = OrderLogic::getError(); - if ($msg == '购物车为空') { - return $this->data([]); - } - return $this->fail(OrderLogic::getError()); - } return $this->data($res); } @@ -230,8 +216,6 @@ class OrderController extends BaseApiController return $this->fail('支付方式错误'); } // return $this->data(['order_id' => $order->id]); - } else { - return $this->fail(OrderLogic::getError()); } } @@ -306,17 +290,11 @@ class OrderController extends BaseApiController } } $result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'] ?? 1, $redirectUrl); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } return $this->success('', $result); break; case PayEnum::WECHAT_PAY_BARCODE: //微信条码支付 $result = PaymentLogic::codepay($auth_code, $order); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); } else { @@ -336,9 +314,6 @@ class OrderController extends BaseApiController case PayEnum::ALIPAY_BARCODE: //支付宝条码支付 $result = PaymentLogic::ali_auth_code($auth_code, $order); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } if ($result['msg'] !== 'Success') { return $this->success('用户支付中'); } @@ -388,11 +363,8 @@ class OrderController extends BaseApiController { $params = $this->request->get(); $res = OrderLogic::frequentlyPurchase($params); - if (OrderLogic::hasError()) { - return $this->fail(OrderLogic::getError()); - } else { - return $this->data($res); - } + return $this->data($res); + } /** @@ -466,7 +438,7 @@ class OrderController extends BaseApiController if ($res) { return $this->success('核销成功'); } - return $this->fail('核销失败' . OrderLogic::getError()); + return $this->fail('核销失败'); } @@ -476,7 +448,7 @@ class OrderController extends BaseApiController $date = $this->request->get('date', date('Y-m-d')); $store_id = SystemStoreStaff::where('phone', $this->userInfo['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺'); + return $this->fail('该用户未绑定店铺'); } $where[] = ['store_id', '=', $store_id]; $where[] = ['paid', '=', 1]; diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index e6335462b..cbf9528f2 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -89,20 +89,11 @@ class StoreController extends BaseApiController $params['create_uid']=$this->userId; if(isset($params['user_ship']) && in_array($params['user_ship'],[2,3])){ UserUserLogic::checkAddress($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } } $find=UserUserLogic::StoreAdd($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } }else{ if($find['user_ship']!=$params['user_ship'] && in_array($params['user_ship'],[2,3])){ UserUserLogic::checkAddress($params); - if(UserUserLogic::hasError()){ - return $this->fail(UserUserLogic::getError()); - } } $find['real_name']=$params['real_name']; $find['label_id']=$params['label_id']??0; @@ -144,9 +135,6 @@ class StoreController extends BaseApiController $order['pay_price']=$order['price']; $order['attach']='recharge'; $result = PaymentLogic::codepay($auth_code, $order,'条码支付'); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { Cache::set('trade_state' . time(), json_encode($result)); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); @@ -181,9 +169,6 @@ class StoreController extends BaseApiController $order['pay_price']=$order['price']; $order['attach']='recharge'; $result = PaymentLogic::codepay($auth_code, $order,'条码支付'); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError()); - } if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); } else { diff --git a/app/api/controller/user/AddressController.php b/app/api/controller/user/AddressController.php index 781f6f9e3..c19c26115 100644 --- a/app/api/controller/user/AddressController.php +++ b/app/api/controller/user/AddressController.php @@ -23,11 +23,8 @@ class AddressController extends BaseApiController $params = (new UserAddressValidate())->post()->goCheck('add'); $params['uid'] = $this->request->userId; $res=AddressLogic::add($params); - if(AddressLogic::hasError()){ - return $this->fail(AddressLogic::getError()); - }else{ - return $this->success('添加成功'); - } + return $this->success('添加成功'); + } /** * 商户给用户添加地址 @@ -62,9 +59,8 @@ class AddressController extends BaseApiController $params['uid'] = $this->request->userId; if(AddressLogic::edit($params)){ return $this->success('编辑成功'); - }else{ - return $this->fail(AddressLogic::getError()); } + return $this->fail('编辑失败'); } diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index d4ea0558e..82ee81392 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -42,9 +42,7 @@ class UserController extends BaseApiController $params = (new UserValidate())->post()->goCheck('getMobileByMnp'); $params['user_id'] = $this->userId; $result = UserLogic::getMobileByMnp($params); - if ($result === false) { - return $this->fail(UserLogic::getError()); - } + if ($result && is_numeric($result)) { $data = UserLogic::info($result); $userInfo = UserTokenService::setToken($result, 1); @@ -104,9 +102,6 @@ class UserController extends BaseApiController $order = UserLogic::recharge($params); $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl); - if (PaymentLogic::hasError()) { - return $this->fail(PaymentLogic::getError(), $params); - } return $this->success('', $result); } diff --git a/app/api/controller/user/UserFeedbackController.php b/app/api/controller/user/UserFeedbackController.php index 46cedd303..1a680551b 100644 --- a/app/api/controller/user/UserFeedbackController.php +++ b/app/api/controller/user/UserFeedbackController.php @@ -30,6 +30,6 @@ if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(UserFeedbackLogic::getError()); + return $this->fail('添加失败'); } } diff --git a/app/api/controller/user/UserVisitController.php b/app/api/controller/user/UserVisitController.php index d777c094a..362f51455 100644 --- a/app/api/controller/user/UserVisitController.php +++ b/app/api/controller/user/UserVisitController.php @@ -30,8 +30,6 @@ class UserVisitController extends BaseApiController if (true === $result) { return $this->success('ok'); } - return $this->fail(UserVisitLogic::getError()); - } @@ -54,7 +52,6 @@ class UserVisitController extends BaseApiController if (true === $result) { return $this->success('添加成功', [], 1, 1); } - return $this->fail(UserVisitLogic::getError()); } diff --git a/app/api/controller/user_product_storage/UserProductStorageController.php b/app/api/controller/user_product_storage/UserProductStorageController.php index 806a56204..eb73615b8 100644 --- a/app/api/controller/user_product_storage/UserProductStorageController.php +++ b/app/api/controller/user_product_storage/UserProductStorageController.php @@ -38,9 +38,6 @@ class UserProductStorageController extends BaseApiController $store_id=$params['store_id']; $times=$params['times']; UserProductStorageLogic::supply($info,$uid,$store_id,0,$times); - if(UserProductStorageLogic::hasError()){ - return $this->fail(UserProductStorageLogic::getError()); - } return $this->success('操作成功'); } } \ No newline at end of file diff --git a/app/api/controller/user_ship/UserShipController.php b/app/api/controller/user_ship/UserShipController.php index 3e6afa1b9..af297a228 100644 --- a/app/api/controller/user_ship/UserShipController.php +++ b/app/api/controller/user_ship/UserShipController.php @@ -31,10 +31,7 @@ class UserShipController extends BaseApiController public function is_user_ship(){ $data=$this->request->post(); UserShipLogic::user_ship($data); - if(UserShipLogic::hasError()){ - return $this->fail(UserShipLogic::getError()); - }else{ - return $this->success('ok'); - } + return $this->success('ok'); + } } \ No newline at end of file diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index fae9c37fe..e5dcd48df 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -27,7 +27,7 @@ use app\common\service\{ }; use app\common\model\user\{User, UserAuth}; use app\common\service\wechat\WeChatMnpService; - +use support\exception\BusinessException; use Webman\Config; /** @@ -88,7 +88,7 @@ class LoginLogic extends BaseLogic $user = User::where($where)->findOrEmpty(); if ($user->isEmpty()) { - throw new \Exception('用户不存在'); + throw new BusinessException('用户不存在'); } //更新登录信息 @@ -121,8 +121,7 @@ class LoginLogic extends BaseLogic 'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']), ]; } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -214,9 +213,8 @@ class LoginLogic extends BaseLogic } return $userInfo; - } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -242,9 +240,8 @@ class LoginLogic extends BaseLogic // Db::commit(); return $userInfo; } catch (\Exception $e) { + throw new BusinessException($e->getMessage()); // Db::rollback(); - self::$error = $e->getMessage(); - return false; } } @@ -260,7 +257,7 @@ class LoginLogic extends BaseLogic { $user = User::findOrEmpty($userId); if ($user->isEmpty()) { - throw new \Exception('用户不存在'); + throw new BusinessException('用户不存在'); } $time = time(); @@ -348,7 +345,7 @@ class LoginLogic extends BaseLogic //先检查openid是否有记录 $isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty(); if (!$isAuth->isEmpty()) { - throw new \Exception('该微信已被绑定'); + throw new BusinessException('该微信已被绑定'); } if (isset($response['unionid']) && !empty($response['unionid'])) { @@ -356,7 +353,7 @@ class LoginLogic extends BaseLogic $userAuth = UserAuth::where(['unionid' => $response['unionid']]) ->findOrEmpty(); if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) { - throw new \Exception('该微信已被绑定'); + throw new BusinessException('该微信已被绑定'); } } @@ -456,8 +453,7 @@ class LoginLogic extends BaseLogic if($find){ $auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的 if($auth){ - self::$error ='该手机号已绑定'; - return false; + throw new BusinessException('该手机号已绑定'); }else{ UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]); } diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index df53b367a..33e387349 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -6,6 +6,7 @@ namespace app\api\logic\order; use app\common\model\order\Cart; use app\common\logic\BaseLogic; use app\common\model\store_product_log\StoreProductLog; +use support\exception\BusinessException; use think\facade\Db; @@ -28,8 +29,7 @@ class CartLogic extends BaseLogic public static function add(array $params) { if ($params['store_id'] <= 0) { - self::setError('门店ID不能为空'); - return false; + throw new BusinessException('门店ID不能为空'); } Db::startTrans(); try { @@ -66,10 +66,9 @@ class CartLogic extends BaseLogic ]); Db::commit(); return $cart; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -93,10 +92,9 @@ class CartLogic extends BaseLogic ->update(['cart_num' => $params['cart_num']]); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index dc6692c10..19f9e74ad 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -67,15 +67,13 @@ class OrderLogic extends BaseLogic static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0) { if(empty($params['store_id']) || $params['store_id'] <= 0){ - self::setError('请选择门店'); - return false; + throw new BusinessException('请选择门店'); } $where = ['is_pay' => 0]; $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } try { self::$total_price = 0; @@ -93,14 +91,12 @@ class OrderLogic extends BaseLogic foreach ($cart_select as $k => $v) { $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); if (!$find) { - self::setError('商品不存在'); - return false; + throw new BusinessException('商品不存在'); } if (convertNumber($v['cart_num']) == false) { $is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk'); if ($is_bulk == 0) { - self::setError('非计量商品,不能有小数,请编辑购物车'); - return false; + throw new BusinessException('非计量商品,不能有小数,请编辑购物车'); } } $StoreCategory = StoreCategory::where('id', $find['cate_id'])->find(); @@ -195,8 +191,7 @@ class OrderLogic extends BaseLogic //判断生鲜是否大于200 if ($createOrder == 1 && self::$fresh_price > 0) { if (self::$pay_price < 200) { - self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单'); - return false; + throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单'); } } if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) { @@ -256,10 +251,10 @@ class OrderLogic extends BaseLogic $currentDate = date('Y-m-d'); $alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days')); } - } catch (\Exception $e) { - d($e); - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); + + } return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'], 'alert' => $alert]; } @@ -276,17 +271,10 @@ class OrderLogic extends BaseLogic $params['order_id'] = $order_id; $params['verify_code'] = $verify_code; $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1); - if ($orderInfo == false) { - self::setError(self::getError()); - return false; - } - if (!$orderInfo) { - return false; - } $uid = $user['id'] ?? 0; $_order = $orderInfo['order']; if ($_order['pay_price'] == 0) { - throw new \Exception('支付金额不能为0'); + throw new BusinessException('支付金额不能为0'); } $_order['uid'] = $uid; $_order['spread_uid'] = $params['spread_uid'] ?? 0; @@ -327,7 +315,7 @@ class OrderLogic extends BaseLogic $_order['status'] = 1; } if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) { - throw new \Exception('余额不足'); + throw new BusinessException('余额不足'); } //生成核销码 // $generator = new BarcodeGeneratorPNG(); @@ -356,8 +344,7 @@ class OrderLogic extends BaseLogic return $order; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -378,8 +365,7 @@ class OrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $params['cart_id']) ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } $newArr = []; //检查购物车对比店铺得商品数量差异 @@ -447,12 +433,11 @@ class OrderLogic extends BaseLogic // 提交事务 Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { // 回滚事务 Db::rollback(); Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); - self::setError('支付失败' . $e->getMessage()); - return false; + throw new BusinessException('支付失败'. $e->getMessage()); } } @@ -469,9 +454,8 @@ class OrderLogic extends BaseLogic $goods_arr = array_unique($goods_id); $select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); return $select->toArray(); - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -584,8 +568,7 @@ class OrderLogic extends BaseLogic 'verify_code' => $params['verify_code'] ])->find(); if (empty($order)) { - self::setError('订单不存在'); - return false; + throw new BusinessException('订单不存在'); } Db::startTrans(); try { @@ -631,10 +614,9 @@ class OrderLogic extends BaseLogic } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -643,7 +625,7 @@ class OrderLogic extends BaseLogic { $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺请查看'); + throw new BusinessException('该用户未绑定店铺请查看'); } $query = StoreOrderCartInfo::alias('o') ->leftJoin('store_branch_product p', 'p.id = o.product_id') @@ -693,7 +675,7 @@ class OrderLogic extends BaseLogic $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); if (empty($store_id)) { - throw new \Exception('该用户未绑定店铺请查看'); + throw new BusinessException('该用户未绑定店铺请查看'); } //先查商品相似 @@ -785,7 +767,7 @@ class OrderLogic extends BaseLogic self::dealChangeCartInfo($refundOrder); // d($leftOrder,$refundOrder); Db::commit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { // 回滚事务 Db::rollback(); throw new BusinessException($e->getMessage()); diff --git a/app/api/logic/user/AddressLogic.php b/app/api/logic/user/AddressLogic.php index 694c1a16a..4a5dea6bc 100644 --- a/app/api/logic/user/AddressLogic.php +++ b/app/api/logic/user/AddressLogic.php @@ -4,6 +4,7 @@ namespace app\api\logic\user; use app\common\logic\BaseLogic; use app\common\model\user\UserAddress; +use support\exception\BusinessException; use think\facade\Db; /** @@ -48,10 +49,9 @@ class AddressLogic extends BaseLogic ]); Db::commit(); return $id; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -95,10 +95,9 @@ class AddressLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/api/logic/user/UserFeedbackLogic.php b/app/api/logic/user/UserFeedbackLogic.php index 42cba90e6..c1f53dacb 100644 --- a/app/api/logic/user/UserFeedbackLogic.php +++ b/app/api/logic/user/UserFeedbackLogic.php @@ -4,7 +4,8 @@ use app\common\logic\BaseLogic; use app\common\model\user\UserFeedback; - use think\facade\Db; +use support\exception\BusinessException; +use think\facade\Db; class UserFeedbackLogic extends BaseLogic { @@ -29,10 +30,10 @@ ]); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } } \ No newline at end of file diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index 8e609df0d..9bb617246 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -24,6 +24,7 @@ use app\common\{logic\BaseLogic, use app\common\logic\UserSignLogic; use app\common\model\user_label\UserLabel; use support\Cache; +use support\exception\BusinessException; use think\facade\Db; @@ -49,7 +50,7 @@ class UserLogic extends BaseLogic $response = (new WeChatMnpService())->getUserPhoneNumber($params['code']); $phoneNumber = $response['phone_info']['purePhoneNumber'] ?? ''; if (empty($phoneNumber)) { - throw new \Exception('获取手机号码失败'); + throw new BusinessException('获取手机号码失败'); } $user = User::where([ @@ -75,9 +76,8 @@ class UserLogic extends BaseLogic ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } @@ -211,7 +211,7 @@ class UserLogic extends BaseLogic $code = generateRandomCode(); $phone = User::where('id',$uid)->value('mobile'); if(empty($phone)){ - throw new \Exception('用户未设置手机号'); + throw new BusinessException('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code); diff --git a/app/api/logic/user/UserVisitLogic.php b/app/api/logic/user/UserVisitLogic.php index fa00f3e4d..dfefb9954 100644 --- a/app/api/logic/user/UserVisitLogic.php +++ b/app/api/logic/user/UserVisitLogic.php @@ -5,7 +5,8 @@ use app\common\logic\BaseLogic; use app\common\model\store_visit\StoreVisit; use app\common\model\user\UserVisit; - use think\facade\Db; +use support\Log; +use think\facade\Db; class UserVisitLogic extends BaseLogic { @@ -39,10 +40,9 @@ } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + Log::error('添加商品浏览失败:'.$e->getMessage()); } } @@ -70,10 +70,9 @@ } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + Log::error('添加用户访问失败:'.$e->getMessage()); } diff --git a/app/common/logic/PaymentLogic.php b/app/common/logic/PaymentLogic.php index 322cc442d..433c6a625 100644 --- a/app/common/logic/PaymentLogic.php +++ b/app/common/logic/PaymentLogic.php @@ -8,7 +8,9 @@ use app\common\enum\PayEnum; use app\common\model\user\UserAuth; use app\common\service\pay\PayService; use Exception; +use support\exception\BusinessException; use support\Log; +use Throwable; use function DI\string; @@ -40,34 +42,33 @@ class PaymentLogic extends BaseLogic return ['pay_way' => PayEnum::BALANCE_PAY]; } try { - if(isset($order['price'])){ - $order['pay_price'] = $order['price']; - } - switch ($payWay) { - case PayEnum::WECHAT_PAY_MINI: - $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); - $order = [ - 'out_trade_no' => $paySn, - 'description' => '商品', - 'amount' => [ - 'total' => intval($order['pay_price'] * 100), - 'currency' => 'CNY', - ], - "payer" => [ - "openid" => $auth['openid'] - ], - 'attach' => $from - ]; - $wechat = new PayService(1); - $result = $wechat->wechat->mini($order)->toArray(); - break; - default: - self::$error = '订单异常'; - $result = false; - } - } catch (Exception $e) { - \support\Log::info($e->extra['message']?? $e->getMessage()); - throw new \Exception($e->extra['message']?? $e->getMessage()); + if (isset($order['price'])) { + $order['pay_price'] = $order['price']; + } + switch ($payWay) { + case PayEnum::WECHAT_PAY_MINI: + $auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty(); + $order = [ + 'out_trade_no' => $paySn, + 'description' => '商品', + 'amount' => [ + 'total' => intval($order['pay_price'] * 100), + 'currency' => 'CNY', + ], + "payer" => [ + "openid" => $auth['openid'] + ], + 'attach' => $from + ]; + $wechat = new PayService(1); + $result = $wechat->wechat->mini($order)->toArray(); + break; + default: + throw new BusinessException('支付方式异常'); + } + } catch (Throwable $e) { + Log::info($e->extra['message'] ?? $e->getMessage()); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } return $result; } @@ -75,13 +76,12 @@ class PaymentLogic extends BaseLogic /** * 微信条码支付 */ - public static function codepay($auth_code, $order,$description='条码商品') + public static function codepay($auth_code, $order, $description = '条码商品') { $pattern = '/^(10|11|12|13|14|15)\d{16}$/'; if (!preg_match($pattern, (string)$auth_code)) { - self::$error = '请使用正确的微信收付款条码'; - return false; + throw new BusinessException('请使用正确的微信收付款条码'); } $data = [ 'description' => $description, @@ -94,26 +94,25 @@ class PaymentLogic extends BaseLogic ], 'scene_info' => [ "store_info" => [ - 'id' => (string)$order['store_id']??1 + 'id' => (string)$order['store_id'] ?? 1 ] ], - 'attach'=>'wechat_common' + 'attach' => 'wechat_common' ]; - if(isset($order['attach']) && $order['attach']!=''){ + if (isset($order['attach']) && $order['attach'] != '') { $data['attach'] = $order['attach']; } $wechat = new PayService(1); try { $result = $wechat->wechat->pos($data)->toArray(); - } catch (Exception $e) { - Log::error('条码支付报错',['message' => $e->extra['message']?? $e->getMessage(),'code'=>$e->getCode()]); + } catch (Throwable $e) { + Log::error('条码支付报错', ['message' => $e->extra['message'] ?? $e->getMessage(), 'code' => $e->getCode()]); if (getenv('APP_DEBUG') == true) { - self::$error = $e->extra['message'] ?? $e->getMessage(); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } else { - self::$error = $e->getMessage(); + throw new BusinessException($e->getMessage()); } - return false; } return $result; } @@ -126,26 +125,24 @@ class PaymentLogic extends BaseLogic $pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/'; if (!preg_match($pattern, (string)$auth_code)) { - self::$error = '请使用正确的支付宝收付款条码'; - return false; + throw new BusinessException('请使用正确的支付宝收付款条码'); } $order = [ 'subject' => '条码商品', 'out_trade_no' => (string)$order['order_id'], 'auth_code' => (string)$auth_code, 'total_amount' => $order['pay_price'], - 'extend_params'=>['attach'=>'alipay_cashier'] + 'extend_params' => ['attach' => 'alipay_cashier'] ]; $wechat = new PayService(); try { $result = $wechat->alipay->pos($order)->toArray(); - } catch (Exception $e) { + } catch (Throwable $e) { if (getenv('APP_DEBUG') == true) { - self::$error = $e->extra['message'] ?? $e->getMessage(); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } else { - self::$error = $e->getMessage(); + throw new BusinessException($e->getMessage()); } - return false; } return $result; } diff --git a/app/common/logic/user_product_storage/UserProductStorageLogic.php b/app/common/logic/user_product_storage/UserProductStorageLogic.php index f9e2af9fe..efe212f6b 100644 --- a/app/common/logic/user_product_storage/UserProductStorageLogic.php +++ b/app/common/logic/user_product_storage/UserProductStorageLogic.php @@ -9,6 +9,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\user\User; use app\common\model\user_product_storage\UserProductStorage; use app\common\model\user_product_storage_log\UserProductStorageLog; +use support\exception\BusinessException; use think\facade\Db; /** @@ -54,9 +55,7 @@ class UserProductStorageLogic extends BaseLogic $find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find(); if($find){ if($find['nums']<$v['nums']){ - self::setError('库存不足'); - Db::commit(); - return false; + throw new BusinessException("库存不足"); } $nums=bcsub($find['nums'],$v['nums']); $find->nums=$nums; @@ -86,17 +85,14 @@ class UserProductStorageLogic extends BaseLogic $data_log[$k]['times']=$times; $data_log[$k]['status']=$status; }else{ - self::setError('没有查询到该商品'); - Db::commit(); - return false; + throw new BusinessException("没有查询到该商品"); } } (new UserProductStorageLog())->saveAll($data_log); Db::commit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } \ No newline at end of file From 94df5f79de662cf3ca4eb65a94536ee615e0240a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 27 Aug 2024 20:46:44 +0800 Subject: [PATCH 05/72] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C=E4=BD=BF=E7=94=A8BusinessE?= =?UTF-8?q?xception=E6=9B=BF=E4=BB=A3setError=E5=92=8Crollback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/ConfigLogic.php | 11 ++++----- app/admin/logic/app_update/AppUpdateLogic.php | 11 ++++----- app/admin/logic/auth/AdminLogic.php | 16 ++++++------- .../delivery_service/DeliveryServiceLogic.php | 11 ++++----- app/admin/logic/dept/DeptLogic.php | 7 +++--- app/admin/logic/dept/JobsLogic.php | 7 +++--- .../FinancialTransfersLogic.php | 23 ++++++++----------- .../InventoryTransferLogic.php | 16 +++++-------- .../purchase_order/PurchaseOrderLogic.php | 7 +++--- .../PurchaseOrderInfoLogic.php | 4 ++-- .../PurchaseProductOfferLogic.php | 13 ++++------- app/admin/logic/setting/CategoryLogic.php | 7 +++--- .../StoreBranchProductLogic.php | 3 +-- .../StoreCashFinanceFlowLogic.php | 7 +++--- .../store_category/StoreCategoryLogic.php | 7 +++--- .../logic/store_extract/StoreExtractLogic.php | 7 +++--- .../StoreFinanceFlowLogic.php | 7 +++--- .../logic/store_order/StoreOrderLogic.php | 4 ++-- .../StoreProductAttrValueLogic.php | 7 +++--- .../StoreProductUnitLogic.php | 7 +++--- app/admin/logic/supplier/SupplierLogic.php | 7 +++--- .../logic/system_store/SystemStoreLogic.php | 9 ++++---- .../SystemStoreStorageLogic.php | 10 ++++---- app/admin/logic/user/UserFeedbackLogic.php | 7 +++--- app/admin/logic/user_bill/UserBillLogic.php | 7 +++--- app/admin/logic/user_label/UserLabelLogic.php | 8 +++---- .../logic/user_recharge/UserRechargeLogic.php | 9 ++++---- app/admin/logic/user_ship/UserShipLogic.php | 8 +++---- app/admin/logic/warehouse/WarehouseLogic.php | 9 ++++---- .../warehouse_order/WarehouseOrderLogic.php | 3 +-- app/api/logic/LoginLogic.php | 3 +-- .../logic/store_order/StoreOrderLogic.php | 13 +++++------ .../service/generator/stub/php/logic.stub | 11 ++++----- app/store/logic/auth/AdminLogic.php | 10 ++++---- .../StoreBranchProductLogic.php | 8 +++---- .../logic/store_order/StoreOrderLogic.php | 7 +++--- .../logic/store_product/StoreProductLogic.php | 7 +++--- .../StoreProductAttrValueLogic.php | 7 +++--- 38 files changed, 144 insertions(+), 181 deletions(-) diff --git a/app/admin/logic/ConfigLogic.php b/app/admin/logic/ConfigLogic.php index a2b705d0c..44cd45dc8 100644 --- a/app/admin/logic/ConfigLogic.php +++ b/app/admin/logic/ConfigLogic.php @@ -18,6 +18,7 @@ use app\common\logic\BaseLogic; use app\common\model\Config; use app\common\model\dict\DictData; use app\common\service\{FileService, ConfigService}; +use support\exception\BusinessException; use think\facade\Db; /** @@ -46,10 +47,9 @@ class ConfigLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -73,10 +73,9 @@ class ConfigLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/app_update/AppUpdateLogic.php b/app/admin/logic/app_update/AppUpdateLogic.php index c32200227..c4e2921f0 100644 --- a/app/admin/logic/app_update/AppUpdateLogic.php +++ b/app/admin/logic/app_update/AppUpdateLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\app_update; use app\common\model\app_update\AppUpdate; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,10 +41,9 @@ class AppUpdateLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -71,10 +71,9 @@ class AppUpdateLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/auth/AdminLogic.php b/app/admin/logic/auth/AdminLogic.php index 0f92fa397..bff5eb111 100644 --- a/app/admin/logic/auth/AdminLogic.php +++ b/app/admin/logic/auth/AdminLogic.php @@ -24,6 +24,7 @@ use app\common\model\auth\AdminRole; use app\common\model\auth\AdminSession; use app\common\cache\AdminTokenCache; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; use think\facade\Db; @@ -70,10 +71,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -138,10 +138,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -177,10 +176,9 @@ class AdminLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/delivery_service/DeliveryServiceLogic.php b/app/admin/logic/delivery_service/DeliveryServiceLogic.php index c9a1eba72..99f671683 100644 --- a/app/admin/logic/delivery_service/DeliveryServiceLogic.php +++ b/app/admin/logic/delivery_service/DeliveryServiceLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\delivery_service; use app\common\model\delivery_service\DeliveryService; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -37,10 +38,9 @@ class DeliveryServiceLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -65,10 +65,9 @@ class DeliveryServiceLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/dept/DeptLogic.php b/app/admin/logic/dept/DeptLogic.php index d39e42b2b..e7e37737c 100644 --- a/app/admin/logic/dept/DeptLogic.php +++ b/app/admin/logic/dept/DeptLogic.php @@ -17,7 +17,7 @@ namespace app\admin\logic\dept; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\model\dept\Dept; - +use support\exception\BusinessException; /** * 部门管理逻辑 @@ -147,9 +147,8 @@ class DeptLogic extends BaseLogic 'sort' => $params['sort'] ?? 0 ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/dept/JobsLogic.php b/app/admin/logic/dept/JobsLogic.php index f23c0551f..ec137b68e 100644 --- a/app/admin/logic/dept/JobsLogic.php +++ b/app/admin/logic/dept/JobsLogic.php @@ -17,7 +17,7 @@ namespace app\admin\logic\dept; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\model\dept\Jobs; - +use support\exception\BusinessException; /** * 岗位管理逻辑 @@ -65,9 +65,8 @@ class JobsLogic extends BaseLogic 'remark' => $params['remark'] ?? '', ]); return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/financial_transfers/FinancialTransfersLogic.php b/app/admin/logic/financial_transfers/FinancialTransfersLogic.php index d9b0577b3..f8dd223b2 100644 --- a/app/admin/logic/financial_transfers/FinancialTransfersLogic.php +++ b/app/admin/logic/financial_transfers/FinancialTransfersLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\financial_transfers; use app\common\model\financial_transfers\FinancialTransfers; use app\common\logic\BaseLogic; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; +use support\exception\BusinessException; use think\facade\Db; @@ -43,10 +44,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -76,10 +76,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -123,10 +122,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -138,7 +136,7 @@ class FinancialTransfersLogic extends BaseLogic $date = date('Y-m-d', $time); //获取一个月前的日期 $receivable = StoreCashFinanceFlow::whereMonth('create_time', $date)->where('status', 0)->sum('receivable'); if($receivable==0){ - self::setError('暂无法确认,还有未收取的现金'); + throw new BusinessException('暂无法确认,还有未收取的现金'); } Db::startTrans(); try { @@ -149,10 +147,9 @@ class FinancialTransfersLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } diff --git a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php index 445a69b3d..bae2f627b 100644 --- a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php +++ b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php @@ -7,6 +7,7 @@ use app\common\model\inventory_transfer\InventoryTransfer; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use support\exception\BusinessException; use think\facade\Db; @@ -35,8 +36,7 @@ class InventoryTransferLogic extends BaseLogic if($params['one_type']==1){ $stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock'); if ($stock < $params['nums']) { - self::setError('调拨数量不能大于当前门店库存'); - return false; + throw new BusinessException('调拨数量不能大于当前门店库存'); } if($params['two_type']==1){ $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); @@ -51,8 +51,7 @@ class InventoryTransferLogic extends BaseLogic }elseif($params['one_type']==2){ $stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums'); if ($stock < $params['nums']) { - self::setError('调拨数量不能大于当前仓库库存'); - return false; + throw new BusinessException('调拨数量不能大于当前仓库库存'); } if($params['two_type']==1){ $stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock'); @@ -65,8 +64,7 @@ class InventoryTransferLogic extends BaseLogic $two_before_nums = $stock_two; $two_after_nums = bcadd($stock_two, $params['nums']); }else{ - self::setError('调拨类型错误'); - return false; + throw new BusinessException('调拨类型错误'); } Db::startTrans(); @@ -97,8 +95,7 @@ class InventoryTransferLogic extends BaseLogic return true; } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -127,8 +124,7 @@ class InventoryTransferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/purchase_order/PurchaseOrderLogic.php b/app/admin/logic/purchase_order/PurchaseOrderLogic.php index 7f7ddfdbb..2ce0f4072 100644 --- a/app/admin/logic/purchase_order/PurchaseOrderLogic.php +++ b/app/admin/logic/purchase_order/PurchaseOrderLogic.php @@ -11,6 +11,7 @@ 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\system_store\SystemStore; +use support\exception\BusinessException; use think\facade\Db; @@ -181,8 +182,7 @@ class PurchaseOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -231,8 +231,7 @@ class PurchaseOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php b/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php index 44d5483a4..25089631f 100644 --- a/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php +++ b/app/admin/logic/purchase_order_info/PurchaseOrderInfoLogic.php @@ -6,6 +6,7 @@ use app\common\logic\BaseLogic; use app\common\model\purchase_order_info\PurchaseOrderInfo; use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\store_product\StoreProduct; +use support\exception\BusinessException; use think\facade\Db; class PurchaseOrderInfoLogic extends BaseLogic @@ -37,8 +38,7 @@ class PurchaseOrderInfoLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index d9b5fc996..32fd6aac4 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\purchase_product_offer; use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\logic\BaseLogic; use app\common\model\delivery_service\DeliveryService; +use support\exception\BusinessException; use think\facade\Db; @@ -53,8 +54,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -94,8 +94,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -106,8 +105,7 @@ class PurchaseProductOfferLogic extends BaseLogic { if($params['is_buyer']==1){ if($params['buyer_id']==''){ - self::setError('采购人不能为空'); - return false; + throw new BusinessException('采购人不能为空'); } $data['buyer_id']=$params['buyer_id']; $data['buyer_nums']=$params['buyer_nums']; @@ -120,8 +118,7 @@ class PurchaseProductOfferLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } /** diff --git a/app/admin/logic/setting/CategoryLogic.php b/app/admin/logic/setting/CategoryLogic.php index 2afd91ffc..875d3d5df 100644 --- a/app/admin/logic/setting/CategoryLogic.php +++ b/app/admin/logic/setting/CategoryLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\setting; use app\common\model\setting\Category; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -43,8 +44,7 @@ class CategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -75,8 +75,7 @@ class CategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index f76a43d5f..cf365b69b 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -36,8 +36,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php index a8a1b4c24..e7787183a 100644 --- a/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php +++ b/app/admin/logic/store_cash_finance_flow/StoreCashFinanceFlowLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_cash_finance_flow; use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -64,8 +64,7 @@ class StoreCashFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_category/StoreCategoryLogic.php b/app/admin/logic/store_category/StoreCategoryLogic.php index ba0b1c08b..5fd79536b 100644 --- a/app/admin/logic/store_category/StoreCategoryLogic.php +++ b/app/admin/logic/store_category/StoreCategoryLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_category; use app\common\model\store_category\StoreCategory; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class StoreCategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class StoreCategoryLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_extract/StoreExtractLogic.php b/app/admin/logic/store_extract/StoreExtractLogic.php index f11d97ccd..70b5a4622 100644 --- a/app/admin/logic/store_extract/StoreExtractLogic.php +++ b/app/admin/logic/store_extract/StoreExtractLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_extract; use app\common\model\store_extract\StoreExtract; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreExtractLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreExtractLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php b/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php index d4dec2553..c39bd660e 100644 --- a/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php +++ b/app/admin/logic/store_finance_flow/StoreFinanceFlowLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_finance_flow; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreFinanceFlowLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index a46665fe7..e4dae7376 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -16,6 +16,7 @@ use app\common\model\store_product\StoreProduct; use app\common\model\user\User; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use support\exception\BusinessException; use think\facade\Db; @@ -73,8 +74,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php index 32f3370dd..d6ba4c20d 100644 --- a/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php +++ b/app/admin/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_attr_value; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/store_product_unit/StoreProductUnitLogic.php b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php index 9ea649ec1..caa9bb9d8 100644 --- a/app/admin/logic/store_product_unit/StoreProductUnitLogic.php +++ b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_product_unit; use app\common\model\store_product_unit\StoreProductUnit; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class StoreProductUnitLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class StoreProductUnitLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/supplier/SupplierLogic.php b/app/admin/logic/supplier/SupplierLogic.php index ba686ab0b..907b352e2 100644 --- a/app/admin/logic/supplier/SupplierLogic.php +++ b/app/admin/logic/supplier/SupplierLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\supplier; use app\common\model\supplier\Supplier; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -41,8 +42,7 @@ class SupplierLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -71,8 +71,7 @@ class SupplierLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/system_store/SystemStoreLogic.php b/app/admin/logic/system_store/SystemStoreLogic.php index 4e68384b3..fbf3302e1 100644 --- a/app/admin/logic/system_store/SystemStoreLogic.php +++ b/app/admin/logic/system_store/SystemStoreLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic\system_store; use app\common\model\system_store\SystemStore; use app\common\logic\BaseLogic; use app\common\model\system_store\SystemStoreStaff; +use support\exception\BusinessException; use think\facade\Db; use Webman\Config; @@ -70,8 +71,8 @@ class SystemStoreLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -137,8 +138,8 @@ class SystemStoreLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 03fac3aea..21eea8686 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -10,6 +10,7 @@ use app\common\logic\BaseLogic; use app\common\model\store_product\StoreProduct; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use support\exception\BusinessException; use think\facade\Db; @@ -44,10 +45,9 @@ class SystemStoreStorageLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -74,8 +74,8 @@ class SystemStoreStorageLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/user/UserFeedbackLogic.php b/app/admin/logic/user/UserFeedbackLogic.php index 4f291ebdc..aa612ccf3 100644 --- a/app/admin/logic/user/UserFeedbackLogic.php +++ b/app/admin/logic/user/UserFeedbackLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user; use app\common\logic\BaseLogic; use app\common\model\user\UserFeedback; +use support\exception\BusinessException; use think\facade\Db; @@ -40,8 +41,7 @@ class UserFeedbackLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -69,8 +69,7 @@ class UserFeedbackLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user_bill/UserBillLogic.php b/app/admin/logic/user_bill/UserBillLogic.php index f586146df..fd68aff01 100644 --- a/app/admin/logic/user_bill/UserBillLogic.php +++ b/app/admin/logic/user_bill/UserBillLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_bill; use app\common\model\user_bill\UserBill; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class UserBillLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class UserBillLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/user_label/UserLabelLogic.php b/app/admin/logic/user_label/UserLabelLogic.php index d8a766b7c..af080ae80 100644 --- a/app/admin/logic/user_label/UserLabelLogic.php +++ b/app/admin/logic/user_label/UserLabelLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_label; use app\common\model\user_label\UserLabel; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class UserLabelLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,8 @@ class UserLabelLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/user_recharge/UserRechargeLogic.php b/app/admin/logic/user_recharge/UserRechargeLogic.php index 27fb78dc4..c60c1e8c3 100644 --- a/app/admin/logic/user_recharge/UserRechargeLogic.php +++ b/app/admin/logic/user_recharge/UserRechargeLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\user_recharge; use app\common\model\user_recharge\UserRecharge; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,8 @@ class UserRechargeLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -61,8 +62,8 @@ class UserRechargeLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/user_ship/UserShipLogic.php b/app/admin/logic/user_ship/UserShipLogic.php index 6075c5cb8..40cd0650c 100644 --- a/app/admin/logic/user_ship/UserShipLogic.php +++ b/app/admin/logic/user_ship/UserShipLogic.php @@ -41,8 +41,8 @@ class UserShipLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -68,8 +68,8 @@ class UserShipLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/warehouse/WarehouseLogic.php b/app/admin/logic/warehouse/WarehouseLogic.php index 13568bdbe..88e24f4fc 100644 --- a/app/admin/logic/warehouse/WarehouseLogic.php +++ b/app/admin/logic/warehouse/WarehouseLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse; use app\common\model\warehouse\Warehouse; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -42,8 +43,8 @@ class WarehouseLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -73,8 +74,8 @@ class WarehouseLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } diff --git a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php index 441d57aab..8c9d262c3 100644 --- a/app/admin/logic/warehouse_order/WarehouseOrderLogic.php +++ b/app/admin/logic/warehouse_order/WarehouseOrderLogic.php @@ -88,8 +88,7 @@ class WarehouseOrderLogic extends BaseLogic { $find = WarehouseOrder::where('id', $params['id'])->find(); if (!$find) { - self::setError('订单不存在'); - return false; + throw new BusinessException('订单不存在'); } Db::startTrans(); try { diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index e5dcd48df..bb5f57f66 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -63,8 +63,7 @@ class LoginLogic extends BaseLogic return true; } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 53e5d26fd..b3f84aaf8 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -21,6 +21,7 @@ use Exception; use support\Cache; use think\facade\Db; use app\common\model\system_store\SystemStore; +use support\exception\BusinessException; class StoreOrderLogic extends BaseLogic { @@ -46,7 +47,7 @@ class StoreOrderLogic extends BaseLogic $where = ['is_pay' => 0]; $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); + throw new BusinessException('购物车为空'); return false; } try { @@ -164,8 +165,7 @@ class StoreOrderLogic extends BaseLogic } } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } return ['order' => $order, 'cart_list' => $cart_select]; } @@ -222,8 +222,8 @@ class StoreOrderLogic extends BaseLogic return $order; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); + } } @@ -413,8 +413,7 @@ class StoreOrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $params['cart_id']) ->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray(); if (empty($cart_select)) { - self::setError('购物车为空'); - return false; + throw new BusinessException('购物车为空'); } $newArr = []; //检查购物车对比店铺得商品数量差异 diff --git a/app/common/service/generator/stub/php/logic.stub b/app/common/service/generator/stub/php/logic.stub index e7ad55245..901e5232d 100644 --- a/app/common/service/generator/stub/php/logic.stub +++ b/app/common/service/generator/stub/php/logic.stub @@ -5,6 +5,7 @@ {USE} use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -34,10 +35,9 @@ class {UPPER_CAMEL_NAME}Logic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -59,10 +59,9 @@ class {UPPER_CAMEL_NAME}Logic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/auth/AdminLogic.php b/app/store/logic/auth/AdminLogic.php index fd63d0ef4..9f8af98bc 100644 --- a/app/store/logic/auth/AdminLogic.php +++ b/app/store/logic/auth/AdminLogic.php @@ -25,6 +25,7 @@ use app\common\model\auth\AdminSession; use app\common\cache\AdminTokenCache; use app\common\model\system_store\SystemStoreStaff; use app\common\service\FileService; +use support\exception\BusinessException; use Webman\Config; use think\facade\Db; @@ -73,8 +74,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -141,8 +141,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -180,8 +179,7 @@ class AdminLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_branch_product/StoreBranchProductLogic.php b/app/store/logic/store_branch_product/StoreBranchProductLogic.php index d37e60cad..7837ac1b5 100644 --- a/app/store/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/store/logic/store_branch_product/StoreBranchProductLogic.php @@ -65,8 +65,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -95,8 +94,7 @@ class StoreBranchProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -151,7 +149,7 @@ class StoreBranchProductLogic extends BaseLogic public static function checkAuth($product) { if (request()->adminInfo['store_id'] != $product['store_id']) { - throw new \Exception('没有权限操作'); + throw new BusinessException('没有权限操作'); } } diff --git a/app/store/logic/store_order/StoreOrderLogic.php b/app/store/logic/store_order/StoreOrderLogic.php index 80df42e05..13b7948a0 100644 --- a/app/store/logic/store_order/StoreOrderLogic.php +++ b/app/store/logic/store_order/StoreOrderLogic.php @@ -7,6 +7,7 @@ use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -38,8 +39,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -63,8 +63,7 @@ class StoreOrderLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_product/StoreProductLogic.php b/app/store/logic/store_product/StoreProductLogic.php index 7af0b7980..594a72821 100644 --- a/app/store/logic/store_product/StoreProductLogic.php +++ b/app/store/logic/store_product/StoreProductLogic.php @@ -7,6 +7,7 @@ use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_attr_value\StoreProductAttrValue; +use support\exception\BusinessException; use think\facade\Db; @@ -34,8 +35,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -58,8 +58,7 @@ class StoreProductLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php index 2520412a2..0572ba6ce 100644 --- a/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php +++ b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -5,6 +5,7 @@ namespace app\store\logic\store_product_attr_value; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\logic\BaseLogic; +use support\exception\BusinessException; use think\facade\Db; @@ -36,8 +37,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } @@ -61,8 +61,7 @@ class StoreProductAttrValueLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::setError($e->getMessage()); - return false; + throw new BusinessException($e->getMessage()); } } From 79edaa03f15fb5a12531e5202fef31bbf63ff4f8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 27 Aug 2024 20:50:53 +0800 Subject: [PATCH 06/72] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C=E4=BD=BF=E7=94=A8BusinessE?= =?UTF-8?q?xception=E6=9B=BF=E4=BB=A3setError=E5=92=8Crollback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/auth/RoleLogic.php | 7 +++---- app/admin/logic/tools/GeneratorLogic.php | 19 +++++++------------ app/store/logic/auth/RoleLogic.php | 7 +++---- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app/admin/logic/auth/RoleLogic.php b/app/admin/logic/auth/RoleLogic.php index 8146899f0..099ebeedc 100644 --- a/app/admin/logic/auth/RoleLogic.php +++ b/app/admin/logic/auth/RoleLogic.php @@ -20,6 +20,7 @@ use app\common\{ logic\BaseLogic, model\auth\SystemRoleMenu }; +use support\exception\BusinessException; use think\facade\Db; @@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/admin/logic/tools/GeneratorLogic.php b/app/admin/logic/tools/GeneratorLogic.php index d88a288fe..dcef7c75f 100644 --- a/app/admin/logic/tools/GeneratorLogic.php +++ b/app/admin/logic/tools/GeneratorLogic.php @@ -21,6 +21,7 @@ use app\common\model\tools\GenerateTable; use app\common\service\generator\GenerateService; use support\Cache; use support\Container; +use support\exception\BusinessException; use think\facade\Db; @@ -78,8 +79,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -134,8 +134,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -157,8 +156,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -187,8 +185,7 @@ class GeneratorLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -228,8 +225,7 @@ class GeneratorLogic extends BaseLogic return ['file' => $zipFile]; } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -252,8 +248,7 @@ class GeneratorLogic extends BaseLogic return Container::get(GenerateService::class)->preview($table); } catch (\Exception $e) { - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } diff --git a/app/store/logic/auth/RoleLogic.php b/app/store/logic/auth/RoleLogic.php index e0113d50b..adb39bee9 100644 --- a/app/store/logic/auth/RoleLogic.php +++ b/app/store/logic/auth/RoleLogic.php @@ -20,6 +20,7 @@ use app\common\{ logic\BaseLogic, model\auth\SystemRoleMenu }; +use support\exception\BusinessException; use think\facade\Db; @@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } @@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); - self::$error = $e->getMessage(); - return false; + throw new BusinessException($e->getMessage()); } } From 7967f0b9cd6326e5053f51fa93600abd28fa16d8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 27 Aug 2024 21:10:13 +0800 Subject: [PATCH 07/72] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20IndexControl?= =?UTF-8?q?ler=20=E4=B8=AD=E7=9A=84=E8=B7=9D=E7=A6=BB=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8F=90=E9=AB=98=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 9add06bd8..dbe09f340 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -135,9 +135,8 @@ class IndexController extends BaseApiController $latitude = $params['lat']; $longitude = $params['long']; // 计算距离的SQL表达式 - $distanceSql = "SQRT(POW(69.1 * (latitude - {$latitude}), 2) + - POW(69.1 * ({$longitude} - longitude) * COS(latitude / 57.3), 2))"; - $find = SystemStore::field("id, name,abbreviation, {$distanceSql} AS distance") + $distanceExpr = "6371 * 2 * ASIN(SQRT(POWER(SIN(({$latitude} - abs(latitude)) * pi()/180 / 2), 2) + COS({$latitude} * pi()/180) * COS(abs(latitude) * pi()/180) * POWER(SIN(({$longitude} - longitude) * pi()/180 / 2), 2)))"; + $find = SystemStore::field("id, name,abbreviation, {$distanceExpr} AS distance") ->where('is_show', '=', 1) ->where('latitude', '<>', '') ->where('longitude', '<>', '') From 84f39f0ac7d94a355b95e558229dde0beac6d138 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 11:09:24 +0800 Subject: [PATCH 08/72] =?UTF-8?q?feat(CartController):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=95=86=E5=93=81=E8=B5=B7?= =?UTF-8?q?=E6=89=B9=E5=8F=91=E9=87=8F=E5=88=A4=E6=96=AD=E5=92=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/CartController.php | 17 ++++++++++++++--- app/api/lists/order/CartList.php | 5 +++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index 03fea3e5b..90a35cd75 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -25,7 +25,7 @@ class CartController extends BaseApiController $params = (new CartValidate())->post()->goCheck('add'); $params['uid'] = $this->request->userId; $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( [ @@ -36,7 +36,6 @@ class CartController extends BaseApiController if (!$branchProduct) { return $this->fail('商品不存在'); } - $params['cart_num']=intval($params['cart_num']); if ($params['cart_num'] < $branchProduct['batch']) { return $this->fail('起批发量低于最低值' . $branchProduct['batch']); } @@ -85,7 +84,19 @@ class CartController extends BaseApiController { $params = (new CartValidate())->post()->goCheck('change'); $params['uid'] = $this->request->userId; - $params['cart_num']=intval($params['cart_num']); + $params['cart_num']=bcadd($params['cart_num'],0,2); + if (convertNumber($params['cart_num']) === false) { + $branchProduct = StoreBranchProduct::where( + [ + 'product_id' => $params['product_id'], + 'store_id' => $params['store_id'] + ] + )->find(); + $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); + if ($is_bulk == 0) { + return $this->fail('非计量商品,不能有小数,请编辑购物车'); + } + } $res = CartLogic::edit($params, 'dec'); if ($res) { return $this->success('修改成功'); diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index a16c31e08..5b6c770c9 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -65,9 +65,9 @@ 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'; + $field = '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'; + $field = '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; @@ -84,6 +84,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists } $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); + $item['batch'] = $find['batch']; $item['imgs'] = $find['image']; $item['price'] = $find['price']; $item['cost'] = $find['cost']; 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 09/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=BA=93=E5=AD=98=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=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 7681a721d..6b2f16248 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 cf365b69b..0b19ba485 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 8dc2575af..2134c5133 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 dbe09f340..2a090cd52 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 90a35cd75..5810409fa 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 8157169f4..21c52e4be 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 5b6c770c9..e734eb108 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 a08142f77..5e6652654 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 d15d822f2..ac126989f 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 f9c4b2d09..ee66cd1c3 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 19f9e74ad..1dda5e8c4 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 b2ceaef7a..54f53d86f 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 1bdacd40c..efa80f521 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 124eb2233..c74b0bcd5 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 dc810fdda..7f8b6fbb5 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 074aa2d02..b8c71cf67 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 e2b128000..7087f1979 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 29d3cf937..3674f732e 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 27ca4ecf3..bfa55e9de 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 ee8448c4a..7db7057d5 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], ], ] ], From 4cef86fb877ef19b2380110b5d048140b1a052fb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 15:47:22 +0800 Subject: [PATCH 10/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9SystemStoreList?= =?UTF-8?q?s=E7=B1=BB=E4=BB=A5=E4=BC=98=E5=8C=96=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/store/SystemStoreLists.php | 101 +++++++++++++---------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 9f52831f3..64c1d6c6b 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -48,62 +48,76 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function lists(): array { - $latitude = $this->request->get('latitude',''); - $longitude = $this->request->get('longitude',''); - $cart_id = $this->request->get('cart_id',''); -// if(empty($longitude) || empty($latitude)){ -// throw new Exception('缺失经纬度'); -// } - $where[]=['is_show','=',YesNoEnum::YES]; + $latitude = $this->request->get('latitude', ''); + $longitude = $this->request->get('longitude', ''); + $cart_id = $this->request->get('cart_id', ''); + // if(empty($longitude) || empty($latitude)){ + // throw new Exception('缺失经纬度'); + // } + $where[] = ['is_show', '=', YesNoEnum::YES]; $data = SystemStore::where($this->searchWhere)->where($where) - ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', - 'day_time','is_store','latitude','longitude','day_start','day_end','is_store' - ,'is_send','abbreviation' + ->field([ + 'id', + 'name', + 'phone', + 'detailed_address', + 'image', + 'is_show', + 'day_time', + 'is_store', + 'latitude', + 'longitude', + 'day_start', + 'day_end', + 'is_store', + 'is_send', + 'abbreviation' ]) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); - if($cart_id){ - if($latitude && $longitude){ - $cart_id = explode(',',$cart_id); - $cart_select = Cart::whereIn('id', $cart_id) - ->field('id,product_id,cart_num,store_id')->select()->toArray(); - foreach ($cart_select as $v) { - foreach ($data as &$values){ - $store = StoreBranchProduct::where([ - 'store_id'=>$values['id'], - 'product_id'=>$v['product_id'], - ])->field('id,store_name,stock')->withTrashed()->find(); - if(empty($store)){ - $store['stock'] =0; - } - $values['reservation'] = 0; - if($store['stock'] < $v['cart_num']){ - $values['reservation'] = 1; - } - $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); - } + if ($cart_id) { + if ($latitude && $longitude) { + foreach ($data as &$values) { + $values['distance'] = haversineDistance($values['latitude'], $values['longitude'], $latitude, $longitude); + $values['reservation'] = 1; } - }else{ - foreach ($data as &$values){ + + // $cart_id = explode(',',$cart_id); + // $cart_select = Cart::whereIn('id', $cart_id) + // ->field('id,product_id,cart_num,store_id')->select()->toArray(); + // foreach ($cart_select as $v) { + // foreach ($data as &$values){ + // $store = StoreBranchProduct::where([ + // 'store_id'=>$values['id'], + // 'product_id'=>$v['product_id'], + // ])->field('id,store_name,stock')->withTrashed()->find(); + // if(empty($store)){ + // $store['stock'] =0; + // } + // $values['reservation'] = 0; + // if($store['stock'] < $v['cart_num']){ + // } + // } + + // } + } else { + foreach ($data as &$values) { $values['distance'] = 0; } } - - }else{ - if($latitude && $longitude){ - foreach ($data as &$value){ - $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); - + } else { + if ($latitude && $longitude) { + foreach ($data as &$value) { + $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $latitude, $longitude); } - }else{ - foreach ($data as &$values){ + } else { + foreach ($data as &$values) { $values['distance'] = 0; } } - } usort($data, function ($a, $b) { @@ -121,8 +135,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function count(): int { - $where[]=['is_show','=',YesNoEnum::YES]; + $where[] = ['is_show', '=', YesNoEnum::YES]; return SystemStore::where($this->searchWhere)->where($where)->count(); } - -} \ No newline at end of file +} From a2b121462ca37b9fafbe6857c674dc6dee2a4b43 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 16:43:08 +0800 Subject: [PATCH 11/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=95=86=E5=93=81=E7=8A=B6=E6=80=81=E7=9A=84API?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_product/StoreProductController.php | 10 ++++++ .../logic/store_product/StoreProductLogic.php | 35 ++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 50cc68465..55c5f43d7 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -62,6 +62,16 @@ class StoreProductController extends BaseAdminController } + /** + * @notes 修改商品状态 + * @return \think\response\Json + * @date 2024/05/31 10:53 + */ + public function status(){ + $params=$this->request->post(); + StoreProduct::where('id',$params['id'])->update(['is_show'=>$params['is_show']]); + return $this->success('操作成功',[],1,1); + } /** * @notes 删除商品列表 diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 875b9cc96..d8f28f88f 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -36,6 +36,16 @@ class StoreProductLogic extends BaseLogic */ public static function add(array $params): bool { + $count=count($params['cate_arr']); + $top_cate_id=0; + $two_cate_id=0; + if($count==3){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][1]; + }elseif($count==2){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][0]; + } Db::startTrans(); try { $data = [ @@ -43,6 +53,8 @@ class StoreProductLogic extends BaseLogic 'image' => $params['image'], 'store_info' => $params['store_info'] ?? '', 'bar_code' => $params['bar_code'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, 'cate_id' => $params['cate_id'], 'unit' => $params['unit'], 'stock' => 0, @@ -57,6 +69,7 @@ class StoreProductLogic extends BaseLogic 'batch' => $params['batch'] ?? 0, 'store_batch' => $params['store_batch'] ?? 1, 'product_type' => $params['product_type'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, ]; // if ($params['rose'] > 0) { // $rose_price = bcmul($params['cost'], $params['rose'], 2); @@ -171,11 +184,23 @@ class StoreProductLogic extends BaseLogic { Db::startTrans(); try { + $count=count($params['cate_arr']); + $top_cate_id=0; + $two_cate_id=0; + if($count==3){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][1]; + }elseif($count==2){ + $top_cate_id=$params['cate_arr'][0]; + $two_cate_id=$params['cate_arr'][0]; + } $data = [ 'store_name' => $params['store_name'], 'image' => $params['image'], 'bar_code' => $params['bar_code'] ?? '', 'store_info' => $params['store_info'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, 'cate_id' => $params['cate_id'], 'unit' => $params['unit'], 'stock' => $params['stock'], @@ -189,12 +214,12 @@ class StoreProductLogic extends BaseLogic 'store_batch' => $params['store_batch'] ?? 1, 'manufacturer_information' => $params['manufacturer_information'] ?? '', 'swap' => $params['swap'] ?? 0, - 'rose' => $params['rose'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, ]; StoreProduct::where('id', $params['id'])->update($data); - $dealCate = self::dealChangeCate($params['cate_id']); + // $dealCate = self::dealChangeCate($params['cate_id']); //修改 StoreBranchProduct::where('product_id', $params['id'])->update([ 'price' => $params['price'], @@ -206,11 +231,13 @@ class StoreProductLogic extends BaseLogic 'manufacturer_information' => $params['manufacturer_information'] ?? '', 'store_info' => $params['store_info'] ?? '', 'cate_id' => $params['cate_id'], - 'top_cate_id' => $dealCate['top_cate_id'], - 'two_cate_id' => $dealCate['two_cate_id'], + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, + 'cate_id' => $params['cate_id'], 'bar_code' => $params['bar_code'], 'purchase' => $params['purchase'], 'rose' => $params['rose'] ?? 0, + 'status' => $params['is_show'] ?? 0, 'image' => $params['image'], 'store_batch' => $params['store_batch'] ?? 1, From fc779f1e7ea58812def34c720a31d9d55ae7c234 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 18:01:04 +0800 Subject: [PATCH 12/72] =?UTF-8?q?feat(UserLists.php):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?'between=5Ftime'=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/user/UserLists.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/admin/lists/user/UserLists.php b/app/admin/lists/user/UserLists.php index a419056cc..e94de5530 100644 --- a/app/admin/lists/user/UserLists.php +++ b/app/admin/lists/user/UserLists.php @@ -29,6 +29,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsS '=' => ['store_id','user_ship','is_disable'], '%like%' => ['account','mobile'], '%pipe_like%' => ['nickname'=>'nickname|real_name'], + 'between_time' => 'vip_time' ]; } From 4a2378f15b2faed051184bc33480d6fb6a995e4b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 28 Aug 2024 20:39:02 +0800 Subject: [PATCH 13/72] =?UTF-8?q?feat(WarehouseProductStorege.php):=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BA=86=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=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 --- .../warehouse_product_storege/WarehouseProductStorege.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index b8c71cf67..fd8cefcd0 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -19,12 +19,4 @@ 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 From 4d1d2e0745a2e9b70275c1e0a7381970728be981 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 29 Aug 2024 11:01:25 +0800 Subject: [PATCH 14/72] =?UTF-8?q?feat(CartList):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=92=8C=E5=8D=95=E4=BD=8D=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/lists/cart/CartList.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/store/lists/cart/CartList.php b/app/store/lists/cart/CartList.php index bfa55e9de..f136bdfcc 100644 --- a/app/store/lists/cart/CartList.php +++ b/app/store/lists/cart/CartList.php @@ -49,7 +49,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists 'is_pay' => 0 ]; $list = Cart::where($this->searchWhere)->where($where) - ->limit($this->limitOffset, $this->limitLength) + ->limit(100) ->order(['id' => 'desc']) ->select()->each(function ($item) { @@ -91,7 +91,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists $item['image'] = $find['image']; $item['cost'] = $find['cost']; $item['store_name'] = $find['store_name']; - $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $unit = StoreProductUnit::where('id', $find['unit'])->find(); + if($unit){ + $item['unit_name']=$unit['name']; + $item['is_bulk']=$unit['is_bulk']; + }else{ + $item['unit_name']=''; + $item['is_bulk']=0; + } } } return $list; From c25aef2197de53fcdfc711e1fa2a482739a0cf4e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 29 Aug 2024 17:49:30 +0800 Subject: [PATCH 15/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=9D=A1=E4=BB=B6=20'between=5Ftime'=20=E5=92=8C?= =?UTF-8?q?=E5=9B=9B=E4=B8=AAID=E5=8F=82=E6=95=B0=E5=88=B0=20WarehouseOrde?= =?UTF-8?q?rLists=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/warehouse_order/WarehouseOrderLists.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/admin/lists/warehouse_order/WarehouseOrderLists.php b/app/admin/lists/warehouse_order/WarehouseOrderLists.php index 543c26ca7..491184e7b 100644 --- a/app/admin/lists/warehouse_order/WarehouseOrderLists.php +++ b/app/admin/lists/warehouse_order/WarehouseOrderLists.php @@ -29,7 +29,8 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter public function setSearch(): array { return [ - '='=>['financial_pm'] + '='=>['financial_pm','supplier_id','warehouse_id','store_id'], + 'between_time' => 'create_time' ]; } From 7326ef78e394b962dd2c27bc22e9e7e61ef9afeb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 29 Aug 2024 20:15:21 +0800 Subject: [PATCH 16/72] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=80=BB=E8=BE=91=E5=92=8C=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E6=8F=90=E5=8D=87=E7=B3=BB=E7=BB=9F=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=80=A7=E5=92=8C=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 5 ----- app/api/logic/order/CartLogic.php | 19 +++++++++++++------ app/store/validate/LoginValidate.php | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 2a090cd52..28fd3f781 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,11 +44,6 @@ 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]); } diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index 33e387349..2ad0c6107 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -84,12 +84,19 @@ class CartLogic extends BaseLogic { Db::startTrans(); try { - Cart::where([ - 'uid' => $params['uid'], - 'store_id' => $params['store_id'], - 'product_id' => $params['product_id'] - ]) - ->update(['cart_num' => $params['cart_num']]); + if(isset($params['type']) && $params['type']=='inc'){ + Cart::where([ + 'uid' => $params['uid'], + 'store_id' => $params['store_id'], + 'product_id' => $params['product_id'] + ])->inc('cart_num')->update(); + }else{ + Cart::where([ + 'uid' => $params['uid'], + 'store_id' => $params['store_id'], + 'product_id' => $params['product_id'] + ])->update(['cart_num' => $params['cart_num']]); + } Db::commit(); return true; } catch (\Throwable $e) { diff --git a/app/store/validate/LoginValidate.php b/app/store/validate/LoginValidate.php index b7c80593f..89b79407b 100644 --- a/app/store/validate/LoginValidate.php +++ b/app/store/validate/LoginValidate.php @@ -10,7 +10,7 @@ use app\common\model\auth\Admin; use app\common\model\system_store\SystemStoreStaff; use app\common\service\ConfigService; use app\common\validate\BaseValidate; -use app\MyBusinessException; +use support\exception\BusinessException; use Webman\Config; class LoginValidate extends BaseValidate @@ -55,7 +55,7 @@ class LoginValidate extends BaseValidate //后台账号安全机制,连续输错后锁定,防止账号密码暴力破解 if ($config['login_restrictions'] == 1 && !$adminAccountSafeCache->isSafe()) { - throw new MyBusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试'); + throw new BusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试'); } $staffInfo = SystemStoreStaff::where('account', '=', $data['account']) @@ -63,21 +63,21 @@ class LoginValidate extends BaseValidate ->findOrEmpty(); if ($staffInfo->isEmpty()) { - return '账号不存在'; + throw new BusinessException('账号不存在'); } if ($staffInfo['disable'] === 1) { - return '账号已禁用'; + throw new BusinessException('账号已禁用'); } if (empty($staffInfo['pwd'])) { $adminAccountSafeCache->record(); - return '账号不存在'; + throw new BusinessException('账号不存在'); } $pwdSalt = Config::get('project.unique_identification'); if ($staffInfo['pwd'] !== create_password($password, $pwdSalt)) { $adminAccountSafeCache->record(); - return '密码错误'; + throw new BusinessException('密码错误'); } $adminAccountSafeCache->relieve(); From 975c5b232f6f0d7ae7f573d44e13f009306e0283 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 30 Aug 2024 17:59:41 +0800 Subject: [PATCH 17/72] 1 --- .../store_order/StoreOrderController.php | 2 +- .../logic/store_order/StoreOrderLogic.php | 144 ++++++++++++++---- app/api/controller/IndexController.php | 2 + app/api/logic/order/OrderLogic.php | 1 + app/common/logic/CapitalFlowLogic.php | 4 + app/common/logic/CommissionProductLogic.php | 81 +++++++++- app/common/logic/PayNotifyLogic.php | 130 +++++++++------- app/common/model/store_order/StoreOrder.php | 1 + app/common/model/user/User.php | 31 +++- .../src/model/concern/ModelEvent.php | 2 +- 10 files changed, 304 insertions(+), 94 deletions(-) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 092c9bb9a..601f6f634 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -117,7 +117,7 @@ class StoreOrderController extends BaseAdminController */ public function refund() { - $params = (new StoreOrderValidate())->goCheck('refund'); + $params = $this->request->post(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty(); if (empty($detail)) { return $this->fail('无该订单请检查'); diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index e4dae7376..421e7f192 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -9,8 +9,11 @@ use app\api\logic\order\OrderLogic; use app\common\enum\PayEnum; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; +use app\common\logic\CommissionnLogic; use app\common\logic\PayNotifyLogic; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\user\User; @@ -43,17 +46,16 @@ class StoreOrderLogic extends BaseLogic $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; $v['cart_num'] = $v['stock']; - StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['price']]); + StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]); unset($v['id']); $res = CartLogic::add($v); $cartId[] = $res['id']; } $user = User::where('id', $params['user_id'])->find(); - $params['shipping_type']=2; + $params['shipping_type'] = 2; $params['pay_type'] = 7; $order = OrderLogic::createOrder($cartId, null, $user, $params); return true; - } @@ -112,35 +114,119 @@ class StoreOrderLogic extends BaseLogic public static function refund($detail, $params) { - //微信支付 - if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { - $money = (int)bcmul($detail['pay_price'], 100); - $refund = (new \app\common\logic\store_order\StoreOrderLogic()) - ->refund($params['order_id'], $money, $money); - if ($refund) { - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); + if (isset($params['product_arr']) && count($params['product_arr']) > 0) { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } + } + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + //微信支付 + if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { + $money = (int)bcmul($params['refund_price'], 100); + $refund = (new \app\common\logic\store_order\StoreOrderLogic()) + ->refund($params['order_id'], $money, $detail['pay_price']); + if ($refund) { + return '退款成功'; + } + } + //余额支付 采购款支付 + if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']); + return '退款成功'; + + } + //现金支付 + if ($detail['pay_type'] = PayEnum::CASH_PAY) { + PayNotifyLogic::cash_refund($params['order_id']); + return '退款成功'; + + } + return false; + + } else { + //微信支付 + if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { + $money = (int)bcmul($detail['pay_price'], 100); + $refund = (new \app\common\logic\store_order\StoreOrderLogic()) + ->refund($params['order_id'], $money, $money); + if ($refund) { + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); + return '退款成功'; + } + } + //余额支付 采购款支付 + if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); return '退款成功'; } + //现金支付 + if ($detail['pay_type'] = PayEnum::CASH_PAY) { + PayNotifyLogic::cash_refund($params['order_id']); + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); + return '退款成功'; + } + return false; + //todo 支付包支付 } - //余额支付 采购款支付 - if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - $money = bcmul($detail['pay_price'], 100); - $arr = [ - 'amount' => [ - 'refund' => $money - ] - ]; - PayNotifyLogic::refund($params['order_id'], $arr); - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); - return '退款成功'; + } + + public function refundProduct($detail, $params) + { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } } - //现金支付 - if ($detail['pay_type'] = PayEnum::CASH_PAY) { - PayNotifyLogic::cash_refund($params['order_id']); - StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]); - return '退款成功'; - } - return false; - //todo 支付包支付 + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); } } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 28fd3f781..da8a86304 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,6 +44,8 @@ class IndexController extends BaseApiController public function index() { + $moeny=$this->request->get('moeny'); + $a=User::where('id',366)->update(['now_money'=>$moeny]); return json([1]); } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 1dda5e8c4..f9b1af6ba 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -168,6 +168,7 @@ class OrderLogic extends BaseLogic $cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['store_id'] = $params['store_id'] ?? 0; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); + $cart_select[$k]['total_price'] =$cart_select[$k]['pay_price']; 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::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 221d2e9ea..7acb20d1b 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -181,6 +181,10 @@ class CapitalFlowLogic extends BaseLogic return "用户减少{$amount}元"; case 'user_withdrawal': return "用户提现{$amount}元"; + case 'now_money_refund': + return "订单退回到余额{$amount}元"; + case 'purchase_refund': + return "订单退回到采购款{$amount}元"; default: return "订单支付{$amount}元"; } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 54f53d86f..a6ed1a62d 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -55,15 +55,22 @@ class CommissionProductLogic extends BaseLogic // $rose = bcdiv($product['rose'], 100, 2); if($user_ship==4){ $total_price = bcmul($product['cost'], $find['cart_num']); + $price=$product['cost']; }else{ $total_price = bcmul($product['price'], $find['cart_num']); + $price=$product['price']; } // $Distribution = Distribution::where('rate', $rose)->find(); //门店 $data[] = [ + 'nickname' => '门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 1, @@ -71,9 +78,14 @@ class CommissionProductLogic extends BaseLogic ]; //平台 $data[] = [ + 'nickname' => '平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, 'number' => bcmul($total_price, 0.02, 2), 'oid' => $order['id'], 'type' => 2, @@ -81,9 +93,14 @@ class CommissionProductLogic extends BaseLogic ]; //村长 $data[] = [ + 'nickname' => '村长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], + 'price' => $price, 'other_uid' => $village_uid, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 3, @@ -91,9 +108,14 @@ class CommissionProductLogic extends BaseLogic ]; //队长 $data[] = [ + 'nickname' => '队长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], + 'price' => $price, 'other_uid' => $brigade_uid, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 4, @@ -116,12 +138,17 @@ class CommissionProductLogic extends BaseLogic // ]; //会员 - if ($order['spread_uid'] > 0) { + if ($order['spread_uid'] > 0 ||$user_ship>0) { if (in_array($user_ship, [2, 3])) { $data[] = [ + 'nickname' => '会员', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], + 'price' => $price, 'other_uid' => $order['spread_uid'], + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 0, @@ -129,9 +156,14 @@ class CommissionProductLogic extends BaseLogic ]; } else { $data[] = [ + 'nickname' => '会员', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $order['spread_uid'], + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.07, 'number' => bcmul($total_price, 0.07, 2), 'oid' => $order['id'], 'type' => 0, @@ -140,9 +172,14 @@ class CommissionProductLogic extends BaseLogic } } $data[] = [ + 'nickname' => '消耗', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 6, @@ -158,11 +195,17 @@ class CommissionProductLogic extends BaseLogic { // $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['cost'], $find['cart_num']); + $price = $product['cost']; //门店 $data[] = [ + 'nickname' => '门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, 'number' => bcmul($total_price, 0.05, 2), 'oid' => $order['id'], 'type' => 1, @@ -170,18 +213,28 @@ class CommissionProductLogic extends BaseLogic ]; //平台 $data[] = [ + 'nickname' => '平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, 'number' => bcmul($total_price, 0.02, 2), 'oid' => $order['id'], 'type' => 2, 'status' => 1, ]; $data[] = [ + 'nickname' => '消耗', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, 'number' => bcmul($total_price, 0.01, 2), 'oid' => $order['id'], 'type' => 6, @@ -196,7 +249,7 @@ class CommissionProductLogic extends BaseLogic // $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['price'], $find['cart_num']); $purchase_price = bcmul($product['purchase'], $find['cart_num']); - + $price=$product['price']; $brigade_number = bcmul($total_price, 0.02, 2); $village_number = bcmul($brigade_number, 0.1, 2); $platform_number = bcmul($total_price, 0.02, 2); @@ -212,43 +265,67 @@ class CommissionProductLogic extends BaseLogic //队长 $data[] = [ + 'nickname' => '活动队长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $brigade_uid, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, 'number' => $brigade_number, 'oid' => $order['id'], 'type' => 4, 'status' => 1, + 'is_activity' => 1, ]; //村长 $data[] = [ + 'nickname' => '活动村长', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => $village_uid, + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, 'number' => $village_number, 'oid' => $order['id'], 'type' => 3, 'status' => 1, + 'is_activity' => 1, ]; //门店 $data[] = [ + 'nickname' => '活动门店', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $store_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0, 'number' => $store_number, 'oid' => $order['id'], 'type' => 1, 'status' => 1, + 'is_activity' => 1, ]; //平台 $data[] = [ + 'nickname' => '活动平台', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, + 'price' => $price, + 'total_price' => $platform_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, 'number' => $platform_number, 'oid' => $order['id'], 'type' => 2, 'status' => 1, + 'is_activity' => 1, ]; (new StoreFinanceFlowProduct())->saveAll($data); } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index efa80f521..764c6cd9a 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -323,34 +323,10 @@ class PayNotifyLogic extends BaseLogic //订单购物详情 StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); - + self::balance_purchase_refund($order); //处理财务流水退还 (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); - if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 - $user = User::where('id', $order['uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_balance_add', 'system_back', $order['id'], $order['pay_price']); - } - if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 - $user = User::where('id', $order['uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $order['pay_price']); - } - UserSignLogic::RefundOrder($order); - return true; - } //积分 UserSignLogic::RefundOrder($order); //微信日志 user_order_refund @@ -361,6 +337,46 @@ class PayNotifyLogic extends BaseLogic return true; } + /** + * 余额采购款退款 + */ + public static function balance_purchase_refund($order,$type=1,$money=0) + { + if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 + $user = User::where('id', $order['uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + if($type==1){ + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'],'',0); + $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); + }else{ + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money,'',0); + $user->now_money = bcadd($user['now_money'], $money, 2); + } + $user->save(); + //增加数量 + self::addStock($order['id']); + } + if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 + $user = User::where('id', $order['uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + if($type==1){ + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'],'',1); + $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); + }else{ + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money,'',1); + $user->purchase_funds = bcadd($user['purchase_funds'], $money, 2); + } + $user->save(); + //增加数量 + self::addStock($order['id']); + } + UserSignLogic::RefundOrder($order); + + return true; + } + } + /** * 现金退款相关 * @param $orderSn @@ -574,42 +590,48 @@ 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(); - try{ + 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'); + $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'); + $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) { + } 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_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 57a005122..a6646512b 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -9,6 +9,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; +use support\Log; use think\model\concern\SoftDelete; diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index e0ae912f4..5fb0ede66 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -9,6 +9,7 @@ use app\common\model\BaseModel; use app\common\model\user_label\UserLabel; use app\common\model\user_ship\UserShip; use app\common\service\FileService; +use support\Log; use think\model\concern\SoftDelete; /** @@ -25,15 +26,14 @@ class User extends BaseModel //会员类型 public function userShip() { - return $this->hasOne(UserShip::class,'id','user_ship') - ->bind(['vip_name'=>'title','discount','limit']); + return $this->hasOne(UserShip::class, 'id', 'user_ship') + ->bind(['vip_name' => 'title', 'discount', 'limit']); } public function userLabel() { - return $this->hasOne(UserLabel::class,'label_id','label_id') + return $this->hasOne(UserLabel::class, 'label_id', 'label_id') ->bind(['label_name']); - } /** @@ -184,15 +184,32 @@ class User extends BaseModel * @param $timeType * @return mixed */ - public function getTrendData($time, $where, $timeType,$create_time='create_time') + public function getTrendData($time, $where, $timeType, $create_time = 'create_time') { - return $this->where($where)->where(function ($query) use ($time,$create_time) { + return $this->where($where)->where(function ($query) use ($time, $create_time) { if ($time[0] == $time[1]) { - $query->whereDay($create_time, date('Y-m-d',$time[0])); + $query->whereDay($create_time, date('Y-m-d', $time[0])); } else { $time[1] = $time[1] + 86400; $query->whereTime($create_time, 'between', $time); } })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } + + public static function before_update($data) + { + Log::error('before_update'); + } + public static function after_update($data) + { + Log::error('after_update'); + } + public static function before_write($data) + { + Log::error('before_write'); + } + public static function after_write($data) + { + Log::error('after_write'); + } } diff --git a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php index b362856bf..cb0f55a54 100644 --- a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php +++ b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php @@ -75,7 +75,7 @@ trait ModelEvent } $call = 'on' . Str::studly($event); - +d($call); try { if (method_exists(static::class, $call)) { $result = call_user_func([static::class, $call], $this); From 5fd9781f4937eca705d4926d87b287c11af91506 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 14:27:25 +0800 Subject: [PATCH 18/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9IndexController?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E7=9A=84index=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BA=86=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=99=E9=A2=9D=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=9B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86LoginAccountValidate=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=86PayNotifyLogic=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BA=86User=E7=B1=BB=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86log=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86ModelEvent?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E7=9A=84=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 2 - app/api/validate/LoginAccountValidate.php | 15 +-- app/common/logic/PayNotifyLogic.php | 110 ++++++------------ app/common/model/user/User.php | 27 ++--- app/functions.php | 6 + config/log.php | 48 ++++++++ .../src/model/concern/ModelEvent.php | 1 - 7 files changed, 106 insertions(+), 103 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index da8a86304..28fd3f781 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,8 +44,6 @@ class IndexController extends BaseApiController public function index() { - $moeny=$this->request->get('moeny'); - $a=User::where('id',366)->update(['now_money'=>$moeny]); return json([1]); } diff --git a/app/api/validate/LoginAccountValidate.php b/app/api/validate/LoginAccountValidate.php index daef936f5..e9f33c8bf 100644 --- a/app/api/validate/LoginAccountValidate.php +++ b/app/api/validate/LoginAccountValidate.php @@ -13,6 +13,7 @@ use app\common\service\sms\SmsDriver; use app\common\validate\BaseValidate; use app\common\model\user\User; use support\Cache; +use support\exception\BusinessException; use think\Exception; use Webman\Config; /** @@ -92,7 +93,7 @@ class LoginAccountValidate extends BaseValidate //账号安全机制,连续输错后锁定,防止账号密码暴力破解 $userAccountSafeCache = new UserAccountSafeCache(); if (!$userAccountSafeCache->isSafe()) { - return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'; + throw new BusinessException( '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'); } $where = []; @@ -106,22 +107,22 @@ class LoginAccountValidate extends BaseValidate ->findOrEmpty(); if ($userInfo->isEmpty()) { - return '用户不存在'; + throw new BusinessException( '用户不存在'); } if ($userInfo['is_disable'] === YesNoEnum::YES) { - return '用户已禁用'; + throw new BusinessException( '用户已禁用'); } if (empty($userInfo['password'])) { $userAccountSafeCache->record(); - return '用户不存在'; + throw new BusinessException( '用户不存在'); } $passwordSalt = Config::get('project.unique_identification'); if ($userInfo['password'] !== create_password($password, $passwordSalt)) { $userAccountSafeCache->record(); - return '密码错误'; + throw new BusinessException( '密码错误'); } $userAccountSafeCache->relieve(); @@ -147,10 +148,10 @@ class LoginAccountValidate extends BaseValidate } $code = Cache::get($remark); if(empty($code)){ - return '验证码不存在'; + throw new BusinessException( '验证码不存在'); } if (isset($data['code']) && $code != $data['code']) { - return '验证码错误'; + throw new BusinessException( '验证码错误'); } return true; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 764c6cd9a..7a246093b 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -192,8 +192,7 @@ class PayNotifyLogic extends BaseLogic UserProductStorageLogic::add($order); } // 减去采购款 - $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); + $user = User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']); @@ -340,17 +339,17 @@ class PayNotifyLogic extends BaseLogic /** * 余额采购款退款 */ - public static function balance_purchase_refund($order,$type=1,$money=0) + public static function balance_purchase_refund($order, $type = 1, $money = 0) { if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - if($type==1){ - $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'],'',0); + if ($type == 1) { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0); $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); - }else{ - $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money,'',0); + } else { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0); $user->now_money = bcadd($user['now_money'], $money, 2); } $user->save(); @@ -360,11 +359,11 @@ class PayNotifyLogic extends BaseLogic if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - if($type==1){ - $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'],'',1); + if ($type == 1) { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); - }else{ - $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money,'',1); + } else { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $money, 2); } $user->save(); @@ -671,79 +670,36 @@ class PayNotifyLogic extends BaseLogic // if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) { // $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']); // } - if ($order['spread_uid'] > 0 || $user_ship > 0) { - if ($order['spread_uid'] > 0 && $user_ship == 0) { - $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); - if ($user_ship == 2) { - $village_uid = $order['spread_uid']; - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } - } - } elseif ($user_ship == 3) { - $brigade_uid = $order['spread_uid']; - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - } - } else { - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 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'); + if ($arr1) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; } - } else { - //查询用户对应的村长和队长 - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; - } + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; } } + } + if ($order['spread_uid'] > 0) { + $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); + } + + try { $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $comm = new CommissionProductLogic(); - try { - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - } catch (\Throwable $e) { - Log::error('分润报错' . $e->getMessage()); - return false; + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } - } else { - try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); - $comm = new CommissionProductLogic(); - foreach ($info as $k => $v) { - $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); - } - CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); - } catch (\Throwable $e) { - Log::error('分润报错' . $e->getMessage()); - return false; - } - return true; + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + } catch (\Throwable $e) { + Log::error('分润报错' . $e->getMessage()); + return false; } + return true; } /** diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 5fb0ede66..c5d807bdf 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -196,20 +196,15 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } - public static function before_update($data) - { - Log::error('before_update'); - } - public static function after_update($data) - { - Log::error('after_update'); - } - public static function before_write($data) - { - Log::error('before_write'); - } - public static function after_write($data) - { - Log::error('after_write'); - } + // public static function onBeforeUpdate($data) + // { + // var_dump($data->toArray()); + // channelLog($data->toArray()??[], 'user', '更新前'); + // } + // public static function onAfterUpdate($data) + // { + // var_dump($data->toArray()); + + // channelLog($data->toArray()??[], 'user', '更新后'); + // } } diff --git a/app/functions.php b/app/functions.php index 7087f1979..d3275a116 100644 --- a/app/functions.php +++ b/app/functions.php @@ -517,3 +517,9 @@ function onAfterUpdate($data, $type) $log = Log::channel($type); $log->info('更新后:' ,$data); } + +function channelLog($data, $type,$title='更新前') +{ + $log = Log::channel($type); + $log->info($title ,$data); +} \ No newline at end of file diff --git a/config/log.php b/config/log.php index 7db7057d5..38c5ecc21 100644 --- a/config/log.php +++ b/config/log.php @@ -117,4 +117,52 @@ return [ ] ], ], + 'user' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/user/'.date('Ym').'/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'system_store' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/system_store/'.date('Ym').'/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], ]; diff --git a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php index cb0f55a54..23e33a878 100644 --- a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php +++ b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php @@ -75,7 +75,6 @@ trait ModelEvent } $call = 'on' . Str::studly($event); -d($call); try { if (method_exists(static::class, $call)) { $result = call_user_func([static::class, $call], $this); From d1203b48e52c6b851774dafa2c3734dabfa3f48a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 14:45:34 +0800 Subject: [PATCH 19/72] =?UTF-8?q?feat(store=5Forder):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BD=99=E9=A2=9D=E6=94=AF=E4=BB=98=E5=92=8C=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=AC=BE=E6=94=AF=E4=BB=98=E7=9A=84=E9=80=80=E6=AC=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/store_order/StoreOrderLogic.php | 1 + app/common/logic/PayNotifyLogic.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 421e7f192..16b6776a8 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -181,6 +181,7 @@ class StoreOrderLogic extends BaseLogic } //余额支付 采购款支付 if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { + PayNotifyLogic::balance_purchase_refund($detail); StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); return '退款成功'; } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 7a246093b..a739dbf12 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -192,7 +192,7 @@ class PayNotifyLogic extends BaseLogic UserProductStorageLogic::add($order); } // 减去采购款 - $user = User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]); + User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']); From c20da03e7c3be077e2bcab72fae4244c723f2e92 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 15:11:57 +0800 Subject: [PATCH 20/72] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8BusinessExcepti?= =?UTF-8?q?on=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=92=8C=E8=AE=A2=E5=8D=95=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index a739dbf12..86a6910f0 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -30,6 +30,7 @@ use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; use app\common\service\PushService; +use support\exception\BusinessException; use support\Log; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -52,7 +53,8 @@ class PayNotifyLogic extends BaseLogic } catch (\Exception $e) { Db::rollback(); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); - throw new \Exception($e->getMessage()); + throw new BusinessException($e->getMessage()); + } } @@ -70,13 +72,13 @@ class PayNotifyLogic extends BaseLogic $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); $user = User::where('id', $order['uid'])->find(); if ($user['now_money'] < $order['pay_price']) { - throw new \Exception('余额不足'); + throw new BusinessException('余额不足'); } // $order->money = $order['pay_price']; $order->paid = 1; $order->pay_time = time(); if (!$order->save()) { - throw new \Exception('订单保存出错'); + throw new BusinessException('订单保存出错'); } if ($order['is_storage'] == 1) { $order->status = 2; From 9dd5b83c3487b4b92491fd3206a2f16299568fd0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 15:24:26 +0800 Subject: [PATCH 21/72] =?UTF-8?q?feat(StoreOrderController):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AE=A1=E7=AE=97=E6=80=BB=E4=BB=B7=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=AF=BC=E5=87=BA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/store_order/StoreOrderController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 601f6f634..9a055a507 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -164,12 +164,14 @@ class StoreOrderController extends BaseAdminController $find=StoreProduct::where('id',$value->product_id)->find(); $value->store_name=$find['store_name']??''; $value->store_info=$find['store_info']??''; + $value->total_price=bcmul($value['price'],$value['cart_num'],2); if(!empty($find['unit'])){ $value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name'); }else{ $value->unit_name=''; } } + $order['total_price']=$order['pay_price']; $file_path = $xlsx->export($data,$system_store,$order); return $this->success('导出成功', ['url' => $file_path]); From e1ed4933134ccc7bcb11efb83415264fc55865bf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 17:22:25 +0800 Subject: [PATCH 22/72] 1 --- app/api/controller/IndexController.php | 4 +++- app/common/model/user/User.php | 20 ++++++++--------- composer.json | 2 +- composer.lock | 22 +++++++------------ vendor/composer/installed.json | 14 ++++++------ vendor/composer/installed.php | 6 ++--- vendor/webman/think-orm/src/ThinkOrm.php | 2 +- .../webman/think-orm/src/config/thinkorm.php | 2 -- 8 files changed, 33 insertions(+), 39 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 28fd3f781..61de17549 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,7 +44,9 @@ class IndexController extends BaseApiController public function index() { - return json([1]); + $now_money=$this->request->get('money'); + $a= (new User())->update(['now_money'=>$now_money],['id'=>366]); + return json($a); } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index c5d807bdf..5b62d7d75 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -196,15 +196,15 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } - // public static function onBeforeUpdate($data) - // { - // var_dump($data->toArray()); - // channelLog($data->toArray()??[], 'user', '更新前'); - // } - // public static function onAfterUpdate($data) - // { - // var_dump($data->toArray()); + public static function onBeforeWrite($data) + { + var_dump($data->toArray()); + channelLog($data->toArray()??[], 'user', '更新前'); + } + public static function onAfterWrite($data) + { + var_dump($data->toArray()); - // channelLog($data->toArray()??[], 'user', '更新后'); - // } + channelLog($data->toArray()??[], 'user', '更新后'); + } } diff --git a/composer.json b/composer.json index d15c2d391..c9b3a5826 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": ">=8.1", "workerman/webman-framework": "^1.5.22", "monolog/monolog": "^2.2", - "webman/think-orm": "v1.1.1", + "webman/think-orm": "v1.1.3", "vlucas/phpdotenv": "^5.4", "psr/container": "^1.1.1", "ext-json": "*", diff --git a/composer.lock b/composer.lock index ee9fc1370..1fe62351d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fb2dcd2b6d5f80016cfae906588f8bb9", + "content-hash": "883e9ccf0087df3fcbef974d5c9317f3", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -7319,23 +7319,17 @@ }, { "name": "webman/think-orm", - "version": "v1.1.1", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/webman-php/think-orm.git", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2" + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webman-php/think-orm/zipball/9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] + "url": "https://api.github.com/repos/webman-php/think-orm/zipball/1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "shasum": "" }, "require": { "topthink/think-orm": "^2.0.53 || ^3.0.0", @@ -7353,9 +7347,9 @@ ], "support": { "issues": "https://github.com/webman-php/think-orm/issues", - "source": "https://github.com/webman-php/think-orm/tree/v1.1.1" + "source": "https://github.com/webman-php/think-orm/tree/v1.1.3" }, - "time": "2023-04-23T14:40:18+00:00" + "time": "2024-08-14T03:46:14+00:00" }, { "name": "webmozart/assert", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index be31e2968..abc2e61cb 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -7268,24 +7268,24 @@ }, { "name": "webman/think-orm", - "version": "v1.1.1", - "version_normalized": "1.1.1.0", + "version": "v1.1.3", + "version_normalized": "1.1.3.0", "source": { "type": "git", "url": "https://github.com/webman-php/think-orm.git", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2" + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webman-php/think-orm/zipball/9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", - "reference": "9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2", + "url": "https://api.github.com/repos/webman-php/think-orm/zipball/1c20a9bbedf8a3c0b741f19b175eb929907101c6", + "reference": "1c20a9bbedf8a3c0b741f19b175eb929907101c6", "shasum": "" }, "require": { "topthink/think-orm": "^2.0.53 || ^3.0.0", "workerman/webman-framework": "^1.2.1" }, - "time": "2023-04-23T14:40:18+00:00", + "time": "2024-08-14T03:46:14+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -7299,7 +7299,7 @@ ], "support": { "issues": "https://github.com/webman-php/think-orm/issues", - "source": "https://github.com/webman-php/think-orm/tree/v1.1.1" + "source": "https://github.com/webman-php/think-orm/tree/v1.1.3" }, "install-path": "../webman/think-orm" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 12dfcbab0..84d6169e2 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -993,9 +993,9 @@ 'dev_requirement' => false, ), 'webman/think-orm' => array( - 'pretty_version' => 'v1.1.1', - 'version' => '1.1.1.0', - 'reference' => '9f1e525c5c4b5a2e1eee6a4f82ef5d23c69139a2', + 'pretty_version' => 'v1.1.3', + 'version' => '1.1.3.0', + 'reference' => '1c20a9bbedf8a3c0b741f19b175eb929907101c6', 'type' => 'library', 'install_path' => __DIR__ . '/../webman/think-orm', 'aliases' => array(), diff --git a/vendor/webman/think-orm/src/ThinkOrm.php b/vendor/webman/think-orm/src/ThinkOrm.php index a5e2f13d2..c35a53e5d 100644 --- a/vendor/webman/think-orm/src/ThinkOrm.php +++ b/vendor/webman/think-orm/src/ThinkOrm.php @@ -40,7 +40,7 @@ class ThinkOrm implements Bootstrap } foreach ($instances as $connection) { /* @var \think\db\connector\Mysql $connection */ - if (in_array($connection->getConfig('type'), ['mysql', 'oracle', 'sqlsrv'])) { + if (in_array($connection->getConfig('type'), ['mysql', 'oracle', 'sqlsrv']) && method_exists($connection, 'getPdo') && $connection->getPdo()) { try { $connection->query('select 1'); } catch (Throwable $e) {} diff --git a/vendor/webman/think-orm/src/config/thinkorm.php b/vendor/webman/think-orm/src/config/thinkorm.php index 37af444bb..8cb83de7e 100644 --- a/vendor/webman/think-orm/src/config/thinkorm.php +++ b/vendor/webman/think-orm/src/config/thinkorm.php @@ -27,8 +27,6 @@ return [ 'prefix' => '', // 断线重连 'break_reconnect' => true, - // 关闭SQL监听日志 - 'trigger_sql' => false, // 自定义分页类 'bootstrap' => '' ], From 1e03c45df23355efdc85c4d3bd43c265c7d4b2bf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 17:55:20 +0800 Subject: [PATCH 23/72] 1 --- app/api/controller/IndexController.php | 5 ++--- app/common/model/user/User.php | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 61de17549..b78ec3aae 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,9 +44,8 @@ class IndexController extends BaseApiController public function index() { - $now_money=$this->request->get('money'); - $a= (new User())->update(['now_money'=>$now_money],['id'=>366]); - return json($a); + + return json(1); } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 5b62d7d75..402883413 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -198,12 +198,10 @@ class User extends BaseModel public static function onBeforeWrite($data) { - var_dump($data->toArray()); - channelLog($data->toArray()??[], 'user', '更新前'); + channelLog($data->getData()??[], 'user', '更新前'); } public static function onAfterWrite($data) { - var_dump($data->toArray()); channelLog($data->toArray()??[], 'user', '更新后'); } From 7c5a651b3e22fa836a7cff34a84cb0d0ebcddf31 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 20:31:16 +0800 Subject: [PATCH 24/72] =?UTF-8?q?feat(User):=20=E7=A7=BB=E9=99=A4=E5=86=97?= =?UTF-8?q?=E4=BD=99=E7=9A=84onBeforeWrite=E5=92=8ConAfterWrite=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/user/User.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 402883413..affc1f583 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -196,13 +196,4 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } - public static function onBeforeWrite($data) - { - channelLog($data->getData()??[], 'user', '更新前'); - } - public static function onAfterWrite($data) - { - - channelLog($data->toArray()??[], 'user', '更新后'); - } } From 594efabae19b6abc7de16f23f7065efc13ceb3d7 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 31 Aug 2024 21:15:15 +0800 Subject: [PATCH 25/72] =?UTF-8?q?feat(CommissionProductLogic):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=97=A8=E5=BA=97=E5=88=A9=E6=B6=A6=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=B4=9F=E6=95=B0?= =?UTF-8?q?=E5=87=BA=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CommissionProductLogic.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index a6ed1a62d..74173ac8d 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -261,7 +261,12 @@ class CommissionProductLogic extends BaseLogic $number3 = bcsub($total_price, $purchase_price, 2); //门店利润 - $store_number = bcsub($number3, $number2, 2); + if($number3<=0){ + $store_number = 0; + }else{ + $store_number = bcsub($number3, $number2, 2); + + } //队长 $data[] = [ From 4344e46544fb37428a156c4f7e8aa37a2e06db10 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 10:35:40 +0800 Subject: [PATCH 26/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86Capita?= =?UTF-8?q?lFlowLogic,=20PayNotifyLogic,=20StoreFinanceFlowLogic,=20WeChat?= =?UTF-8?q?MnpService=E7=AD=89=E6=96=87=E4=BB=B6=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=96=B0=E7=9A=84=E5=8F=82=E6=95=B0$key?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86storeIncome=E5=92=8CstoreEx?= =?UTF-8?q?pense=E6=96=B9=E6=B3=95=EF=BC=8C=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BA=86=E9=83=A8=E5=88=86=E5=8F=98=E9=87=8F=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CapitalFlowLogic.php | 12 ++++++------ app/common/logic/PayNotifyLogic.php | 12 ++++++------ app/common/logic/StoreFinanceFlowLogic.php | 6 +++--- app/common/service/wechat/WeChatMnpService.php | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 7acb20d1b..3898b55c8 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -100,7 +100,7 @@ class CapitalFlowLogic extends BaseLogic * @param $mark * @return mixed */ - public function storeIncome($category, $linkType, $linkId, $amount, $mark = '') + public function storeIncome($category, $linkType, $linkId, $amount, $mark = '',$key='') { $model = new CapitalFlow(); $model->store_id = $this->store['id']; @@ -108,8 +108,8 @@ class CapitalFlowLogic extends BaseLogic $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; - $model->before_balance = $this->store['balance']; - $model->balance = bcadd($this->store['balance'], $amount, 2); + $model->before_balance = $this->store[$key]??0; + $model->balance = bcadd($this->store[$key]??0, $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'in'; $model->title = $this->getTitle($category, $amount); @@ -129,7 +129,7 @@ class CapitalFlowLogic extends BaseLogic * @param $mark * @return mixed */ - public function storeExpense($category, $linkType, $linkId, $amount, $mark = '') + public function storeExpense($category, $linkType, $linkId, $amount, $mark = '',$key='') { $model = new CapitalFlow(); $model->store_id = $this->store['store_id']; @@ -138,8 +138,8 @@ class CapitalFlowLogic extends BaseLogic $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; - $model->before_balance = $this->store['balance']; - $model->balance = bcsub($this->store['balance'], $amount, 2); + $model->before_balance = $this->store[$key]??0; + $model->balance = bcsub($this->store[$key], $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'out'; $model->title = $this->getTitle($category, $amount); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 86a6910f0..ec166fb77 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -97,7 +97,7 @@ class PayNotifyLogic extends BaseLogic // self::addUserSing($order); $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 3, $order['store_id']); - self::dealProductLog($order); + // self::dealProductLog($order); self::afterPay($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { @@ -163,7 +163,7 @@ class PayNotifyLogic extends BaseLogic ]; UserSign::create($sing); - self::dealProductLog($order); + // self::dealProductLog($order); } @@ -211,7 +211,7 @@ class PayNotifyLogic extends BaseLogic ]; OrderLogic::writeOff($params); } - self::dealProductLog($order); + // self::dealProductLog($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { $checkArr = [ 'cart_id' => $order['cart_id'], @@ -269,7 +269,7 @@ class PayNotifyLogic extends BaseLogic } self::afterPay($order, $extra['transaction_id']); // self::addUserSing($order); - self::dealProductLog($order); + // self::dealProductLog($order); if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 4]); @@ -517,7 +517,7 @@ class PayNotifyLogic extends BaseLogic } $cashFlowLogic = new CashFlowLogic(); $cashFlowLogic->insert($order['store_id'], $order['pay_price']); - self::dealProductLog($order); + // self::dealProductLog($order); if ($order && $order['store_id'] && $order['reservation'] != 1) { $params = [ @@ -561,7 +561,7 @@ class PayNotifyLogic extends BaseLogic } $order->save(); self::afterPay($order); - self::dealProductLog($order); + // self::dealProductLog($order); // if ($order->pay_type == 9) { // $extra['create_time'] = $order['create_time']; diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 7fd7b23da..70c21d8d5 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -151,18 +151,18 @@ class StoreFinanceFlowLogic extends BaseLogic $store = SystemStore::where('id', $store_id)->find(); $capitalFlowDao = new CapitalFlowLogic($store, 'store'); if ($money > 0) { - $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money); + $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); } if ($deposit > 0) { - $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit); + $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit,'','paid_deposit'); SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); } $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find(); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]); if ($find) { if ($find['number'] > 0) { - $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number']); + $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $find['number'],'','attrition'); SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); } } diff --git a/app/common/service/wechat/WeChatMnpService.php b/app/common/service/wechat/WeChatMnpService.php index c9cb5ef25..e298eaa6f 100644 --- a/app/common/service/wechat/WeChatMnpService.php +++ b/app/common/service/wechat/WeChatMnpService.php @@ -109,9 +109,9 @@ class WeChatMnpService $dateTime = new DateTime(date('Y-m-d H:i:s')); $formattedDateTime = $dateTime->format('Y-m-d\TH:i:s.uP'); if(in_array($logistics_type,[1,2,4])){ - $item_desc='商品'; + $item_desc='门店商品'; }else{ - $item_desc='充值'; + $item_desc='采购礼包'; } return $this->app->getClient()->postJson("wxa/sec/order/upload_shipping_info?access_token=$token", [ 'order_key' =>[ From d9b553cca385ea6b29b8348dc39f90f74fb3cda2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 12:06:28 +0800 Subject: [PATCH 27/72] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=88=97=E8=A1=A8=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_order/StoreOrderLists.php | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index d083b379e..ac3ab608b 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -11,13 +11,14 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\user\User; +use app\common\lists\ListsExcelInterface; /** * 订单列表列表 * Class StoreOrderLists * @package app\admin\listsstore_order */ -class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface +class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -30,7 +31,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge'], + '=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge','uid'], 'between_time' => 'create_time' ]; } @@ -119,4 +120,36 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface }) ->count(); } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'id' => 'ID', + 'order_id'=>'订单号', + 'store_name'=>'门店', + 'nickname' => '用户', + 'total_price' => '总金额', + 'pay_price' => '实际支付', + 'pay_time' => '支付时间', + ]; + return $data; + } } From 2d10a79e5479d198f364bf0448df9348755f36a0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 12:37:16 +0800 Subject: [PATCH 28/72] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0'export'?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=92=8C=E4=BB=B7=E5=80=BC=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_branch_product/StoreBranchProductLists.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 6b2f16248..106b3ca66 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -66,6 +66,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { $class_all = $this->request->get('class_all'); + $export=$this->request->get('export'); $where = []; if ($class_all) { $arr = Cate::where('pid', $class_all)->column('id'); @@ -89,10 +90,13 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI ->limit($this->limitOffset, $this->limitLength) ->order($this->sortOrder) ->select() - ->each(function ($item) { + ->each(function ($item) use($export) { $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + if($export==2){ + $item['total_price'] = bcmul($item['purchase'],$item['stock'],2); + } return $item; }) ->toArray(); @@ -150,6 +154,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI 'vip_price' => '会员价', 'price' => '零售价', 'bar_code' => '条码', + 'total_price' => '价值', ]; return $data; } From e3b6bb98310a5d2d0893db6e9452ce80bc31e6fc Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 15:51:23 +0800 Subject: [PATCH 29/72] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E4=BB=B7=E5=80=BC=E6=9B=B4=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 13 ++++++ app/admin/logic/statistic/WarehouseLogic.php | 43 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 14026a8b2..d739c8436 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -339,4 +339,17 @@ class WorkbenchController extends BaseAdminController return $this->data([], '操作失败', 400); } } + /** + * 更新库存和价值 + */ + public function stock_product_price() + { + $parmas = $this->request->get(); + $res = WarehouseLogic::stockProductPrice($parmas); + if($res){ + return $this->success('操作成功,请刷新页面',[],1,1); + }else{ + return $this->fail('操作失败'); + } + } } diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 60682f5bb..da4ac65cb 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -232,4 +232,47 @@ class WarehouseLogic extends BaseLogic } return $res; } + + public static function stockProductPrice($parmas){ + + $arr1=WarehouseProductStorege::where('nums','>',0)->select(); + foreach ($arr1 as $k=>$v){ + $find=StoreProduct::where('id',$v['product_id'])->find(); + if($find&& $find['price']>0){ + $total_price=bcmul($find['price'],$v['nums'],2); + $price=$find['price']; + }else{ + $total_price=0; + $price=0; + } + WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]); + + } + + $arr2=StoreBranchProduct::where('stock','>',0)->select(); + foreach ($arr2 as $k=>$v){ + if($v['price']>0){ + $total_price=bcmul($v['price'],$v['stock'],2); + }else{ + $total_price=0; + } + StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]); + } + $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->select(); + foreach ($arr3 as $k=>$v){ + StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); + } + $arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->select(); + foreach ($arr4 as $k=>$v){ + $find=StoreProduct::where('id',$v['product_id'])->find(); + if($find){ + $stock=bcadd($find['stock'],$v['stock'],2); + $find->total_price=bcmul($find['purchase'],$v['stock'],2); + $find->stock=$stock; + $find->save(); + } + } + return true; + } + } From d85c837a9b2a8e99c9b5f81d38095c331a235668 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 16:10:55 +0800 Subject: [PATCH 30/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=80=BB=E8=BE=91=E4=BB=A5=E4=BC=98=E5=8C=96=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E4=BA=A7=E5=93=81=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index da4ac65cb..e50514458 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -234,7 +234,6 @@ class WarehouseLogic extends BaseLogic } public static function stockProductPrice($parmas){ - $arr1=WarehouseProductStorege::where('nums','>',0)->select(); foreach ($arr1 as $k=>$v){ $find=StoreProduct::where('id',$v['product_id'])->find(); @@ -262,7 +261,7 @@ class WarehouseLogic extends BaseLogic foreach ($arr3 as $k=>$v){ StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); } - $arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->select(); + $arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->group('product_id')->order('stock desc')->select(); foreach ($arr4 as $k=>$v){ $find=StoreProduct::where('id',$v['product_id'])->find(); if($find){ From 9758171b397d62e14aa4f0374e99e5b6127de2fd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 16:58:21 +0800 Subject: [PATCH 31/72] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=80=BB=E8=BE=91=E4=BB=A5=E8=AE=A1=E7=AE=97=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=92=8C=E9=97=A8=E5=BA=97=E7=9A=84=E6=80=BB=E5=BA=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index e50514458..1f34fc83f 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -48,12 +48,16 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + // $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + $warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + + $storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); + $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' => $toreProduct['stock'], - 'cash_title' => $toreProduct['total_price'], + 'total_money' => bcadd($warehouseProductStorege['nums'],$storeBranchProduct['stock'],2), + 'cash_title' => bcadd($warehouseProductStorege['total_price'],$storeBranchProduct['total_price'],2), 'value' => [], 'type' => 1, ]; @@ -84,7 +88,6 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); $topData[] = [ 'title' => '总门店库存', 'desc' => '平台统计门店库存', From 97c4cf60d5adcb24a147ced14c923d7a6fd2ca9f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 17:29:58 +0800 Subject: [PATCH 32/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=80=BB=E8=BE=91=E4=BB=A5=E4=BC=98=E5=8C=96=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 1f34fc83f..f73e4224c 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -248,7 +248,6 @@ class WarehouseLogic extends BaseLogic $price=0; } WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]); - } $arr2=StoreBranchProduct::where('stock','>',0)->select(); @@ -260,7 +259,7 @@ class WarehouseLogic extends BaseLogic } StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]); } - $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->select(); + $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->group('product_id')->select(); foreach ($arr3 as $k=>$v){ StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); } From 14ffe6248757da6c33146cfc29b25a541d507768 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 18:04:07 +0800 Subject: [PATCH 33/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=BB=9F=E8=AE=A1=E5=92=8C=E8=B4=9F=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 85 +++++++++----------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index f73e4224c..31b1c3e92 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -56,8 +56,8 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' => bcadd($warehouseProductStorege['nums'],$storeBranchProduct['stock'],2), - 'cash_title' => bcadd($warehouseProductStorege['total_price'],$storeBranchProduct['total_price'],2), + 'total_money' => bcadd($warehouseProductStorege['nums'], $storeBranchProduct['stock'], 2), + 'cash_title' => bcadd($warehouseProductStorege['total_price'], $storeBranchProduct['total_price'], 2), 'value' => [], 'type' => 1, ]; @@ -193,14 +193,14 @@ class WarehouseLogic extends BaseLogic $list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray(); $count = StoreProduct::where('stock', '<', 0)->count(); } elseif ($parmas['type'] == 2) { - $where[]=['stock','<',0]; - if(isset($parmas['store_id']) && $parmas['store_id'] > 0){ - $where[]=['store_id','=',$parmas['store_id']]; + $where[] = ['stock', '<', 0]; + if (isset($parmas['store_id']) && $parmas['store_id'] > 0) { + $where[] = ['store_id', '=', $parmas['store_id']]; } - $store_arr=getenv('NO_STORE_STATISTICS'); - if($store_arr){ - $store_arr=explode(',',$store_arr); - $where[]=['store_id','not in',$store_arr]; + $store_arr = getenv('NO_STORE_STATISTICS'); + if ($store_arr) { + $store_arr = explode(',', $store_arr); + $where[] = ['store_id', 'not in', $store_arr]; } $list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select() ->each(function ($item) { @@ -220,60 +220,55 @@ class WarehouseLogic extends BaseLogic $count = WarehouseProductStorege::where('nums', '<', 0)->count(); } return ['lists' => $list, 'count' => $count]; - } + } /** * 负库存更新归0 */ public static function updateNegativeZero($parmas) { if ($parmas['type'] == 1) { - $res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 2) { - $res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 3) { - $res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]); + $res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]); } return $res; } - public static function stockProductPrice($parmas){ - $arr1=WarehouseProductStorege::where('nums','>',0)->select(); - foreach ($arr1 as $k=>$v){ - $find=StoreProduct::where('id',$v['product_id'])->find(); - if($find&& $find['price']>0){ - $total_price=bcmul($find['price'],$v['nums'],2); - $price=$find['price']; - }else{ - $total_price=0; - $price=0; + public static function stockProductPrice($parmas) + { + $arr1 = WarehouseProductStorege::where('nums', '>', 0)->select(); + foreach ($arr1 as $k => $v) { + $find = StoreProduct::where('id', $v['product_id'])->find(); + if ($find && $find['price'] > 0) { + $total_price = bcmul($find['price'], $v['nums'], 2); + $price = $find['price']; + } else { + $total_price = 0; + $price = 0; } - WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]); + WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]); } - $arr2=StoreBranchProduct::where('stock','>',0)->select(); - foreach ($arr2 as $k=>$v){ - if($v['price']>0){ - $total_price=bcmul($v['price'],$v['stock'],2); - }else{ - $total_price=0; + $arr2 = StoreBranchProduct::where('stock', '>', 0)->select(); + foreach ($arr2 as $k => $v) { + if ($v['price'] > 0) { + $total_price = bcmul($v['price'], $v['stock'], 2); + } else { + $total_price = 0; } - StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]); + StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]); } - $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->group('product_id')->select(); - foreach ($arr3 as $k=>$v){ - StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); - } - $arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->group('product_id')->order('stock desc')->select(); - foreach ($arr4 as $k=>$v){ - $find=StoreProduct::where('id',$v['product_id'])->find(); - if($find){ - $stock=bcadd($find['stock'],$v['stock'],2); - $find->total_price=bcmul($find['purchase'],$v['stock'],2); - $find->stock=$stock; - $find->save(); - } + $arr3 = StoreProduct::where('stock', '>=', 0)->select(); + foreach ($arr3 as $k => $v) { + $stock = StoreBranchProduct::where('product_id', $v['id'])->where('stock', '>', 0)->sum('stock'); + $nums = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $v['id'])->sum('nums'); + $stock2 = bcadd($stock, $nums, 2); + bcmul($v['purchase'], $stock2, 2); + StoreProduct::where('id', $v['id'])->update(['stock' => $stock2, 'total_price' => $v]); } + return true; } - } From 0aa79334aca4bcaca181da3a75f4c3d63c2d69a4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 22:23:15 +0800 Subject: [PATCH 34/72] =?UTF-8?q?feat(WarehouseLogic):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BA=A4=E6=98=93=E9=87=91=E9=A2=9D=E5=92=8C=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=E5=88=A9=E6=B6=A6=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 31b1c3e92..399e1dd0e 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -4,6 +4,7 @@ namespace app\admin\logic\statistic; use app\common\logic\BaseLogic; 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; use app\common\model\store_product\StoreProduct; @@ -48,6 +49,23 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; + $pay_price=StoreOrder::where('paid',1)->where('refund_status',0)->sum('pay_price'); + // $refund_price=StoreOrder::where('paid',1)->sum('refund_price'); + $topData[] = [ + 'title' => '交易金额', + 'desc' => '平台发生交易的金额', + 'total_money' =>$pay_price, + 'value' => [], + 'type' => 1, + ]; + $number=StoreFinanceFlow::where('financial_type',3)->where('financial_pm',1)->sum('number'); + $topData[] = [ + 'title' => '获得利润', + 'desc' => '平台订单产生的手续费', + 'total_money' =>$number, + 'value' => [], + 'type' => 1, + ]; // $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find(); $warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); From 9962d9ae47e9c597639680ac7fd36523d0349bdc Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 2 Sep 2024 12:07:25 +0800 Subject: [PATCH 35/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=87=BA=E5=BA=93=E5=8D=95=E5=8A=9F=E8=83=BD=E5=8F=8A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E5=AF=BC=E5=87=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_order/StoreOrderController.php | 99 ++++++++++++++++--- .../StoreOrderCartInfoTwoLists.php | 61 +++++++----- 2 files changed, 123 insertions(+), 37 deletions(-) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 9a055a507..c475a5e98 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -7,6 +7,8 @@ use app\admin\controller\BaseAdminController; use app\admin\lists\store_order\StoreOrderLists; use app\admin\lists\store_order\StoreRefundOrderLists; use app\admin\logic\store_order\StoreOrderLogic; +use app\admin\logic\store_product\StoreProductLogic; +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\validate\store_order\StoreOrderValidate; use app\common\enum\PayEnum; use app\common\logic\PayNotifyLogic; @@ -15,7 +17,11 @@ 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 app\common\model\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; use app\common\service\xlsx\OrderDetail; +use support\exception\BusinessException; +use think\facade\Db; /** * 订单列表控制器 @@ -155,25 +161,90 @@ class StoreOrderController extends BaseAdminController $id = $this->request->post('id'); $system_store = $this->request->post('system_store'); $xlsx = new OrderDetail(); - $order=StoreOrder::where('id',$id)->findOrEmpty(); - $time= strtotime('+1 day', $order['pay_time']); - $order['pay_time']=date('Y-m-d H:i:s',$order['pay_time']); - $order['delivery_time']=date('Y-m-d', $time); + $order = StoreOrder::where('id', $id)->findOrEmpty(); + $time = strtotime('+1 day', $order['pay_time']); + $order['pay_time'] = date('Y-m-d H:i:s', $order['pay_time']); + $order['delivery_time'] = date('Y-m-d', $time); $data = StoreOrderCartInfo::where('oid', $id)->select(); foreach ($data as $key => &$value) { - $find=StoreProduct::where('id',$value->product_id)->find(); - $value->store_name=$find['store_name']??''; - $value->store_info=$find['store_info']??''; - $value->total_price=bcmul($value['price'],$value['cart_num'],2); - if(!empty($find['unit'])){ - $value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name'); - }else{ - $value->unit_name=''; + $find = StoreProduct::where('id', $value->product_id)->find(); + $value->store_name = $find['store_name'] ?? ''; + $value->store_info = $find['store_info'] ?? ''; + $value->total_price = bcmul($value['price'], $value['cart_num'], 2); + if (!empty($find['unit'])) { + $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + } else { + $value->unit_name = ''; } } - $order['total_price']=$order['pay_price']; - $file_path = $xlsx->export($data,$system_store,$order); + $order['total_price'] = $order['pay_price']; + $file_path = $xlsx->export($data, $system_store, $order); return $this->success('导出成功', ['url' => $file_path]); } + + /** + * 创建出库单 + */ + public function createOutboundOrder() + { + $id = $this->request->post('id'); + $store_id = $this->request->post('store_id'); + $warehouse_id = $this->request->post('warehouse_id'); + $delivery_time = $this->request->post('delivery_time'); + $mark = $this->request->post('mark'); + $find = WarehouseOrder::where('oid',$id)->find(); + if($find){ + return $this->fail('该订单已创建出库单'); + } + $product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select(); + if(!$product_arr){ + return $this->fail('无商品'); + } + Db::startTrans(); + try { + $arr = [ + 'oid' => $id, + 'warehouse_id' => $warehouse_id, + 'store_id' => $store_id, + 'supplier_id' => 0, + 'code' => getNewOrderId('PS'), + 'admin_id' => $this->adminId, + 'financial_pm' => 0, + 'batch' => 0, + 'mark' => $mark ?? "", + ]; + $arr['delivery_time'] = strtotime($delivery_time); + $res = WarehouseOrder::create($arr); + foreach ($product_arr as $key => $arr) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['stock'], + 'status' => 1, + 'admin_id' => $this->adminId, + ]; + $storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + if ($arr['stock'] == 0) { + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct); + } else { + $data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2); + $data['purchase'] = $storeProduct['purchase']; + $data['oid'] = $res['id']; + $data['financial_pm'] = 0; + WarehouseProductLogic::add($data); + $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); + } + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); + } } diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php index 8874e9358..313b20ff0 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php @@ -63,13 +63,13 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear if ($this->request->get('start_time') == '') { $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; } - $this->searchWhere[]=['is_pay','=',1]; - $this->searchWhere[]=['status','>=',0]; + $this->searchWhere[] = ['is_pay', '=', 1]; + $this->searchWhere[] = ['status', '>=', 0]; $query = StoreOrderCartInfo::where($this->searchWhere); if ($this->request->get('is_group') == 1) { $query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']); } else { - $query->field('store_id,product_id,price,total_price,cart_num'); + $query->field('store_id,product_id,price,total_price,cart_num,create_time'); } return $query->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { @@ -78,16 +78,16 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear $item['image'] = $find['image']; //商品图片 $item['store_name'] = $find['store_name']; //商品名称 $item['store_info'] = $find['store_info']; //商品规格 - $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??''; - $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??''; - $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??''; - }else{ - $item['image']='';//商品图片 - $item['store_name']='';//商品名称 - $item['store_info']='';//商品规格-(数据库叫商品简介) - $item['unit_name']='';// - $item['cate_name']='';// - $item['system_store']='';// + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? ''; + $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name') ?? ''; + } else { + $item['image'] = ''; //商品图片 + $item['store_name'] = ''; //商品名称 + $item['store_info'] = ''; //商品规格-(数据库叫商品简介) + $item['unit_name'] = ''; // + $item['cate_name'] = ''; // + $item['system_store'] = ''; // } return $item; //返回处理后的数据。 }) @@ -130,16 +130,31 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear */ public function setExcelFields(): array { - $data = [ - 'system_store' => '门店', - 'store_name' => '商品名称', - 'store_info' => '规格', - 'unit_name' => '单位', - 'cate_name' => '分类', - 'cart_num' => '数量', - 'price' => '单价', - 'total_price' => '总价', - ]; + if ($this->request->get('is_group') == 1) { + $data = [ + 'system_store' => '门店', + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + } else { + $data = [ + 'system_store' => '门店', + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + 'create_time' => '时间', + ]; + } + return $data; } } From efc72861620cf5ea47f9638544f42efb7b5a7fcc Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 2 Sep 2024 15:31:07 +0800 Subject: [PATCH 36/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=88=96?= =?UTF-8?q?=E4=BF=AE=E6=94=B9API=EF=BC=9B=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9B=20refactor:=20=E9=87=8D=E5=86=99/?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BD=86=E6=9C=AA?= =?UTF-8?q?=E6=94=B9=E5=8F=98API=E8=A1=8C=E4=B8=BA=EF=BC=9B=20style:=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A9=BA=E6=A0=BC=E3=80=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E3=80=81=E7=BC=BA=E5=A4=B1=E7=9A=84=E5=88=86=E5=8F=B7?= =?UTF-8?q?=E7=AD=89=EF=BC=9B=20test:=20=E6=B7=BB=E5=8A=A0=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E7=9A=84=E6=B5=8B=E8=AF=95=E6=88=96=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=9A=84=E6=B5=8B=E8=AF=95=EF=BC=9B=20docs:?= =?UTF-8?q?=20=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3=E5=A6=82readme=EF=BC=9B?= =?UTF-8?q?=20build:=20=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96=E3=80=81?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=89=88=E6=9C=AC=EF=BC=9B=20ops:=20?= =?UTF-8?q?=E5=BD=B1=E5=93=8D=E6=93=8D=E4=BD=9C=E7=BB=84=E4=BB=B6=E5=A6=82?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=AE=BE=E6=96=BD=E3=80=81=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E3=80=81=E5=A4=87=E4=BB=BD=E3=80=81=E6=81=A2=E5=A4=8D=EF=BC=9B?= =?UTF-8?q?=20chore:=20=E4=BF=AE=E6=94=B9.gitignore=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 请根据以上信息生成规范的用中文conventional commit message,谨慎选择最能说明更改的Commit type,请控制你的输出在一行内,你的回复中应该仅有一条commit message。 Your reply format: --- .../StoreBranchProductLogic.php | 24 +-- .../logic/store_order/StoreOrderLogic.php | 1 - .../logic/store_product/StoreProductLogic.php | 2 +- .../WarehouseProductLogic.php | 31 ++-- app/api/lists/product/ProductLists.php | 11 ++ .../StoreBranchProduct.php | 12 +- .../store_finance_flow/StoreFinanceFlow.php | 11 +- .../StoreFinanceFlowProduct.php | 12 +- app/common/model/store_order/StoreOrder.php | 11 +- .../StoreOrderCartInfo.php | 11 ++ .../model/store_product/StoreProduct.php | 11 +- app/common/model/system_store/SystemStore.php | 12 +- app/common/model/user/User.php | 9 + .../warehouse_product/WarehouseProduct.php | 12 +- .../WarehouseProductStorege.php | 14 +- config/log.php | 154 +++++++++++++++++- 16 files changed, 280 insertions(+), 58 deletions(-) diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index 0b19ba485..d3bf75c31 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -87,32 +87,16 @@ class StoreBranchProductLogic extends BaseLogic $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'); + StoreBranchProduct::update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=> $params['id']]); + StoreProduct::update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=> $params['product_id']]); - 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'); + StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=>$params['id']]); + StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]); - 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/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 16b6776a8..ec66af92d 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -46,7 +46,6 @@ class StoreOrderLogic extends BaseLogic $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; $v['cart_num'] = $v['stock']; - StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]); unset($v['id']); $res = CartLogic::add($v); $cartId[] = $res['id']; diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index d8f28f88f..49f45c5b1 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -217,7 +217,7 @@ class StoreProductLogic extends BaseLogic 'is_show' => $params['is_show'] ?? 0, ]; - StoreProduct::where('id', $params['id'])->update($data); + StoreProduct::update($data,['id'=>$params['id']]); // $dealCate = self::dealChangeCate($params['cate_id']); //修改 diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 2134c5133..20c547c90 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -42,7 +42,7 @@ 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(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } @@ -52,17 +52,12 @@ class WarehouseProductLogic extends BaseLogic // if ($after_nums < 0) { // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // } - 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'); + WarehouseProductStorege::update(['nums'=>$after_nums, 'total_price' => $total_price],['id'=> $storege['id']]); //门店加库存 $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); if (!$storeBranchProduct) { - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } @@ -74,34 +69,32 @@ class WarehouseProductLogic extends BaseLogic } else { $after_nums = $storege['nums'] + $params['nums']; if ($type == 1) { - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { 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'); + WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price],['id'=>$storege['id']]); } } $before_nums = $storege['nums']; } else { $after_nums = $params['nums']; - $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); if (!$storeProduct) { throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - $storege=WarehouseProductStorege::create([ + $data=[ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], 'nums' => $params['nums'], 'total_price'=>$total_price - ]); - onAfterUpdate($storege->toArray(),'product_storege'); + ]; + if($params['financial_pm']==0){ + $data['nums']=-$params['nums']; + } + $storege=WarehouseProductStorege::create($data); } $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/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index ac126989f..3c2bd5d0e 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -69,6 +69,17 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function lists(): array { + $store_name=$this->request->get('store_name'); + if($store_name && $store_name!=''){ + if (preg_match('/^1234-/',$store_name)) { + foreach($this->searchWhere as $k=>$v){ + if($v[0]=='store_name|bar_code'){ + unset($this->searchWhere[$k]); + $this->searchWhere[$k]=['bar_code','=',$store_name]; + } + } + } + } $order = $this->request->get('order', ''); $field = $this->request->get('field', ''); if (empty($order) || empty($field)) { diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index c74b0bcd5..ae0ad6b83 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -7,8 +7,9 @@ use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店商品属性值辅助表模型 @@ -40,4 +41,13 @@ class StoreBranchProduct extends BaseModel { return $this->hasOne(StoreProduct::class,'id','product_id'); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'branch_product','更新前'); + channelLog($data->toArray(),'branch_product','更新后'); + }catch(Throwable $e){ + Log::error('branch_product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/store_finance_flow/StoreFinanceFlow.php b/app/common/model/store_finance_flow/StoreFinanceFlow.php index c3d449622..38f79b90c 100644 --- a/app/common/model/store_finance_flow/StoreFinanceFlow.php +++ b/app/common/model/store_finance_flow/StoreFinanceFlow.php @@ -7,8 +7,9 @@ use app\common\model\BaseModel; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店流水模型 @@ -36,4 +37,12 @@ class StoreFinanceFlow extends BaseModel return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); } + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_finance_flow','更新前'); + channelLog($data->toArray(),'store_finance_flow','更新后'); + }catch(Throwable $e){ + Log::error('store_finance_flow:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php index f371f35ba..bea36cb01 100644 --- a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php +++ b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php @@ -4,8 +4,9 @@ namespace app\common\model\store_finance_flow_product; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 财务流水商品明细 @@ -17,4 +18,13 @@ class StoreFinanceFlowProduct extends BaseModel use SoftDelete; protected $name = 'store_finance_flow_product'; protected $deleteTime = 'delete_time'; + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_finance_flow_product','更新前'); + channelLog($data->toArray(),'store_finance_flow_product','更新后'); + }catch(Throwable $e){ + Log::error('store_finance_flow_product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index a6646512b..815958362 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -11,7 +11,7 @@ use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 订单列表模型 @@ -100,4 +100,13 @@ class StoreOrder extends BaseModel })->field("FROM_UNIXTIME(create_time,'$timeType') as days,$str as num") ->group('days')->select()->toArray(); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_order','更新前'); + channelLog($data->toArray(),'store_order','更新后'); + }catch(Throwable $e){ + Log::error('store_order:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php index 2939ba149..93b2b3518 100644 --- a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php +++ b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php @@ -4,7 +4,9 @@ namespace app\common\model\store_order_cart_info; use app\common\model\BaseModel; use app\common\model\store_branch_product\StoreBranchProduct; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; +use Throwable; class StoreOrderCartInfo extends BaseModel { @@ -18,4 +20,13 @@ class StoreOrderCartInfo extends BaseModel { return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'store_order_cart_info','更新前'); + channelLog($data->toArray(),'store_order_cart_info','更新后'); + }catch(Throwable $e){ + Log::error('store_order_cart_info:'.$e->getMessage()); + } + } } diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index 7f8b6fbb5..ddcfe97e9 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -8,7 +8,7 @@ use app\common\model\store_category\StoreCategory; use app\common\model\store_product_unit\StoreProductUnit; use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 商品列表模型 @@ -33,4 +33,13 @@ class StoreProduct extends BaseModel return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); } + + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'product','更新前'); + channelLog($data->toArray(),'product','更新后'); + }catch(Throwable $e){ + Log::error('product:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php index ac1c4345b..ff209e545 100644 --- a/app/common/model/system_store/SystemStore.php +++ b/app/common/model/system_store/SystemStore.php @@ -4,8 +4,9 @@ namespace app\common\model\system_store; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 门店列表模型 @@ -18,5 +19,12 @@ class SystemStore extends BaseModel protected $name = 'system_store'; protected $deleteTime = 'delete_time'; - + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'system_store','更新前'); + channelLog($data->toArray(),'system_store','更新后'); + }catch(Throwable $e){ + Log::error('system_store:'.$e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index affc1f583..704b7ed2a 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -11,6 +11,7 @@ use app\common\model\user_ship\UserShip; use app\common\service\FileService; use support\Log; use think\model\concern\SoftDelete; +use Throwable; /** * 用户模型 @@ -196,4 +197,12 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'user','更新前'); + channelLog($data->toArray(),'user','更新后'); + }catch(Throwable $e){ + Log::error('user:'.$e->getMessage()); + } + } } diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 5f8abf079..24e61c73e 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -4,8 +4,9 @@ namespace app\common\model\warehouse_product; use app\common\model\BaseModel; +use Illuminate\Support\Facades\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 商品仓储信息模型 @@ -18,5 +19,12 @@ class WarehouseProduct extends BaseModel protected $name = 'warehouse_product'; protected $deleteTime = 'delete_time'; - + public static function onAfterWrite($data){ + try{ + channelLog($data->getOrigin(),'warehouse_product','更新前'); + channelLog($data->toArray(),'warehouse_product','更新后'); + }catch(Throwable $e){ + Log::error('warehouse_product:'.$e->getMessage()); + } + } } \ 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 fd8cefcd0..9d86d6924 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -6,7 +6,7 @@ namespace app\common\model\warehouse_product_storege; use app\common\model\BaseModel; use support\Log; use think\model\concern\SoftDelete; - +use Throwable; /** * 仓库商品存储 @@ -18,5 +18,13 @@ class WarehouseProductStorege extends BaseModel use SoftDelete; protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; - -} \ No newline at end of file + public static function onAfterWrite($data) + { + try { + channelLog($data->getOrigin(), 'warehouse_product_storege', '更新前'); + channelLog($data->toArray(), 'warehouse_product_storege', '更新后'); + } catch (Throwable $e) { + Log::error('warehouse_product_storege:' . $e->getMessage()); + } + } +} diff --git a/config/log.php b/config/log.php index 38c5ecc21..1b75ae61d 100644 --- a/config/log.php +++ b/config/log.php @@ -53,7 +53,7 @@ return [ 'class' => Monolog\Handler\RotatingFileHandler::class, // handler类的构造函数参数 'constructor' => [ - runtime_path() . '/product/'.date('Ym').'/.log', + runtime_path() . '/product/' . date('Ym') . '/.log', 2048, Monolog\Logger::DEBUG, true, @@ -77,7 +77,7 @@ return [ 'class' => Monolog\Handler\RotatingFileHandler::class, // handler类的构造函数参数 'constructor' => [ - runtime_path() . '/branch_product/'.date('Ym').'/.log', + runtime_path() . '/branch_product/' . date('Ym') . '/.log', 2048, Monolog\Logger::DEBUG, true, @@ -101,7 +101,7 @@ return [ 'class' => Monolog\Handler\RotatingFileHandler::class, // handler类的构造函数参数 'constructor' => [ - runtime_path() . '/product_storege/'.date('Ym').'/.log', + runtime_path() . '/product_storege/' . date('Ym') . '/.log', 2048, Monolog\Logger::DEBUG, true, @@ -125,7 +125,7 @@ return [ 'class' => Monolog\Handler\RotatingFileHandler::class, // handler类的构造函数参数 'constructor' => [ - runtime_path() . '/user/'.date('Ym').'/.log', + runtime_path() . '/user/' . date('Ym') . '/.log', 2048, Monolog\Logger::DEBUG, true, @@ -149,7 +149,151 @@ return [ 'class' => Monolog\Handler\RotatingFileHandler::class, // handler类的构造函数参数 'constructor' => [ - runtime_path() . '/system_store/'.date('Ym').'/.log', + runtime_path() . '/system_store/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_finance_flow' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_finance_flow/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_finance_flow_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_finance_flow_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], + ], + ] + ], + ], + 'store_order' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_order/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'store_order_cart_info' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/store_order_cart_info/' . date('Ym') . '/.log', + 2048, + Monolog\Logger::DEBUG, + true, + 0755 + ], + // 格式相关 + 'formatter' => [ + // 格式化处理类的名字 + 'class' => Monolog\Formatter\LineFormatter::class, + // 格式化处理类的构造函数参数 + 'constructor' => [null, 'Y-m-d H:i:s', true], + ], + ] + ], + ], + 'warehouse_product' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/warehouse_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], + ], + ] + ], + ], + 'warehouse_product_storege' => [ + // 处理默认通道的handler,可以设置多个 + 'handlers' => [ + [ + // handler类的名字 + 'class' => Monolog\Handler\RotatingFileHandler::class, + // handler类的构造函数参数 + 'constructor' => [ + runtime_path() . '/warehouse_product_storege/' . date('Ym') . '/.log', 2048, Monolog\Logger::DEBUG, true, From a5d93516b254b91a14d65010bd668d40a33ad230 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 2 Sep 2024 16:52:49 +0800 Subject: [PATCH 37/72] =?UTF-8?q?feat(StoreOrderLogic):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=92=88=E5=AF=B9=E7=89=B9=E5=AE=9A=E5=95=86=E5=BA=97?= =?UTF-8?q?ID=E7=9A=84=E4=BB=B7=E6=A0=BC=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_order/StoreOrderLogic.php | 4 ++ app/common/logic/StoreFinanceFlowLogic.php | 55 ++++++++++--------- process/Task.php | 2 +- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index ec66af92d..6b54d1d93 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -46,6 +46,9 @@ class StoreOrderLogic extends BaseLogic $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; $v['cart_num'] = $v['stock']; + if(in_array($params['store_id'],[17,18])){ + StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]); + } unset($v['id']); $res = CartLogic::add($v); $cartId[] = $res['id']; @@ -53,6 +56,7 @@ class StoreOrderLogic extends BaseLogic $user = User::where('id', $params['user_id'])->find(); $params['shipping_type'] = 2; $params['pay_type'] = 7; + $params['source'] =2; $order = OrderLogic::createOrder($cartId, null, $user, $params); return true; } diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 70c21d8d5..98b3131be 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -183,39 +183,40 @@ class StoreFinanceFlowLogic extends BaseLogic ->select(); foreach ($list as $k => $value) { //用户 - switch ($value['type']) { - case 0: - if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { - $user = User::where('id', $value['other_uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $user->now_money = bcsub($user['now_money'], $value['number'], 2); - $user->save(); - // Log::error('aa'.$a); - // Log::error('aa'.$user['now_money']); - // Log::error('aa'.$value['number']); - $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); - } - break; - //商户 - case 1: - $store = SystemStore::where('id', $store_id)->find(); - $capitalFlowDao = new CapitalFlowLogic($store, 'store'); - if ($value['number'] > 0 && $value['financial_type'] == 2) { - SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update(); - $capitalFlowDao->storeExpense('store_paid_deposit_dec', 'order', $value['order_id'],$value['number']); + if($value['type']==0){ + if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { + $user = User::where('id', $value['other_uid'])->findOrEmpty(); + $capitalFlowDao = new CapitalFlowLogic($user); + $user->now_money = bcsub($user['now_money'], $value['number'], 2); + $user->save(); + $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); + } + }elseif($value['type']==1){ + $store = SystemStore::where('id', $store_id)->find(); + $capitalFlowDao = new CapitalFlowLogic($store, 'store'); + if ($value['number'] > 0 && $value['financial_type'] == 2) { + $find=SystemStore::where('id', $value['store_id'])->find(); + $find->store_money=bcsub($find['store_money'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_money_refund', 'order', $value['order_id'],$value['number'],'','store_money'); - } - if ($value['number'] > 0 && $value['financial_type'] == 16) { - SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update(); - $capitalFlowDao->storeExpense('store_attrition_dec', 'order', $value['order_id'], $value['number']); + } + if ($value['number'] > 0 && $value['financial_type'] == 16) { + $find=SystemStore::where('id', $value['store_id'])->find(); + $find->attrition=bcsub($find['attrition'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_attrition_refund', 'order', $value['order_id'], $value['number'],'','attrition'); - } - break; + } } } $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find(); if ($find && $find['number'] > 0) { - SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update(); + $find=SystemStore::where('id', $value['store_id'])->find(); + $capitalFlowDao = new CapitalFlowLogic($find, 'store'); + $find->paid_deposit=bcsub($find['paid_deposit'], $value['number'],2); + $find->save(); + $capitalFlowDao->storeExpense('store_paid_deposit_refund', 'order', $value['order_id'],$value['number'],'','paid_deposit'); } // $data = StoreFinanceFlow::where('order_sn', $orderSn)->select(); // foreach ($data as $k => &$value) { diff --git a/process/Task.php b/process/Task.php index 2fedfff83..a25bda15f 100644 --- a/process/Task.php +++ b/process/Task.php @@ -23,7 +23,7 @@ class Task new Crontab('0 */10 * * * *', function () { $where = ['paid' => 0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 - $where[] = ['shipping_type', '<>',4]; + $where[] = ['source', '<',2]; // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 if ($oid) { From 3c305cfaf0f6d1947fcee4229dc2532e454fa0a1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 2 Sep 2024 20:52:25 +0800 Subject: [PATCH 38/72] =?UTF-8?q?refactor(PayNotifyLogic,=20StoreOrderCont?= =?UTF-8?q?roller):=20=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E6=A0=B8?= =?UTF-8?q?=E9=94=80=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=9B=B4=E6=96=B0=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 96 ++++++++----------- .../store_order/StoreOrderController.php | 20 ++++ 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index ec166fb77..eb296badd 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -107,14 +107,14 @@ class PayNotifyLogic extends BaseLogic ]; self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); } - if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } if (in_array($order['shipping_type'], [1, 2])) { PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } @@ -203,14 +203,14 @@ class PayNotifyLogic extends BaseLogic // } // self::addUserSing($order); self::afterPay($order); - if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order && $order['store_id'] && $order['reservation'] != 1 && $order['source'] == 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } // self::dealProductLog($order); if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { $checkArr = [ @@ -504,7 +504,8 @@ class PayNotifyLogic extends BaseLogic } $order->paid = 1; $order->pay_time = time(); - $order->status = 2; + $order->status = 1; + // $order->status = 2; if ($order['reservation'] == 1) { $order->status = 1; } @@ -519,14 +520,14 @@ class PayNotifyLogic extends BaseLogic $cashFlowLogic->insert($order['store_id'], $order['pay_price']); // self::dealProductLog($order); - if ($order && $order['store_id'] && $order['reservation'] != 1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order && $order['store_id'] && $order['reservation'] != 1) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } // Redis::send('push-platform-print', ['id' => $order['id']]); @@ -571,14 +572,14 @@ class PayNotifyLogic extends BaseLogic // else { // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); // } - if ($order->pay_type == 13) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::writeOff($params); - } + // if ($order->pay_type == 13) { + // $params = [ + // 'verify_code' => $order['verify_code'], + // 'store_id' => $order['store_id'], + // 'staff_id' => $order['staff_id'] + // ]; + // OrderLogic::writeOff($params); + // } return true; } @@ -596,36 +597,20 @@ class PayNotifyLogic extends BaseLogic $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([ + StoreBranchProduct::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'); + ],['id'=>$branchProduct['id']]); } $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([ + StoreProduct::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'); + ],['id'=>$v['product_id']]); } } } catch (\Throwable $e) { @@ -668,11 +653,6 @@ class PayNotifyLogic extends BaseLogic return false; } - //如果是会员需要返回会员金额 - // if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) { - // $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']); - // } - if($order['uid']>0){ $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); if ($address) { diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index d5b269ac7..e03a0b68f 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -542,4 +542,24 @@ class StoreOrderController extends BaseAdminController return $this->fail('订单支付中'); } } + + /** + * 不配送核销 + */ + public function noDelivery(){ + $id=$this->request->post('id'); + if($id){ + $params = StoreOrder::where('id', $id)->find(); + if (!$params) { + return $this->fail('无该核销码请检查'); + } + $params['store_id'] = $this->adminInfo['store_id']; + $params['staff_id'] = $this->adminId; + $res = OrderLogic::writeOff($params); + if ($res) { + return $this->success('核销成功'); + } + return $this->fail('核销失败' . OrderLogic::getError()); + } + } } From 729b05efbf3528b39f553718a05f0a0d684eaca1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 2 Sep 2024 21:10:48 +0800 Subject: [PATCH 39/72] =?UTF-8?q?refactor(WorkbenchLogic):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=94=AF=E4=BB=98=E8=AE=A2=E5=8D=95=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/logic/WorkbenchLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 10faeb625..95c54f02a 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -140,7 +140,7 @@ class WorkbenchLogic extends BaseLogic $data['order_list'] = StoreOrder::with('user')->where($where) // ->whereBetweenTime('pay_time', $startTime, $endTime) ->order('pay_time', 'desc') -// ->limit(6) + ->limit(10) ->select()->each(function($item){ $item->pay_time=$item->pay_time>0?date('Y-m-d H:i:s',$item->pay_time):''; }) From 5b64d0d9b29506f02bdd604d3b59b3018d1e0dcf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Sep 2024 15:50:17 +0800 Subject: [PATCH 40/72] =?UTF-8?q?feat:=20=E5=90=8E=E5=8F=B0=E4=B8=8B?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=E5=8F=8A=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/store_order/StoreOrderLogic.php | 2 +- app/api/logic/order/OrderLogic.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 6b54d1d93..fc29cda10 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -56,7 +56,7 @@ class StoreOrderLogic extends BaseLogic $user = User::where('id', $params['user_id'])->find(); $params['shipping_type'] = 2; $params['pay_type'] = 7; - $params['source'] =2; + $params['source'] =2;//后台下单 $order = OrderLogic::createOrder($cartId, null, $user, $params); return true; } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index f9b1af6ba..ac0b3e735 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -89,7 +89,12 @@ class OrderLogic extends BaseLogic $off_activity = Config::where('name', 'off_activity')->value('value'); $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; foreach ($cart_select as $k => $v) { - $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); + if (isset($params['source']) && $params['source'] == 2) { + $field = 'product_id,product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; + $find = StoreProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); + }else{ + $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); + } if (!$find) { throw new BusinessException('商品不存在'); } @@ -472,9 +477,6 @@ class OrderLogic extends BaseLogic $data[$k]['store_id'] = $v['store_id']; $data[$k]['staff_id'] = $v['staff_id']; $data[$k]['combination_id'] = 0; - $data[$k]['seckill_id'] = 0; - $data[$k]['bargain_id'] = 0; - $data[$k]['discount_id'] = 0; $data[$k]['status'] = 1; $data[$k]['staff_id'] = 0; $data[$k]['is_new'] = 0; From b0a6d7da504b5728a034b162eacbeb674c5d81ef Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Sep 2024 15:58:55 +0800 Subject: [PATCH 41/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=80=BB=E8=BE=91=E4=BB=A5=E6=9F=A5=E8=AF=A2=E5=88=86?= =?UTF-8?q?=E5=BA=97=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index ac0b3e735..5993d6eb1 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -91,7 +91,7 @@ class OrderLogic extends BaseLogic foreach ($cart_select as $k => $v) { if (isset($params['source']) && $params['source'] == 2) { $field = 'product_id,product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; - $find = StoreProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); + $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); }else{ $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); } From 60c7b154a564bf4d96e29428a10d2f624634f321 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Sep 2024 17:17:21 +0800 Subject: [PATCH 42/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86StoreP?= =?UTF-8?q?roductLists.php=E6=96=87=E4=BB=B6=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BA=86=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?'store=5Finfo'=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E7=9B=B8=E5=BA=94=E7=9A=84=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_product/StoreProductLists.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index c4f4f50a5..11b086cf3 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -62,7 +62,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa } } return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_name', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) + ->field(['id', 'image', 'store_info','store_name', 'swap', 'product_type', '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) { @@ -125,6 +125,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa 'store_name' => '商品名称', 'cate_name'=>'分类', 'unit_name'=>'单位', + 'store_info'=>'规格', 'stock' => '库存', 'purchase' => '采购价', 'cost' => '商户', From cbeb06426d05002dccd7e5b3aa8133f4c9fcc60e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Sep 2024 17:55:14 +0800 Subject: [PATCH 43/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=89=B9?= =?UTF-8?q?=E5=8F=91=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/CartController.php | 7 ++ .../controller/product/ProductController.php | 10 ++ app/api/lists/cate/CateLists.php | 4 + app/api/lists/order/CartWholesaleList.php | 109 ++++++++++++++++ .../lists/product/ProductWholesaleLists.php | 117 ++++++++++++++++++ app/api/logic/order/CartLogic.php | 7 +- app/api/logic/order/OrderLogic.php | 61 ++++----- app/common/validate/BaseValidate.php | 7 +- 8 files changed, 288 insertions(+), 34 deletions(-) create mode 100644 app/api/lists/order/CartWholesaleList.php create mode 100644 app/api/lists/product/ProductWholesaleLists.php diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index 5810409fa..90b370357 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -6,6 +6,7 @@ use app\api\logic\order\CartLogic; use app\api\validate\CartValidate; use app\api\controller\BaseApiController; use app\api\lists\order\CartList; +use app\api\lists\order\CartWholesaleList; use app\common\model\order\Cart; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; @@ -16,7 +17,13 @@ class CartController extends BaseApiController { return $this->dataLists(new CartList()); } + /** + * 批发商品列表 + */ + public function wholesale_lists(){ + return $this->dataLists(new CartWholesaleList()); + } /** * @notes 添加购物车 */ diff --git a/app/api/controller/product/ProductController.php b/app/api/controller/product/ProductController.php index b7f5af617..2b4c4f771 100644 --- a/app/api/controller/product/ProductController.php +++ b/app/api/controller/product/ProductController.php @@ -3,11 +3,14 @@ namespace app\api\controller\product; use app\api\controller\BaseApiController; use app\api\lists\product\ProductLists; +use app\api\lists\product\ProductWholesaleLists; use app\api\lists\product\StoreProductLists; use app\common\model\system_store\SystemStoreStaff; class ProductController extends BaseApiController{ + public $notNeedLogin = ['lists']; + /** * 商品列表 */ @@ -16,6 +19,13 @@ class ProductController extends BaseApiController{ return $this->dataLists(new ProductLists()); } + /** + * 批发商品列表 + */ + public function wholesale_lists(){ + + return $this->dataLists(new ProductWholesaleLists()); + } /** * 商品列表 */ diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index 21c52e4be..87644e174 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -45,9 +45,13 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { $level = Request()->get('level', 1); + $source = Request()->get('source'); $pid = $this->request->get('pid',0); // $this->searchWhere[] = ['stock', '>', 0]; $this->searchWhere[] = ['is_show', '=', 1]; + if($source && $source==4){ + $this->searchWhere[] = ['product_type', '=', 5]; + } if($pid && $level ==2){ $this->searchWhere[] = ['top_cate_id','=',$pid]; $cate_arr = StoreProduct::where($this->searchWhere)->distinct() diff --git a/app/api/lists/order/CartWholesaleList.php b/app/api/lists/order/CartWholesaleList.php new file mode 100644 index 000000000..766785d8d --- /dev/null +++ b/app/api/lists/order/CartWholesaleList.php @@ -0,0 +1,109 @@ +['store_id','source']]; + } + + + /** + * @notes 购物车列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @date 2024/04/27 11:26 + */ + public function lists($where = []): array + { + $userId = $this->request->userId; + if (!$userId) return []; + $where = [ + 'uid' => $userId, + 'is_pay' => 0 + ]; + $list = Cart::where($this->searchWhere)->where($where) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; + foreach ($list as $key => &$item) { + $find = StoreProduct::where(['id' => $item['product_id']]) + ->field($field) + ->find(); + if ($find) { + $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); + $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); + $item['batch'] = $find['batch']; + $item['imgs'] = $find['image']; + $item['price'] = $find['price']; + $item['cost'] = $find['cost']; + $item['goods_name'] = $find['store_name']; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + } + } + return $list; + } + + + /** + * @notes 购物车数量 + * @return int + * @date 2024/04/27 11:26 + */ + public function count(): int + { + $userId = $this->request->userId; + if (!$userId) return 0; + $where = [ + 'uid' => $userId, + 'is_pay' => 0 + ]; + return Cart::where($this->searchWhere)->where($where)->count(); + } + + public function extend() + { + $data = [ + 'off_activity' => $this->off_activity, + 'total_price' => $this->total_price, + 'msg' => '', + 'pay_price' => $this->total_price + ]; + return $data; + } +} diff --git a/app/api/lists/product/ProductWholesaleLists.php b/app/api/lists/product/ProductWholesaleLists.php new file mode 100644 index 000000000..75f3b58c4 --- /dev/null +++ b/app/api/lists/product/ProductWholesaleLists.php @@ -0,0 +1,117 @@ + [ 'cate_id', 'top_cate_id', 'two_cate_id'], + '%pipe_like%' => ['store_name' => 'store_name|bar_code'], + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['sell' => 'price', 'sales' => 'sales',]; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['price' => 'asc', 'id' => 'desc']; + } + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function lists(): array + { + + $order = $this->request->get('order', ''); + $field = $this->request->get('field', ''); + if (empty($order) || empty($field)) { + $order = $this->sortOrder; + } else { + $order = [$field => $order]; + } + $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'; + + $this->searchWhere[] = ['is_show', '=', 1]; + $this->searchWhere[] = ['product_type', '=', 5]; + // $this->searchWhere[] = ['stock', '>', 0]; + return StoreProduct::where($this->searchWhere) + ->field($fields) + ->with(['className', 'unitName']) + ->limit($this->limitOffset, $this->limitLength) + ->order($order) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + return StoreProduct::where($this->searchWhere) + ->count(); + } + public function extend() + { + $price = 'price'; + $op_price = 'price'; + $data = [ + 'off_activity' => $this->off_activity, + 'price' => $price, + 'op_price' => $op_price, + ]; + return $data; + } +} diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index 2ad0c6107..67ad68b47 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -28,9 +28,10 @@ class CartLogic extends BaseLogic */ public static function add(array $params) { - if ($params['store_id'] <= 0) { + if ($params['store_id'] < 0) { throw new BusinessException('门店ID不能为空'); } + $source=$params['source'] ?? 0; Db::startTrans(); try { //check @@ -38,7 +39,8 @@ class CartLogic extends BaseLogic 'uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], - 'is_pay' => 0 + 'is_pay' => 0, + 'source' => $source, ])->field('id')->find(); if ($check) { Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num']) @@ -53,6 +55,7 @@ class CartLogic extends BaseLogic 'staff_id' => $params['staff_id'] ?? 0, 'cart_num' => $params['cart_num'], 'is_new' => $params['is_new'] ?? 0, + 'source' =>$source, ]); } StoreProductLog::create([ diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 5993d6eb1..3779f81c7 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -66,12 +66,15 @@ class OrderLogic extends BaseLogic */ static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0) { - if(empty($params['store_id']) || $params['store_id'] <= 0){ + if (empty($params['store_id']) || $params['store_id'] <= 0) { throw new BusinessException('请选择门店'); } - + $source=0; + if (isset($params['source']) && $params['source'] >0) { + $source=$params['source']; + } $where = ['is_pay' => 0]; - $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); + $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num,source')->select()->toArray(); if (empty($cart_select)) { throw new BusinessException('购物车为空'); } @@ -89,10 +92,10 @@ class OrderLogic extends BaseLogic $off_activity = Config::where('name', 'off_activity')->value('value'); $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; foreach ($cart_select as $k => $v) { - if (isset($params['source']) && $params['source'] == 2) { + if ($source == 2) { $field = 'product_id,product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; - $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); - }else{ + $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); + } else { $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); } if (!$find) { @@ -116,21 +119,26 @@ class OrderLogic extends BaseLogic } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { - $price = $find['cost']; - } else { - $price = $find['price']; - //单门店活动判断 - if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) { - $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price'); - if ($storeBranchPrice) { - $price = $storeBranchPrice; + if ($v['source'] != 4) { + if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { + $price = $find['cost']; + } else { + $price = $find['price']; + //单门店活动判断 + if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) { + $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price'); + if ($storeBranchPrice) { + $price = $storeBranchPrice; + } } } + if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { + $price = $find['cost']; + } + } else { + $price = $find['price']; } - if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { - $price = $find['cost']; - } + $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; $cart_select[$k]['vip'] = 0; @@ -173,7 +181,7 @@ class OrderLogic extends BaseLogic $cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['store_id'] = $params['store_id'] ?? 0; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); - $cart_select[$k]['total_price'] =$cart_select[$k]['pay_price']; + $cart_select[$k]['total_price'] = $cart_select[$k]['pay_price']; 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::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); @@ -195,7 +203,7 @@ class OrderLogic extends BaseLogic $pay_price = self::$pay_price; // bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 //判断生鲜是否大于200 - if ($createOrder == 1 && self::$fresh_price > 0) { + if ($createOrder == 1 && self::$fresh_price > 0 &&$source!=2) { if (self::$pay_price < 200) { throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单'); } @@ -223,7 +231,7 @@ class OrderLogic extends BaseLogic 'activities' => $off_activity, 'deduction_price' => self::$deduction_price, //抵扣金额 'frozen_money' => 0, //self::$frozen_money, //返还金额(活动关闭得时候有) - 'source' => 0, + 'source' => $source, 'is_storage' => $params['is_storage'] ?? 0, 'address_id' => 0, ]; @@ -231,9 +239,6 @@ class OrderLogic extends BaseLogic if ($params['store_id']) { $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send'); } - if (isset($params['source']) && $params['source'] > 0) { - $order['source'] = $params['source']; - } if (isset($params['store_id']) && $params['store_id'] > 0) { $store_id = $params['store_id']; @@ -259,8 +264,6 @@ class OrderLogic extends BaseLogic } } catch (\Throwable $e) { throw new BusinessException($e->getMessage()); - - } return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'], 'alert' => $alert]; } @@ -335,7 +338,7 @@ class OrderLogic extends BaseLogic $order = StoreOrder::create($_order); $goods_list = $orderInfo['cart_list']; - + foreach ($goods_list as $k => $v) { $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $uid; @@ -443,7 +446,7 @@ class OrderLogic extends BaseLogic // 回滚事务 Db::rollback(); Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine()); - throw new BusinessException('支付失败'. $e->getMessage()); + throw new BusinessException('支付失败' . $e->getMessage()); } } @@ -499,7 +502,7 @@ 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 = 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/validate/BaseValidate.php b/app/common/validate/BaseValidate.php index 92bf44e7a..e5c1fd36b 100644 --- a/app/common/validate/BaseValidate.php +++ b/app/common/validate/BaseValidate.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace app\common\validate; use app\common\service\JsonService; +use support\exception\BusinessException; use taoser\Validate; class BaseValidate extends Validate @@ -31,7 +32,7 @@ class BaseValidate extends Validate public function post() { if (!(request()->method() == 'POST')) { - JsonService::throw('请求方式错误,请使用post请求方式'); + throw new BusinessException('请求方式错误,请使用post请求方式'); } $this->method = 'POST'; return $this; @@ -45,7 +46,7 @@ class BaseValidate extends Validate public function get() { if (!(request()->method() == 'GET')) { - JsonService::throw('请求方式错误,请使用get请求方式'); + throw new BusinessException('请求方式错误,请使用get请求方式'); } return $this; } @@ -79,7 +80,7 @@ class BaseValidate extends Validate if (!$result) { $exception = is_array($this->error) ? implode(';', $this->error) : $this->error; - JsonService::throw($exception); + throw new BusinessException($exception); } // 3.成功返回数据 return $params; From c2a617aca88d4cd15cd82a915abec279013d0af9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 3 Sep 2024 22:53:26 +0800 Subject: [PATCH 44/72] =?UTF-8?q?feat(CapitalFlowLogic,=20CommissionProduc?= =?UTF-8?q?tLogic):=20=E6=96=B0=E5=A2=9E/=E4=BF=AE=E6=94=B9=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A5=E5=A4=84=E7=90=86=E8=AE=A2=E5=8D=95=E6=94=AF?= =?UTF-8?q?=E4=BB=98/=E9=80=80=E6=AC=BE=E5=8F=8A=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CapitalFlowLogic.php | 3 +++ app/common/logic/CommissionProductLogic.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 3898b55c8..6590a2759 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -166,6 +166,7 @@ class CapitalFlowLogic extends BaseLogic case 'store_order_refund': return "店铺订单退款{$amount}元"; case 'store_margin_refund': + case 'store_paid_deposit_refund': return "店铺退还保证金{$amount}元"; case 'user_order_promotion': return "订单推广佣金{$amount}元"; @@ -185,6 +186,8 @@ class CapitalFlowLogic extends BaseLogic return "订单退回到余额{$amount}元"; case 'purchase_refund': return "订单退回到采购款{$amount}元"; + case 'store_paid_deposit_add': + return "门店增加保证金{$amount}元"; default: return "订单支付{$amount}元"; } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 74173ac8d..f6e1688f8 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -250,9 +250,9 @@ class CommissionProductLogic extends BaseLogic $total_price = bcmul($product['price'], $find['cart_num']); $purchase_price = bcmul($product['purchase'], $find['cart_num']); $price=$product['price']; - $brigade_number = bcmul($total_price, 0.02, 2); - $village_number = bcmul($brigade_number, 0.1, 2); - $platform_number = bcmul($total_price, 0.02, 2); + $brigade_number = bcmul($total_price, 0.02, 2);//队长 + $village_number = bcmul($brigade_number, 0.1, 2);//村长 + $platform_number = bcmul($total_price, 0.02, 2);//平台 $number1 = bcadd($brigade_number, $village_number, 2); $number2 = bcadd($number1, $platform_number, 2); From 1fbc0b6ceec1ec77310d2ea705855635382694be Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 10:31:29 +0800 Subject: [PATCH 45/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index eb296badd..bb1ddb59e 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -76,6 +76,7 @@ class PayNotifyLogic extends BaseLogic } // $order->money = $order['pay_price']; $order->paid = 1; + $order->status = 1; $order->pay_time = time(); if (!$order->save()) { throw new BusinessException('订单保存出错'); @@ -185,6 +186,7 @@ class PayNotifyLogic extends BaseLogic } $order->money = $order['pay_price']; $order->paid = 1; + $order->status = 1; $order->pay_time = time(); if (!$order->save()) { throw new \Exception('订单保存出错'); From c57c73b40eaa330e503708ea2dde51b9cd0d5e28 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 11:37:01 +0800 Subject: [PATCH 46/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=93=81ID=E5=88=97=E5=88=B0Excel=E5=AF=BC=E5=87=BA=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_product/StoreProductLists.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 11b086cf3..382d7d46b 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -122,6 +122,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function setExcelFields(): array { $data = [ + 'id' => '商品id', 'store_name' => '商品名称', 'cate_name'=>'分类', 'unit_name'=>'单位', From 9b6bf999c0be5f6106b789dd86130b0308156be7 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 16:10:59 +0800 Subject: [PATCH 47/72] =?UTF-8?q?feat(warehouse=5Forder):=20=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E4=BB=93=E5=BA=93=E8=AE=A2=E5=8D=95=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../warehouse_order/WarehouseOrderController.php | 6 +++++- .../StoreOrderCartInfoTwoLists.php | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index a4dabf8e8..787347de1 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -227,7 +227,11 @@ class WarehouseOrderController extends BaseAdminController $order['total_num'] = 0; $total_price=0; foreach ($data as $key => &$value) { - $find = StoreProduct::where('id', $value->product_id)->find(); + if(in_array($order['store_id'],[17,18])){ + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); + }else{ + $find = StoreProduct::where('id', $value->product_id)->find(); + } $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; if($type==2){ diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php index 313b20ff0..6d5716796 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php @@ -63,20 +63,25 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear if ($this->request->get('start_time') == '') { $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; } + $is_group=$this->request->get('is_group'); $this->searchWhere[] = ['is_pay', '=', 1]; $this->searchWhere[] = ['status', '>=', 0]; $query = StoreOrderCartInfo::where($this->searchWhere); - if ($this->request->get('is_group') == 1) { + if ($is_group == 1) { $query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']); } else { $query->field('store_id,product_id,price,total_price,cart_num,create_time'); } return $query->limit($this->limitOffset, $this->limitLength) - ->select()->each(function ($item) { + ->select()->each(function ($item) use($is_group){ $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find(); if ($find) { $item['image'] = $find['image']; //商品图片 - $item['store_name'] = $find['store_name']; //商品名称 + if($is_group==1){ + $item['store_name'] = $find['store_name'].'-'.$item['create_time']; //商品名称 + }else{ + $item['store_name'] = $find['store_name']; //商品名称 + } $item['store_info'] = $find['store_info']; //商品规格 $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? ''; From 869faf2f44f0e15607f8c111ca0dd839fbe94788 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 21:57:12 +0800 Subject: [PATCH 48/72] =?UTF-8?q?refactor(StoreProductLists,=20WorkbenchLo?= =?UTF-8?q?gic):=20=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=8A=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=8F=8A=E8=AE=A2=E5=8D=95=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/statistics/StoreProductLists.php | 31 ++++++++++++++----- app/store/logic/WorkbenchLogic.php | 24 +++++++------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index fb3586f91..b6bb67044 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -80,21 +80,36 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $list = StoreProduct::where($this->searchWhere) ->alias('p') // 为 StoreProduct 表设置别名 ->limit($this->limitOffset, $this->limitLength) - ->field('p.id, p.store_name, p.image,p.stock as total_stock, + ->field('p.id, p.store_name, p.image,p.stock as total_stock,p.unit, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, - (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.delete_time IS NULL) AS total_purchase, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.financial_pm=1 AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') ->order($this->sortOrder) ->select() ->each(function ($item) { // 计算总库存 - $item->total_completed_amount=$item->total_completed_amount??0; - $item->warehouse_stock=$item->warehouse_stock??0; - $item->total_outstanding_amount=$item->total_outstanding_amount??0; - $item->total_purchase=$item->total_purchase??0; + $unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); + $item->sales=$item->sales.'|'.$unit_name; + $item->store_stock=$item->store_stock.'|'.$unit_name; + $item->warehouse_stock=$item->warehouse_stock.'|'.$unit_name; + if($item->total_completed_amount){ + $item->total_completed_amount=$item->total_completed_amount.'元'; + }else{ + $item->total_completed_amount='0元'; + } + if($item->total_outstanding_amount){ + $item->total_outstanding_amount=$item->total_outstanding_amount.'元'; + }else{ + $item->total_outstanding_amount='0元'; + } + if($item->total_purchase){ + $item->total_purchase=$item->total_purchase.'元'; + }else{ + $item->total_purchase='0元'; + } }) ->toArray(); return $list; diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 95c54f02a..bf80beba0 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -74,22 +74,24 @@ class WorkbenchLogic extends BaseLogic //余额支付总金额 $data['balance_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::BALANCE_PAY])); //微信条码支付总金额 - $data['wechat_code_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::WECHAT_PAY_BARCODE])); + $data['wechat_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => [7,9]])); //支付条码支付总金额 - $data['alipay_code_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::ALIPAY_BARCODE])); + $data['alipay_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::ALIPAY_BARCODE])); + //采购款 + $data['purchase_funds_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::PURCHASE_FUNDS])); + //现金 + $data['cash_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::CASH_PAY])); //线下收银总金额 - $data['cashier_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 3])); + // $data['cashier_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 3])); //现金收银总金额 - $data['cash_amount'] = StoreCashFinanceFlow::where($cashFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price'); + // $data['cash_amount'] = StoreCashFinanceFlow::where($cashFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price'); //核销订单金额 - $data['verify_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 2])); + // $data['verify_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 2])); //门店收益金额 $data['income_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); //门店收款金额 - $all_where['paid'] = 1; -// $data['receipt_amount'] = OrderLogic::dayPayPrice($all_where,date('Y-m-d',time())); - $data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime); -// $data['receipt_amount'] = UserRecharge::where($userRechargeWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('price'); + // $all_where['paid'] = 1; + // $data['receipt_amount'] = OrderLogic::dealFlexiblePrice($all_where,$startTime,$endTime); //保证金金额 $data['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhereTwo)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number'); /**门店损耗金 */ @@ -210,8 +212,8 @@ class WorkbenchLogic extends BaseLogic ]; $data['pay_type'] = [ - ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], - ['name' => '核销订单', 'value' => $data['verify_amount']], + // ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], + // ['name' => '核销订单', 'value' => $data['verify_amount']], ['name' => '现金收银订单', 'value' => $data['cash_amount']], ]; return $data; From 8e9e2b8ded2bea4e780401ec76c7c833421ef0f2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 22:13:14 +0800 Subject: [PATCH 49/72] =?UTF-8?q?refactor(WorkbenchLogic):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=94=AF=E4=BB=98=E8=AE=A2=E5=8D=95=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=A4=84=E7=90=86=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/logic/WorkbenchLogic.php | 44 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index bf80beba0..bcb3fffb7 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -158,31 +158,31 @@ class WorkbenchLogic extends BaseLogic ->select() ->toArray(); - $orderList = StoreOrder::field($field) - ->where($where) - ->whereBetweenTime('pay_time', $startTime, $endTime) - ->group($group) - ->select() - ->toArray(); + // $orderList = StoreOrder::field($field) + // ->where($where) + // ->whereBetweenTime('pay_time', $startTime, $endTime) + // ->group($group) + // ->select() + // ->toArray(); $userList = StoreOrder::field($field . ',count(uid) as user_num') ->where($where) ->whereBetweenTime('pay_time', $startTime, $endTime) ->group($group . ',uid') ->select() ->toArray(); - $orderList = reset_index($orderList, 'pay_time'); + // $orderList = reset_index($orderList, 'pay_time'); $userList = reset_index($userList, 'pay_time'); - $orderListTmp = []; + // $orderListTmp = []; $userListTmp = []; $range = []; $mergedListTmp = []; foreach ($timeRange as $item) { $range[] = $item; - if (!isset($orderList[$item])) { - $orderListTmp[$item] = 0; - } else { - $orderListTmp[$item] = $orderList[$item]['pay_price']; - } + // if (!isset($orderList[$item])) { + // $orderListTmp[$item] = 0; + // } else { + // $orderListTmp[$item] = $orderList[$item]['pay_price']; + // } if (!isset($userList[$item])) { $userListTmp[$item] = 0; } else { @@ -196,25 +196,29 @@ class WorkbenchLogic extends BaseLogic $mergedListTmp[$item] += $recharge['pay_price']; } } - foreach ($orderList as $order) { - if ($order['pay_time'] == $item) { - $mergedListTmp[$item] += $order['pay_price']; - } - } + // foreach ($orderList as $order) { + // if ($order['pay_time'] == $item) { + // $mergedListTmp[$item] += $order['pay_price']; + // } + // } } $data['statistics'] = [ 'range' => $range, 'data' => [ // 'order_amount' => array_values($orderListTmp), 'user_number' => array_values($userListTmp), - 'order_amount' => array_values($mergedListTmp) + // 'order_amount' => array_values($mergedListTmp) ] ]; $data['pay_type'] = [ // ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], // ['name' => '核销订单', 'value' => $data['verify_amount']], - ['name' => '现金收银订单', 'value' => $data['cash_amount']], + ['name' => '微信订单', 'value' => $data['wechat_amount']], + ['name' => '支付宝订单', 'value' => $data['alipay_amount']], + ['name' => '采购款订单', 'value' => $data['purchase_funds_amount']], + ['name' => '余额订单', 'value' => $data['balance_amount']], + ['name' => '现金订单', 'value' => $data['cash_amount']], ]; return $data; } From 73565cace915ca01faf2b4e6c1b10657a2437b2d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 5 Sep 2024 22:21:06 +0800 Subject: [PATCH 50/72] =?UTF-8?q?feat(PayNotifyLogic):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=94=B6=E9=93=B6=E5=8F=B0=E6=94=AF=E4=BB=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=A7=BB=E9=99=A4=E8=AE=A2=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index bb1ddb59e..6ce86964f 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -255,7 +255,7 @@ class PayNotifyLogic extends BaseLogic } $user = User::where('id', $order['uid'])->find(); if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 - $order->status = 2; + // $order->status = 2; } else { $capitalFlowDao = new CapitalFlowLogic($user); //微信支付和用户余额无关 From ea4bd28a0e180c907a5a48625f8e4eeace725050 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 10:06:38 +0800 Subject: [PATCH 51/72] =?UTF-8?q?feat(OrderLogic):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=9F=E9=B2=9C=E4=BA=A7=E5=93=81=E8=AE=A2=E5=8D=95=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E9=99=90=E5=88=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 3779f81c7..e444f5863 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -203,11 +203,11 @@ class OrderLogic extends BaseLogic $pay_price = self::$pay_price; // bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 //判断生鲜是否大于200 - if ($createOrder == 1 && self::$fresh_price > 0 &&$source!=2) { - if (self::$pay_price < 200) { - throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单'); - } - } + // if ($createOrder == 1 && self::$fresh_price > 0 &&$source!=2) { + // if (self::$pay_price < 200) { + // throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单'); + // } + // } if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) { $off_activity = 1; } From 473b276e55f922ca811c98ab1134179b5b64e773 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 11:32:30 +0800 Subject: [PATCH 52/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=93=81ID=E5=88=B0Excel=E5=AD=97=E6=AE=B5=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_branch_product/StoreBranchProductLists.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 106b3ca66..032545c97 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -143,6 +143,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function setExcelFields(): array { $data = [ + 'product_id' => '商品ID', 'store_name' => '商品名称', 'store_info' => '规格', 'unit_name' => '单位', From 816521c6bef03d8406142072eb28432c88b2fe9c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 13:46:27 +0800 Subject: [PATCH 53/72] =?UTF-8?q?feat(store=5Forder):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BA=97=E9=93=BAID=E6=9D=A5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=88=86=E6=94=AF=E5=95=86=E5=93=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/store_order/StoreOrderController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index c475a5e98..efa371bbe 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -13,6 +13,7 @@ use app\admin\validate\store_order\StoreOrderValidate; use app\common\enum\PayEnum; use app\common\logic\PayNotifyLogic; use app\common\model\delivery_service\DeliveryService; +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; @@ -167,7 +168,11 @@ class StoreOrderController extends BaseAdminController $order['delivery_time'] = date('Y-m-d', $time); $data = StoreOrderCartInfo::where('oid', $id)->select(); foreach ($data as $key => &$value) { - $find = StoreProduct::where('id', $value->product_id)->find(); + if(in_array($order['store_id'],[17,18])){ + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); + }else{ + $find = StoreProduct::where('id', $value->product_id)->find(); + } $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; $value->total_price = bcmul($value['price'], $value['cart_num'], 2); From 2cbe0fc8a3e8d6532dbe0a17e1c4702e2120556c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 14:05:33 +0800 Subject: [PATCH 54/72] =?UTF-8?q?fix(StoreProductLogic):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF=20store=5Fid=20?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/store_product/StoreProductLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 49f45c5b1..115890c38 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -221,7 +221,7 @@ class StoreProductLogic extends BaseLogic // $dealCate = self::dealChangeCate($params['cate_id']); //修改 - StoreBranchProduct::where('product_id', $params['id'])->update([ + StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id',[17,18])->update([ 'price' => $params['price'], 'vip_price' => $params['vip_price'], 'cost' => $params['cost'], From 1dca91528d5982b70e78d8f999b555e0db24ff34 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 14:12:56 +0800 Subject: [PATCH 55/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BF=A1=E6=81=AF=E7=A9=BA=E5=80=BC=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/warehouse_product/WarehouseProductLists.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 419199631..beffc5978 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -106,6 +106,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } } else { $item->store_name = ''; + $item->image = ''; + $item->price = ''; } if ($item->warehouse_id) { $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); @@ -114,6 +116,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } if ($item->supplier_id) { $item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name'); + }else{ + $item->supplier_name = ''; } $item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : ''; $item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : ''; From 6e0a9e73f1ea0a63ab14298d02a95b9199f168cd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 17:53:43 +0800 Subject: [PATCH 56/72] =?UTF-8?q?feat(warehouse=5Fproduct):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BB=93=E5=BA=93=E4=BA=A7=E5=93=81=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WarehouseProductController.php | 11 ++++++++++ .../lists/statistics/StoreProductLists.php | 12 ++++++++++- .../StoreBranchProductLists.php | 2 +- app/admin/lists/supplier/SupplierLists.php | 7 +++++-- .../WarehouseProductLists.php | 4 ++-- .../WarehouseProductLogic.php | 21 +++++++++++++++++++ .../validate/supplier/SupplierValidate.php | 4 ++-- app/common/service/xlsx/OrderDetail.php | 18 +++++++++------- 8 files changed, 64 insertions(+), 15 deletions(-) diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index 35f2971d9..1578d14a1 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -109,6 +109,17 @@ class WarehouseProductController extends BaseAdminController return $this->data($result); } + /** + * @notes 结算 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function settlement(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::settlement($id); + return $this->success('结算成功', [], 1, 1); + } /** * 确认操作 */ diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index b6bb67044..f64a536df 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -80,7 +80,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $list = StoreProduct::where($this->searchWhere) ->alias('p') // 为 StoreProduct 表设置别名 ->limit($this->limitOffset, $this->limitLength) - ->field('p.id, p.store_name, p.image,p.stock as total_stock,p.unit, + ->field('p.id, p.store_name, p.image,p.stock as total_stock,p.unit,p.total_price, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock, @@ -110,6 +110,16 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa }else{ $item->total_purchase='0元'; } + if($item->total_price){ + $item->total_price=$item->total_price.'元'; + }else{ + $item->total_price='0元'; + } + if($item->total_stock){ + $item->total_stock=$item->total_stock.'|'.$unit_name; + }else{ + $item->total_stock=''; + } }) ->toArray(); return $list; diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 032545c97..3feb38d73 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -83,7 +83,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI $this->searchWhere[] = $where; } return StoreBranchProduct::where($this->searchWhere) - ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information']) + ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price']) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) diff --git a/app/admin/lists/supplier/SupplierLists.php b/app/admin/lists/supplier/SupplierLists.php index a9321cc6b..c0757cda9 100644 --- a/app/admin/lists/supplier/SupplierLists.php +++ b/app/admin/lists/supplier/SupplierLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\supplier; use app\admin\lists\BaseAdminDataLists; use app\common\model\supplier\Supplier; use app\common\lists\ListsSearchInterface; - +use app\common\model\warehouse_product\WarehouseProduct; /** * 供应链列表 @@ -47,7 +47,10 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface ->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item) { + $item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price'); + $item->total_outstanding_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',0)->sum('total_price'); + }) ->toArray(); } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index beffc5978..c36d44e23 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt public function setSearch(): array { return [ - '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id'], + '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id','is_pay'], 'between_time' => 'create_time' ]; } @@ -71,7 +71,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } } return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time']) + ->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 20c547c90..336528981 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -236,6 +236,27 @@ class WarehouseProductLogic extends BaseLogic throw new BusinessException('没有查到出入库信息'); } + /** + * * @notes 结算 + * @param $id + * @return void + */ + public static function settlement($id){ + Db::startTrans(); + try { + $find=WarehouseProduct::where(['id'=>$id,'financial_pm'=>1,'is_pay'=>0])->find(); + if($find){ + $find->is_pay=1; + $find->save(); + } else{ + throw new BusinessException('没有查到出入库信息'); + } + Db::commit(); + } catch (\Throwable $th) { + Db::rollback(); + throw new BusinessException($th->getMessage()); + } + } /** * @notes 获取商品仓储信息详情 * @param $params diff --git a/app/admin/validate/supplier/SupplierValidate.php b/app/admin/validate/supplier/SupplierValidate.php index 92f4322c2..1aa1d6622 100644 --- a/app/admin/validate/supplier/SupplierValidate.php +++ b/app/admin/validate/supplier/SupplierValidate.php @@ -52,7 +52,7 @@ class SupplierValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['mer_name','phone','settle_cycle','address','mark','status']); + return $this->only(['mer_name','phone','settle_cycle','address']); } @@ -64,7 +64,7 @@ class SupplierValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','mer_name','phone','settle_cycle','address','mark','status']); + return $this->only(['id','mer_name','phone','settle_cycle','address']); } diff --git a/app/common/service/xlsx/OrderDetail.php b/app/common/service/xlsx/OrderDetail.php index 84ba39e80..2fa5e115d 100644 --- a/app/common/service/xlsx/OrderDetail.php +++ b/app/common/service/xlsx/OrderDetail.php @@ -106,13 +106,17 @@ class OrderDetail $sheet->mergeCells('A' . ($count + 11) . ':J' . $count + 11); - $sheet->setCellValue('A' . $count + 12, '仓库',); - // $sheet->setCellValue('B' . $count + 11, $this->warehouse); + + $sheet->setCellValue('A' . $count + 12, '下单人',); $sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12); - $sheet->setCellValue('D' . $count + 12, '送货'); - $sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12); - $sheet->setCellValue('G' . $count + 12, '签收人'); - $sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12); + $sheet->setCellValue('D' . $count + 12, '电话'); + + $sheet->setCellValue('A' . $count + 13, '仓库',); + $sheet->mergeCells('B' . ($count + 13) . ':C' . $count + 13); + $sheet->setCellValue('D' . $count + 13, '送货'); + $sheet->mergeCells('E' . ($count + 13) . ':F' . $count + 13); + $sheet->setCellValue('G' . $count + 13, '签收人'); + $sheet->mergeCells('H' . ($count + 13) . ':J' . $count + 13); // 设置单元格的样式 $styleArray = [ @@ -131,7 +135,7 @@ class OrderDetail ], ], ]; - $sheet->getStyle('A1:J' . ($count + 12))->applyFromArray($styleArray); + $sheet->getStyle('A1:J' . ($count + 13))->applyFromArray($styleArray); // 保存文件到 public 下 From 663defd80df239f6ad0b5249c45914c746eb20cb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 17:57:26 +0800 Subject: [PATCH 57/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86StoreP?= =?UTF-8?q?roductLists.php=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E5=BA=93=E5=AD=98=E8=AE=A1=E7=AE=97=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=BA=93=E5=AD=98=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E5=87=86=E7=A1=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/statistics/StoreProductLists.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index f64a536df..d80652d02 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -116,7 +116,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $item->total_price='0元'; } if($item->total_stock){ - $item->total_stock=$item->total_stock.'|'.$unit_name; + $item->total_stock=bcadd($item->total_stock,$item->warehouse_stock,2).'|'.$unit_name; }else{ $item->total_stock=''; } From 27e4295df589ae24955a67988f4ca5dfe95e2c96 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 6 Sep 2024 23:57:57 +0800 Subject: [PATCH 58/72] =?UTF-8?q?feat(ProductLists):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F=E8=A7=84?= =?UTF-8?q?=E5=88=99=EF=BC=8C=E5=A2=9E=E5=8A=A0'sort'=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/product/ProductLists.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index 3c2bd5d0e..9f98a14ea 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -55,7 +55,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function setDefaultOrder(): array { - return ['price' => 'asc', 'id' => 'desc']; + return ['price' => 'asc', 'id' => 'desc','sort'=>'desc']; } /** From e0713be0a0e442dd8ff34891e2e73f09edfb4d56 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 7 Sep 2024 00:03:49 +0800 Subject: [PATCH 59/72] =?UTF-8?q?feat(ProductLists):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4'sort'=E4=BC=98=E5=85=88=E7=BA=A7=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E6=8E=92=E5=BA=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/product/ProductLists.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index 9f98a14ea..cf59126b6 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -55,7 +55,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis */ public function setDefaultOrder(): array { - return ['price' => 'asc', 'id' => 'desc','sort'=>'desc']; + return ['sort'=>'desc','price' => 'asc', 'id' => 'desc']; } /** From e7687a25a5443c610c540c0984d5dc568b59e4c4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 7 Sep 2024 18:07:58 +0800 Subject: [PATCH 60/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=AD=A3=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=92=8C=E8=AE=A2=E5=8D=95=E9=87=91=E9=A2=9D=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CommissionProductLogic.php | 96 +++++++++++++++---- .../logic/store_order/StoreOrderLogic.php | 7 +- 2 files changed, 78 insertions(+), 25 deletions(-) diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index f6e1688f8..ea3f3ab53 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -193,27 +193,31 @@ class CommissionProductLogic extends BaseLogic */ public function b($find, $order, $product,$user_ship) { - // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['cost'], $find['cart_num']); - $price = $product['cost']; - //门店 + $total_price = bcmul($product['price'], $find['cart_num']); + $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $price=$product['purchase']; + + $brigade_number = bcmul($purchase_price, 0.02, 2);//队长 + $village_number = bcmul($brigade_number, 0.1, 2);//村长 + $platform_number = bcmul($purchase_price, 0.02, 2);//平台 + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + //门店利润 + if($number3<=0){ + $store_number = 0; + }else{ + $store_number = bcsub($number3, $number2, 2); + + } + + //队长 $data[] = [ - 'nickname' => '门店', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.05, - 'number' => bcmul($total_price, 0.05, 2), - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - //平台 - $data[] = [ - 'nickname' => '平台', + 'nickname' => '商户价队长预留', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, @@ -221,11 +225,61 @@ class CommissionProductLogic extends BaseLogic 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, - 'number' => bcmul($total_price, 0.02, 2), + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => 1, + ]; + //村长 + $data[] = [ + 'nickname' => '商户价村长预留', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 1, + ]; + //门店 + $data[] = [ + 'nickname' => '商户价门店', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $store_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + $data[] = [ + 'nickname' => '商户价平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $platform_number, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, 'oid' => $order['id'], 'type' => 2, 'status' => 1, + 'is_activity' => 1, ]; + $data[] = [ 'nickname' => '消耗', 'store_id' => $order['store_id'], diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index b3f84aaf8..1141ae14d 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -48,7 +48,6 @@ class StoreOrderLogic extends BaseLogic $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray(); if (empty($cart_select)) { throw new BusinessException('购物车为空'); - return false; } try { self::$total_price = 0; @@ -238,7 +237,7 @@ class StoreOrderLogic extends BaseLogic $query->field(['id', 'oid', 'product_id', 'cart_info']); }])->where($params)->find(); if (empty($order)) { - throw new \Exception('订单不存在'); + throw new BusinessException('订单不存在'); } $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; @@ -372,7 +371,7 @@ class StoreOrderLogic extends BaseLogic return false; } catch (Exception $e) { \support\Log::info($e->extra['message'] ?? $e->getMessage()); - throw new \Exception($e->extra['message'] ?? $e->getMessage()); + throw new BusinessException($e->getMessage()); } } @@ -383,7 +382,7 @@ class StoreOrderLogic extends BaseLogic $code = generateRandomCode(); $phone = User::where('id',$param['uid'])->value('mobile'); if(empty($phone)){ - throw new \Exception('用户未设置手机号'); + throw new BusinessException('用户未设置手机号'); } $template = getenv('SMS_TEMPLATE'); $check =(new SmsService())->client($phone,$template,$code); From 0214b50ca8a693aa9d2fbe63f1af8de0f9f93d77 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 9 Sep 2024 17:47:08 +0800 Subject: [PATCH 61/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=92=8C=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=96=B0=E5=A2=9E=E4=BA=86=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E4=BB=B7=E6=96=B9=E5=BC=8F=E3=80=81=E8=87=AA?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E3=80=81=E4=BE=9B=E5=BA=94=E5=95=86=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E7=AD=89=E5=AD=97=E6=AE=B5=EF=BC=9B=20fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=AA=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B=20refactor:=20=E9=87=8D=E6=9E=84=E4=BA=86?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E9=83=A8=E5=88=86=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E5=90=8D=EF=BC=9B=20style:=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=BA=86=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E7=A9=BA=E6=A0=BC=E3=80=81=E5=88=86=E5=8F=B7=E7=AD=89?= =?UTF-8?q?=EF=BC=9B=20test:=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=B5=8B=E8=AF=95=EF=BC=9B=20docs:=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E7=9B=B8=E5=85=B3=E6=96=87=E6=A1=A3=EF=BC=9B?= =?UTF-8?q?=20build:=20=E6=9B=B4=E6=96=B0=E4=BA=86=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=EF=BC=9B=20ops:=20=E6=9B=B4=E6=96=B0=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC=EF=BC=9B=20chore:=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E9=A1=B9=E7=9B=AE=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoLists.php | 24 +- .../lists/store_product/StoreProductLists.php | 41 ++- app/api/controller/IndexController.php | 11 +- app/common/logic/CommissionProductLogic.php | 346 +++++++++--------- app/common/logic/PayNotifyLogic.php | 2 + 5 files changed, 252 insertions(+), 172 deletions(-) diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index dd9234c10..2d92d411f 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -13,6 +13,8 @@ use app\common\lists\ListsExcelInterface; use app\common\model\store_category\StoreCategory; use app\common\model\store_order\StoreOrder; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\system_store\SystemStore; +use app\common\model\user\User; /** * 订单购物详情列表 @@ -49,11 +51,26 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('oid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) + ->field('oid,uid,cart_info,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){ + if($item['uid']>0){ + $user=User::where('id',$item['uid'])->field('real_name,mobile')->find(); + if($user){ + if($user['real_name']!=''){ + $item['nickname']=$user['real_name']; + }else{ + $item['nickname']=$user['mobile']; + } + }else{ + $item['nickname']='无'; + } + }else{ + $item['nickname']='无'; + } $item['image']=$find['image'];//商品图片 + $item['system_store']=SystemStore::where('id',$item['store_id'])->value('name')??""; $item['store_name']=$find['store_name'];//商品名称 $item['store_info']=$find['store_info'];//商品规格 $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; @@ -64,6 +81,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI $item['cate_name']='';//商品图片 $item['store_name']='';//商品名称 $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['nickname']=''; + $item['system_store']=''; } return $item; //返回处理后的数据。 }) @@ -108,12 +127,15 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI { $data=[ 'store_name' => '商品名称', + 'system_store' => '门店', + 'nickname' => '用户', 'store_info' => '规格', 'unit_name' => '单位', 'cate_name' => '分类', 'cart_num' => '数量', 'price' => '单价', 'total_price' => '总价', + 'create_time' => '时间', ]; return $data; } diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 382d7d46b..59476522e 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -62,15 +62,49 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa } } return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_info','store_name', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) + ->field(['id', 'image', 'store_info','store_name', 'top_cate_id','two_cate_id','swap', 'product_type', '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) { + $item['bar_code_two']=''; + if(in_array($item['unit'],[2,21])){ + $item['bar_code_two']=$item['bar_code']; + if($item['bar_code']==0){ + $item['bar_code_two']=''; + } + $item['bar_code']=''; + $item['unit_names'] = '称重商品'; + }else{ + if(strlen($item['bar_code'])<10){ + $item['bar_code_two']=$item['bar_code']; + if($item['bar_code']==0){ + $item['bar_code_two']=''; + } + $item['bar_code']=''; + } + $item['unit_names'] = '标准商品'; + } + + $item['supplier_name'] = '自购'; $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); $item['stock'] = bcadd($nums, $stock); - $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + $cate_name=''; + $category_top=StoreCategory::where('id', $item['top_cate_id'])->value('name'); + if($category_top!=''){ + $cate_name='/'.$category_top; + } + // $category_two=StoreCategory::where('id', $item['two_cate_id'])->value('name'); + // if($category_two!=''){ + // $cate_name=$cate_name.'/'.$category_two; + // } + $category_three=StoreCategory::where('id', $item['cate_id'])->value('name'); + if($category_three){ + $cate_name=$cate_name.'/'.$category_three; + } + $item['cate_name'] = $cate_name; + // $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); return $item; })?->toArray(); } @@ -123,6 +157,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa { $data = [ 'id' => '商品id', + 'unit_names' => '计价方式', 'store_name' => '商品名称', 'cate_name'=>'分类', 'unit_name'=>'单位', @@ -132,6 +167,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa 'cost' => '商户', 'price' => '零售', 'bar_code' => '条码', + 'bar_code_two' => '自编码', + 'supplier_name' => '供应商', ]; return $data; } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index b78ec3aae..4021947d1 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,8 +44,17 @@ class IndexController extends BaseApiController public function index() { - return json(1); + + $financeFlow = new StoreFinanceFlow(); + $financeFlowLogic = new StoreFinanceFlowLogic(); + $select_1 = $financeFlow->where('id',16197)->select(); + + foreach ($select_1 as $k => $v) { + if ($v['other_uid'] > 0) { + $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); + } + } } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index ea3f3ab53..17fce9c02 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -31,15 +31,14 @@ class CommissionProductLogic extends BaseLogic if ($user_ship == 5) { $top_cate_id = $product['top_cate_id']; if ($top_cate_id == 15189) { - $this->b($find, $order, $product,$user_ship); + $this->b($find, $order, $product, $user_ship); return true; } - } elseif($user_ship==0) { - $this->b($find, $order, $product,$user_ship); + } elseif ($user_ship == 0) { + $this->b($find, $order, $product, $user_ship); return true; - }else{ + } else { $this->a($find, $order, $village_uid, $brigade_uid, $user_ship, $product); - } } @@ -51,155 +50,15 @@ class CommissionProductLogic extends BaseLogic * 零售价结算 */ public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) - { - // $rose = bcdiv($product['rose'], 100, 2); - if($user_ship==4){ - $total_price = bcmul($product['cost'], $find['cart_num']); - $price=$product['cost']; - }else{ - $total_price = bcmul($product['price'], $find['cart_num']); - $price=$product['price']; - } - // $Distribution = Distribution::where('rate', $rose)->find(); - //门店 - $data[] = [ - 'nickname' => '门店', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.05, - 'number' => bcmul($total_price, 0.05, 2), - 'oid' => $order['id'], - 'type' => 1, - 'status' => 1, - ]; - //平台 - $data[] = [ - 'nickname' => '平台', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.02, - 'number' => bcmul($total_price, 0.02, 2), - 'oid' => $order['id'], - 'type' => 2, - 'status' => 1, - ]; - //村长 - $data[] = [ - 'nickname' => '村长', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'price' => $price, - 'other_uid' => $village_uid, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.01, - 'number' => bcmul($total_price, 0.01, 2), - 'oid' => $order['id'], - 'type' => 3, - 'status' => 1, - ]; - //队长 - $data[] = [ - 'nickname' => '队长', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'price' => $price, - 'other_uid' => $brigade_uid, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.01, - 'number' => bcmul($total_price, 0.01, 2), - 'oid' => $order['id'], - 'type' => 4, - 'status' => 1, - ]; - //会员 - // if ($user_ship == 1) { - // $uid = $order['spread_uid']; - // } else { - // $uid = 0; - // } - // $data[] = [ - // 'store_id' => $order['store_id'], - // 'product_id' => $find['product_id'], - // 'other_uid' => $uid, - // 'number' => bcmul($total_price, $Distribution['user'], 2), - // 'oid' => $order['id'], - // 'type' => 0, - // 'status' => 1, - // ]; - - //会员 - if ($order['spread_uid'] > 0 ||$user_ship>0) { - if (in_array($user_ship, [2, 3])) { - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'price' => $price, - 'other_uid' => $order['spread_uid'], - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.05, - 'number' => bcmul($total_price, 0.05, 2), - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - } else { - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $order['spread_uid'], - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.07, - 'number' => bcmul($total_price, 0.07, 2), - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - } - } - $data[] = [ - 'nickname' => '消耗', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => 0, - 'price' => $price, - 'total_price' => $total_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.01, - 'number' => bcmul($total_price, 0.01, 2), - 'oid' => $order['id'], - 'type' => 6, - 'status' => 1, - ]; - (new StoreFinanceFlowProduct())->saveAll($data); - } - - /** - * 商户价结算 - */ - public function b($find, $order, $product,$user_ship) { $total_price = bcmul($product['price'], $find['cart_num']); $purchase_price = bcmul($product['purchase'], $find['cart_num']); - $price=$product['purchase']; + $price = $product['purchase']; - $brigade_number = bcmul($purchase_price, 0.02, 2);//队长 - $village_number = bcmul($brigade_number, 0.1, 2);//村长 - $platform_number = bcmul($purchase_price, 0.02, 2);//平台 + $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($purchase_price, 0.02, 2); //平台 + $attrition_number = bcmul($purchase_price, 0.01, 2); //损耗 $number1 = bcadd($brigade_number, $village_number, 2); $number2 = bcadd($number1, $platform_number, 2); @@ -207,12 +66,164 @@ class CommissionProductLogic extends BaseLogic //零售-供货价 $number3 = bcsub($total_price, $purchase_price, 2); - //门店利润 - if($number3<=0){ - $store_number = 0; - }else{ - $store_number = bcsub($number3, $number2, 2); + $number4 = bcadd($attrition_number, $number2, 2); + //会员 + if ($order['spread_uid'] > 0 || $user_ship > 0) { + if (in_array($user_ship, [2, 3])) { + $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 + $data[] = [ + 'nickname' => '会员', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'price' => $price, + 'other_uid' => $order['spread_uid'], + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + $number4=bcadd($number4, $vip_number, 2); + } else { + $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 + $data[] = [ + 'nickname' => '会员', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $order['spread_uid'], + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.07, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + ]; + $number4=bcadd($number4, $vip_number, 2); + } + } + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, $number4, 2); + } + + //队长 + $data[] = [ + 'nickname' => '零售队长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $brigade_number, + 'oid' => $order['id'], + 'type' => 4, + 'status' => 1, + 'is_activity' => 1, + ]; + //村长 + $data[] = [ + 'nickname' => '零售村长', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $brigade_number, + 'cart_num' => 0, + 'rate' => 0.01, + 'number' => $village_number, + 'oid' => $order['id'], + 'type' => 3, + 'status' => 1, + 'is_activity' => 1, + ]; + //门店 + $data[] = [ + 'nickname' => '零售门店', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $total_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0, + 'number' => $store_number, + 'oid' => $order['id'], + 'type' => 1, + 'status' => 1, + 'is_activity' => 1, + ]; + //平台 + $data[] = [ + 'nickname' => '零售平台', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.02, + 'number' => $platform_number, + 'oid' => $order['id'], + 'type' => 2, + 'status' => 1, + 'is_activity' => 1, + ]; + + $data[] = [ + 'nickname' => '零售消耗', + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => 0, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.01, + 'number' => $attrition_number, + 'oid' => $order['id'], + 'type' => 6, + 'status' => 1, + ]; + + + (new StoreFinanceFlowProduct())->saveAll($data); + } + + /** + * 商户价结算 + */ + public function b($find, $order, $product, $user_ship) + { + $total_price = bcmul($product['price'], $find['cart_num']); + $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $price = $product['purchase']; + + $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($purchase_price, 0.02, 2); //平台 + $attrition_number = bcmul($purchase_price, 0.01, 2); //损耗 + + $number1 = bcadd($brigade_number, $village_number, 2); + $number2 = bcadd($number1, $platform_number, 2); + + //零售-供货价 + $number3 = bcsub($total_price, $purchase_price, 2); + + $number4 = bcadd($attrition_number, $number2, 2); + + //门店利润 + if ($number3 <= 0) { + $store_number = 0; + } else { + $store_number = bcsub($number3, $number4, 2); } //队长 @@ -222,7 +233,7 @@ class CommissionProductLogic extends BaseLogic 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, - 'total_price' => $total_price, + 'total_price' => $purchase_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => $brigade_number, @@ -254,7 +265,7 @@ class CommissionProductLogic extends BaseLogic 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, - 'total_price' => $store_number, + 'total_price' => $total_price, 'cart_num' => $find['cart_num'], 'rate' => 0, 'number' => $store_number, @@ -270,7 +281,7 @@ class CommissionProductLogic extends BaseLogic 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, - 'total_price' => $platform_number, + 'total_price' => $purchase_price, 'cart_num' => $find['cart_num'], 'rate' => 0.02, 'number' => $platform_number, @@ -281,15 +292,15 @@ class CommissionProductLogic extends BaseLogic ]; $data[] = [ - 'nickname' => '消耗', + 'nickname' => '商户价消耗', 'store_id' => $order['store_id'], 'product_id' => $find['product_id'], 'other_uid' => 0, 'price' => $price, - 'total_price' => $total_price, + 'total_price' => $purchase_price, 'cart_num' => $find['cart_num'], 'rate' => 0.01, - 'number' => bcmul($total_price, 0.01, 2), + 'number' => $attrition_number, 'oid' => $order['id'], 'type' => 6, 'status' => 1, @@ -303,10 +314,10 @@ class CommissionProductLogic extends BaseLogic // $rose = bcdiv($product['rose'], 100, 2); $total_price = bcmul($product['price'], $find['cart_num']); $purchase_price = bcmul($product['purchase'], $find['cart_num']); - $price=$product['price']; - $brigade_number = bcmul($total_price, 0.02, 2);//队长 - $village_number = bcmul($brigade_number, 0.1, 2);//村长 - $platform_number = bcmul($total_price, 0.02, 2);//平台 + $price = $product['price']; + $brigade_number = bcmul($total_price, 0.02, 2); //队长 + $village_number = bcmul($brigade_number, 0.1, 2); //村长 + $platform_number = bcmul($total_price, 0.02, 2); //平台 $number1 = bcadd($brigade_number, $village_number, 2); $number2 = bcadd($number1, $platform_number, 2); @@ -315,11 +326,10 @@ class CommissionProductLogic extends BaseLogic $number3 = bcsub($total_price, $purchase_price, 2); //门店利润 - if($number3<=0){ + if ($number3 <= 0) { $store_number = 0; - }else{ + } else { $store_number = bcsub($number3, $number2, 2); - } //队长 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 6ce86964f..f90a6dbd1 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -352,6 +352,7 @@ class PayNotifyLogic extends BaseLogic if ($type == 1) { $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0); $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); + StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]); } else { $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0); $user->now_money = bcadd($user['now_money'], $money, 2); @@ -366,6 +367,7 @@ class PayNotifyLogic extends BaseLogic if ($type == 1) { $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); + StoreOrder::where('id', $order['id'])->update(['refund_status' => 2]); } else { $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $money, 2); From b65ab15e2af5374e589e2796cebab06e7b84f673 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 9 Sep 2024 17:57:03 +0800 Subject: [PATCH 62/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_product/StoreProductLists.php | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 59476522e..f2902ad5a 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -62,25 +62,25 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa } } return StoreProduct::where($this->searchWhere) - ->field(['id', 'image', 'store_info','store_name', 'top_cate_id','two_cate_id','swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information']) + ->field(['id', 'image', 'store_info', 'store_name', 'top_cate_id', 'two_cate_id', 'swap', 'product_type', '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) { - $item['bar_code_two']=''; - if(in_array($item['unit'],[2,21])){ - $item['bar_code_two']=$item['bar_code']; - if($item['bar_code']==0){ - $item['bar_code_two']=''; + $item['bar_code_two'] = ''; + if (in_array($item['unit'], [2, 21])) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; } - $item['bar_code']=''; + $item['bar_code'] = ''; $item['unit_names'] = '称重商品'; - }else{ - if(strlen($item['bar_code'])<10){ - $item['bar_code_two']=$item['bar_code']; - if($item['bar_code']==0){ - $item['bar_code_two']=''; + } else { + if (strlen($item['bar_code']) < 10) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; } - $item['bar_code']=''; + $item['bar_code'] = ''; } $item['unit_names'] = '标准商品'; } @@ -90,18 +90,20 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); $item['stock'] = bcadd($nums, $stock); - $cate_name=''; - $category_top=StoreCategory::where('id', $item['top_cate_id'])->value('name'); - if($category_top!=''){ - $cate_name='/'.$category_top; + $cate_name = ''; + $category_top = StoreCategory::where('id', $item['top_cate_id'])->value('name'); + if ($category_top != '') { + $cate_name = '/' . $category_top; } - // $category_two=StoreCategory::where('id', $item['two_cate_id'])->value('name'); - // if($category_two!=''){ - // $cate_name=$cate_name.'/'.$category_two; - // } - $category_three=StoreCategory::where('id', $item['cate_id'])->value('name'); - if($category_three){ - $cate_name=$cate_name.'/'.$category_three; + if (!$category_top) { + $category_two = StoreCategory::where('id', $item['two_cate_id'])->value('name'); + if ($category_two != '') { + $cate_name = $cate_name . '/' . $category_two; + } + } + $category_three = StoreCategory::where('id', $item['cate_id'])->value('name'); + if ($category_three) { + $cate_name = $cate_name . '/' . $category_three; } $item['cate_name'] = $cate_name; // $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); @@ -118,8 +120,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa */ public function count(): int { - $export=$this->request->get('export'); - if($export==1){ + $export = $this->request->get('export'); + if ($export == 1) { $class_all = $this->request->get('class_all'); if ($class_all) { //查3级别的 @@ -159,9 +161,9 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa 'id' => '商品id', 'unit_names' => '计价方式', 'store_name' => '商品名称', - 'cate_name'=>'分类', - 'unit_name'=>'单位', - 'store_info'=>'规格', + 'cate_name' => '分类', + 'unit_name' => '单位', + 'store_info' => '规格', 'stock' => '库存', 'purchase' => '采购价', 'cost' => '商户', From be8881b1ad92e263813b9f876357ed1951563f61 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 9 Sep 2024 17:57:33 +0800 Subject: [PATCH 63/72] =?UTF-8?q?feat(StoreProductLists):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_product/StoreProductLists.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index f2902ad5a..85b0210f1 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -85,7 +85,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa $item['unit_names'] = '标准商品'; } - $item['supplier_name'] = '自购'; $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); @@ -170,7 +169,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa 'price' => '零售', 'bar_code' => '条码', 'bar_code_two' => '自编码', - 'supplier_name' => '供应商', ]; return $data; } From 20095c8085ef5d23039897256bc63e27af1e89d1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 15:15:07 +0800 Subject: [PATCH 64/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoLists.php | 5 +- .../logic/store_order/StoreOrderLogic.php | 64 +++++------ app/common/logic/CommissionProductLogic.php | 100 +++++++++++------- app/common/logic/CommissionnLogic.php | 4 +- .../logic/store_order/StoreOrderLogic.php | 31 ++++-- 5 files changed, 123 insertions(+), 81 deletions(-) diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index 2d92d411f..859a8987e 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,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) + ->field('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){ @@ -75,6 +75,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI $item['store_info']=$find['store_info'];//商品规格 $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; }else{ $item['image']='';//商品图片 $item['unit_name']='';//商品图片 @@ -83,6 +85,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI $item['store_info']='';//商品规格-(数据库叫商品简介) $item['nickname']=''; $item['system_store']=''; + $item['cart_info']=[]; } return $item; //返回处理后的数据。 }) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index fc29cda10..d340cad97 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -118,42 +118,44 @@ class StoreOrderLogic extends BaseLogic public static function refund($detail, $params) { if (isset($params['product_arr']) && count($params['product_arr']) > 0) { - $refund_price = $params['refund_price']; - $refund_num = 0; - foreach ($params['product_arr'] as $k => $v) { - $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); - if ($find) { - $refund_num += $v['cart_num']; - $cart_num = bcsub($find['cart_num'], $v['cart_num']); - $total_price = bcmul($find['price'], $cart_num); - $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; - StoreOrderCartInfo::where('id', $find['id'])->update($data); - $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); - foreach ($arr as $key => $value) { - $value['cart_num'] = $cart_num; - $value['total_price'] = bcmul($cart_num, $value['price'], 2); - $value['number'] = bcmul($value['total_price'], $value['rate'], 2); - StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); - unset($value['id']); - $value['create_time'] = strtotime($value['create_time']); - $value['update_time'] = strtotime($value['update_time']); - StoreFinanceFlowProduct::create($value); - } - } - } - $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); - $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); - $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); - StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); - CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); - - StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); //微信支付 if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { $money = (int)bcmul($params['refund_price'], 100); + $pay_price = (int)bcmul($detail['pay_price'], 100); $refund = (new \app\common\logic\store_order\StoreOrderLogic()) - ->refund($params['order_id'], $money, $detail['pay_price']); + ->refund($params['order_id'], $money, $pay_price); if ($refund) { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } + } + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + $detail['refund_price']=$refund_price; + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); return '退款成功'; } } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 17fce9c02..68d2e52cb 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -7,6 +7,7 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\user\User; use PDO; use support\Log; @@ -51,8 +52,8 @@ class CommissionProductLogic extends BaseLogic */ public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['purchase']; $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 @@ -69,43 +70,60 @@ class CommissionProductLogic extends BaseLogic $number4 = bcadd($attrition_number, $number2, 2); //会员 - if ($order['spread_uid'] > 0 || $user_ship > 0) { - if (in_array($user_ship, [2, 3])) { - $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'price' => $price, - 'other_uid' => $order['spread_uid'], - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.05, - 'number' => $vip_number, - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - $number4=bcadd($number4, $vip_number, 2); - } else { - $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $order['spread_uid'], - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.07, - 'number' => $vip_number, - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - $number4=bcadd($number4, $vip_number, 2); + $uid = 0; + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } + if ($order['uid'] > 0) { + $uid = $order['uid']; + } + $user = User::where('id', $uid)->find(); + $delete_time=null; + $nickname='会员'; + if ($user) { + $moeny = bcsub($user['total_recharge_amount'], $user['purchase_funds'], 2); + if ($moeny < $user['first_purchase_funds']) { + $delete_time=1; + $nickname='首充没用完,会员不分配'; } } + if (in_array($user_ship, [2, 3])) { + $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'price' => $price, + 'other_uid' => $uid, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } else { + $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $uid, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.07, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } //门店利润 if ($number3 <= 0) { $store_number = 0; @@ -202,8 +220,8 @@ class CommissionProductLogic extends BaseLogic */ public function b($find, $order, $product, $user_ship) { - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['purchase']; $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 @@ -312,8 +330,8 @@ class CommissionProductLogic extends BaseLogic public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['price']; $brigade_number = bcmul($total_price, 0.02, 2); //队长 $village_number = bcmul($brigade_number, 0.1, 2); //村长 diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index 79c823916..d3da5fd75 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order = $order; $financeLogic->user['uid'] = $order['uid']; - $pay_price = $order['pay_price']; + $pay_price=bcsub($order['pay_price'],$order['refund_price'],2); $number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number'); $fees = bcsub($pay_price, $number, 2); if ($fees > 0) { @@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic $financeLogic->user['uid'] = $order['uid']; $financeLogic->other_arr['vip_uid'] = $uid; $financeLogic->order = $order; - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 1141ae14d..a67acfad3 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -250,12 +250,31 @@ class StoreOrderLogic extends BaseLogic if ($order['pay_type'] == 19){ $order['deduction_price'] = "0.00"; } - - $detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray(); + $product=StoreOrderCartInfo::where(['oid'=>$order['id']]) + ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time') + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); + if($find){ + $item['image']=$find['image'];//商品图片 + $item['name']=$find['store_name'];//商品名称 + $item['store_info']=$find['store_info'];//商品规格 + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; + }else{ + $item['image']='';//商品图片 + $item['unit_name']='';//商品图片 + $item['cate_name']='';//商品图片 + $item['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['nickname']=''; + $item['system_store']=''; + $item['cart_info']=[]; + } + return $item; //返回处理后的数据。 + }); + $order['product']=$product; $vip =0; - if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){ - $vip = 1; - } $order['vip'] = $vip; return $order->toArray(); } @@ -371,7 +390,7 @@ class StoreOrderLogic extends BaseLogic return false; } catch (Exception $e) { \support\Log::info($e->extra['message'] ?? $e->getMessage()); - throw new BusinessException($e->getMessage()); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } } From 6b0d5e3edb88e02bdb86717e04018079c2470c8f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 17:10:15 +0800 Subject: [PATCH 65/72] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F=E4=BB=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BA=93=E5=AD=98=E6=80=BB=E9=87=8F=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/statistics/StoreProductLists.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index d80652d02..af5b65560 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -92,6 +92,11 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa ->each(function ($item) { // 计算总库存 $unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); + if($item->total_stock){ + $item->total_stock=bcadd($item->total_stock??0,$item->warehouse_stock??0,2).'|'.$unit_name; + }else{ + $item->total_stock=''; + } $item->sales=$item->sales.'|'.$unit_name; $item->store_stock=$item->store_stock.'|'.$unit_name; $item->warehouse_stock=$item->warehouse_stock.'|'.$unit_name; @@ -115,11 +120,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa }else{ $item->total_price='0元'; } - if($item->total_stock){ - $item->total_stock=bcadd($item->total_stock,$item->warehouse_stock,2).'|'.$unit_name; - }else{ - $item->total_stock=''; - } }) ->toArray(); return $list; From 40cc604461beacc924076c16fef28ba43d124c45 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 17:58:23 +0800 Subject: [PATCH 66/72] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=A7=AF=E5=88=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/UserSignLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/logic/UserSignLogic.php b/app/common/logic/UserSignLogic.php index 47cfc609b..7e0d443cf 100644 --- a/app/common/logic/UserSignLogic.php +++ b/app/common/logic/UserSignLogic.php @@ -67,7 +67,7 @@ class UserSignLogic extends BaseLogic $write = self::write($order, $total_vip, 0, 1, 9); self::write_log($write, $total_vip, 0, 7); self::write_log($write, $total_vip, 0, 9, 0); - User::where('id', $order->uid)->inc('integral', $total_vip)->update(); + User::where('id', $order->uid)->update(['integral'=>$total_vip,'first_purchase_funds'=>$order['price']]); } return true; } From bbbed26fbf2ce2d1204c69e01adc18c46c145db4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 21:47:14 +0800 Subject: [PATCH 67/72] feat(StoreOrderLists, UserRechargeLists, OrderLogic): updated lists, logic for orders & refunds, fixed bugs, improved code quality --- .../lists/store_order/StoreOrderLists.php | 2 ++ .../lists/user_recharge/UserRechargeLists.php | 33 ++++++++++++++++++- app/api/logic/order/OrderLogic.php | 2 -- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index ac3ab608b..187af04e6 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -148,6 +148,8 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface 'nickname' => '用户', 'total_price' => '总金额', 'pay_price' => '实际支付', + 'status_name' => '状态', + 'refund_price' => '退款金额', 'pay_time' => '支付时间', ]; return $data; diff --git a/app/admin/lists/user_recharge/UserRechargeLists.php b/app/admin/lists/user_recharge/UserRechargeLists.php index c1e7a1ee3..01d0a4670 100644 --- a/app/admin/lists/user_recharge/UserRechargeLists.php +++ b/app/admin/lists/user_recharge/UserRechargeLists.php @@ -7,13 +7,14 @@ use app\admin\lists\BaseAdminDataLists; use app\common\model\user_recharge\UserRecharge; use app\common\lists\ListsSearchInterface; use app\common\model\user\User; +use app\common\lists\ListsExcelInterface; /** * 充值记录列表 * Class UserRechargeLists * @package app\admin\listsuser_recharge */ -class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface +class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -88,4 +89,34 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa return UserRecharge::where($this->searchWhere)->count(); } + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'id' => 'ID', + 'order_id'=>'订单号', + 'nickname' => '用户', + 'price' => '实际支付', + 'paid_name' => '状态', + 'pay_time' => '支付时间', + ]; + return $data; + } } \ No newline at end of file diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index e444f5863..fb9ac27af 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -302,8 +302,6 @@ class OrderLogic extends BaseLogic if ($uid > 0) { $address = UserAddress::where(['uid' => $uid])->find(); if ($address) { - $_order['real_name'] = $address['real_name']; - $_order['user_phone'] = $address['phone']; if ($address['area']) { $_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? ''; } 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 68/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=95=86=E5=93=81=E3=80=81=E7=BC=96=E8=BE=91=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=95=86=E5=93=81=E5=92=8C=E5=88=A0=E9=99=A4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=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 a6aabe21a..955f37fa5 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 859a8987e..2c712c047 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 84c9a84f0..02bb82690 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 f90a6dbd1..0092c9410 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'); From 4fd112b900e0fc04121b3c5289d10173785f6a90 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 13 Sep 2024 09:22:20 +0800 Subject: [PATCH 69/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E9=85=8D=E7=BD=AE=E7=9A=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoLogic.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php index 02bb82690..711996c56 100644 --- a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -4,6 +4,7 @@ namespace app\admin\logic\store_order_cart_info; use app\admin\logic\statistic\TradeStatisticLogic; use app\common\logic\BaseLogic; +use app\common\model\dict\DictData; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; @@ -29,10 +30,18 @@ class StoreOrderCartInfoLogic extends BaseLogic { Db::startTrans(); try { + $cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find(); if($cart_info['is_pay']==1){ throw new BusinessException('已支付订单无法追加'); } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($cart_info['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } foreach($params['product_arr'] as $k=>$v){ $find=StoreProduct::where('id',$v['product_id'])->find(); @@ -97,6 +106,13 @@ class StoreOrderCartInfoLogic extends BaseLogic if($find['is_pay']==1){ throw new BusinessException('已支付订单无法编辑'); } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($find['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } $find->cart_num = $params['cart_num']; $find->total_price = bcmul($params['cart_num'], $find->price, 2); $find->save(); @@ -128,6 +144,13 @@ class StoreOrderCartInfoLogic extends BaseLogic if($find['is_pay']==1){ throw new BusinessException('已支付订单无法删除'); } + $value=DictData::where('type_value','vendors_store')->column('value'); + if(!$value){ + throw new BusinessException('请先配置店铺'); + } + if(!in_array($find['store_id'],$value)){ + throw new BusinessException('该订单不属于可设置店铺'); + } $find->delete_time=time(); $find->save(); $total_price = StoreOrderCartInfo::where('oid', $find['oid'])->sum('total_price'); From ca58281282dd6d86a1fec51544937d595a6f8e21 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 13 Sep 2024 11:47:14 +0800 Subject: [PATCH 70/72] =?UTF-8?q?feat(StoreOrderLists):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E9=80=80=E6=AC=BE=E4=BB=B7=E6=A0=BC=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_order/StoreOrderLists.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 187af04e6..2ab7640cd 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -63,7 +63,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $query->whereIn('status', $status); } }) - ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id']) + ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id','refund_price']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { From f480e8aee76bff0903433be2065199ec3fcd4f8b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 13 Sep 2024 13:58:39 +0800 Subject: [PATCH 71/72] =?UTF-8?q?feat(SystemStoreMenu):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BD=AF=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system_store/SystemStoreMenu.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/common/model/system_store/SystemStoreMenu.php b/app/common/model/system_store/SystemStoreMenu.php index 827a7a273..d1ecfcc07 100644 --- a/app/common/model/system_store/SystemStoreMenu.php +++ b/app/common/model/system_store/SystemStoreMenu.php @@ -16,6 +16,7 @@ namespace app\common\model\system_store; use app\common\model\BaseModel; +use think\model\concern\SoftDelete; /** @@ -25,7 +26,8 @@ use app\common\model\BaseModel; */ class SystemStoreMenu extends BaseModel { - + use SoftDelete; + protected $deleteTime = 'delete_time'; } From 765e08fe9ad98bd13b072d415eab8fd20797a539 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 13 Sep 2024 16:27:30 +0800 Subject: [PATCH 72/72] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0is=5Flack?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=88=B0ProductLists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/product/ProductLists.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index cf59126b6..78a9fc274 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -87,7 +87,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis } else { $order = [$field => $order]; } - $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'; + $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,is_lack'; $off_activity = Config::where('name', 'off_activity')->value('value'); if ($off_activity == 1) { $tag = '赠10%品牌礼品券'; @@ -104,7 +104,7 @@ 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,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'; + $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,is_lack'; } } $this->off_activity = $off_activity; @@ -119,6 +119,9 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis if ($off_activity == 0 && $user_ship == 5 && $item['top_cate_id'] == 15189) { $item['price'] = $item['cost']; } + if($item['is_lack']==1){ + $tag='缺货'; + } $item['tag'] = $tag; return $item; })