176 lines
5.6 KiB
PHP
176 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace app\controller\api\store\merchant;
|
|
|
|
use app\validate\merchant\StoreServiceValidate;
|
|
use crmeb\services\QrcodeService;
|
|
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/23 10:08
|
|
* @return mixed
|
|
*/
|
|
public function inviteQrCode(){
|
|
// 参数获取
|
|
$merId = $this->request->param('mer_id');
|
|
if((int)$merId > 0){
|
|
try{
|
|
// 生成参数
|
|
$valueData = 'mer_id=' . $merId;
|
|
$path = 'pages/admin/business/edit_staff';// /pages/admin/business/edit_staff
|
|
$name = md5($path . $valueData) . '.jpg';
|
|
$qrcode = app()->make(QrcodeService::class)->getRoutineQrcodePath($name, $path, $valueData);
|
|
if (!$qrcode) throw new \Exception('二维码生成失败');
|
|
|
|
return app('json')->success([
|
|
'qr_code' => $qrcode
|
|
]);
|
|
}catch(\Exception $e){
|
|
return app('json')->fail($e->getMessage());
|
|
}catch(\Throwable $e){
|
|
return app('json')->fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
return app('json')->fail('小程序码生成失败!');
|
|
}
|
|
|
|
|
|
/**
|
|
* 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],
|
|
'qr_code_show',
|
|
'online_payment',
|
|
'product_exchange',
|
|
'purchase_permission'
|
|
]);
|
|
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');
|
|
},
|
|
'merchant' => function($query){
|
|
$query->field('mer_id,mer_name,mer_avatar,merchant_type')->bind(['mer_name','mer_avatar','merchant_type']);
|
|
}
|
|
])->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('删除成功');
|
|
}
|
|
|
|
}
|