添加店员管理

This commit is contained in:
luofei 2024-06-06 15:00:33 +08:00
parent 73f6fe4032
commit 8515960d83
4 changed files with 237 additions and 6 deletions

View File

@ -0,0 +1,67 @@
<?php
namespace app\common\lists;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\system_store\SystemStoreStaff;
class StoreStaffLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/05/31 16:02
*/
public function setSearch(): array
{
return [
];
}
/**
* @notes 获取订单列表列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/05/31 16:02
*/
public function lists(): array
{
return SystemStoreStaff::field('id,staff_name,avatar,account,phone,is_admin,is_manager')
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
})
->when(!empty($this->params['keyword']), function ($query) {
$query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%");
})
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取订单列表数量
* @return int
* @author admin
* @date 2024/05/31 16:02
*/
public function count(): int
{
return SystemStoreStaff::when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
})
->when(!empty($this->params['keyword']), function ($query) {
$query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%");
})
->count();
}
}

View File

@ -3,6 +3,8 @@
namespace app\common\logic;
use app\common\model\system_store\SystemStoreStaff;
use app\common\service\FileService;
use Webman\Config;
class SystemStoreStaffLogic extends BaseLogic
{
@ -12,4 +14,56 @@ class SystemStoreStaffLogic extends BaseLogic
return SystemStoreStaff::where($where)->field($field)->select()->toArray();
}
public function add($params)
{
try {
$model = new SystemStoreStaff();
$model->setAttrs($params);
$model->store_id = request()->adminInfo['store_id'];
$passwordSalt = Config::get('project.unique_identification');
$model->pwd = create_password($params['pwd'], $passwordSalt);
$defaultAvatar = config('project.default_image.admin_avatar');
$model->avatar = !empty($model['avatar']) ? FileService::setFileUrl($model['avatar']) : $defaultAvatar;
$model->save();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function edit($id, $params)
{
try {
$model = SystemStoreStaff::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
$model->setAttrs($params);
$model->save();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function delete($id)
{
try {
$model = SystemStoreStaff::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
$model->delete();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function detail($id)
{
$model = SystemStoreStaff::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
return $model->toArray();
}
}

View File

@ -4,6 +4,7 @@ namespace app\common\model\system_store;
use app\common\model\BaseModel;
use app\common\service\FileService;
use think\model\concern\SoftDelete;
@ -18,5 +19,16 @@ class SystemStoreStaff extends BaseModel
protected $name = 'system_store_staff';
protected $deleteTime = 'delete_time';
}
/**
* @notes 头像获取器 - 头像路径添加域名
* @param $value
* @return string
* @author Tab
* @date 2021/7/13 11:35
*/
public function getAvatarAttr($value)
{
return empty($value) ? FileService::getFileUrl(config('project.default_image.admin_avatar')) : FileService::getFileUrl(trim($value, '/'));
}
}

View File

@ -2,6 +2,8 @@
namespace app\store\controller;
use app\common\controller\Definitions;
use app\common\lists\StoreStaffLists;
use app\common\logic\SystemStoreStaffLogic;
use hg\apidoc\annotation as ApiDoc;
@ -15,19 +17,115 @@ class StaffController extends BaseAdminController
ApiDoc\Method('GET'),
ApiDoc\NotHeaders(),
ApiDoc\Author('中国队长'),
ApiDoc\Query(name: 'keyword', type: 'string', require: false, desc: '店员名称/手机号/账号'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(ref: [Definitions::class, "page"]),
ApiDoc\ResponseSuccess("data", type: "array", children: [
['name' => 'id', 'desc' => 'id', 'type' => 'int'],
['name' => 'staff_name', 'desc' => '店员名称', 'type' => 'string'],
['name' => 'avatar', 'desc' => '头像', 'type' => 'string'],
['name' => 'account', 'desc' => '账号', 'type' => 'string'],
['name' => 'phone', 'desc' => '手机号', 'type' => 'string'],
['name' => 'is_admin', 'desc' => '是否是管理员', 'type' => 'string'],
['name' => 'is_manager', 'desc' => '是否是店长', 'type' => 'string'],
['name' => 'is_admin', 'desc' => '是否是管理员1是0不是', 'type' => 'int'],
['name' => 'is_manager', 'desc' => '是否是店长1是0不是', 'type' => 'int'],
]),
]
public function lists(SystemStoreStaffLogic $staffLogic)
public function lists()
{
return $this->data($staffLogic->listByWhere(['store_id' => $this->request->adminInfo['store_id'], 'status' => 1], 'id,staff_name,avatar,account,phone,is_admin,is_manager'));
return $this->dataLists(new StoreStaffLists());
}
#[
ApiDoc\Title('添加'),
ApiDoc\url('/store/staff/add'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Param(name: 'account', type: 'string', require: true, desc: '账号'),
ApiDoc\Param(name: 'pwd', type: 'string', require: true, desc: '密码'),
ApiDoc\Param(name: 'avatar', type: 'string', require: true, desc: '头像'),
ApiDoc\Param(name: 'staff_name', type: 'string', require: true, desc: '店员名称'),
ApiDoc\Param(name: 'phone', type: 'string', require: true, desc: '手机号'),
ApiDoc\Param(name: 'verify_status', type: 'string', require: true, desc: '核销开关1开启0关闭'),
ApiDoc\Param(name: 'order_status', type: 'string', require: true, desc: '订单状态1开启0关闭'),
ApiDoc\Param(name: 'is_manager', type: 'string', require: true, desc: '是否是店长1是0不是'),
ApiDoc\Param(name: 'status', type: 'string', require: true, desc: '状态1启用0禁用'),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function add(SystemStoreStaffLogic $staffLogic)
{
$params = $this->request->post();
$staffLogic->add($params);
return $this->success('操作成功', [], 1, 1);
}
#[
ApiDoc\Title('编辑'),
ApiDoc\url('/store/staff/edit'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Param(name: 'account', type: 'string', require: true, desc: '账号'),
ApiDoc\Param(name: 'pwd', type: 'string', require: true, desc: '密码'),
ApiDoc\Param(name: 'avatar', type: 'string', require: true, desc: '头像'),
ApiDoc\Param(name: 'staff_name', type: 'string', require: true, desc: '店员名称'),
ApiDoc\Param(name: 'phone', type: 'string', require: true, desc: '手机号'),
ApiDoc\Param(name: 'verify_status', type: 'string', require: true, desc: '核销开关1开启0关闭'),
ApiDoc\Param(name: 'order_status', type: 'string', require: true, desc: '订单状态1开启0关闭'),
ApiDoc\Param(name: 'is_manager', type: 'string', require: true, desc: '是否是店长1是0不是'),
ApiDoc\Param(name: 'status', type: 'string', require: true, desc: '状态1启用0禁用'),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function edit(SystemStoreStaffLogic $staffLogic)
{
$id = $this->request->get('id');
$params = $this->request->post();
$staffLogic->edit($id, $params);
return $this->success('操作成功', [], 1, 1);
}
#[
ApiDoc\Title('删除'),
ApiDoc\url('/store/staff/delete'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function delete(SystemStoreStaffLogic $staffLogic)
{
$id = $this->request->get('id');
$staffLogic->delete($id);
return $this->success('操作成功', [], 1, 1);
}
#[
ApiDoc\Title('详情'),
ApiDoc\url('/store/staff/detail'),
ApiDoc\Method('GET'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'),
ApiDoc\ResponseSuccess("data", type: "array", children: [
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
['name' => 'account', 'desc' => '账号', 'type' => 'string'],
['name' => 'avatar', 'desc' => '头像', 'type' => 'string'],
['name' => 'staff_name', 'desc' => '店员名称', 'type' => 'string'],
['name' => 'phone', 'desc' => '手机号', 'type' => 'string'],
['name' => 'verify_status', 'desc' => '核销开关1开启0关闭', 'type' => 'int'],
['name' => 'order_status', 'desc' => '订单状态1开启0关闭', 'type' => 'int'],
['name' => 'is_admin', 'desc' => '是否管理员1是0不是', 'type' => 'int'],
['name' => 'is_manager', 'desc' => '是否是店长1是0不是', 'type' => 'int'],
['name' => 'status', 'desc' => '状态1启用0禁用', 'type' => 'int'],
]),
]
public function detail(SystemStoreStaffLogic $staffLogic)
{
$id = $this->request->get('id');
$data = $staffLogic->detail($id);
return $this->data($data);
}
}