post(); $user = User::where(['id' => $request->user->id])->findOrEmpty(); if (!$user->is_photographer) { throw new Exception('你还不是摄影师,请先成为摄影师再申请加入'); } if ($user->studio_id) { throw new Exception('您已加入了工作室,不能重复申请'); } $photographer = Photographer::where(['user_id' => $user->id])->findOrEmpty(); if ($photographer->isEmpty()) { throw new Exception('未找到您的摄影师信息,申请失败'); } $studio = Studio::where(['id' => $data['studio_id']])->findOrEmpty(); if ($studio->isEmpty()) { throw new Exception('未找到工作室信息,申请失败'); } $studio_apply = StudioApply::where(['user_id' => $user->id, 'photographer_id' => $photographer->id, 'apply_status' => 0])->findOrEmpty(); if (!$studio_apply->isEmpty()) { throw new Exception('您有申请正在审批,不能重复申请'); } $res = StudioApply::create([ 'user_id' => $user->id, 'photographer_id' => $photographer->id, 'studio_id' => $studio->id ]); if (!$res) { throw new Exception('申请失败'); } return [ 'code' => ResponseCode::SUCCESS, 'msg' => '申请成功,请等待工作室审核通过' ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } /** * @desc 申请列表 * @param $request * @return array */ public function getPhotographerApplyList($request) { try { if(!isset($request['studio_id'])){ throw new Exception('参数错误'); } $apply = StudioApply::order('id desc')->where(['id' => $request['studio_id']]); $page = isset($request['page']) ? $request['page'] : 1; $limit = isset($request['limit']) ? $request['limit'] : 10; $total = $apply->count(); $list = $apply->with(['photographer'])->page($page, $limit)->select(); return [ 'code' => ResponseCode::SUCCESS, 'data' => [ 'list' => $list, 'total' => $total, 'page' => $page ], ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } /** * @desc 更改审核状态 * @param $request * @return array */ public function changeApplyStatus($request) { try { $data = $request->post(); $user = User::where(['id' => $request->user->id])->findOrEmpty(); $apply = StudioApply::where(['id' => $data['id']])->findOrEmpty(); $studio = Studio::where(['id' => $apply->studio_id])->findOrEmpty(); if ($apply->isEmpty()) { throw new Exception('申请不存在,修改失败'); } if ($user->id != $studio->user_id) { throw new Exception('非工作室管理人员禁止操作'); } $apply->save(['apply_status' => $request['apply_status']]); if ($request['apply_status'] == 1) { //通过 $photographer = Photographer::where(['id' => $apply->photographer_id])->findOrEmpty(); $photographer->save(['studio_id' => $apply->studio_id]); User::where(['id' => $photographer->user_id])->save(['studio_id' => $apply->studio_id]); } else { //拒绝 $photographer = Photographer::where(['id' => $apply->photographer_id])->findOrEmpty(); $photographer->save(['studio_id' => 0]); User::where(['id' => $photographer->user_id])->save(['studio_id' => 0]); } return [ 'code' => ResponseCode::SUCCESS, 'msg' => '操作成功' ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } }