添加:移动端员工管理相关接口

This commit is contained in:
wuhui_zzw 2024-01-22 19:16:58 +08:00
parent 33fb06bd45
commit ad7eb11e9d
7 changed files with 246 additions and 52 deletions

View File

@ -39,27 +39,36 @@ class StoreServiceDao extends BaseDao
* @author xaboy
* @day 2020/5/29
*/
public function search(array $where)
{
return StoreService::getDB()->where('is_del', 0)->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
$query->where('status', $where['status']);
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('nickname', "%{$where['keyword']}%");
})->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})->when(isset($where['customer']) && $where['customer'] !== '', function ($query) use ($where) {
$query->where('customer', $where['customer']);
})->when(isset($where['is_verify']) && $where['is_verify'] !== '', function ($query) use ($where) {
$query->where('is_verify', $where['is_verify']);
})->when(isset($where['is_goods']) && $where['is_goods'] !== '', function ($query) use ($where) {
$query->where('is_goods', $where['is_goods']);
})->when(isset($where['is_open']) && $where['is_open'] !== '', function ($query) use ($where) {
$query->where('is_open', $where['is_open']);
})->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
$query->where('uid', $where['uid']);
})->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
$query->where('service_id', $where['service_id']);
});
public function search(array $where){
return StoreService::getDB()
->where('is_del',0)
->when(isset($where['status']) && $where['status'] !== '',function($query) use ($where){
$query->where('status',$where['status']);
})
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query) use ($where){
$query->whereLike('nickname',"%{$where['keyword']}%");
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query) use ($where){
$query->where('mer_id',$where['mer_id']);
})
->when(isset($where['customer']) && $where['customer'] !== '',function($query) use ($where){
$query->where('customer',$where['customer']);
})
->when(isset($where['is_verify']) && $where['is_verify'] !== '',function($query) use ($where){
$query->where('is_verify',$where['is_verify']);
})
->when(isset($where['is_goods']) && $where['is_goods'] !== '',function($query) use ($where){
$query->where('is_goods',$where['is_goods']);
})
->when(isset($where['is_open']) && $where['is_open'] !== '',function($query) use ($where){
$query->where('is_open',$where['is_open']);
})
->when(isset($where['uid']) && $where['uid'] !== '',function($query) use ($where){
$query->where('uid',$where['uid']);
})
->when(isset($where['service_id']) && $where['service_id'] !== '',function($query) use ($where){
$query->where('service_id',$where['service_id']);
});
}
public function getService($uid, $merId = null)

View File

