258 lines
8.3 KiB
PHP
258 lines
8.3 KiB
PHP
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use app\common\model\Favorite;
|
|
use app\common\model\Photographer;
|
|
use app\common\model\Requirement;
|
|
use app\common\model\ServiceType;
|
|
use app\common\model\Studio;
|
|
use app\common\model\User;
|
|
use app\common\validate\PhotographerValidate;
|
|
use app\constant\ResponseCode;
|
|
use think\Exception;
|
|
|
|
class PhotographerService
|
|
{
|
|
|
|
/**
|
|
* @desc 摄影师申请
|
|
* @param $request
|
|
* @return array
|
|
*/
|
|
public function apply($request)
|
|
{
|
|
try {
|
|
$requestData = $request->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()
|
|
];
|
|
}
|
|
}
|
|
|
|
} |