model = new \app\admin\model\FcWithdraw; $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 提现打款/驳回 */ public function pay() { $ids = $this->request->post('ids'); $op = $this->request->post('op'); $reason = $this->request->post('reason', ''); if (!in_array($op, ['pay', 'reject'])) { $this->error('操作类型错误'); } if ($op === 'reject' && trim((string)$reason) === '') { $this->error('驳回需填写原因'); } $ids = is_array($ids) ? $ids : explode(',', (string)$ids); $ids = array_filter($ids); if (!$ids) { $this->error('请选择要操作的提现记录'); } $withdraws = Db::name('fc_withdraw')->where('id', 'in', $ids)->select(); if (!$withdraws) { $this->error('提现记录不存在'); } foreach ($withdraws as $withdraw) { if ($op === 'pay') { Db::name('fc_withdraw')->where('id', $withdraw['id'])->update([ 'status' => 'paid', 'paytime' => time(), 'updatetime' => time(), ]); Db::name('fc_finance_flow')->insert([ 'flow_no' => 'WD' . date('YmdHis') . $withdraw['id'], 'type' => 'expense', 'scene' => '佣金提现', 'amount' => $withdraw['amount'], 'balance' => 0, 'related_id' => $withdraw['id'], 'remark' => '提现打款', 'createtime' => time(), ]); } else { Db::name('fc_withdraw')->where('id', $withdraw['id'])->update([ 'status' => 'rejected', 'reason' => $reason, 'updatetime' => time(), ]); } Db::name('fc_message')->insert([ 'user_id' => $withdraw['user_id'], 'type' => 'system', 'title' => $op === 'pay' ? '提现成功' : '提现驳回', 'content' => $op === 'pay' ? '您的提现申请「' . $withdraw['withdraw_no'] . '」已打款,金额:' . $withdraw['amount'] . '元' : '您的提现申请「' . $withdraw['withdraw_no'] . '」被驳回' . ($reason ? ',原因:' . $reason : ''), 'isread' => 0, 'createtime' => time(), ]); } $this->success($op === 'pay' ? '打款成功' : '驳回成功'); } }