checkExist($user['user_id'])) { throw new BaseException(['msg' => '该用户已提交过申请,请勿重复提交']); } // 表单数据 $data['user_id'] = $user['user_id']; $data['apply_status'] = 10; $data['app_id'] = $user['app_id']; // 开启事务 $this->startTrans(); try { // 保存申请信息 $this->save($data); // 新增VIP专区用户 VipUserModel::add($user['user_id'], [ 'real_name' => $data['real_name'], 'mobile' => $data['mobile'], 'referee_id' => $user['referee_id'] ?? 0, ]); $this->commit(); return true; } catch (\Exception $e) { $this->rollback(); throw new BaseException(['msg' => $e->getMessage()]); } } /** * 检查是否已提交申请 * @param $user_id * @return bool */ private function checkExist($user_id) { return (new self)->where('user_id', '=', $user_id) ->where('apply_status', '<>', 30) ->count() > 0; } /** * 获取申请列表 * @param $user_id * @param int $status * @param array $query * @return \think\Paginator * @throws \think\exception\DbException */ public function getList($user_id, $status = -1, $query = []) { $model = $this->where('user_id', '=', $user_id); if ($status > -1) { $model = $model->where('apply_status', '=', $status); } return $model->with(['user']) ->order(['create_time' => 'desc']) ->paginate($query, false, [ 'query' => \request()->request() ]); } }