From 88c6c8aa7b58ed0edaf77ea794c232420dc55bab Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 22 Jun 2024 11:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E5=AE=8C=E5=96=84=E8=BF=94=E5=86=BB?= =?UTF-8?q?=E7=BB=93=E7=9B=B8=E5=85=B3=E8=BF=94=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/BackController.php | 138 ++++++++++++++++++++++++++ app/common/logic/CapitalFlowLogic.php | 4 + 2 files changed, 142 insertions(+) create mode 100644 app/api/controller/BackController.php diff --git a/app/api/controller/BackController.php b/app/api/controller/BackController.php new file mode 100644 index 00000000..50860985 --- /dev/null +++ b/app/api/controller/BackController.php @@ -0,0 +1,138 @@ +=', $startTime) + ->where('create_time', '<', $endTime) + ->group('user_id, pay_type') + ->field('user_id, pay_type, COUNT(*) as transaction_count, SUM(number) as total_amount') + ->select()->toArray(); + + // 遍历查询结果并分类 现金不进入反的逻辑 + //3余额 18采购款 7微信小程序 9微信条码 13 支付宝条码支付 + $Balance = []; + $Procurement = []; + $WechatMiniPay = []; + $WechatBarcodePay = []; + $AliBarcodePay = []; + foreach ($result as $row) { + $payType = $row['pay_type']; + $userId = $row['user_id']; + $totalAmount = $row['total_amount']; + switch ($payType) { + case 3: + $user_now_money = User::where( + [ + 'id' => $userId + ] + )->withTrashed()->value('now_money'); + $Balance[] = [ + 'id' => $userId, + 'now_money' => bcadd($user_now_money, $totalAmount, 2), + ]; + break; + case 7: + $WechatMiniPay[] = [ + 'id' => $userId, + 'total_amount' => $totalAmount, + ]; + break; + case 9: + $WechatBarcodePay[] = [ + 'id' => $userId, + 'total_amount' => $totalAmount, + ]; + break; + case 13: + $AliBarcodePay[] = [ + 'id' => $userId, + 'total_amount' => $totalAmount, + ]; + break; + case 18: + $purchase_funds_money = User::where( + [ + 'id' => $userId + ] + )->withTrashed()->value('purchase_funds'); + $Procurement[] = [ + 'id' => $userId, + 'purchase_funds' => bcadd($purchase_funds_money, $totalAmount, 2), + ]; + break; + } + + } + //入记录表的话查询后便利入 3余额 18采购款 + if ($Balance) { + (new User())->saveAll($Balance); + $this->dealCapital($startTime, $endTime, 3); + } + if ($Procurement) { + (new User())->saveAll($Procurement); + $this->dealCapital($startTime, $endTime, 18); + } + //7微信小程序 9微信条码 13 支付宝条码支付 + + + } + + public function dealCapital($startTime, $endTime, $pay_type) + { + $vipFrozen = VipFlow::where('create_time', '>=', $startTime) + ->where('create_time', '<', $endTime) + ->where('pay_type', $pay_type)->select()->toArray(); + if ($pay_type == 18) { + $category_title = 'system_purchase_add'; + $title = '系统增加采购款'; + $mark = '系统增加采购款'; + $filed = 'purchase_funds'; + } else { + $category_title = 'system_balance_add'; + $title = '系统增加余额'; + $mark = '系统反余额冻结'; + $filed = 'now_money'; + } + + $newArr = []; + foreach ($vipFrozen as $k => $value) { + $user_funds = User::where('id', $value['user_id'])->value($filed); + $newArr[$k]['uid'] = $value['user_id']; + $newArr[$k]['category'] = $category_title; + $newArr[$k]['link_type'] = 'order'; + $newArr[$k]['link_id'] = $value['order_id']; + $newArr[$k]['amount'] = $value['number']; + $newArr[$k]['before_balance'] = $user_funds; + $newArr[$k]['balance'] = bcadd($user_funds, $value['number'], 2); + $newArr[$k]['create_time'] = date('Y-m-d H:i:s'); + $newArr[$k]['type'] = 'in'; + $newArr[$k]['title'] = $title . "{$value['number']}元"; + $newArr[$k]['mark'] = $mark; + } + (new CapitalFlow())->saveAll($newArr); + + } + + +} \ No newline at end of file diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 1b6aea9b..0226e07a 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -143,6 +143,8 @@ class CapitalFlowLogic extends BaseLogic switch ($category) { case 'user_balance_recharge': return "用户充值{$amount}元"; + case 'user_order_purchase_pay': + return "用户采购款支付{$amount}元"; case 'store_margin': return "店铺自动扣除保证金{$amount}元"; case 'store_order_income': @@ -159,6 +161,8 @@ class CapitalFlowLogic extends BaseLogic return "退还订单推广佣金{$amount}元"; case 'system_balance_add': return "系统增加余额{$amount}元"; + case 'system_purchase_add': + return "系统增加采购款{$amount}元"; case 'system_balance_reduce': return "系统减少余额{$amount}元"; default: