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 1/8] 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 2/8] =?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 3/8] =?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 4/8] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8BusinessException?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=94=AF=E4=BB=98=E5=9B=9E?= =?UTF-8?q?=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 5/8] =?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 6/8] 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 7/8] 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 8/8] =?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', '更新后'); - } }