new-admin-api/app/controller/api/store/merchant/Service.php

135 lines
4.2 KiB
PHP

<?php
namespace app\controller\api\store\merchant;
use app\validate\merchant\StoreServiceValidate;
use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\store\service\StoreServiceRepository;
use think\exception\ValidateException;
class Service extends BaseController{
protected $repository;
protected $userInfo;
public function __construct(App $app,StoreServiceRepository $repository){
parent::__construct($app);
$this->repository = $repository;
$this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : NULL;
}
/**
* Common: 获取员工列表
* Author: wu-hui
* Time: 2024/01/22 14:58
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lst(){
$params = $this->request->params(['keyword','mer_id']);
[$page, $limit] = $this->getPage();
$data = $this->repository->getList($params, $page, $limit);
return app('json')->success($data);
}
/**
* Common: 编辑信息
* Author: wu-hui
* Time: 2024/01/22 18:43
* @param StoreServiceValidate $validate
* @return mixed
* @throws \think\db\exception\DbException
*/
public function editInfo(StoreServiceValidate $validate){
// 参数获取
$params = $this->checkParams($validate);
$serviceId = (int)$params['service_id'];
unset($params['service_id']);
// 操作
if($serviceId > 0) $this->repository->updateInfo((int)$serviceId, $params);
else $this->repository->createInfo($params);
return app('json')->success('操作成功');
}
/**
* Common: 编辑参数获取
* Author: wu-hui
* Time: 2024/01/22 17:39
* @param StoreServiceValidate $validate
* @return array
*/
public function checkParams(StoreServiceValidate $validate){
// 参数获取
$data = $this->request->params([
['mer_id',0],
['service_id',0],
['uid',[]],
'nickname',
'account',
'pwd',
'confirm_pwd',
'is_open',
['status',0],
'customer',
'is_verify',
'is_goods',
'is_user',
'staff_manage',
'notify',
'avatar',
'phone',
['sort',0]
]);
if(is_array(json_decode($data['uid'], true))) $data['uid'] = json_decode($data['uid'], true);
// 是否编辑
if((int)$data['service_id'] > 0) $validate->update();
$validate->check($data);
if ($data['pwd'] && $data['pwd'] != $data['confirm_pwd']) {
throw new ValidateException('员工密码与确认密码不一致');
}
$data['uid'] = $data['uid']['id'];
unset($data['confirm_pwd']);
return $data;
}
/**
* Common: 获取用户信息
* Author: wu-hui
* Time: 2024/01/22 18:34
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function staffInfo(){
$id = $this->request->param('service_id');
$service = $this->repository->getWith($id,[
'user' => function($query){
$query->field('avatar,uid');
}
])->toArray();
if($service['user'] ?? null){
$service['uid'] = ['id' => $service['uid'], 'src' => $service['user']['avatar'] ?: $service['avatar']];
}else{
unset($service['uid']);
}
unset($service['user'], $service['pwd']);
return app('json')->success($service);
}
/**
* Common: 删除员工信息
* Author: wu-hui
* Time: 2024/01/22 15:56
* @return mixed
* @throws \think\db\exception\DbException
*/
public function delInfo(){
$params = $this->request->params(['service_id','mer_id']);
$this->repository->deleteInfo((int)$params['service_id'], (int)$params['mer_id']);
return app('json')->success('删除成功');
}
}