diff --git a/app/api/controller/BackController.php b/app/api/controller/BackController.php new file mode 100644 index 000000000..50860985d --- /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 1b6aea9ba..0226e07af 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: