Files
huangjingfen/pro_v3.5.1_副本/app/services/store/SystemStoreStaffServices.php
apple 434aa8c69d feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods

Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口

Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则

Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)

Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口

Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单

Made-with: Cursor
2026-03-23 22:32:19 +08:00

690 lines
32 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\store;
use app\dao\store\SystemStoreStaffDao;
use app\services\BaseServices;
use app\services\order\OtherOrderServices;
use app\services\order\store\BranchOrderServices;
use app\services\system\SystemRoleServices;
use app\services\user\UserCardServices;
use app\services\user\UserRechargeServices;
use app\services\user\UserSpreadServices;
use crmeb\exceptions\AdminException;
use crmeb\services\FormBuilder;
use think\annotation\Inject;
use think\exception\ValidateException;
/**
* 门店店员
* Class SystemStoreStaffServices
* @package app\services\system\store
* @mixin SystemStoreStaffDao
*/
class SystemStoreStaffServices extends BaseServices
{
/**
* @var FormBuilder
*/
#[Inject]
protected FormBuilder $builder;
/**
* @var SystemStoreStaffDao
*/
#[Inject]
protected SystemStoreStaffDao $dao;
/**
* 获取低于等级的店员名称和id
* @param string $field
* @param int $level
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrdAdmin(string $field = 'real_name,id', int $storeId = 0, int $level = 0)
{
return $this->dao->getWhere()->when('store_id', $storeId)->where('level', '>=', $level)->field($field)->select()->toArray();
}
/**
* 获取门店客服列表
* @param int $store_id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCustomerList(int $store_id, string $field = '*')
{
return $this->dao->getWhere()->where('store_id', $store_id)->where('status', 1)->where('is_del', 0)->where('is_customer', 1)->field($field)->select()->toArray();
}
/**
* 获取店员详情
* @param int $id
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStaffInfo(int $id, string $field = '*')
{
$info = $this->dao->getOne(['id' => $id, 'is_del' => 0], $field);
if (!$info) {
throw new ValidateException('店员不存在');
}
return $info;
}
/**
* 根据uid获取门店店员信息
* @param int $uid
* @param int $store_id
* @param string $field
* @return array|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStaffInfoByUid(int $uid, int $store_id = 0, string $field = '*')
{
$where = ['uid' => $uid, 'is_del' => 0, 'status' => 1];
if ($store_id) $where['store_id'] = $store_id;
$info = $this->dao->getOne($where, $field);
if (!$info) {
throw new ValidateException('店员不存在');
}
return $info;
}
/**
* 获取门店|店员统计
* @param int $store_id
* @param int $staff_id
* @param string $time
* @return array
*/
public function getStoreData(int $uid, int $store_id, int $staff_id = 0, string $time = 'today')
{
$where = ['store_id' => $store_id, 'time' => $time];
if ($staff_id) {
$where['staff_id'] = $staff_id;
}
$data = [];
$order_where = ['pid' => 0, 'paid' => 1, 'refund_status' => [0, 3], 'is_del' => 0, 'is_system_del' => 0];
/** @var BranchOrderServices $orderServices */
$orderServices = app()->make(BranchOrderServices::class);
$data['send_price'] = $orderServices->sum($where + $order_where + ['type' => 107], 'pay_price', true);
$data['send_count'] = $orderServices->count($where + $order_where + ['type' => 107]);
$data['refund_price'] = $orderServices->sum($where + ['status' => -3], 'pay_price', true);
$data['refund_count'] = $orderServices->count($where + ['status' => -3]);
$data['cashier_price'] = $orderServices->sum($where + $order_where + ['type' => 106], 'pay_price', true);
$data['writeoff_price'] = $orderServices->sum($where + $order_where + ['type' => 105], 'pay_price', true);
/** @var OtherOrderServices $otherOrder */
$otherOrder = app()->make(OtherOrderServices::class);
$data['svip_price'] = $otherOrder->sum($where + ['paid' => 1, 'type' => [0, 1, 2, 4]], 'pay_price', true);
/** @var UserRechargeServices $userRecharge */
$userRecharge = app()->make(UserRechargeServices::class);
$data['recharge_price'] = $userRecharge->getWhereSumField($where + ['paid' => 1], 'price');
/** @var UserSpreadServices $userSpread */
$userSpread = app()->make(UserSpreadServices::class);
$data['spread_count'] = $userSpread->count($where + ['timeKey' => 'spread_time']);
/** @var UserCardServices $userCard */
$userCard = app()->make(UserCardServices::class);
$data['card_count'] = $userCard->count($where + ['is_submit' => 1]);
return $data;
}
/**
* 判断是否是有权限核销的店员
* @param int $uid
* @return int
*/
public function verifyStatus(int $uid)
{
return (bool)$this->dao->getOne(['uid' => $uid, 'status' => 1, 'is_del' => 0, 'verify_status' => 1]);
}
/**
* 获取店员列表
* @param array $where
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreStaffList(array $where, array $with = [])
{
$with = array_merge($with, [
'workMember' => function ($query) {
$query->field(['uid', 'name', 'position', 'qr_code', 'external_position']);
}
]);
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getStoreStaffList($where, '*', $page, $limit, $with);
if ($list) {
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$allRole = $service->getRoleArray(['type' => 2, 'store_id' => $where['store_id'], 'status' => 1]);
foreach ($list as &$item) {
if ($item['roles']) {
$roles = [];
foreach ($item['roles'] as $id) {
if (isset($allRole[$id])) $roles[] = $allRole[$id];
}
if ($roles) {
$item['roles'] = implode(',', $roles);
} else {
$item['roles'] = '';
}
} else {
$item['roles'] = '';
}
}
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 不查询总数
* @param array $where
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreStaff(array $where, array $with = [])
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getStoreStaffList($where, '*', $page, $limit, $with);
foreach ($list as $key => $item) {
unset($list[$key]['pwd']);
}
return $list;
}
/**
* 店员详情
* @param int $id
* @return array|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function read(int $id)
{
$staffInfo = $this->getStaffInfo($id);
$info = [
'id' => $id,
'headerList' => $this->getHeaderList($id, $staffInfo),
'ps_info' => $staffInfo
];
return $info;
}
/**
* 店员详情头部信息
* @param int $id
* @param array $staffInfo
* @return array[]
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHeaderList(int $id, $staffInfo = [])
{
if (!$staffInfo) {
$staffInfo = $this->dao->get($id);
}
$where = ['store_id' => $staffInfo['store_id'], 'staff_id' => $staffInfo['id']];
/** @var BranchOrderServices $orderServices */
$orderServices = app()->make(BranchOrderServices::class);
$cashier_order = $orderServices->sum($where + ['pid' => 0, 'type' => 106, 'paid' => 1, 'refund_status' => 0, 'is_del' => 0, 'is_system_del' => 0], 'pay_price', true);
$writeoff_order = $orderServices->sum($where + ['pid' => 0, 'type' => 105, 'paid' => 1, 'refund_status' => 0, 'is_del' => 0, 'is_system_del' => 0], 'pay_price', true);
$self_order = $orderServices->sum($where + ['pid' => 0, 'type' => 107, 'paid' => 1, 'refund_status' => 0, 'is_del' => 0, 'is_system_del' => 0], 'pay_price', true);
/** @var UserRechargeServices $userRechargeServices */
$userRechargeServices = app()->make(UserRechargeServices::class);
$recharge = $userRechargeServices->sum($where + ['paid' => 1], 'price', true);
/** @var UserSpreadServices $userSpreadServices */
$userSpreadServices = app()->make(UserSpreadServices::class);
$spread = $userSpreadServices->count($where);
/** @var UserCardServices $userCardServices */
$userCardServices = app()->make(UserCardServices::class);
$card = $userCardServices->count($where + ['is_submit' => 1]);
/** @var OtherOrderServices $otherOrderServices */
$otherOrderServices = app()->make(OtherOrderServices::class);
$svip = $otherOrderServices->sum($where, 'pay_price', true);
return [
[
'title' => '收银订单',
'value' => $cashier_order,
'key' => '元',
],
[
'title' => '核销订单',
'value' => $writeoff_order,
'key' => '元',
],
[
'title' => '配送订单',
'value' => $self_order,
'key' => '元',
],
[
'title' => '充值订单',
'value' => $recharge,
'key' => '元',
],
[
'title' => '付费会员',
'value' => $svip,
'key' => '元',
],
[
'title' => '推广用户数',
'value' => $spread,
'key' => '人',
],
[
'title' => '激活会员卡',
'value' => $card,
'key' => '张',
]
];
}
/**
* 获取select选择框中的门店列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreSelectFormData()
{
/** @var SystemStoreServices $service */
$service = app()->make(SystemStoreServices::class);
$menus = [];
foreach ($service->getStore() as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
}
return $menus;
}
/**
* 获取核销员表单
* @param array $formData
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function createStaffForm(array $formData = [])
{
if ($formData) {
$field[] = $this->builder->frameImage('image', '更换头像', $this->url('admin/widget.images/index', array('fodder' => 'image'), true), $formData['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
} else {
$field[] = $this->builder->frameImage('image', '商城用户', $this->url('admin/system.User/list', ['fodder' => 'image'], true))->icon('ios-add')->width('960px')->height('550px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
}
$field[] = $this->builder->hidden('uid', $formData['uid'] ?? 0);
$field[] = $this->builder->hidden('avatar', $formData['avatar'] ?? '');
$field[] = $this->builder->select('store_id', '所属提货点', ($formData['store_id'] ?? 0))->setOptions($this->getStoreSelectFormData())->filterable(true);
$field[] = $this->builder->input('staff_name', '核销员名称', $formData['staff_name'] ?? '')->col(24)->required();
$field[] = $this->builder->input('phone', '手机号码', $formData['phone'] ?? '')->col(24)->required();
$field[] = $this->builder->radio('verify_status', '核销开关', $formData['verify_status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('status', '状态', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
return $field;
}
/**
* 添加核销员表单
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function createForm()
{
return create_form('添加核销员', $this->createStaffForm(), $this->url('/merchant/store_staff/save/0'));
}
/**
* 编辑核销员form表单
* @param int $id
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updateForm(int $id)
{
$storeStaff = $this->dao->get($id);
if (!$storeStaff) {
throw new AdminException('没有查到信息,无法修改');
}
return create_form('修改核销员', $this->createStaffForm($storeStaff->toArray()), $this->url('/merchant/store_staff/save/' . $id));
}
/**
* 获取门店店员
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreAdminList($where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getStoreAdminList($where, $page, $limit);
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$allRole = $service->getRoleArray(['type' => 2, 'store_id' => $where['store_id']]);
foreach ($list as &$item) {
if ($item['roles']) {
$roles = [];
foreach ($item['roles'] as $id) {
if (isset($allRole[$id])) $roles[] = $allRole[$id];
}
if ($roles) {
$item['roles'] = implode(',', $roles);
} else {
$item['roles'] = '';
}
}
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 添加门店管理员
* @param int $store_id
* @param $level
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function createStoreAdminForm(int $store_id, $level)
{
$field[] = $this->builder->input('staff_name', '管理员名称')->col(24)->required();
$field[] = $this->builder->frameImage('avatar', '管理员头像', $this->url('store/widget.images/index', ['fodder' => 'avatar'], true))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
$field[] = $this->builder->input('account', '管理员账号')->maxlength(35)->required('请填写管理员账号');
$field[] = $this->builder->input('phone', '手机号码')->col(24)->required();
$field[] = $this->builder->input('pwd', '管理员密码')->type('password')->required('请填写管理员密码');
$field[] = $this->builder->input('conf_pwd', '确认密码')->type('password')->required('请输入确认密码');
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$options = $service->getRoleFormSelect($level, 1, $store_id);
$roles = [];
$field[] = $this->builder->select('roles', '管理员身份', $roles)->setOptions(FormBuilder::setOptions($options))->multiple(true)->required('请选择管理员身份');
$field[] = $this->builder->radio('status', '状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
return create_form('添加门店管理员', $field, $this->url('/system/admin'));
}
/**
* 修改门店管理员
* @param $id
* @param $level
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updateStoreAdminForm($id, $level)
{
$adminInfo = $this->dao->get($id);
if (!$adminInfo) {
throw new AdminException('门店管理员不存在!');
}
if ($adminInfo->is_del) {
throw new AdminException('门店管理员已经删除');
}
$adminInfo = $adminInfo->toArray();
$field[] = $this->builder->input('staff_name', '门店管理员名称', $adminInfo['staff_name'])->col(24)->required('请填写门店管理员名称');
$field[] = $this->builder->frameImage('avatar', '管理员头像', $this->url('store/widget.images/index', ['fodder' => 'avatar'], true), $adminInfo['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
$field[] = $this->builder->input('account', '门店管理员账号', $adminInfo['account'])->maxlength(35)->required('请填写门店管理员账号');
$field[] = $this->builder->input('phone', '手机号码', $adminInfo['phone'])->col(24)->required();
$field[] = $this->builder->input('pwd', '门店管理员密码')->placeholder('不更改密码请留空')->type('password');
$field[] = $this->builder->input('conf_pwd', '确认密码')->placeholder('不更改密码请留空')->type('password');
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$options = $service->getRoleFormSelect($level, 1, (int)$adminInfo['store_id']);
$roles = [];
if ($adminInfo && isset($adminInfo['roles']) && $adminInfo['roles']) {
foreach ($adminInfo['roles'] as $role) {
$roles[] = (int)$role;
}
}
$field[] = $this->builder->select('roles', '管理员身份', $roles)->setOptions(FormBuilder::setOptions($options))->multiple(true)->required('请选择门店管理员身份');
$field[] = $this->builder->radio('status', '状态', (int)$adminInfo['status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
return create_form('修改门店管理员', $field, $this->url('/system/admin/' . $id), 'put');
}
/**
* 添加门店店员
* @param int $store_id
* @param $level
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function createStoreStaffForm(int $store_id, $level)
{
$field[] = $this->builder->input('staff_name', '店员名称')->col(24)->required('请输入门店店员名称');
// $field[] = $this->builder->frameImage('avatar', '店员头像', $this->url('store/widget.images/index', ['fodder' => 'avatar'], true))->icon('ios-add')->width('960px')->height('430px');
$field[] = $this->builder->frameImage('image', '商城用户', $this->url('store/system.User/list', ['fodder' => 'image'], true))->icon('ios-add')->width('960px')->height('450px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
$field[] = $this->builder->hidden('uid', 0);
$field[] = $this->builder->hidden('avatar', '');
$field[] = $this->builder->input('account', '店员账号')->maxlength(35)->required('请填写门店店员账号');
$field[] = $this->builder->input('pwd', '店员密码')->type('password')->required('请填写门店店员密码');
$field[] = $this->builder->input('conf_pwd', '确认密码')->type('password')->required('请输入确认密码');
$field[] = $this->builder->input('phone', '手机号码')->col(24)->required('请输入手机号');
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$options = $service->getRoleFormSelect($level, 1, $store_id);
$roles = [];
$field[] = $this->builder->select('roles', '店员身份', $roles)->setOptions(FormBuilder::setOptions($options))->multiple(true)->required('请选择店员身份');
$field[] = $this->builder->radio('is_manager', '是否是店长', 0)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('order_status', '订单管理', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('verify_status', '核销开关', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('is_cashier', '是否是收银员', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('is_customer', '是否是客服', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])->appendControl(1, [
$this->builder->input('customer_phone', '客服手机号码')->col(24),
$this->builder->frameImage('customer_url', '客服二维码', $this->url('store/widget.images/index', ['fodder' => 'customer_url'], true))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])
]);
$field[] = $this->builder->radio('notify', '通知开关', 0)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('status', '状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
return create_form('添加门店店员', $field, $this->url('/staff/staff'));
}
/**
* 编辑门店店员
* @param $id
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updateStoreStaffForm($id, $level)
{
$staffInfo = $this->dao->get($id);
if (!$staffInfo) {
throw new AdminException('门店店员不存在!');
}
if ($staffInfo->is_del) {
throw new AdminException('门店店员已经删除');
}
$field[] = $this->builder->input('staff_name', '店员名称', $staffInfo['staff_name'])->col(24)->required('请填写门店店员名称');
$field[] = $this->builder->frameImage('avatar', '店员头像', $this->url('store/widget.images/index', ['fodder' => 'avatar'], true), $staffInfo['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
$field[] = $this->builder->input('account', '店员账号', $staffInfo['account'])->maxlength(35)->required('请填写门店店员账号');
$field[] = $this->builder->input('pwd', '店员密码')->placeholder('不更改密码请留空')->type('password');
$field[] = $this->builder->input('conf_pwd', '确认密码')->placeholder('不更改密码请留空')->type('password');
$field[] = $this->builder->input('phone', '手机号码', $staffInfo['phone'])->col(24)->required('请输入手机号');
/** @var SystemRoleServices $service */
$service = app()->make(SystemRoleServices::class);
$options = $service->getRoleFormSelect($level, 1, (int)$staffInfo['store_id']);
$roles = [];
if ($staffInfo && isset($staffInfo['roles']) && $staffInfo['roles']) {
foreach ($staffInfo['roles'] as $role) {
$roles[] = (int)$role;
}
}
$field[] = $this->builder->select('roles', '店员身份', $roles)->setOptions(FormBuilder::setOptions($options))->multiple(true)->required('请选择店员身份');
$field[] = $this->builder->radio('is_manager', '是否是店长', (int)$staffInfo['is_manager'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('order_status', '订单管理', (int)$staffInfo['order_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('verify_status', '核销开关', (int)$staffInfo['verify_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('is_cashier', '是否是收银员', (int)$staffInfo['is_cashier'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('is_customer', '是否是客服', (int)$staffInfo['is_customer'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])->appendControl(1, [
$this->builder->input('customer_phone', '客服手机号码', $staffInfo['customer_phone'] ?? '')->col(24),
$this->builder->frameImage('customer_url', '客服二维码', $this->url('store/widget.images/index', ['fodder' => 'customer_url'], true), $staffInfo['customer_url'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])
]);
$field[] = $this->builder->radio('notify', '通知开关', (int)$staffInfo['notify'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = $this->builder->radio('status', '状态', (int)$staffInfo['status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
return create_form('编辑门店店员', $field, $this->url('/staff/staff/' . $id), 'put');
}
/**
* 获取店员select
* @param array $where
* @return mixed
*/
public function getSelectList($where = [])
{
$list = $this->dao->getSelectList($where);
$menus = [];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['staff_name'] ?? ''];
}
return $menus;
}
/**
* 首页店员统计
* @param int $store_id
* @param array $time
* @return array
*/
public function staffChart(int $store_id, array $time)
{
$list = $this->dao->getStoreStaffList(['store_id' => $store_id, 'is_del' => 0], 'id,uid,avatar,staff_name');
if ($list) {
/** @var UserSpreadServices $userSpreadServices */
$userSpreadServices = app()->make(UserSpreadServices::class);
/** @var BranchOrderServices $orderServices */
$orderServices = app()->make(BranchOrderServices::class);
/** @var OtherOrderServices $otherOrderServices */
$otherOrderServices = app()->make(OtherOrderServices::class);
$where = ['store_id' => $store_id, 'time' => $time];
$order_where = ['paid' => 1, 'pid' => 0, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3]];
$staffIds = array_unique(array_column($list, 'id'));
$otherStaff = $otherOrderServices->preStaffTotal($where + ['staff_id' => $staffIds, 'paid' => 1, 'type' => [0, 1, 2, 4]], 'distinct(`uid`)');
$otherStaff = array_combine(array_column($otherStaff, 'staff_id'), $otherStaff);
foreach ($list as &$item) {
$staff_where = ['staff_id' => $item['id']];
$spread_uid = $userSpreadServices->getColumn($where + ['timeKey' => 'spread_time'] + $staff_where, 'uid', '', true);
$item['spread_count'] = count($spread_uid);
$item['speread_order_price'] = 0;
if ($spread_uid) {
$item['speread_order_price'] = $orderServices->sum($where + $order_where + ['uid' => $spread_uid], 'pay_price', true);
}
$item['vip_count'] = $otherStaff[$item['id']]['count'] ?? 0;
$item['vip_price'] = $otherStaff[$item['id']]['price'] ?? 0;
unset($spread);
}
}
return $list;
}
/**
* 修改当前店员信息
* @param int $id
* @param array $data
* @return bool
*/
public function updateStaffPwd(int $id, array $data)
{
$staffInfo = $this->dao->get($id);
if (!$staffInfo)
throw new AdminException('店员信息未查到');
if ($staffInfo->is_del) {
throw new AdminException('店员已经删除');
}
if ($data['real_name']) {
$staffInfo->staff_name = $data['real_name'];
}
if ($data['avatar']) {
$staffInfo->avatar = $data['avatar'];
}
if ($data['pwd']) {
if (!password_verify($data['pwd'], $staffInfo['pwd']))
throw new AdminException('原始密码错误');
if (!$data['new_pwd'])
throw new AdminException('请输入新密码');
if (!$data['conf_pwd'])
throw new AdminException('请输入确认密码');
if ($data['new_pwd'] != $data['conf_pwd'])
throw new AdminException('两次输入的密码不一致');
$staffInfo->pwd = $this->passwordHash($data['new_pwd']);
}
if ($staffInfo->save())
return true;
else
return false;
}
/**
* 获取门店接收通知店员
* @param int $store_id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNotifyStoreStaffList(int $store_id, string $field = '*')
{
$where = [
'store_id' => $store_id,
'status' => 1,
'is_del' => 0,
'notify' => 1
];
$list = $this->dao->getStoreStaffList($where, $field);
return $list;
}
/**
* 获取所有门店有用的手机号
* @return array
*/
public function getPhoneAll()
{
$phone = array_merge(array_unique($this->dao->getColumn([
['is_del', '=', 0],
['status', '=', 1],
], 'phone')));
return $phone ?: [0];
}
}