199 lines
6.2 KiB
PHP
199 lines
6.2 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\common\service;
|
||
|
|
||
|
use app\common\model\Photographer;
|
||
|
use app\common\model\PhotoService;
|
||
|
use app\common\validate\PhotoServiceValidate;
|
||
|
use app\constant\ResponseCode;
|
||
|
use think\Exception;
|
||
|
|
||
|
class PhotoServiceService
|
||
|
{
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @desc 获取摄影师自己的的服务列表
|
||
|
* @param $request
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getPhotographerSelfService($request)
|
||
|
{
|
||
|
try {
|
||
|
$list = PhotoService::where(['user_id' => $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()
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
}
|