get('userid');//中间件产生的参数 // 状态配置(带 tag_type) $transaction_status_map = [ 0 => ['label' => '关闭', 'tag_type' => 'default'], 1 => ['label' => '待审核', 'tag_type' => 'warning'], 2 => ['label' => '拒绝', 'tag_type' => 'error'], 3 => ['label' => '完成', 'tag_type' => 'success'], ]; $loan_status_map = [ 0 => ['label' => '关闭', 'tag_type' => 'default'], 1 => ['label' => '申请中', 'tag_type' => 'warning'], 2 => ['label' => '审核通过', 'tag_type' => 'info'], 3 => ['label' => '已放款', 'tag_type' => 'success'], 4 => ['label' => '已还款', 'tag_type' => 'success'], 5 => ['label' => '拒绝', 'tag_type' => 'error'], ]; $type_label = [ [ 'key' => 0, 'label' => '全部', 'fuhao' => ' ', 'color' => '#333333' ], [ 'key' => 1, 'label' => '充值', 'fuhao' => '+', 'color' => '#009900' ], [ 'key' => 2, 'label' => '利息收益', 'fuhao' => '+', 'color' => '#009900' ], [ 'key' => 3, 'label' => '提现', 'fuhao' => '-', 'color' => '#FF0000' ], [ 'key' => 4, 'label' => '借款', 'fuhao' => '+', 'color' => '#FF0000' ] ]; $type_map = []; foreach ($type_label as $tl) { $type_map[$tl['key']] = $tl; } if ($type === 0) { $ck_list = DB::table('transactions') ->select('id', 'type', 'amount', 'created_at', 'status') ->where(['member_id' => $userid, 'is_del' => 0]) ->get() ->map(function ($item) { $item->source = 'transaction'; // 标记来源 return $item; }); $jk_list = DB::table('loans') ->select('id', DB::raw('NULL as type'), 'amount', 'created_at', 'status') // 对齐字段 ->where(['member_id' => $userid, 'is_del' => 0]) ->get() ->map(function ($item) { $item->source = 'loan'; // 标记来源 return $item; }); $list = $ck_list->merge($jk_list) ->sortByDesc('created_at'); // 可选:按时间倒序排序 } else if ($type === 4) { $list = DB::table('loans') ->select('id', DB::raw('NULL as type'), 'amount', 'created_at', 'status') // 对齐字段 ->where(['member_id' => $userid, 'is_del' => 0]) ->orderBy('id', 'desc') ->get() ->map(function ($item) { $item->source = 'loan'; // 标记来源 return $item; }); } else { $list = DB::table('transactions') ->select('id', 'type', 'amount', 'created_at', 'status') ->where(['member_id' => $userid, 'type' => $type, 'is_del' => 0]) ->orderBy('id', 'desc') ->get() ->map(function ($item) { $item->source = 'transaction'; // 标记来源 return $item; }); } // 处理标签和 tag_type(PHP 7.3 安全) $list = $list->map(function ($item) use ($type_map, $transaction_status_map, $loan_status_map) { if ($item->source === 'loan') { $actual_type = 4; // 借款固定对应 type=4 } else { $actual_type = isset($item->type) ? $item->type : 0; // transaction 的 type,若无则 fallback } if (isset($type_map[$actual_type])) { $type_info = $type_map[$actual_type]; } else { $type_info = $type_map[0]; } $item->type_label = $type_info['label']; $item->fuhao = $type_info['fuhao']; $item->color = $type_info['color']; // 设置 status_label 和 tag_type if ($item->source === 'loan') { if (isset($loan_status_map[$item->status])) { $status_info = $loan_status_map[$item->status]; } else { $status_info = ['label' => '未知状态', 'tag_type' => 'primary']; } } else { if (isset($transaction_status_map[$item->status])) { $status_info = $transaction_status_map[$item->status]; } else { $status_info = ['label' => '未知状态', 'tag_type' => 'primary']; } } $item->status_label = $status_info['label']; $item->tag_type = $status_info['tag_type']; return $item; })->values()->toArray(); return \Yz::Return(true, '查询完成', ['list' => $list]); } //充值 public function Recharge(Request $request) { $systemStatus = \Yz::systemStatusCheck(); if(!$systemStatus['status']){ return \Yz::echoError1($systemStatus['msg']); } $dayCutCheck = \Yz::DayCutCheck(); if(!$dayCutCheck['status']){ return \Yz::echoError1($dayCutCheck['msg']); } $userid = $request->get('userid');//中间件产生的参数 $amount = request('amount'); $img = request('img'); if (empty($img)) { return \Yz::echoError1('请上传充值凭证!'); } if (empty($amount) || $amount < 10000) { return \Yz::echoError1('充值金额不能小于10000元'); } $memberInfo = DB::table('members')->where(['id' => $userid, 'is_del' => 0])->first(); if (!$memberInfo) { return \Yz::echoError1('用户不存在'); } // var_dump($memberInfo->balance); // var_dump($amount); // $new_balance = bcadd($memberInfo->balance, $amount, 2); // var_dump($new_balance); $insertData = [ 'member_id' => $userid, 'type' => 1, 'amount' => $amount, 'img' => $img, 'status' => 1, 'source' => 'member', 'operator_id' => $userid, 'created_at' => date('Y-m-d H:i:s'), ]; $id = DB::table('transactions')->insertGetId($insertData); if (!!$id) { return \Yz::Return(true, '充值成功!', ['id' => $id]); } else { return \Yz::echoError1('提交失败'); } } //提现 public function Withdraw(Request $request) { $systemStatus = \Yz::systemStatusCheck(); if(!$systemStatus['status']){ return \Yz::echoError1($systemStatus['msg']); } $dayCutCheck = \Yz::DayCutCheck(); if(!$dayCutCheck['status']){ return \Yz::echoError1($dayCutCheck['msg']); } $userid = $request->get('userid');//中间件产生的参数 $amount = request('amount'); if (empty($amount) || $amount < 0) { return \Yz::echoError1('提现金额不能为0元'); } $memberInfo = DB::table('members')->where(['id' => $userid, 'is_del' => 0])->first(); if (!$memberInfo) { return \Yz::echoError1('用户不存在'); } if ($memberInfo->balance < $amount) { return \Yz::echoError1('余额不足'); } $insertData = [ 'member_id' => $userid, 'type' => 3, 'amount' => $amount, 'status' => 1, 'source' => 'member', 'operator_id' => $userid, 'created_at' => date('Y-m-d H:i:s'), ]; $id = DB::table('transactions')->insertGetId($insertData); if (!!$id) { return \Yz::Return(true, '充值成功!', ['id' => $id]); } else { return \Yz::echoError1('提交失败'); } } }