model = new \app\agent\model\finance\Withdraw(); } /** * 显示资源列表 * * @return \think\Response */ public function index() { $where = []; !empty($this->auth->user()['user_id']) && $where[] = ['user_id', '=', $this->auth->user()['user_id']]; (!empty(input('status')) || input('status') == '0') && $where[] = ['status', 'eq', input('status')]; // 时间处理 if (!empty(input('created_at'))){ list($start, $end) = str2arr(input('created_at'),'-'); $where[] = ['created_at', 'between', [strtotime($start), strtotime($end)]]; } $list = $this->model->where($where) ->order(['id' => 'desc']) ->paginate(input('limit'),false); return IResponse::paginate($list); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { // } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response * @throws \think\exception\PDOException */ public function save(Request $request) { $params = input(); $validate = validate('\app\agent\validate\finance\Withdraw'); if (!$validate->scene('save')->check($params)) { return IResponse::failure($validate->getError()); } $admin = $this->auth->user(); $user = model('\app\common\model\Users')->field('id,motor_agent_money') ->find($admin['user_id']); if ($user['motor_agent_money'] < $params['withdraw_amount']) { return IResponse::failure('余额不足'); } $this->model->startTrans(); try { $params['user_id'] = $admin['user_id']; $result = $this->model::create($params, true); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); return IResponse::failure($e->getMessage()); } if ($result) { return IResponse::success(); } return IResponse::failure(); } /** * 显示指定的资源 * * @param int $id * @return \think\Response */ public function read($id) { // } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * 保存更新的资源 * * @param int $ids * @return \think\Response */ public function update($ids) { $row = $this->model::get($ids); if (!$row || $row['status'] > 20) { return IResponse::failure('不可操作'); } $result = false; $this->model->startTrans(); try { $result = $row->allowField(true)->save(input()); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result === false) { return IResponse::failure(); } return IResponse::success(); } /** * 删除指定资源 * * @param int $ids * @return \think\Response * @throws \think\exception\PDOException */ public function delete($ids) { $row = $this->model::get($ids); if (!$row) { return IResponse::failure('不可操作'); } $result = false; $this->model->startTrans(); try { $result = $row->delete(); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return IResponse::success(); } return IResponse::failure(); } }