@ -84,6 +84,7 @@ class StoreServiceRepository extends BaseRepository
Elm::switches('is_verify', '开启核销', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8),
Elm::switches('is_user', '客户管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8),
Elm::switches('staff_manage', '员工管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8),
Elm::switches('qr_code_show', '推广二维码', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8),
Elm::switches('notify', '订单通知', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8)->control([
[
'value' => 1,
@ -159,24 +160,54 @@ class StoreServiceRepository extends BaseRepository
$service = $this->dao->getRandService($merId);
if ($service) return $service;
}
public function getServices($uid, array $where = [],$is_sys = 1)
{
$order = $is_sys ? 'ASC' : 'DESC';
// 获取当前用户的员工信息
public function getServices($uid, array $where = [],$is_sys = 1){
$where['uid'] = $uid;
$list = $this->search($where)->with(['merchant' => function ($query) {
$query->field('mer_id,mer_avatar,mer_name');
}])->order('mer_id '.$order)->select()->hidden(['pwd'])->toArray();
$config = systemConfig(['site_logo', 'site_name']);
foreach ($list as &$item){
if ($item['mer_id'] == 0) {
$item['merchant'] = [
'mer_avatar' => $config['site_logo'],
'mer_name' => $config['site_name'],
'mer_id' => 0,
];
$list = $this->dao->getSearch([])
->hasWhere('merchant',function($query){
$query->where('is_del', 0);
})
->where('StoreService.is_del',0)
->where('StoreService.mer_id',$is_sys == 1 ? '=' : '>',0)
->when(isset($where['is_verify']) && $where['is_verify'] !== '',function($query) use ($where){
$query->where('StoreService.is_verify',$where['is_verify']);
})
->when(isset($where['customer']) && $where['customer'] !== '',function($query) use ($where){
$query->where('StoreService.customer',$where['customer']);
})
->when(isset($where['is_goods']) && $where['is_goods'] !== '',function($query) use ($where){
$query->where('StoreService.is_goods',$where['is_goods']);
})
->when(isset($where['is_open']) && $where['is_open'] !== '',function($query) use ($where){
$query->where('StoreService.is_open',$where['is_open']);
})
->when(isset($where['uid']) && $where['uid'] !== '',function($query) use ($where){
$query->where('StoreService.uid',$where['uid']);
})
->with([
'merchant' => function($query){
$query->field('mer_id,mer_avatar,mer_name');
}
])
->order('StoreService.mer_id DESC')
->select()
->hidden(['pwd'])
->toArray();
// 是否处理总平台客服信息
if($is_sys == 1){
$config = systemConfig(['site_logo','site_name']);
foreach($list as &$item){
if($item['mer_id'] == 0){
$item['merchant'] = [
'mer_avatar' => $config['site_logo'],
'mer_name' => $config['site_name'],
'mer_id' => 0,
];
}
}
unset($item);
}
unset($item);
return $list;
}
public function createToken(StoreService $admin)
@ -311,6 +342,21 @@ class StoreServiceRepository extends BaseRepository
return $this->dao->update($id, $data);
}
/**
* Common: 删除信息
* Author: wu-hui
* Time: 2024/01/22 15:56
* @param int $id
* @param int $merId
* @return int
* @throws DbException
*/
public function deleteInfo(int $id,int $merId){
if (!$this->dao->merExists($merId, $id)) throw new ValidateException('数据不存在!');
return $this->dao->delete($id);
}
}

View File

@ -0,0 +1,134 @@
<?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('删除成功');
}
}

View File

@ -46,8 +46,9 @@ class UserMerchant extends BaseController{
* @return mixed
*/
public function getList($merId){
$where = $this->request->params(['nickname']);
$where = $this->request->params(['nickname','default_consume_id']);
$where['mer_id'] = $merId;
if((int)$where['default_consume_id'] > 0) $where['uids'] = [$where['default_consume_id']] ?? [];
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getList($where, $page, $limit));

View File

@ -528,7 +528,9 @@ class User extends BaseController
$uid = $this->user->uid;
$where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]);
$is_sys = $this->request->param('is_sys');
return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys));
$list = app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys);
return app('json')->success($list);
}
public function memberInfo()

View File

@ -172,18 +172,12 @@ class StoreService extends BaseController
return app('json')->success('修改成功');
}
/**
* @param $id
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020/5/29
*/
public function delete($id)
{
if (!$this->repository->merExists($this->request->merId(), $id))
return app('json')->fail('数据不存在');
$this->repository->delete($id);
// 删除员工信息
public function delete($id){
$merId = $this->request->merId();
$this->repository->deleteInfo((int)$id, (int)$merId);
return app('json')->success('删除成功');
}

View File

@ -369,10 +369,19 @@ Route::group('api/', function () {
})->prefix('api.user.');
// 员工管理
Route::group('staff', function () {
Route::get('staff_list', 'Service/lst');// 列表
Route::get('staff_edit', 'Service/editInfo');// 编辑
Route::get('staff_del', 'Service/delInfo');// 删除
Route::get('staff_info', 'Service/staffInfo');// 删除
})->prefix('api.store.merchant.');
})->middleware(UserTokenMiddleware::class, true);
//非强制登录
Route::group(function () {
// 商品兑换
@ -573,7 +582,6 @@ Route::group('api/', function () {
})->prefix('api.Diy');
})->middleware(UserTokenMiddleware::class, false);
//微信支付回调
Route::any('notice/wechat_pay', 'api.Common/wechatNotify')->name('wechatNotify');
//微信支付回调