diff --git a/app/api/controller/CaseShareController.php b/app/api/controller/CaseShareController.php deleted file mode 100644 index 1544cab..0000000 --- a/app/api/controller/CaseShareController.php +++ /dev/null @@ -1,97 +0,0 @@ -insert($request); - return $this->json($res); - } - - /** - * @desc 删除案例 - * @param Request $request - * @return \support\Response - */ - public function del(Request $request) - { - $service = new CaseShareService(); - $res = $service->del($request->post()); - return $this->json($res); - } - - /** - * @desc 更新案例 - * @param Request $request - * @return \support\Response - */ - public function update(Request $request) - { - $service = new CaseShareService(); - $res = $service->update($request); - return $this->json($res); - } - - /** - * @desc 获取案例列表 - * @param Request $request - * @return \support\Response - */ - public function getCaseShareList(Request $request) - { - $service = new CaseShareService(); - $res = $service->getCaseShareList($request->get()); - return $this->json($res); - } - - /** - * @desc 获取用户案例列表 - * @param Request $request - * @return \support\Response - */ - public function getUserCaseShareList(Request $request) - { - $service = new CaseShareService(); - $res = $service->getUserCaseShareList($request); - return $this->json($res); - } - - /** - * @desc 案例详情 - * @param Request $request - * @return \support\Response - */ - public function cashShareDetail(Request $request) - { - $service = new CaseShareService(); - $res = $service->caseDetail($request->get()); - return $this->json($res); - } - - /** - * @desc 摄影师案例服务类型 - * @param Request $request - * @return \support\Response - */ - public function getPhotographerCaseShareServiceType(Request $request) - { - $service = new CaseShareService(); - $res = $service->getPhotographerCaseShareServiceType($request->get()); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/ChatController.php b/app/api/controller/ChatController.php deleted file mode 100644 index facb5d6..0000000 --- a/app/api/controller/ChatController.php +++ /dev/null @@ -1,45 +0,0 @@ -sendMsg($request); - return $this->json($res); - } - - /** - * @desc 获取用户消息 - * @param Request $request - * @return \support\Response - */ - public function getUserChatMsg(Request $request) - { - $service = new ChatRecordsService(); - $res = $service->getUserChatMsg($request); - return $this->json($res); - } - - - public function updateMsgRead(Request $request) - { - $service = new ChatRecordsService(); - $res = $service->updateMsgRead($request); - return $this->json($res); - } - - -} \ No newline at end of file diff --git a/app/api/controller/ChatFriendController.php b/app/api/controller/ChatFriendController.php deleted file mode 100644 index 9958db7..0000000 --- a/app/api/controller/ChatFriendController.php +++ /dev/null @@ -1,24 +0,0 @@ -getFriends($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/DepositOrderController.php b/app/api/controller/DepositOrderController.php deleted file mode 100644 index 6517b36..0000000 --- a/app/api/controller/DepositOrderController.php +++ /dev/null @@ -1,24 +0,0 @@ -payBidOrder($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/DeviceController.php b/app/api/controller/DeviceController.php deleted file mode 100644 index 4e122d8..0000000 --- a/app/api/controller/DeviceController.php +++ /dev/null @@ -1,25 +0,0 @@ -getDeviceService($request->get()); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/FavoriteController.php b/app/api/controller/FavoriteController.php deleted file mode 100644 index 53fe38e..0000000 --- a/app/api/controller/FavoriteController.php +++ /dev/null @@ -1,49 +0,0 @@ -add($request); - return $this->json($res); - } - - /** - * @desc 取消收藏 - * @param Request $request - * @return \support\Response - */ - public function cancel(Request $request) - { - $service = new FavoriteService(); - $res = $service->cancel($request); - return $this->json($res); - } - - /** - * @desc 收藏列表 - * @param Request $request - * @return \support\Response - */ - public function getFavoriteList(Request $request) - { - $service = new FavoriteService(); - $res = $service->getFavoriteList($request); - return $this->json($res); - } - - -} \ No newline at end of file diff --git a/app/api/controller/PaidServiceController.php b/app/api/controller/PaidServiceController.php deleted file mode 100644 index 9178721..0000000 --- a/app/api/controller/PaidServiceController.php +++ /dev/null @@ -1,23 +0,0 @@ -getList($request->get()); - return $this->json($res); - } -} \ No newline at end of file diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php deleted file mode 100644 index 84318f6..0000000 --- a/app/api/controller/PayController.php +++ /dev/null @@ -1,19 +0,0 @@ -payment($request->post()); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/PhotoServiceController.php b/app/api/controller/PhotoServiceController.php deleted file mode 100644 index 24482e7..0000000 --- a/app/api/controller/PhotoServiceController.php +++ /dev/null @@ -1,71 +0,0 @@ -getPhotographerSelfService($request); - return $this->json($res); - } - - /** - * @desc 摄影师拍照服务 - * @param Request $request - * @return \support\Response - */ - public function select(Request $request) - { - $service = new PhotoServiceService(); - $res = $service->select($request->get()); - return $this->json($res); - } - - /** - * @desc 添加拍照服务 - * @param Request $request - * @return \support\Response - */ - public function add(Request $request) - { - $service = new PhotoServiceService(); - $res = $service->add($request); - return $this->json($res); - } - - /** - * @desc 添加拍照服务 - * @param Request $request - * @return \support\Response - */ - public function edit(Request $request) - { - $service = new PhotoServiceService(); - $res = $service->edit($request); - return $this->json($res); - } - - - public function del(Request $request) - { - $service = new PhotoServiceService(); - $res = $service->del($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/PhotoServiceOrderController.php b/app/api/controller/PhotoServiceOrderController.php deleted file mode 100644 index 23f579e..0000000 --- a/app/api/controller/PhotoServiceOrderController.php +++ /dev/null @@ -1,79 +0,0 @@ -pay($request); - return $this->json($res); - } - - /** - * @desc 支付保证金 - * @param Request $request - * @return \support\Response - */ - public function payOrderDeposit(Request $request) - { - $service = new PhotoServiceOrderService(); - $res = $service->payOrderDeposit($request); - return $this->json($res); - } - - /** - * @desc 计算支付价格 - * @param Request $request - * @return \support\Response - */ - public function calculatePrice(Request $request) - { - $service = new PhotoServiceOrderService(); - $res = $service->calculatePrice($request->post()); - return $this->json($res); - } - - /** - * @desc 摄影师拍照订单列表 - * @param Request $request - * @return \support\Response - */ - public function getPhotoServiceOrderForPhotographer(Request $request) - { - $service = new PhotoServiceOrderService(); - $res = $service->getPhotoServiceOrderForPhotographer($request); - return $this->json($res); - } - /** - * @desc 摄影师拍照订单列表 - * @param Request $request - * @return \support\Response - */ - public function getPhotoServiceOrderForUser(Request $request) - { - $service = new PhotoServiceOrderService(); - $res = $service->getPhotoServiceOrderForUser($request); - return $this->json($res); - } - - - public function cancelPhotoOrder(Request $request) - { - $service = new PhotoServiceOrderService(); - $res = $service->getPhotoServiceOrderForUser($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/PhotographerController.php b/app/api/controller/PhotographerController.php deleted file mode 100644 index a569ad9..0000000 --- a/app/api/controller/PhotographerController.php +++ /dev/null @@ -1,76 +0,0 @@ -apply($request); - return $this->json($res); - } - - /** - * @desc 摄影师详情 - * @param Request $request - * @return \support\Response - */ - public function edit(Request $request) - { - $service = new PhotographerService(); - $res = $service->edit($request); - return $this->json($res); - } - - /** - * @desc 摄影师详情 - * @param Request $request - * @return \support\Response - */ - public function detail(Request $request) - { - $service = new PhotographerService(); - $res = $service->detail($request); - return $this->json($res); - } - - /** - * @desc 服务列表 - * @param Request $request - * @return \support\Response - */ - public function getServiceType(Request $request) - { - $service = new PhotographerService(); - $res = $service->getServiceType($request->get()); - return $this->json($res); - } - - - /** - * @desc 退出工作室 - * @param Request $request - * @return \support\Response - */ - public function quitStudio(Request $request) - { - $service = new PhotographerService(); - $res = $service->quitStudio($request); - return $this->json($res); - } - - - -} \ No newline at end of file diff --git a/app/api/controller/RequirementBiddingController.php b/app/api/controller/RequirementBiddingController.php deleted file mode 100644 index e14ce97..0000000 --- a/app/api/controller/RequirementBiddingController.php +++ /dev/null @@ -1,52 +0,0 @@ -bid($request); - return $this->json($res); - } - - - /** - * @desc 获取用户需求的出价列表 - * @param Request $request - * @return \support\Response - */ - public function getUserRequirementBiddingOrderList(Request $request) - { - $service = new RequirementBiddingService(); - $res = $service->getUserRequirementBiddingOrderList($request); - return $this->json($res); - } - - - /** - * @desc 确定出价 - * @param Request $request - * @return \support\Response - */ - public function confirmBid(Request $request) - { - $service = new RequirementBiddingService(); - $res = $service->confirmBid($request); - return $this->json($res); - } - - -} \ No newline at end of file diff --git a/app/api/controller/RequirementController.php b/app/api/controller/RequirementController.php deleted file mode 100644 index 2fb4f2f..0000000 --- a/app/api/controller/RequirementController.php +++ /dev/null @@ -1,86 +0,0 @@ -publish($request); - return $this->json($result); - } - - /** - * @desc 删除需求 - * @param Request $request - * @return \support\Response - */ - public function del(Request $request) - { - $service = new RequirementService(); - $result = $service->del($request); - return $this->json($result); - } - - /** - * @desc 需求详情 - * @param Request $request - * @return \support\Response - */ - public function detail(Request $request) - { - $service = new RequirementService(); - $result = $service->detail($request->get()); - return $this->json($result); - } - - /** - * @desc 需求列表 - * @param Request $request - * @return \support\Response - */ - public function getRequirement(Request $request) - { - $service = new RequirementService(); - $result = $service->getRequirement($request->get()); - return $this->json($result); - } - - - /** - * @desc 用户自己的需求列表 - * @param Request $request - * @return \support\Response - */ - public function getUserSelfRequirementList(Request $request) - { - $service = new RequirementService(); - $result = $service->getUserSelfRequirementList($request); - return $this->json($result); - } - - - /** - * @desc 竞价中的需求 - * @param Request $request - * @return \support\Response - */ - public function getBidRequirements(Request $request) - { - $service = new RequirementService(); - $res = $service->getBidRequirements($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/RequirementOrderController.php b/app/api/controller/RequirementOrderController.php deleted file mode 100644 index 95dd582..0000000 --- a/app/api/controller/RequirementOrderController.php +++ /dev/null @@ -1,36 +0,0 @@ -payRequirement($request); - return $this->json($res); - } - - /** - * @desc 需求退款 - * @param Request $request - * @return \support\Response - */ - public function requirementRefund(Request $request) - { - $service = new RequirementOrderService(); - $res = $service->requirementRefund($request->post()); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/ServiceStandardController.php b/app/api/controller/ServiceStandardController.php deleted file mode 100644 index 48f53e4..0000000 --- a/app/api/controller/ServiceStandardController.php +++ /dev/null @@ -1,24 +0,0 @@ -getStandard($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/ServiceTypeController.php b/app/api/controller/ServiceTypeController.php deleted file mode 100644 index e45d7d7..0000000 --- a/app/api/controller/ServiceTypeController.php +++ /dev/null @@ -1,19 +0,0 @@ -getServiceType($request->get()); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/SlideshowController.php b/app/api/controller/SlideshowController.php deleted file mode 100644 index 27038ec..0000000 --- a/app/api/controller/SlideshowController.php +++ /dev/null @@ -1,20 +0,0 @@ -getSlideshow(); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/StudentController.php b/app/api/controller/StudentController.php new file mode 100644 index 0000000..706db79 --- /dev/null +++ b/app/api/controller/StudentController.php @@ -0,0 +1,25 @@ +login($request->post()); + return $this->json($res); + } + +} \ No newline at end of file diff --git a/app/api/controller/StudioApplyController.php b/app/api/controller/StudioApplyController.php deleted file mode 100644 index 5d87c58..0000000 --- a/app/api/controller/StudioApplyController.php +++ /dev/null @@ -1,48 +0,0 @@ -apply($request); - return $this->json($res); - } - - /** - * @desc 申请列表 - * @param Request $request - * @return \support\Response - */ - public function getPhotographerApplyList(Request $request) - { - $service = new StudioApplyService(); - $res = $service->getPhotographerApplyList($request->get()); - return $this->json($res); - } - - /** - * @desc 更改审核状态 - * @param Request $request - * @return \support\Response - */ - public function changeApplyStatus(Request $request) - { - $service = new StudioApplyService(); - $res = $service->changeApplyStatus($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/StudioController.php b/app/api/controller/StudioController.php deleted file mode 100644 index 436945f..0000000 --- a/app/api/controller/StudioController.php +++ /dev/null @@ -1,76 +0,0 @@ -add($request); - return $this->json($res); - } - - /** - * @desc 工作室列表 - * @param Request $request - * @return \support\Response - */ - public function select(Request $request) - { - $service = new StudioService(); - $res = $service->select($request); - return $this->json($res); - } - - - /** - * @desc 工作室详情 - * @param Request $request - * @return \support\Response - */ - public function detail(Request $request) - { - $service = new StudioService(); - $res = $service->detail($request); - return $this->json($res); - } - - /** - * @desc 工作室摄影师 - * @param Request $request - * @return \support\Response - */ - public function getStudioPhotographer(Request $request) - { - $service = new StudioService(); - $res = $service->getStudioPhotographer($request->get()); - return $this->json($res); - } - - - /** - * @desc 移除摄影师 - * @param Request $request - * @return \support\Response - */ - public function removePhotographer(Request $request) - { - $service = new StudioService(); - $res = $service->removePhotographer($request); - return $this->json($res); - } - -} \ No newline at end of file diff --git a/app/api/controller/TestController.php b/app/api/controller/TestController.php index 654665d..75a4a5e 100644 --- a/app/api/controller/TestController.php +++ b/app/api/controller/TestController.php @@ -7,6 +7,7 @@ use app\common\model\TimeZone; use app\common\service\UploadService; use app\constant\ResponseCode; use app\utils\QiniuUtils; +use support\Redis; use support\Request; use Tinywan\Jwt\JwtToken; @@ -20,6 +21,13 @@ class TestController extends BaseController try { + phpinfo(); + $res = Redis::setEx('test', 60, 10); + + print '
'; + print_r($res); + die; + $time_zone = json_decode(file_get_contents(base_path('/timezones.json')), true); diff --git a/app/common/model/Student.php b/app/common/model/Student.php new file mode 100644 index 0000000..95fe00d --- /dev/null +++ b/app/common/model/Student.php @@ -0,0 +1,28 @@ + $request->user->id])->findOrEmpty(); - if (!$user->is_photographer) { - throw new Exception('您还不是摄影师,不能发布案例'); - } - - $validate = new CaseShareValidate(); - $requestData = $request->post(); - if (!$validate->check($requestData)) { - throw new Exception($validate->getError()); - } - - //查找摄影师 - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('为找到摄影师信息'); - } - $service_type = ServiceType::where(['id'=>$requestData['service_type']])->findOrEmpty(); - CaseShare::create([ - 'user_id' => $request->user->id, - 'photographer_id' => $photographer->id, - 'service_type' => $requestData['service_type'], - 'service_name' => $service_type->service_name, - 'case_name' => $requestData['case_name'], - 'case_briefing' => $requestData['case_briefing'], - 'case_introduce' => $requestData['case_introduce'], - 'imgs' => !empty($requestData['imgs']) ? $requestData['imgs'] : '', -// 'imgs' => !empty($requestData['imgs']) ? json_encode($requestData['imgs'], JSON_UNESCAPED_UNICODE) : '', - ]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [], - 'msg' => '提交成功,审核成功后自动发布' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 更新案例 - * @param $request - * @return array - */ - public function update($request) - { - try { - $req_data = $request->post(); - $case = CaseShare::where(['id' => $req_data['id']])->findOrEmpty(); - if ($case->isEmpty()) { - throw new Exception('未找到案例'); - } - if ($case->user_id != $request->user->id) { - throw new Exception('非案例所有者不能操作'); - } - //查找摄影师 - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('为找到摄影师信息'); - } - - $validate = new CaseShareValidate(); - if (!$validate->check($req_data)) { - throw new Exception($validate->getError()); - } - $res = $case->save([ - 'photographer_id' => $photographer->id, - 'service_type' => $req_data['service_type'], - 'case_name' => $req_data['case_name'], - 'case_briefing' => $req_data['case_briefing'], - 'case_introduce' => $req_data['case_introduce'], - 'imgs' => empty($req_data['imgs']) ? '' : json_encode($req_data['img'], JSON_UNESCAPED_UNICODE), - ]); - - 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 del($request) - { - try { - $case = CaseShare::where(['id' => $request['id']])->findOrEmpty(); - if ($case->isEmpty()) { - throw new Exception('未找到案例或已被删除'); - } - $res = $case->delete(); - 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 getCaseShareList($request) - { - try { - $case = CaseShare::where(['is_apply' => 1]); - if (isset($request['is_recommend']) && $request['is_recommend']) { - $case->where(['is_recommend' => $request['is_recommend']]); - } - if (isset($request['service_type']) && $request['service_type']) { - $case->where(['service_type' => $request['service_type']]); - } - $page = isset($request['page']) ? $request['page'] : 1; - $limit = isset($request['limit']) ? $request['limit'] : 10; - $total = $case->count(); - $list = $case->with(['photographer'])->page($page, $limit)->select(); - - foreach ($list as &$item){ - if($item['imgs']){ - $item['imgs'] = explode(',', stripslashes($item['imgs'])); - } - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list, - 'total' => $total, - 'page' => $page - ], - 'msg' => 'success' - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 用户案例列表 - * @param $request - * @return array - */ - public function getUserCaseShareList($request) - { - try { - $requestData = $request->get(); - $case = CaseShare::where(['user_id' => $request->user->id]); - if (isset($requestData['is_recommend']) && $requestData['is_recommend']) { - $case->where(['is_recommend' => $requestData['is_recommend']]); - } - if (isset($requestData['service_type']) && $requestData['service_type']) { - $case->where(['service_type' => $requestData['service_type']]); - } - $page = isset($requestData['page']) ? $requestData['page'] : 1; - $limit = isset($requestData['limit']) ? $requestData['limit'] : 10; - $total = $case->count(); - $list = $case->page($page, $limit)->select(); - - foreach ($list as &$item){ - if($item['imgs']){ - $item['imgs'] = explode(',', $item['imgs']); - } - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list, - 'total' => $total, - 'page' => $page - ], - 'msg' => 'success' - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 案例详情 - * @param $request - * @return array - */ - public function caseDetail($request) - { - try { - $case = CaseShare::where(['id' => $request['id']])->with(['serviceType', 'photographer'])->findOrEmpty(); - if ($case->isEmpty()) { - throw new Exception('未找到案例'); - } - if ($case->imgs) { - $case->imgs = explode(',', $case->imgs); - } - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $case, - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 摄影师案例服务类型 - * @param $request - * @return array - */ - public function getPhotographerCaseShareServiceType($request) - { - try { - $photographer = Photographer::where(['id' => $request['photographer_id']])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('摄影师不存在'); - } - - $service_type = CaseShare::where(['photographer_id' => $request['photographer_id']])->field('service_type')->select()->toArray(); - if($service_type){ - $service_type = array_unique(array_column($service_type, 'service_type')); - $service_type = ServiceType::where(['id'=>$service_type])->order('sort desc, id desc')->field('id,service_name')->select(); - }else{ - $service_type = []; - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $service_type, - 'msg' => 'success' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - -} \ No newline at end of file diff --git a/app/common/service/ChatFriendService.php b/app/common/service/ChatFriendService.php deleted file mode 100644 index 3fb7111..0000000 --- a/app/common/service/ChatFriendService.php +++ /dev/null @@ -1,45 +0,0 @@ -get(); - $chat_friend = ChatFriend::where(['user_id' => $request->user->id])->with(['friend', 'photographer'])->order('latest_chat_time desc, id desc'); - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - - $total = $chat_friend->count(); - $list = $chat_friend->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() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/ChatRecordsService.php b/app/common/service/ChatRecordsService.php deleted file mode 100644 index 4bf2741..0000000 --- a/app/common/service/ChatRecordsService.php +++ /dev/null @@ -1,145 +0,0 @@ -post(); - //记录聊天数据 - $res = ChatRecords::create([ - 'from_user_id' => $request->user->id, - 'to_user_id' => $data['user_id'], - 'type' => $data['type'], - 'content' => $data['content'], - ]); - - //判断是否是好友 - $friend = ChatFriend::where(['user_id' => $request->user->id, 'friend_id' => $data['user_id']])->findOrEmpty(); - if ($friend->isEmpty()) { - $friend_photographer = Photographer::where(['user_id' => $data['user_id']])->findOrEmpty(); - $friend_photographer_id = 0; - if (!$friend_photographer->isEmpty()) { - $friend_photographer_id = $friend_photographer->id; - } - ChatFriend::create([ - 'user_id' => $request->user->id, - 'friend_id' => $data['user_id'], - 'photographer_id' => $friend_photographer_id - ]); - $photographer = Photographer::where(['user_id' => $data['user_id']])->findOrEmpty(); - $photographer_id = 0; - if (!$photographer->isEmpty()) { - $photographer_id = $photographer->id; - } - ChatFriend::create([ - 'user_id' => $data['user_id'], - 'friend_id' => $request->user->id, - 'photographer_id' => $photographer_id - ]); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '发送成功' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 获取用户发送的消息 - * @param $request - * @return array - */ - public function getUserChatMsg($request) - { - try { - $data = $request->get(); - $chat_msg = ChatRecords::whereRaw('(from_user_id = ? and to_user_id = ?) or (from_user_id = ? and to_user_id = ?)', [ - $request->user->id, - $data['user_id'], - $data['user_id'], - $request->user->id - ]) - ->field('from_user_id,to_user_id,type,content, created_at') - ->order('created_at desc'); - - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - - $total = $chat_msg->count(); - $list = $chat_msg->page($page, $limit)->select()->toArray(); - - foreach ($list as &$item) { - if($item['from_user_id'] == $request->user->id){ - $item['is_i_send'] = 1; - }else{ - $item['is_i_send'] = 0; - } - } - - 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 updateMsgRead($request) - { - try { - - $data = $request->post(); - ChatRecords::where(['from_user_id' => $data['from_user_id'], 'to_user_id' => $request->user->id, 'status' => 0])->update(['status' => 1]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '已读', - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - -} \ No newline at end of file diff --git a/app/common/service/DepositOrderService.php b/app/common/service/DepositOrderService.php deleted file mode 100644 index 17c96f1..0000000 --- a/app/common/service/DepositOrderService.php +++ /dev/null @@ -1,82 +0,0 @@ -post(); - $bidding_order = BiddingOrder::where(['id' => $requestData['bidding_order_id']])->findOrEmpty(); - if ($bidding_order->isEmpty()) { - throw new Exception('未找到出价订单'); - } - if ($bidding_order->bind_status != 1) { - throw new Exception('该出价订单未中标,支付失败'); - } - if ($bidding_order->pay_final_status != 0) { - throw new Exception('订单状态异常,支付失败'); - } - $requirement = Requirement::where(['id' => $bidding_order->requirement_id])->findOrEmpty(); - //@todo:判断是否需要支付定金 - if(1){ - - } - - $trade_no = generate_order_no('B'); - //创建订单 - DepositOrder::create([ - 'user_id' => $bidding_order->user_id, - 'photographer_id' => $bidding_order->photographer_id, - 'detail' => json_encode($requirement->toArray()), - 'order_type' => 'requirement', - 'deposit_amount' => $requirement->deposit_amount, - 'trade_no' => $trade_no, - 'pay_status' => 0, - ]); - - $pay_data = [ - 'trade_no' => $trade_no, - 'total_amount' => $bidding_order->bidding_price, - 'desc' => $requirement->requirement_trade_no . '-定金', - 'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_URL,//回调地址 - 'openid' => $request->user->openid, - ]; - $result = (new PayService())->payment($pay_data); - - if(isset($result['code'])){ - throw new Exception($result['msg']); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $result, - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/DeviceService.php b/app/common/service/DeviceService.php deleted file mode 100644 index b5c8572..0000000 --- a/app/common/service/DeviceService.php +++ /dev/null @@ -1,36 +0,0 @@ -field('id,device_name')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list - ], - 'msg' => 'success' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/FavoriteService.php b/app/common/service/FavoriteService.php deleted file mode 100644 index bff7430..0000000 --- a/app/common/service/FavoriteService.php +++ /dev/null @@ -1,128 +0,0 @@ -post(); - - $redis_key = 'favorite_' . $request->user->id . '-' . $data['photographer_id']; - - if (Redis::get($redis_key)) { - throw new Exception('不能操作太频繁哟~'); - } - Redis::setEx($redis_key, 5, 1); - - $favorite = Favorite::where(['user_id' => $request->user->id, 'photographer_id' => $data['photographer_id']])->findOrEmpty(); - if (!$favorite->isEmpty()) { - throw new Exception('您已收藏了该摄影师,不能重复收藏哟~'); - } - - $res = Favorite::create([ - 'user_id' => $request->user->id, - 'photographer_id' => $data['photographer_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 cancel($request) - { - try { - $data = $request->post(); - - $redis_key = 'favorite_' . $request->user->id . '-' . $data['photographer_id']; - - if (Redis::get($redis_key)) { - throw new Exception('不能操作太频繁哟~'); - } - Redis::setEx($redis_key, 5, 1); - - $favorite = Favorite::where(['user_id' => $request->user->id, 'photographer_id' => $data['photographer_id']])->findOrEmpty(); - if ($favorite->isEmpty()) { - throw new Exception('您未收藏该摄影师'); - } - $res = $favorite->delete(); - 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 getFavoriteList($request) - { - try { - $data = $request->get(); - $favorite = Favorite::order('id desc')->where(['user_id' => $request->user->id]); - - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - $total = $favorite->count(); - $list = $favorite->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() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/PaidServiceService.php b/app/common/service/PaidServiceService.php deleted file mode 100644 index 4a0b423..0000000 --- a/app/common/service/PaidServiceService.php +++ /dev/null @@ -1,38 +0,0 @@ -where(['service_type_id'=>$request['service_type_id']]); - } - - $list = $model->field('id,service_name,price')->select(); - return [ - 'code' => ResponseCode::SUCCESS, - 'data'=> $list - ]; - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/PayService.php b/app/common/service/PayService.php deleted file mode 100644 index 31b17b6..0000000 --- a/app/common/service/PayService.php +++ /dev/null @@ -1,180 +0,0 @@ -merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE); - - // 「商户API证书」的「证书序列号」 - $merchantCertificateSerial = '3297EB3A1132A39DAFFD70A6C4A6C3078CD346F7'; - - // 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名 - $platformCertificateFilePath = 'file://' . base_path() . '/certificate/wechatpay_660FAD2D6E804E37BE9D77EF5882718CC1E3399F.pem'; - $this->platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC); - - // 从「微信支付平台证书」中获取「证书序列号」 - $platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath); - - // 构造一个 APIv3 客户端实例 - $this->instance = Builder::factory([ - 'mchid' => $merchantId, - 'serial' => $merchantCertificateSerial, - 'privateKey' => $this->merchantPrivateKeyInstance, - 'certs' => [ - $platformCertificateSerial => $this->platformPublicKeyInstance, - ], - ]); - - - } - - /** - * @desc jsapi支付 - * @param array $pay_data - * @param $seller_channel - * @return array - */ - public function payment(array $pay_data) - { - try { - - $request_data = [ - 'appid' => getenv('APP_ID'),// 公众号ID - 'mchid' => getenv('MERCHANT_ID'),//直连商户号 - 'description' => $pay_data['desc'],//商品描述 - 'out_trade_no' => $pay_data['out_trade_no'],//商户订单号 - 'notify_url' => $pay_data['notify_url'],//通知地址 - 'amount' => [ - 'total' => round($pay_data['total_amount'] * 100),//总金额 单位为分 - ], - 'payer' => [ - 'openid' => $pay_data['openid'],// 用户在服务商AppID下的唯一标识 - ] - ]; - - $resp = $this->instance - ->chain('/v3/pay/transactions/jsapi') - ->post([ - 'json' => $request_data, -// 'debug' => true - ]); - - $result = json_decode($resp->getBody(), true); - - raw_log('wechat_pay/transactions_jsapi', ['request_data' => $request_data, 'result' => $result]); - - $pay_data = [ - 'appId' => getenv('APP_ID'), //微信小程序appid - 'timeStamp' => strval(Formatter::timestamp()), - 'nonceStr' => Formatter::nonce(), - 'package' => 'prepay_id=' . $result['prepay_id'], - ]; - $pay_data['paySign'] = Rsa::sign( - Formatter::joinedByLineFeed(...array_values($pay_data)), - $this->merchantPrivateKeyInstance - ); - $pay_data['signType'] = 'RSA'; - - return $pay_data; - } catch (RequestException $exception) { - $response = $exception->getResponse(); - $result = json_decode($response->getBody()->getContents(), true); - - raw_log('wechat_pay/transactions_jsapi_failed', ['pay_data' => $pay_data, 'result' => $result]); - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $result['message'] - ]; - } - } - - - /** - * @desc 退款 - * @param $refund_data - * @return array - */ - public function refundPayment($refund_data) - { - try { - //退款数据 - $request_data = [ - 'out_trade_no' => $refund_data['out_trade_no'],//微信支付订单号 - 'out_refund_no' => $refund_data['out_refund_no'],//商户退款单号 - 'reason' => $refund_data['refund_desc'],//退款原因 - 'notify_url' => $refund_data['notify_url'],//通知地址 - 'amount' => [ - 'refund' => round($refund_data['refund_amount'] * 100),//退款金额 - 'total' => round($refund_data['total'] * 100),//原订单金额 - 'currency' => 'CNY',//退款币种 - ] - ]; - $resp = $this->instance - ->chain('/v3/refund/domestic/refunds') - ->post([ - 'json' => $request_data, -// 'debug' => true - ]); - - $result = json_decode($resp->getBody(), true); - raw_log('wechat_pay/refund', ['request_data' => $request_data, 'result' => $result]); - - return [ - 'transaction_id' => $result['transaction_id'], - 'out_transaction_id' => $result['refund_id'], - 'out_trade_no' => $result['out_refund_no'], - ]; - - } catch (RequestException $exception) { - $response = $exception->getResponse(); - $result = json_decode($response->getBody()->getContents(), true); - raw_log('wechat_pay/refund_failed', ['request_data' => $request_data, 'result' => $result]); - - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $result['message'] - ]; - } - } - - - /** - * @desc 余额查询 微信没有余额查询接口,返回假数据 - * @param $seller_channel - * @return array - */ - public function queryBalanceAmount($seller_channel) - { - return [ - 'code'=>ResponseCode::SUCCESS, - 'data'=>[ - 'total_amount'=>0.00, - 'settled_amount'=>0.00, - 'not_settled_amount'=>0.00 - ] - ]; - } - -} \ No newline at end of file diff --git a/app/common/service/PhotoServiceOrderService.php b/app/common/service/PhotoServiceOrderService.php deleted file mode 100644 index 9abdf81..0000000 --- a/app/common/service/PhotoServiceOrderService.php +++ /dev/null @@ -1,378 +0,0 @@ -post(); - - $redis_key = 'photo_service_order_' . $request->user->id; -// if (Redis::get($redis_key)) { -// throw new Exception('请勿频繁操作'); -// } -// Redis::setEx($redis_key, 3, 1); - - //计算服务价格 - $photo_service_price = 0.00; - $paid_service_price = 0.00; - $photo_service_detail = []; - $paid_service_detail = []; - if ($data['photo_service']) { - $photo_service = json_decode($data['photo_service'], true); - foreach ($photo_service as $item) { - $service = PhotoService::where(['id' => $item['id']])->findOrEmpty(); -// if($service->isEmpty()){ -// throw new Exception('所选拍照服务不存在'); -// } - $photo_service_price += round($service->price + $item['number'], 2); - array_push($photo_service_detail, [ - 'service' => $service->toArray(), - 'number' => $item['number'] - ]); - } - } - - if ($data['paid_service']) { - $paid_service = json_decode($data['paid_service'], true); - foreach ($paid_service as $item) { - $service = PaidService::where(['id' => $item['id']])->findOrEmpty(); - $paid_service_price += round($service->price * $item['number'], 2); - array_push($paid_service_detail, [ - 'service' => $service->toArray(), - 'number' => $item['number'] - ]); - } - } - $total = round($photo_service_price + $paid_service_price, 2); - //保证金 - $deposit = 0.00; - if ($data['is_need_deposit']) { - $ratio = RatioService::ratio(); - $deposit = round($total * $ratio / 100, 2); - } - $order_no = generate_order_no('P'); - //插入订单 - $res = PhotoServiceOrder::create([ - 'user_id' => $request->user->id, - 'trade_no' => $order_no, - 'user_name' => $data['user_name'], - 'sex' => $data['sex'], - 'user_mobile' => $data['user_mobile'], - 'service_address' => $data['service_address'], - 'service_time' => $data['service_time'], - 'photo_service_type' => $data['photo_service_type'], - 'photo_service_data' => $data['photo_service'], - 'photo_service_detail' => json_encode($photo_service_detail), - - 'paid_service_type' => $data['paid_service_type'], - 'paid_service_data' => $data['paid_service'], - 'paid_service_detail' => json_encode($paid_service_detail), - - 'photographer_id' => $data['photographer_id'], - 'is_need_deposit' => $data['is_need_deposit'], - 'deposit_amount' => $deposit, - 'total' => $total, - 'remake' => $data['remake'], - ]); - - if (!$res) { - throw new Exception('创建订单失败'); - } - $pay_data = [ - 'trade_no' => $order_no, - 'total_amount' => $total, - 'desc' => '拍照服务付款', - 'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_URL,//回调地址 - 'openid' => $request->user->openid, - ]; - - $result = (new PayService())->payment($pay_data); - if (isset($result['code'])) { - throw new Exception($result['msg']); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $result, - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 计算价格 - * @param $request - * @return array|void - */ - public function calculatePrice($request) - { - try { - $photo_service_price = 0.00; - $paid_service_price = 0.00; - if ($request['photo_service']) { - $photo_service = json_decode($request['photo_service'], true); - foreach ($photo_service as $item) { - $service = PhotoService::where(['id' => $item['id']])->findOrEmpty(); - $photo_service_price += round($service->price + $item['number'], 2); - } - } - if ($request['paid_service']) { - $paid_service = json_decode($request['paid_service'], true); - foreach ($paid_service as $item) { - $service = PaidService::where(['id' => $item['id']])->findOrEmpty(); - $paid_service_price += round($service->price * $item['number'], 2); - } - } - $total = round($photo_service_price + $paid_service_price, 2); - $deposit = 0.00; - if ($request['is_need_deposit']) { - $ratio = RatioService::ratio(); - $deposit = round($total * $ratio / 100, 2); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'total' => $total, - 'deposit' => $deposit, - ] - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 拍照服务支付保证金 - * @param $request - * @return array - */ - public function payOrderDeposit($request) - { - try { - $data = $request->post(); - //查找订单 - $photo_order = PhotoServiceOrder::where(['id' => $data['order_id']])->findOrEmpty(); - if ($photo_order->isEmpty()) { - throw new Exception('订单不存在'); - } - - if ($photo_order->is_need_deposit != 1) { - throw new Exception('该订单无需支付保证金'); - } - if ($photo_order->pay_status != 1) { - throw new Exception('用户未付款,无需支付保证金'); - } - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->id != $photo_order->photographer_id) { - throw new Exception('非摄影师本人无法支付'); - } - $order_no = generate_order_no('D'); - - $deposit_order = DepositOrder::create([ - 'user_id' => $request->user->id, - 'photographer_id' => $photographer->id, - 'order_type' => 'photo', - 'deposit_amount' => $photo_order->deposit_amount, - 'trade_no' => $order_no, - ]); - - if (!$deposit_order) { - throw new Exception('创建订单失败'); - } - //订单表中插入保证金订单号 - $photo_order->save([ - 'deposit_order_id' => $deposit_order->id, - 'deposit_trade_no' => $order_no - ]); - - $pay_data = [ - 'trade_no' => $order_no, - 'total_amount' => $photo_order->deposit_amount, - 'desc' => '拍照服务付款', - 'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_DEPOSIT_URL,//回调地址 - 'openid' => $request->user->openid, - ]; - $result = (new PayService())->payment($pay_data); - if (isset($result['code'])) { - throw new Exception($result['msg']); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $result - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 摄影师拍照订单列表 - * @param $request - * @return array|void - */ - public function getPhotoServiceOrderForPhotographer($request) - { - try { - $data = $request->get(); - //摄影师信息 - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师信息'); - } - $order = PhotoServiceOrder::order('id desc')->where(['photographer_id' => $photographer->id]); - if (isset($data['status']) && $data['status'] != -1) { - $order->where(['status' => $data['status']]); - } - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - $total = $order->count(); - $list = $order->page($page, $limit)->with(['photographer'])->select(); - - foreach ($list as &$item){ - if($item['photo_service_detail']){ - $item['photo_service_detail'] = json_decode($item['photo_service_detail'], true); - } - if($item['paid_service_detail']){ - $item['paid_service_detail'] = json_decode($item['paid_service_detail'], true); - } - } - - 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|void - */ - public function getPhotoServiceOrderForUser($request) - { - try { - $data = $request->get(); - $order = PhotoServiceOrder::order('id desc')->where(['user_id' => $request->user->id]); - if (isset($data['status']) && $data['status'] != -1) { - $order->where(['status' => $data['status']]); - } - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - $total = $order->count(); - $list = $order->page($page, $limit)->with(['photographer'])->select(); - - foreach ($list as &$item){ - if($item['photo_service_detail']){ - $item['photo_service_detail'] = json_decode($item['photo_service_detail'], true); - } - if($item['paid_service_detail']){ - $item['paid_service_detail'] = json_decode($item['paid_service_detail'], true); - } - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list, - 'total' => $total, - 'page' => $page, - ] - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - public function confirmPhotoOrder($request) - { - try { - $data = $request->post(); - $photographer = Photographer::where(['user_id'=>$request->user->id])->findOrEmpty(); - if($photographer->isEmpty()){ - throw new Exception('未找到您的摄影师信息,操作失败'); - } - $order = PhotoServiceOrder::where(['out_trade_no'=>$data['out_trade_no']])->findOrEmpty(); - if($order->isEmpty()){ - throw new Exception('未找到订单信息'); - } - if($order->photographer_id != $photographer->id){ - throw new Exception('非该订单摄影师不能操作'); - } - $order->save([ - - ]); - - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 取消订单 - * @param $request - * @return array|void - */ - public function cancelPhotoOrder($request) - { - try { - - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/PhotoServiceService.php b/app/common/service/PhotoServiceService.php deleted file mode 100644 index ae2bbd6..0000000 --- a/app/common/service/PhotoServiceService.php +++ /dev/null @@ -1,199 +0,0 @@ - $request->user->id])->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $list - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 获取摄影师的服务列表 - * @param $request - * @return array - */ - public function select($request) - { - try { - $photographer_service = PhotoService::where(['photographer_id' => $request['photographer_id']]); - - if(isset($request['service_type']) && !empty($request['service_type'])){ - $photographer_service->where(['service_type' => $request['service_type']]); - } - $list = $photographer_service->field('id,photographer_id,service_type,service_standard,detail,price') - ->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $list - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 添加拍照服务 - * @param $request - * @return array - */ - public function add($request) - { - try { - $data = $request->post(); - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师信息,添加失败'); - } - - $validate = new PhotoServiceValidate(); - if (!$validate->check($data)) { - throw new Exception($validate->getError()); - } - $servicePhotoExit = PhotoService::where(['photographer_id' => $photographer->id, 'service_type' => $data['service_type']])->findOrEmpty(); - if (!$servicePhotoExit->isEmpty()) { - throw new Exception('该服务类型内容已存在,不能重复添加'); - } - - $res = PhotoService::create([ - 'user_id' => $request->user->id, - 'photographer_id' => $photographer->id, - 'service_type' => $data['service_type'], - 'service_standard' => $data['service_standard'], - 'detail' => $data['detail'], - 'price' => $data['price'], - ]); - 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 edit($request) - { - try { - $data = $request->post(); - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师信息,操作失败'); - } - - $validate = new PhotoServiceValidate(); - if (!$validate->check($data)) { - throw new Exception($validate->getError()); - } - $photoService = PhotoService::where(['id' => $data['id']])->findOrEmpty(); - if ($photoService->isEmpty()) { - throw new Exception('服务内容不存在'); - } - if ($photographer->id != $photoService->photographer_id) { - throw new Exception('非摄影师本人不能操作'); - } - - $res = $photoService->save([ - 'service_type' => $data['service_type'], - 'service_standard' => $data['service_standard'], - 'detail' => $data['detail'], - 'price' => $data['price'], - ]); - 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 del($request) - { - try { - $data = $request->post(); - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师信息,操作失败'); - } - - $validate = new PhotoServiceValidate(); - if (!$validate->check($data)) { - throw new Exception($validate->getError()); - } - $photoService = PhotoService::where(['id' => $data['id']])->findOrEmpty(); - if ($photoService->isEmpty()) { - throw new Exception('服务内容不存在'); - } - if ($photographer->id != $photoService->photographer_id) { - throw new Exception('非摄影师本人不能操作'); - } - - $res = $photoService->delete(); - if (!$res) { - throw new Exception('操作失败'); - } - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '操作成功', - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } -} \ No newline at end of file diff --git a/app/common/service/PhotographerService.php b/app/common/service/PhotographerService.php deleted file mode 100644 index 0a42147..0000000 --- a/app/common/service/PhotographerService.php +++ /dev/null @@ -1,258 +0,0 @@ -post(); - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if (!$photographer->findOrEmpty()) { - if ($photographer->apply_status == 0) { - throw new Exception('你已有申请待审批,请勿重新申请'); - } - if ($photographer->apply_status == 1) { - throw new Exception('你是摄影师,请勿重新申请'); - } - } - - $validate = new PhotographerValidate(); - if (!$validate->check($requestData)) { - throw new Exception($validate->getError()); - } - - $res = Photographer::create([ - 'user_id' => $request->user->id, - 'name' => $requestData['name'], - 'avatar' => $requestData['avatar'], - 'sex' => $requestData['sex'], - 'mobile' => $requestData['mobile'], - 'device_id' => $requestData['device_id'], - 'service_type' => $requestData['service_type'], - 'age' => $requestData['age'], - 'province_code' => $requestData['province_code'], - 'province_name' => $requestData['province_name'], - 'city_code' => $requestData['city_code'], - 'city_name' => $requestData['city_name'], - 'work_time' => $requestData['work_time'], - 'work_year' => $requestData['work_year'], - 'introduce' => $requestData['introduce'], - ]); - - 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|void - */ - public function changeApply($request) - { - try { - $photographer = Photographer::where(['id' => $request['id']])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('申请不存在'); - } - - $photographer->save(['apply_status' => $request['apply_status']]); - if ($request['apply_status'] == 1) { - User::where(['id' => $photographer->user_id])->save(['is_photographer' => 1]); - } else { - User::where(['id' => $photographer->user_id])->save(['is_photographer' => 0]); - } - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc 摄影师编辑 - * @param $request - * @return array|void - */ - public function edit($request) - { - try { - $requestData = $request->post(); - $photographer = Photographer::where(['id' => $requestData['id']])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师'); - } - - $photographer->save([ - 'user_id' => $request->user->id, - 'name' => $requestData['name'], - 'avatar' => $requestData['avatar'], - 'sex' => $requestData['sex'], - 'mobile' => $requestData['mobile'], - 'device_id' => $requestData['device_id'], - 'service_type' => $requestData['service_type'], - 'age' => $requestData['age'], - 'city_name' => $requestData['city_name'], - 'work_time' => $requestData['work_time'], - 'work_year' => $requestData['work_year'], - 'introduce' => $requestData['introduce'], - ]); - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 摄影师详情 - * @param $request - * @return array - */ - public function detail($request) - { - try { - $data = $request->get(); - if (!isset($data['id'])) { - throw new Exception('参数错误'); - } - $photographer = Photographer::where(['id' => $data['id'], 'apply_status' => 1])->with('studio')->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('摄影师不存在'); - } - if ($photographer->device_id) { - $photographer->device_id = array_map('intval', explode(',', $photographer->device_id)); - } - if ($photographer->service_type) { - $photographer->service_type = array_map('intval', explode(',', $photographer->service_type)); - } - $photographer->is_favorite = 0; - if (!empty($request->user)) { - $favorite = Favorite::where(['user_id' => $request->user->id, 'photographer_id' => $photographer->id])->findOrEmpty(); - - if (!$favorite->isEmpty()) { - $photographer->is_favorite = 1; - } - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $photographer, - 'msg' => 'success' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 获取摄影师的服务类目 - * @param $request - * @return array - */ - public function getServiceType($request) - { - try { - $photographer = Photographer::where(['id' => $request['photographer_id']])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到摄影师'); - } - $service_type = []; - if ($photographer->service_type) { - $service_type = ServiceType::where(['id' => explode(',', $photographer->service_type)])->order('sort desc, id desc')->field('id,service_name')->select(); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $service_type, - 'msg' => 'success' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - /** - * @desc - * @param $request - * @return array|void - */ - public function quitStudio($request) - { - try { - $data = $request->post(); - - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到您的摄影师数据,退出失败'); - } - if(empty($photographer->studio_id)){ - throw new Exception('摄影师未加入工作室'); - } -// $studio = Studio::where(['id' => $photographer->studio_id])->findOrEmpty(); -// if ($studio->isEmpty()) { -// throw new Exception('未找到工作室信息,退出失败'); -// } - - $photographer->save([ - 'studio_id' => 0 - ]); - User::where(['id' => $request->user->id])->save([ - 'studio_id' => 0 - ]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '操作成功' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/RatioService.php b/app/common/service/RatioService.php deleted file mode 100644 index dd269dd..0000000 --- a/app/common/service/RatioService.php +++ /dev/null @@ -1,19 +0,0 @@ -1])->value('ratio'); - } - -} \ No newline at end of file diff --git a/app/common/service/RequirementBiddingService.php b/app/common/service/RequirementBiddingService.php deleted file mode 100644 index 5d9b007..0000000 --- a/app/common/service/RequirementBiddingService.php +++ /dev/null @@ -1,189 +0,0 @@ -post(); - $requirement = Requirement::where(['id' => $data['requirement_id']])->findOrEmpty(); - if ($requirement->isEmpty()) { - throw new Exception('报价需求不存在'); - } - if ($requirement->status != 1) { - throw new Exception('当前需求已不在报价阶段,无法报价'); - } - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - if ($photographer->isEmpty()) { - throw new Exception('未找到您的摄影师信息,不能报价'); - } - $bidding_order = BiddingOrder::where(['user_id' => $photographer->user_id, 'requirement_id' => $requirement->id])->findOrEmpty(); - if (!$bidding_order->isEmpty()) { - throw new Exception('你已存在报价记录,不能再次报价'); - } - if (!isset($data['bidding_price']) || $data['bidding_price'] <= 0) { - throw new Exception('请输入正确的报价价格'); - } - - $res = BiddingOrder::create([ - 'user_id' => $request->user->id, - 'photographer_id' => $photographer->id, - 'requirement_id' => $requirement->id, - 'requirement_user_id' => $requirement->user_id, - 'requirement_detail' => json_encode($requirement->toArray()), - 'requirement_price' => $requirement->price, - 'bidding_price' => $data['bidding_price'], - ]); - 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 getUserRequirementBiddingOrderList($request) - { - try { - $data = $request->get(); - $bidding_order = BiddingOrder::where(['requirement_user_id' => $request->user->id, 'requirement_id' => $data['requirement_id']])->order('requirement_id desc,id desc'); - - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - $total = $bidding_order->count(); - $list = $bidding_order->with(['photographer']) - ->field('id,user_id,photographer_id,requirement_id,requirement_price,bidding_price,bind_status,created_at') - ->page($page, $limit) - ->select(); - - foreach ($list as &$item) { - if ($item['photographer']) { - $service_type_name = ''; - if($item['photographer']['service_type']){ - $service_type_name = ServiceType::where([ - 'id'=>explode(',',$item['photographer']['service_type']) - ]) - ->field('service_name') - ->order('sort desc, id desc') - ->select(); - if($service_type_name){ - $service_type_name = array_column($service_type_name->toArray(),'service_name'); - } - } - $item['photographer']['service_type_name'] = $service_type_name; - } - } - - $requirement = Requirement::where(['id' => $data['requirement_id']])->with('serviceType')->findOrEmpty(); - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list, - 'requirement' => $requirement, - 'total' => $total, - 'page' => $page - ] - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 确定报价 - * @param $request - * @return array|void - */ - public function confirmBid($request) - { - try { - $data = $request->post(); - $bid_order = BiddingOrder::where(['id' => $data['bidding_order_id']])->findOrEmpty(); - if ($bid_order->isEmpty()) { - throw new Exception('竞价订单不存在'); - } - - $requirement = Requirement::where(['id' => $bid_order->requirement_id])->findOrEmpty(); - if ($requirement->isEmpty()) { - throw new Exception('需求不存在'); - } - if ($requirement->status != 1) { - throw new Exception('需求不在出价中,无法确定报价'); - } - if ($request->user->id != $bid_order->requirement_user_id) { - throw new Exception('非需求本人无法确定报价'); - } - - //计算定金 - $ratio = RatioService::ratio(); - $deposit_amount = 0; - if($requirement->is_need_deposit){ - $deposit_amount = round($ratio * $bid_order->bidding_price / 100, 2); - } - - //需求表 - $requirement->save([ - 'bidding_order_id' => $bid_order->id, - 'bid_win_user_id' => $bid_order->user_id, - 'bid_win_photographer_id' => $bid_order->photographer_id, - 'final_price' => $bid_order->bidding_price, - 'deposit_amount' => $deposit_amount, - 'status' => 2 - ]); - //竞价表 - $bid_order->save([ - 'bind_status' => 1 - ]); - //更新其他竞价数据为【未中标】 - BiddingOrder::where(['requirement_id' => $bid_order->requirement_id])->where('id', '<>', $bid_order->id)->save([ - 'bind_status' => 2 - ]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '确定出价完成,请尽快完成支付', - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/RequirementOrderService.php b/app/common/service/RequirementOrderService.php deleted file mode 100644 index d7c5ac5..0000000 --- a/app/common/service/RequirementOrderService.php +++ /dev/null @@ -1,127 +0,0 @@ -post(); - $requirement = Requirement::where(['id' => $request_data['requirement_id']])->findOrEmpty(); - if ($requirement->status != 2) { - throw new Exception('需求订单状态错误,支付失败'); - } - $requirement_order = RequirementOrder::where(['requirement_trade_no' => $requirement->requirement_trade_no])->findOrEmpty(); - - if ($requirement_order->isEmpty()) { - throw new Exception('需求订单不存在'); - } - if ($requirement_order->pay_status != 0) { - throw new Exception('订单状态校验失败,支付失败'); - } - $out_trade_no = generate_order_no('R'); - $requirement_order->save([ - 'user_id' => $request->user->id, - 'out_trade_no' => $out_trade_no, - 'requirement_detail' => json_encode($requirement->toArray()), - 'amount' => $requirement->final_price - ]); - - $pay_data = [ - 'out_trade_no' => $out_trade_no, -// 'total_amount' => $requirement_order->amount, - 'total_amount' => 0.01, - 'desc' => $requirement->requirement_trade_no . '-支付', - 'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_URL,//回调地址 - 'openid' => $request->user->openid, - ]; - $result = (new PayService())->payment($pay_data); - - if (isset($result['code'])) { - throw new Exception($result['msg']); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $result, - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 需求退款 - * @param $request - * @return array|void - */ - public function requirementRefund($request) - { - try { - //查找订单 - $order = RequirementOrder::where(['out_trade_no' => $request['out_trade_no']])->findOrEmpty(); - if ($order->isEmpty()) { - throw new Exception('未找到订单信息'); - } - if ($order->pay_status != 1) { - throw new Exception('订单状态错误,退款失败'); - } - if ($order->is_refund) { - throw new Exception('订单已退款'); - } - - $refund_trade_no = generate_order_no('T'); - $order->save([ - 'refund_trade_no' => $refund_trade_no, - 'refund_amount' => $order->amount, - ]); - - $refund_data = [ - 'out_trade_no' => $order->out_trade_no, - 'out_refund_no' => $refund_trade_no, - 'refund_desc' => '正常退款', - 'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_REQUIREMENT_REFUND_URL, - 'total' => $order->amount, - 'refund_amount' => $order->amount, - ]; - - $result = (new PayService())->refundPayment($refund_data); - if(isset($result['code'])){ - throw new Exception($result['msg']); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '已申请退款', - ]; - - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/RequirementService.php b/app/common/service/RequirementService.php deleted file mode 100644 index 07bba4f..0000000 --- a/app/common/service/RequirementService.php +++ /dev/null @@ -1,268 +0,0 @@ -post(); - - $validate = new RequirementValidate(); - if (!$validate->check($data)) { - throw new Exception($validate->getError()); - } - $user = User::where(['id' => $request->user->id])->findOrEmpty(); -// if ($user->is_photographer) { -// throw new Exception('只有普通用户可以发布需求哟~'); -// } - - $requirement = Requirement::create([ - 'user_id' => $request->user->id, - 'user_name' => $data['user_name'], - 'sex' => $data['sex'], - 'mobile' => $data['mobile'], - 'service_address' => $data['service_address'], - 'service_time' => $data['service_time'], - 'service_type' => $data['service_type'], - 'is_need_deposit' => $data['is_need_deposit'], - 'price' => $data['price'], - 'mark' => $data['mark'], - 'status' => 1,//0:初始化 1:竞价中 2:已竞价 3:已完成 4:用户取消' - ]); - if (!$requirement) { - throw new Exception('发布失败'); - } - $requirement_trade_no = generate_order_no('D'); - //生成一条需求订单 - $requirement_order = RequirementOrder::create([ - 'requirement_id' => $requirement->id, - 'requirement_trade_no' => $requirement_trade_no, - ]); - - $requirement->save(['requirement_trade_no' => $requirement_trade_no]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '发布成功', - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 删除需求 - * @param $request - * @return array - */ - public function del($request) - { - try { - $data = $request->post(); - - $requirement = Requirement::where(['id' => $data['id']])->findOrEmpty(); - if ($requirement->findOrEmpty()) { - throw new Exception('未找到需求'); - } - - if ($requirement->user_id != $request->user->id) { - throw new Exception('非需求发布者,不能操作'); - } - //@todo:约定某些状态无法删除 - if ($requirement->status == 0) { - - } - - $res = $requirement->delete(); - 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 detail($request) - { - try { - $requirement = Requirement::where(['id' => $request['id']])->with(['serviceType'])->findOrEmpty(); - if ($requirement->isEmpty()) { - throw new Exception('需求未找到'); - } - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $requirement, - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 用户自己的需求列表 - * @param $request - * @return array - */ - public function getUserSelfRequirementList($request) - { - try { - $data = $request->get(); - $requirement = Requirement::order('id desc')->where(['user_id' => $request->user->id]); - - if (isset($data['service_type']) && $data['service_type'] != '') { - $requirement->where(['service_type' => $data['service_type']]); - } - - if (isset($data['status']) && $data['status']) { - if ($data['status'] == 1) { - $requirement->where(['status' => [1, 2]]); - } else { - $requirement->where(['status' => $data['status']]); - } - } - - $page = isset($data['page']) ? $data['page'] : 1; - $limit = isset($data['limit']) ? $data['limit'] : 10; - $total = $requirement->count(); - $list = $requirement->page($page, $limit)->with(['serviceType', 'bidWinPhotographer'])->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 getRequirement($request) - { - try { - $requirement = Requirement::order('id desc'); - if (isset($request['service_type']) && !empty($request['service_type'])) { - $requirement->where(['service_type' => $request['service_type']]); - } - - $page = isset($request['page']) ? $request['page'] : 1; - $limit = isset($request['limit']) ? $request['limit'] : 10; - $total = $requirement->count(); - $list = $requirement->page($page, $limit)->with('serviceType')->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 getBidRequirements($request) - { - try { - $requestData = $request->get(); - $photographer = Photographer::where(['user_id' => $request->user->id])->findOrEmpty(); - $service_type = []; - if ($photographer->service_type) { - $service_type = explode(',', $photographer->service_type); - } - $requirement = Requirement::where(['service_type' => $service_type]); - if (isset($requestData['status']) && $requestData['status']) { - if ($requestData['status'] == 1) { - $requirement->where(['status' => [1, 2]]); - } else { - $requirement->where(['status' => $requestData['status']]); - } - } - $page = isset($requestData['page']) ? $requestData['page'] : 1; - $limit = isset($requestData['limit']) ? $requestData['limit'] : 10; - $total = $requirement->count(); - $list = $requirement->with('serviceType')->page($page, $limit)->order('id desc')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => [ - 'list' => $list, - 'total' => $total, - 'page' => $page, - ] - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - public function cance() - { - - } - -} \ No newline at end of file diff --git a/app/common/service/ServiceStandardService.php b/app/common/service/ServiceStandardService.php deleted file mode 100644 index 2fce5fd..0000000 --- a/app/common/service/ServiceStandardService.php +++ /dev/null @@ -1,34 +0,0 @@ -field('standard_name')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data'=> $standard - ]; - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/ServiceTypeService.php b/app/common/service/ServiceTypeService.php deleted file mode 100644 index 73eadff..0000000 --- a/app/common/service/ServiceTypeService.php +++ /dev/null @@ -1,34 +0,0 @@ -field('id,service_name')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $service, - ]; - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/SlideshowService.php b/app/common/service/SlideshowService.php deleted file mode 100644 index d04bf98..0000000 --- a/app/common/service/SlideshowService.php +++ /dev/null @@ -1,22 +0,0 @@ -order('sort desc,id desc')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $res, - ]; - } - -} \ No newline at end of file diff --git a/app/common/service/StudentService.php b/app/common/service/StudentService.php new file mode 100644 index 0000000..01d8987 --- /dev/null +++ b/app/common/service/StudentService.php @@ -0,0 +1,53 @@ + $request['account']])->findOrEmpty(); + if ($student->isEmpty()) { + throw new Exception('账号不存在'); + } + if (empty($request['password'])) { + throw new Exception('请填写密码'); + } + + if (md5($request['password'] . $student->salt) != $student->password) { + throw new Exception('密码错误,请填写正确的密码'); + } + + $token_data = [ + 'id' => $student->id, + 'role' => 'student' + ]; + $token = JwtToken::generateToken($token_data); + return [ + 'code' => ResponseCode::SUCCESS, + 'data' => $token, + 'msg' => 'success' + ]; + + } catch (Exception $e) { + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + +} \ No newline at end of file diff --git a/app/common/service/StudioApplyService.php b/app/common/service/StudioApplyService.php deleted file mode 100644 index 0d6001a..0000000 --- a/app/common/service/StudioApplyService.php +++ /dev/null @@ -1,143 +0,0 @@ -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() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/StudioService.php b/app/common/service/StudioService.php deleted file mode 100644 index 084891f..0000000 --- a/app/common/service/StudioService.php +++ /dev/null @@ -1,198 +0,0 @@ -post(); - $user = User::where(['id' => $request->user->id])->findOrEmpty(); - if (!$user->is_photographer) { - throw new Exception('您还不是摄影师,请先成为摄影师'); - } - - $studio = Studio::where(['studio_name' => $post_data['studio_name']])->findOrEmpty(); - if (!$studio->isEmpty()) { - throw new Exception('工作室名称已存在,请更换名称'); - } - //@todo:判断是否一个人只能添加一个工作室 - $res = Studio::create([ - 'studio_name' => $post_data['studio_name'], - 'img' => $post_data['img'], - 'introductions' => $post_data['introductions'], - 'user_id' => $request->user->id - ]); - - if (!$res) { - throw new Exception('添加失败'); - } - User::where(['id' => $request->user->id])->save(['studio_id' => $res->id]); - - return [ - 'code' => ResponseCode::SUCCESS, - 'msg' => '添加成功' - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 工作室列表 - * @param $request - * @return array - */ - public function select($request) - { - try { - $list = Studio::order('id desc')->select(); - - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $list, - 'msg' => 'success' - ]; - - }catch (Exception $e){ - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 详情 - * @param $request - * @return array - */ - public function detail($request) - { - try { - $data = $request->get(); - $studio = Studio::where(['id' => $data['id']])->findOrEmpty(); - if ($studio->isEmpty()) { - throw new Exception('工作室不存在'); - } - $studio = $studio->toArray(); - $studio['is_me'] = 0; - if((array)$request->user){ - if($studio['user_id'] == $request->user->id){ - $studio['is_me'] = 1; - } - } - return [ - 'code' => ResponseCode::SUCCESS, - 'data' => $studio, - ]; - } catch (Exception $e) { - return [ - 'code' => ResponseCode::FAIL, - 'msg' => $e->getMessage() - ]; - } - } - - - /** - * @desc 工作室摄影师 - * @param $request - * @return array - */ - public function getStudioPhotographer($request) - { - try { - $studio = Studio::where(['id' => $request['studio_id']])->findOrEmpty(); - if ($studio->isEmpty()) { - throw new Exception('工作室不存在'); - } - $photographer = Photographer::where(['p.studio_id' => $studio->id])->alias('p'); - $page = isset($request['page']) ? $request['page'] : 1; - $limit = isset($request['limit']) ? $request['limit'] : 10; - $total = $photographer->count(); - $list = $photographer->page($page, $limit)->select(); - foreach ($list as &$item) { - $service_type_name = ''; - if ($item['service_type']) { - $service_type_name = ServiceType::where([ - 'id' => explode(',', $item['service_type']) - ]) - ->field('service_name') - ->order('sort desc, id desc') - ->select(); - if ($service_type_name) { - $service_type_name = array_column($service_type_name->toArray(), 'service_name'); - } - } - $item['service_type_name'] = $service_type_name; - } - 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 removePhotographer($request) - { - try { - $data = $request->post(); - $studio = Studio::where(['id' => $data['studio_id']])->findOrEmpty(); - - $photographer = Photographer::where(['id' => $data['photographer_id']])->findOrEmpty(); - - if ($studio->user_id != $request->user->id) { - throw new Exception('非工作室管理者不能操作'); - } - $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() - ]; - } - } - -} \ No newline at end of file diff --git a/app/common/service/TeacherService.php b/app/common/service/TeacherService.php index 83be4a1..61dc246 100644 --- a/app/common/service/TeacherService.php +++ b/app/common/service/TeacherService.php @@ -60,17 +60,30 @@ class TeacherService public function setTimeZone($request) { try { + if(empty($request->teacher)){ + throw new Exception('请教师登陆后再设置'); + } $teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty(); + if($teacher->isEmpty()){ + throw new Exception('未找到教师信息,设置失败'); + } $time_zone = TimeZone::where(['id' => $request->post('time_zone_id')])->findOrEmpty(); - $teacher->save([ + $res = $teacher->save([ 'time_zone_id' => $time_zone->id, 'time_zone_name' => $time_zone->name, 'time_zone_abbr' => $time_zone->abbr, 'time_zone_offset' => $time_zone->offset, ]); + if(!$res){ + throw new Exception('设置失败'); + } + return [ + 'code' => ResponseCode::SUCCESS, + 'msg' => '设置成功' + ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, diff --git a/composer.json b/composer.json index ff9d9e2..bc7c587 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,9 @@ "illuminate/database": "^8.83", "qiniu/php-sdk": "^7.12", "tinywan/jwt": "^1.10", - "webman/think-orm": "^1.1" + "webman/think-orm": "^1.1", + "illuminate/redis": "^8.83", + "illuminate/events": "^8.83" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 9b3da22..9a82a23 100644 --- a/composer.lock +++ b/composer.lock @@ -4,30 +4,30 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1b1fb19381413b411224d4a20cdc7ad7", + "content-hash": "9dc426c41a2a58306c3239ca918e541f", "packages": [ { "name": "carbonphp/carbon-doctrine-types", - "version": "2.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/CarbonPHP/carbon-doctrine-types.git", - "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb" + "reference": "18ba5ddfec8976260ead6e866180bd5d2f71aa1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/99f76ffa36cce3b70a4a6abce41dba15ca2e84cb", - "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb", + "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/18ba5ddfec8976260ead6e866180bd5d2f71aa1d", + "reference": "18ba5ddfec8976260ead6e866180bd5d2f71aa1d", "shasum": "" }, "require": { - "php": "^7.4 || ^8.0" + "php": "^8.1" }, "conflict": { - "doctrine/dbal": "<3.7.0 || >=4.0.0" + "doctrine/dbal": "<4.0.0 || >=5.0.0" }, "require-dev": { - "doctrine/dbal": "^3.7.0", + "doctrine/dbal": "^4.0.0", "nesbot/carbon": "^2.71.0 || ^3.0.0", "phpunit/phpunit": "^10.3" }, @@ -57,7 +57,7 @@ ], "support": { "issues": "https://github.com/CarbonPHP/carbon-doctrine-types/issues", - "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/2.1.0" + "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/3.2.0" }, "funding": [ { @@ -73,7 +73,7 @@ "type": "tidelift" } ], - "time": "2023-12-11T17:09:12+00:00" + "time": "2024-02-09T16:56:22+00:00" }, { "name": "doctrine/inflector", @@ -1175,6 +1175,60 @@ }, "time": "2021-03-26T18:39:16+00:00" }, + { + "name": "illuminate/redis", + "version": "v8.83.27", + "source": { + "type": "git", + "url": "https://github.com/illuminate/redis.git", + "reference": "0fee121324054226823a59623fab3d98ad88fbd5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/redis/zipball/0fee121324054226823a59623fab3d98ad88fbd5", + "reference": "0fee121324054226823a59623fab3d98ad88fbd5", + "shasum": "" + }, + "require": { + "illuminate/collections": "^8.0", + "illuminate/contracts": "^8.0", + "illuminate/macroable": "^8.0", + "illuminate/support": "^8.0", + "php": "^7.3|^8.0" + }, + "suggest": { + "ext-redis": "Required to use the phpredis connector (^4.0|^5.0).", + "predis/predis": "Required to use the predis connector (^1.1.9)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Redis\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Redis package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2022-01-24T02:32:30+00:00" + }, { "name": "illuminate/support", "version": "v8.83.27", @@ -2398,25 +2452,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v2.5.3", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d" + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/80d075412b557d41002320b96a096ca65aa2c98d", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2445,7 +2499,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.3" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" }, "funding": [ { @@ -2461,7 +2515,7 @@ "type": "tidelift" } ], - "time": "2023-01-24T14:02:46+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2939,33 +2993,30 @@ }, { "name": "symfony/service-contracts", - "version": "v2.5.3", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3" + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/a2329596ddc8fd568900e3fc76cba42489ecc7f3", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", "shasum": "" }, "require": { - "php": ">=7.2.5", - "psr/container": "^1.1", - "symfony/deprecation-contracts": "^2.1|^3" + "php": ">=8.1", + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" }, - "suggest": { - "symfony/service-implementation": "" - }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2975,7 +3026,10 @@ "autoload": { "psr-4": { "Symfony\\Contracts\\Service\\": "" - } + }, + "exclude-from-classmap": [ + "/Test/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3002,7 +3056,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v2.5.3" + "source": "https://github.com/symfony/service-contracts/tree/v3.5.0" }, "funding": [ { @@ -3018,7 +3072,7 @@ "type": "tidelift" } ], - "time": "2023-04-21T15:04:16+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/string", @@ -3108,53 +3162,51 @@ }, { "name": "symfony/translation", - "version": "v5.4.40", + "version": "v6.4.8", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "bb51d7f183756d1ac03f50ea47dc5726518cc7e8" + "reference": "a002933b13989fc4bd0b58e04bf7eec5210e438a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/bb51d7f183756d1ac03f50ea47dc5726518cc7e8", - "reference": "bb51d7f183756d1ac03f50ea47dc5726518cc7e8", + "url": "https://api.github.com/repos/symfony/translation/zipball/a002933b13989fc4bd0b58e04bf7eec5210e438a", + "reference": "a002933b13989fc4bd0b58e04bf7eec5210e438a", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "^1.16", - "symfony/translation-contracts": "^2.3" + "symfony/translation-contracts": "^2.5|^3.0" }, "conflict": { - "symfony/config": "<4.4", - "symfony/console": "<5.3", - "symfony/dependency-injection": "<5.0", - "symfony/http-kernel": "<5.0", - "symfony/twig-bundle": "<5.0", - "symfony/yaml": "<4.4" + "symfony/config": "<5.4", + "symfony/console": "<5.4", + "symfony/dependency-injection": "<5.4", + "symfony/http-client-contracts": "<2.5", + "symfony/http-kernel": "<5.4", + "symfony/service-contracts": "<2.5", + "symfony/twig-bundle": "<5.4", + "symfony/yaml": "<5.4" }, "provide": { - "symfony/translation-implementation": "2.3" + "symfony/translation-implementation": "2.3|3.0" }, "require-dev": { + "nikic/php-parser": "^4.18|^5.0", "psr/log": "^1|^2|^3", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/console": "^5.4|^6.0", - "symfony/dependency-injection": "^5.0|^6.0", - "symfony/finder": "^4.4|^5.0|^6.0", - "symfony/http-client-contracts": "^1.1|^2.0|^3.0", - "symfony/http-kernel": "^5.0|^6.0", - "symfony/intl": "^4.4|^5.0|^6.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/console": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/finder": "^5.4|^6.0|^7.0", + "symfony/http-client-contracts": "^2.5|^3.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/intl": "^5.4|^6.0|^7.0", "symfony/polyfill-intl-icu": "^1.21", - "symfony/service-contracts": "^1.1.2|^2|^3", - "symfony/yaml": "^4.4|^5.0|^6.0" - }, - "suggest": { - "psr/log-implementation": "To use logging capability in translator", - "symfony/config": "", - "symfony/yaml": "" + "symfony/routing": "^5.4|^6.0|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/yaml": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -3185,7 +3237,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v5.4.40" + "source": "https://github.com/symfony/translation/tree/v6.4.8" }, "funding": [ { @@ -3201,7 +3253,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:33:22+00:00" + "time": "2024-05-31T14:49:08+00:00" }, { "name": "symfony/translation-contracts", diff --git a/config/redis.php b/config/redis.php index 2f9757a..0eb233d 100644 --- a/config/redis.php +++ b/config/redis.php @@ -18,5 +18,6 @@ return [ 'password' => null, 'port' => 6379, 'database' => 0, + 'prefix'=> 'course_' ], ]; diff --git a/plugin/admin/app/controller/StudentController.php b/plugin/admin/app/controller/StudentController.php new file mode 100644 index 0000000..825be12 --- /dev/null +++ b/plugin/admin/app/controller/StudentController.php @@ -0,0 +1,169 @@ +model = new Student; + } + + /** + * 浏览 + * @return Response + */ + public function index(): Response + { + return view('student/index'); + } + + /** + * 插入 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function insert(Request $request): Response + { + if ($request->method() === 'POST') { + + $request_data = $request->post(); + $salt = random_str(16); + if (empty($request_data['password'])) { + $password = trim(explode('', $request_data['account'])[0]) . '001'; + $password = md5($password . $salt); + } else { + $password = md5($request_data['password'] . $salt); + } + + $res = \app\common\model\Student::create([ + 'student_name' => $request_data['student_name'], + 'account' => $request_data['account'], + 'password' => $password, + 'salt' => $salt, + 'avatar' => $request_data['avatar'], + 'parent_id' => 0, + ]); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => '添加成功' + ]); +// return parent::insert($request); + } + return view('student/insert'); + } + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function update(Request $request): Response + { + if ($request->method() === 'POST') { + try { + $request_data = $request->post(); + + $student = \app\common\model\Student::where(['id' => $request_data['id']])->findOrEmpty(); + if ($student->isEmpty()) { + throw new Exception('未找到学生信息,操作失败'); + } + + if (empty($request_data['password'])) { + $update = [ + 'student_name' => $request_data['student_name'], + 'account' => $request_data['account'], + 'avatar' => $request_data['avatar'], + 'parent_id' => 0, + ]; + } else { + $salt = random_str(16); + $password = md5($request_data['password'] . $salt); + $update = [ + 'student_name' => $request_data['student_name'], + 'account' => $request_data['account'], + 'password' => $password, + 'salt' => $salt, + 'avatar' => $request_data['avatar'], + 'parent_id' => 0, + ]; + } + + $student->save($update); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + +// return parent::update($request); + } + return view('student/update'); + } + + + /** + * @desc 重置密码 + * @param Request $request + * @return Response + */ + public function resetPassword(Request $request) + { + try { + $request_data = $request->post(); + $student = \app\common\model\Student::where(['id' => $request_data['id']])->findOrEmpty(); + $new_password = trim(explode(' ', $student->account)[0]) . '001'; + $salt = random_str(16); + $password = md5($new_password . $salt); + + $res = $student->save([ + 'salt' => $salt, + 'password' => $password + ]); + if(!$res){ + throw new Exception('重置失败'); + } + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => '重置成功' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + +} diff --git a/plugin/admin/app/controller/StudentParentController.php b/plugin/admin/app/controller/StudentParentController.php new file mode 100644 index 0000000..491593d --- /dev/null +++ b/plugin/admin/app/controller/StudentParentController.php @@ -0,0 +1,167 @@ +model = new StudentParent; + } + + /** + * 浏览 + * @return Response + */ + public function index(): Response + { + return view('student-parent/index'); + } + + /** + * 插入 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function insert(Request $request): Response + { + if ($request->method() === 'POST') { + + $request_data = $request->post(); + $salt = random_str(16); + if (empty($request_data['password'])) { + $password = trim(mb_substr($request_data['account'], 0, -2)) . '001'; + $password = md5($password . $salt); + } else { + $password = md5($request_data['password'] . $salt); + } + + $res = \app\common\model\StudentParent::create([ + 'parent_name' => $request_data['parent_name'], + 'account' => $request_data['account'], + 'password' => $password, + 'salt' => $salt, + 'avatar' => $request_data['avatar'], + ]); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => '添加成功' + ]); + +// return parent::insert($request); + } + return view('student-parent/insert'); + } + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function update(Request $request): Response + { + if ($request->method() === 'POST') { + try { + $request_data = $request->post(); + + $student = \app\common\model\StudentParent::where(['id' => $request_data['id']])->findOrEmpty(); + if ($student->isEmpty()) { + throw new Exception('未找到家长信息,操作失败'); + } + + if (empty($request_data['password'])) { + $update = [ + 'parent_name' => $request_data['parent_name'], + 'account' => $request_data['account'], + 'avatar' => $request_data['avatar'], + ]; + } else { + $salt = random_str(16); + $password = md5($request_data['password'] . $salt); + $update = [ + 'parent_name' => $request_data['parent_name'], + 'account' => $request_data['account'], + 'password' => $password, + 'salt' => $salt, + 'avatar' => $request_data['avatar'], + ]; + } + + $student->save($update); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + + return parent::update($request); + } + return view('student-parent/update'); + } + + + /** + * @desc 重置密码 + * @param Request $request + * @return Response + */ + public function resetPassword(Request $request) + { + try { + $request_data = $request->post(); + $parent = \app\common\model\StudentParent::where(['id' => $request_data['id']])->findOrEmpty(); + $new_password = trim(mb_substr($parent->account, 0, -2)) . '001'; + $salt = random_str(16); + $password = md5($new_password . $salt); + + $res = $parent->save([ + 'salt' => $salt, + 'password' => $password + ]); + if(!$res){ + throw new Exception('重置失败'); + } + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => '重置成功' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + +} diff --git a/plugin/admin/app/controller/SubjectController.php b/plugin/admin/app/controller/SubjectController.php index 67067fd..6392f09 100644 --- a/plugin/admin/app/controller/SubjectController.php +++ b/plugin/admin/app/controller/SubjectController.php @@ -9,7 +9,7 @@ use plugin\admin\app\controller\Crud; use support\exception\BusinessException; /** - * 学科设置 + * 课程管理 */ class SubjectController extends Crud { diff --git a/plugin/admin/app/model/Parent.php b/plugin/admin/app/model/Parent.php new file mode 100644 index 0000000..8a8a04d --- /dev/null +++ b/plugin/admin/app/model/Parent.php @@ -0,0 +1,39 @@ + + + + ++ + + + + + + + + + diff --git a/plugin/admin/app/view/student-parent/update.html b/plugin/admin/app/view/student-parent/update.html new file mode 100644 index 0000000..9613df1 --- /dev/null +++ b/plugin/admin/app/view/student-parent/update.html @@ -0,0 +1,180 @@ + + + + +浏览页面 + + + + + + +++ + ++ ++++ + + + + + + + + + + + + + + diff --git a/plugin/admin/app/view/student-parent/insert.html b/plugin/admin/app/view/student-parent/insert.html new file mode 100644 index 0000000..86977dc --- /dev/null +++ b/plugin/admin/app/view/student-parent/insert.html @@ -0,0 +1,143 @@ + + + + ++++
新增页面 + + + + + + +