From acac4d2950cca62e9ae0451167b785362b1adfb2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 10:20:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(admin):=20=E5=85=B3=E9=97=AD=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E5=95=86=E5=93=81=E5=AF=BC=E5=85=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 关闭了 StoreProductController 中的 import 方法,返回接口已关闭的错误信息 - 在 WarehouseLogic、StoreBranchProductLogic 和 SystemStoreStorageLogic 中添加了库存变动日志记录 - 使用 SqlChannelLog 函数记录 StoreProduct、StoreBranchProduct 和 WarehouseProductStorege 表的库存变动 --- .../store_product/StoreProductController.php | 78 -- app/admin/logic/statistic/WarehouseLogic.php | 3 + .../StoreBranchProductLogic.php | 2 + .../SystemStoreStorageLogic.php | 3 + app/common/logic/DemoPayNotifyLogic.php | 850 ------------------ app/common/logic/PayNotifyLogic.php | 4 + .../logic/store_order/StoreOrderLogic.php | 1 + 7 files changed, 13 insertions(+), 928 deletions(-) delete mode 100644 app/common/logic/DemoPayNotifyLogic.php diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index f2dbbe0fc..11e4810d8 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -130,83 +130,5 @@ class StoreProductController extends BaseAdminController public function import() { return $this->fail('接口已关闭'); - $product_arr = $this->request->post('product_arr'); - $store_arr = $this->request->post('store_arr'); - $stock_type = $this->request->post('stock_type', 1); - $warehouse_id = $this->request->post('warehouse_id'); - $count = count($store_arr); - foreach ($product_arr as $key => $arr) { - $stock = bcmul($arr['stock'], $count); - $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums'); - if ($nums < $stock) { - return $this->fail('商品库存不足'); - } - } - if ($count == 1) { - $store_id = $store_arr[0]; - 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, - ]; - if ($arr['stock'] == 0) { - $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - } else { - WarehouseProductLogic::add($data); - $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); - if ($find) { - StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); - } else { - $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); - } - } - // StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - - // Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]); - } - } else { - foreach ($product_arr as $key => $arr) { - foreach ($store_arr as $k => $store_id) { - $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, - ]; - if ($arr['stock'] == 0) { - $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - } else { - WarehouseProductLogic::add($data); - $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); - if ($find) { - StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); - } else { - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); - } - } - - // $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); - // StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - // Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]); - } - } - } - return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); - } } diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index d0fab7414..191c5d51b 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -271,10 +271,13 @@ class WarehouseLogic extends BaseLogic { if ($parmas['type'] == 1) { $res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]); + SqlChannelLog('StoreProduct', $parmas['id'], 0, 0, Request()->url()); } elseif ($parmas['type'] == 2) { $res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]); + SqlChannelLog('StoreBranchProduct', $parmas['id'], 0, 0, Request()->url()); } elseif ($parmas['type'] == 3) { $res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]); + SqlChannelLog('WarehouseProductStorege', $parmas['id'], 0, 0, Request()->url()); } return $res; } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index d3bf75c31..e1394f7ab 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -88,6 +88,7 @@ class StoreBranchProductLogic extends BaseLogic $branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2); StoreBranchProduct::update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=> $params['id']]); + SqlChannelLog('StoreBranchProduct', $params['id'], $params['nums'], 1, Request()->url()); StoreProduct::update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=> $params['product_id']]); } else { @@ -95,6 +96,7 @@ class StoreBranchProductLogic extends BaseLogic $stock = bcsub($find['stock'], $params['nums'], 2); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=>$params['id']]); + SqlChannelLog('StoreBranchProduct', $params['id'], $params['nums'], -1, Request()->url()); StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]); } diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 4e221db77..0a9208d50 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -70,11 +70,13 @@ class SystemStoreStorageLogic extends BaseLogic $branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find(); if($branch_product){ $branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]); + SqlChannelLog('StoreBranchProduct', $branch_product['id'], $find['nums'], 1,Request()->url()); }else{ $storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty(); $storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct); $storeBranchProduct->stock = $find['nums']; $storeBranchProduct->save(); + SqlChannelLog('StoreBranchProduct', $branch_product['id'], $find['nums'], 1,Request()->url()); } }else{ $find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'确认时间:'.date('Y-m-d H:i:s',time())]); @@ -136,6 +138,7 @@ class SystemStoreStorageLogic extends BaseLogic $storage->status = 1; $storage->staff_id = $params['staff_id']; $storage->save(); + SqlChannelLog('StoreBranchProduct', $storage['id'], $storage['nums'], 1,Request()->url()); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/DemoPayNotifyLogic.php b/app/common/logic/DemoPayNotifyLogic.php deleted file mode 100644 index e5025e496..000000000 --- a/app/common/logic/DemoPayNotifyLogic.php +++ /dev/null @@ -1,850 +0,0 @@ -getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); - throw new \Exception($e->getMessage()); - } - } - - /** - * 余额支付 - * @param $orderSn - * @param $extra - * @return bool - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function balancePay($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['now_money'] < $order['pay_price']) { - throw new \Exception('余额不足'); - } - // $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - if ($order['is_storage'] == 1) { - $order->status = 2; - UserProductStorageLogic::add($order); - } - // 减去余额 - $user->now_money = bcsub($user['now_money'], $order['pay_price'], 2); - $user->save(); - - if ($order['spread_uid'] > 0 && $user['user_ship'] == 1) { - $oldUser = User::where('id', $order['spread_uid'])->value('purchase_funds'); - if ($oldUser < $order['pay_price']) { - $order['pay_price'] = $oldUser; - } - } - // self::addUserSing($order); - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - // self::descStock($order['id']); - } - self::afterPay($order); - if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { - $checkArr = [ - 'cart_id' => $order['cart_id'], - 'store_id' => $order['store_id'], - ]; - self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); - } - if ($extra && $extra['store_id'] && $order['reservation'] !=1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['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' => '您有一笔新的订单']); - } - return true; - // Redis::send('push-platform-print', ['id' => $order['id']], 60); - - } - - /** - * 礼品券支付 - * @param $orderSn - * @param $extra - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - - public static function gift_pay($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['integral'] < $order['pay_price']) { - throw new \Exception('礼品券不足'); - } - $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - // 减去礼品券 - $user->integral = bcsub($user['integral'], $order['pay_price'], 2); - $user->save(); - //入礼品券表扣款记录 - $sing = [ - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - // 'title' => '订单扣除兑换券', - 'title' => 5, - 'financial_pm' => 0, - 'status' => 1, - 'store_id' => $order['store_id'], - 'number' => $order['pay_price'], - 'user_ship' => $user['user_ship'], - ]; - UserSign::create($sing); - - if ($extra && $extra['store_id']) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::lessWriteOff($params); - } - self::dealProductLog($order); - } - - - /** - * 采购款支付 - * @param $orderSn - * @param $extra - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function purchase_funds($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - $user = User::where('id', $order['uid'])->find(); - if ($user['purchase_funds'] < $order['pay_price']) { - throw new \Exception('采购款不足'); - } - $order->money = $order['pay_price']; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - if ($order['is_storage'] == 1) { - $order->status = 2; - UserProductStorageLogic::add($order); - } - // 减去采购款 - $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); - - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 1, $order['store_id']); - // if ($user['user_ship'] == 1) { - // self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS); - // } - // self::addUserSing($order); - self::afterPay($order); - if ($extra && $extra['store_id'] && $order['reservation'] !=1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::writeOff($params); - } - self::dealProductLog($order); - if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { - $checkArr = [ - 'cart_id' => $order['cart_id'], - 'store_id' => $order['store_id'], - ]; - self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); - } - - // Redis::send('push-platform-print', ['id' => $order['id']], 60); - if(in_array($order['shipping_type'],[1,2])){ - PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - } - } - - /** - * @notes 微信通用回调 - * @param $orderSn - * @param array $extra - * @date 2023/2/27 15:28 - */ - public static function wechat_common($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - $order->status = 1; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - if ($order['is_storage'] == 1) { - $order->status = 2; - UserProductStorageLogic::add($order); - } - if ($order->pay_type != 10) { - $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); - } else { - $extra['transaction_id'] = time(); - } - $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; - } else { - $capitalFlowDao = new CapitalFlowLogic($user); - //微信支付和用户余额无关 - $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']); - } - $order->save(); - if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) { - $checkArr = [ - 'cart_id' => $order['cart_id'], - 'store_id' => $order['store_id'], - ]; - self::dealGoodsLeft($checkArr, $order['uid'], $order['id']); - } - self::afterPay($order, $extra['transaction_id']); - // self::addUserSing($order); - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); - } - return true; - } - - //退款 - public static function refund($orderSn, $extra = []) - { - //更新状态 - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { - //充值 - $orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); - if ($orderRe->isEmpty() || $orderRe->status == -1) { - return true; - } - $orderRe->status = -1; - $orderRe->refund_price = $orderRe->price; - $orderRe->refund_time = time(); - $orderRe->remarks = ''; - $orderRe->save(); - $purchase_funds = User::where('id', $orderRe['uid'])->value('purchase_funds'); - $user = User::where('id', $orderRe['uid'])->find(); - $capitalFlowDao = new CapitalFlowLogic($user); - if ($purchase_funds >= $orderRe['price']) { - User::where('id', $orderRe['uid'])->dec('purchase_funds', $orderRe['refund_price'])->update(); - $capitalFlowDao->userExpense('user_balance_recharge_refund', 'order', $orderRe['id'], $orderRe['refund_price'], '', 1, $orderRe['store_id']); - } else { - User::where('id', $orderRe['uid'])->dec('purchase_funds', $purchase_funds)->update(); - $capitalFlowDao->userExpense('user_balance_recharge_refund', 'order', $orderRe['id'], $purchase_funds, '', 1, $orderRe['store_id']); - } - //退还 充值得兑换券 - UserSignLogic::RefundRecharge($orderRe); - return true; - } - $order->status = OrderEnum::REFUND_PAY; - $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; - $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2); - $order->refund_reason_time = time(); - $order->refund_num += 1; - $order->save(); - //日志记录 - //加用户余额,采购款, 日志记录 加数量 - $user = User::where('id', $order['uid'])->findOrEmpty(); - $capitalFlowDao = new CapitalFlowLogic($user); - $deal_money = bcdiv($extra['amount']['refund'], 100, 2); - //对应比例得退礼品券逻辑 - $discount = self::getDiscount($user->user_ship); - $total_price = bcmul($order->refund_price, $discount, 2); - if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { - if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 - $user->now_money = bcadd($user->now_money, $deal_money, 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money); - } - if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 - $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); - $user->save(); - //增加数量 - self::addStock($order['id']); - //退款 - $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); - } - UserSignLogic::RefundOrder($order); - - return true; - } - //积分 - UserSignLogic::RefundOrder($order); - //微信日志 user_order_refund - $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); - //处理财务流水退还 - (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); - self::addStock($order['id']); //微信 - return true; - // self::afterPay($order,$extra['transaction_id']); - } - - /** - * 现金退款相关 - * @param $orderSn - * @param $extra - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function cash_refund($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { - return true; - } - $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; - $order->refund_price = $order->pay_price; - $order->refund_reason_time = time(); - $order->refund_num += 1; - $order->save(); - //日志记录 - $model = new StoreCashFinanceFlow(); - $model->store_id = $order['store_id'] ?? 0; - $model->cash_price = $order->pay_price; - $model->receivable = $order->pay_price; - $model->remark = '退款'; - $model->type = 1; - $model->status = YesNoEnum::YES; - $model->save(); - //增加数量 - self::addStock($order['id']); - return true; - } - - /** - * 充值现金退款相关 - * @param $orderId - * @param $extra - * @return true - */ - public static function recharge_cash_refund($orderId, $extra = []) - { - $order = UserRecharge::where('id', $orderId)->findOrEmpty(); - if ($order->isEmpty() || $order->status == -1) { - return true; - } - $order->status = -1; - $order->refund_price = $order->price; - $order->refund_time = time(); - $order->remarks = ''; - $order->save(); - return true; - } - - /** - * 充值 - */ - public static function recharge($orderSn, $extra = [], $type = 'wechat') - { - $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - if ($type == 'wechat') { - $price = bcdiv($extra['amount']['payer_total'], 100, 2); - } else { - $price = $extra['buyer_pay_amount']; - } - $order->price = $price; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - $order->save(); - $uid = $order->uid; - $user = User::where('id', $uid)->findOrEmpty(); - //check store_id - if(empty($user->store_id)){ - $user->store_id = $order['store_id']; - } - - //用户的财务add - $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price, [], 1); - - if ($user->isEmpty()) { - return true; - } - bcscale(2); - - UserSignLogic::dealRechargeFrozen($user, $order, $order['user_ship']); - - //更新等级 - $user->user_ship = $order['user_ship']; - - $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); - $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); - $user->save(); - if ($order['other_uid'] > 0) { - $uid = $order['other_uid']; - } - - - PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); - PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); - if (!empty($extra['payer']['openid'])) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); - } - return true; - } - - /** - * 现金支付 - */ - public static function cash_pay($orderSn,$extra =[]) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - $order->paid = 1; - $order->pay_time = strtotime($order['create_time']); - $order->status = 2; - if ($order['reservation'] ==1) { - $order->status = 1; - } - if (!$order->save()) { - throw new \Exception('订单保存出错'); - } - self::afterPay($order); - if ($order['is_storage'] == 1) { - UserProductStorageLogic::add($order); - } - $cashFlowLogic = new CashFlowLogic(); - $cashFlowLogic->insert($order['store_id'], $order['pay_price']); - self::dealProductLog($order); - - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - - if ($extra && $extra['store_id'] && $order['reservation'] !=1) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $extra['store_id'], - 'staff_id' => $extra['staff_id'] - ]; - OrderLogic::writeOff($params); - } - - - // Redis::send('push-platform-print', ['id' => $order['id']]); - return true; - } - - /** - * @notes 阿里回调 - * @param $orderSn - * @param array $extra - * @author 段誉 - * @date 2023/2/27 15:28 - */ - public static function alipay_cashier($orderSn, $extra = []) - { - $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); - - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { - return true; - } - if ($order->pay_type != 10) { - $order->money = $extra['buyer_pay_amount']; - $order->paid = 1; - $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300)); - $order->status = 1; - $order->save(); - } else { - $extra['transaction_id'] = time(); - } - if ($order->pay_type == 9) { - $order->status = 2; - self::afterPay($order); - UserProductStorageLogic::add($order); - } - self::dealProductLog($order); - if ($order['shipping_type'] == 3) { - self::descStock($order['id']); - } - - // if ($order->pay_type == 9) { - // $extra['create_time'] = $order['create_time']; - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); - // Redis::send('push-platform-print', ['id' => $order['id']]); - // } - // else { - // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - // } - return true; - } - - /** - * 支付后逻辑 - * @param $order - * @return void - */ - public static function afterPay($order, $transaction_id = 0) - { - $financeLogic = new StoreFinanceFlowLogic(); - $off_activity = Config::where('name', 'off_activity')->value('value'); - $village_uid = 0; - $brigade_uid = 0; - $user_ship = 0; - $order['dealVipAmount'] = 0; - try { - Redis::send('order_wetcha_push_send', ['order' => $order]); - } catch (\Exception $e) { - Log::error('订单推送失败:' . $e->getMessage()); - // 异常处理代码,例如记录日志或发送通知等。 - } - if ($order['uid'] > 0) { - // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 - //用户下单该用户等级为1得时候才处理冻结金额 - $user = User::where('id', $order['uid'])->find(); - $user_ship = $user['user_ship']; - - } - //积分写入 - if(isset($user) && $user['user_ship']==0){ - UserSignLogic::OrderWrite($order); - } - if ($off_activity == 1) { - //-----活动价结算更改 - $financeLogic->order = $order; - $financeLogic->user = ['uid' => $order['uid']]; - $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, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - $financeLogic->save(); - return false; - } - - } - - /** - * 回调日志 - * @param $order - * @param $extra - * @return void - */ - public static function notifyLog($order, $extra) - { - $data = [ - 'pay_type' => 'wechat', - 'type' => OrderEnum::PAY, - 'amount' => $extra['amount']['payer_total'], //分 - 'order_sn' => $order, - 'out_trade_no' => $extra['transaction_id'], - 'attach' => $extra['attach'], - 'create_time' => date('Y-m-d H:i:s', time()), - ]; - PayNotify::create($data); - } - - /** - * 冻结金额 - * @param $oid - * @return int|mixed - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - - public static function dealFrozenPrice($oid) - { - $detail = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - $total_vip = 0; - foreach ($detail as $value) { - $total_vip += $value['cart_info']['vip_frozen_price']; - } - return $total_vip; - } - - - /** - * 处理用户为vip1时得冻结资金 - * @param $order - * @param $pay_type - * @param $transaction_id - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function dealVipAmount($order, $pay_type = 1, $transaction_id = 0) - { - $total_vip = self::dealFrozenPrice($order['id']); - $data = [ - 'order_id' => $order['id'], - 'transaction_id' => $transaction_id ?? 0, - 'order_sn' => $order['order_id'], - 'user_id' => $order['uid'], - 'number' => $total_vip, - 'all' => $order['pay_price'], - 'pay_type' => $pay_type ?? 1, - 'status' => 0, - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'], - 'create_time' => time() - ]; - Db::name('vip_flow')->insert($data); - return $total_vip; - } - - /** - * 商品统计逻辑 - * @param $order - * @return true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function dealProductLog($order) - { - $store_id = $order['store_id']; - $cart_id = $order['cart_id']; - $uid = $order['uid']; - if ($uid && $cart_id && $store_id) { - $cart_id = explode(',', $cart_id); - $productLog = StoreProductLog::where([ - 'uid' => $uid - ])->whereIn('cart_id', $cart_id) - ->select()->toArray(); - - foreach ($productLog as &$value) { - $value['pay_uid'] = $uid; - $value['oid'] = $order['id']; - $value['store_id'] = $store_id; - $cart_info = StoreOrderCartInfo::where([ - 'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'oid' => $value['oid'] - ])->find(); - $value['order_num'] = $cart_info['cart_num'] ?? 1; - $value['pay_num'] = $cart_info['cart_num'] ?? 1; - $value['pay_price'] = $cart_info['price'] ?? 0; - $value['cost_price'] = $cart_info['cart_info']['cost'] ?? 0; - $value['update_time'] = time(); - unset($value['create_time'], $value['delete_time']); - } - - (new StoreProductLog())->saveAll($productLog); - } - return true; - } - - - public static function descSwap($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'swap' => $StoreBranchProduct['swap'] - $v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; - } - - (new StoreBranchProduct())->saveAll($updateData); - } - - - /** - * 扣库存 - * @param $oid - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function descStock($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - if ($StoreBranchProduct) { - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'stock' => $StoreBranchProduct['stock'] - $v['cart_num'], - 'sales' => ['inc', $v['cart_num']] - ]; - } - } - - (new StoreBranchProduct())->saveAll($updateData); - } - - /** - * 加库存 - * @param $oid - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function addStock($oid) - { - $updateData = []; - $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); - foreach ($goods_list as $v) { - $StoreBranchProduct = StoreBranchProduct::where( - [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - ] - )->withTrashed()->find(); - if ($StoreBranchProduct) { - $updateData[] = [ - 'id' => $StoreBranchProduct['id'], - 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], - // 'sales' => ['inc', $v['cart_num']] - // 'sales' => ['inc', $v['cart_num']] - ]; - } - } - - (new StoreBranchProduct())->saveAll($updateData); - } - - - /** - * 处理商品缺失新增到缺失列表 - * @param $cart_id //购物车ids - * @param $uid //用户id - * @param $oid //订单id - * @return void - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public static function dealGoodsLeft($cart_id, $uid, $oid) - { - if (is_array($cart_id)) { - $cart_id['cart_id'] = $cart_id; - } else { - $cart_id['cart_id'] = explode(',', $cart_id); - } - $data = OrderLogic::checkLeft($cart_id, $uid, 1); - $format = $data['detail']; - foreach ($format as &$value) { - $value['oid'] = $oid; - $value['create_time'] = time(); - } - Db::name('store_product_miss')->insertAll($format); - } - - - - /** - * 会员等级对应得折扣比例 - * @param $level - * @return float|mixed - */ - public static function getDiscount($level) - { - switch ($level) { - case 0: //普通 - return Config::where('name', 'ordinary_member')->value('value') ?? 0.1; - case 1: //vip - return Config::where('name', 'vip_member')->value('value') ?? 0.1; - case 4: //商户 - return Config::where('name', 'merchant')->value('value') ?? 0.1; - default: - return 0.1; - } - } -} diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index c91074eee..434fd546e 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -34,6 +34,7 @@ use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; use app\common\service\PushService; use app\common\service\xpyun\XpsdkPrintApi; +use app\Request; use support\exception\BusinessException; use support\Log; use think\facade\Db; @@ -627,12 +628,14 @@ class PayNotifyLogic extends BaseLogic 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2) ], ['id' => $branchProduct['id']]); + SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $v['cart_num'], -1, Request()->url()); } 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']]); + SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $v['cart_num'], -1, Request()->url()); } } } catch (\Throwable $e) { @@ -874,6 +877,7 @@ class PayNotifyLogic extends BaseLogic } (new StoreBranchProduct())->saveAll($updateData); + SqlChannelLog('StoreBranchProduct',0,0,1,Request()->url()); } diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index a67acfad3..0c68cec6a 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -215,6 +215,7 @@ class StoreOrderLogic extends BaseLogic (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; (new StoreBranchProduct())->saveAll($updateData); + SqlChannelLog('StoreBranchProduct', 0, $v['cart_num'], -1, Request()->url()); (new StoreProduct())->saveAll($updateDataTwo); Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); Db::commit();