chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
339
app/services/store/DeliveryServiceServices.php
Normal file
339
app/services/store/DeliveryServiceServices.php
Normal file
@@ -0,0 +1,339 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\store;
|
||||
|
||||
|
||||
use app\dao\store\DeliveryServiceDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\store\BranchOrderServices;
|
||||
use app\services\message\service\StoreServiceLogServices;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
|
||||
/**
|
||||
* 配送
|
||||
* Class DeliveryServiceServices
|
||||
* @package app\services\store
|
||||
* @mixin DeliveryServiceDao
|
||||
*/
|
||||
class DeliveryServiceServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 创建form表单
|
||||
* @var FormBuilder
|
||||
*/
|
||||
#[Inject]
|
||||
protected FormBuilder $builder;
|
||||
|
||||
/**
|
||||
* @var DeliveryServiceDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected DeliveryServiceDao $dao;
|
||||
|
||||
/**
|
||||
* 获取配送员详情
|
||||
* @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 getDeliveryInfo(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 $type
|
||||
* @param int $relation_id
|
||||
* @param array $field
|
||||
* @return array|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDeliveryInfoByUid(int $uid, int $type = 0, int $relation_id = 0, array $field = ['*'])
|
||||
{
|
||||
$where = ['uid' => $uid, 'is_del' => 0, 'status' => 1];
|
||||
if ($type && $relation_id) {
|
||||
$where['type'] = $type;
|
||||
$where['relation_id'] = $relation_id;
|
||||
}
|
||||
$info = $this->dao->get($where, $field);
|
||||
if (!$info) {
|
||||
throw new ValidateException('配送员不存在');
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配送员所在门店id
|
||||
* @param int $uid
|
||||
* @param int $type
|
||||
* @param string $field
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
public function getDeliveryStoreIds(int $uid, int $type = 0, string $field = '*', string $key = '')
|
||||
{
|
||||
return $this->dao->getColumn(['uid' => $uid, 'type' => $type, 'is_del' => 0, 'status' => 1], $field, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个配送员统计信息
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deliveryDetail(int $id)
|
||||
{
|
||||
$deliveryInfo = $this->getDeliveryInfo($id);
|
||||
if (!$deliveryInfo) {
|
||||
throw new AdminException('配送员不存在');
|
||||
}
|
||||
$where = ['store_id' => $deliveryInfo['store_id'], 'delivery_uid' => $deliveryInfo['uid']];
|
||||
/** @var BranchOrderServices $orderServices */
|
||||
$orderServices = app()->make(BranchOrderServices::class);
|
||||
$order_where = ['paid' => 1, 'refund_status' => [0, 3], 'is_del' => 0, 'is_system_del' => 0];
|
||||
|
||||
$field = ['id', 'type', 'order_id', 'real_name', 'total_num', 'total_price', 'pay_price', 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time', 'paid', 'pay_type', 'activity_id', 'pink_id'];
|
||||
$list = $orderServices->getStoreOrderList($where + $order_where, $field, [], true);
|
||||
$data = ['id' => $id];
|
||||
$data['info'] = $deliveryInfo;
|
||||
$data['list'] = $list;
|
||||
$data['data'] = [
|
||||
[
|
||||
'title' => '待配送订单数',
|
||||
'value' => $orderServices->count($where + $order_where + ['status' => 2]),
|
||||
'key' => '单',
|
||||
],
|
||||
[
|
||||
'title' => '已配送订单数',
|
||||
'value' => $orderServices->count($where + $order_where + ['status' => 3]),
|
||||
'key' => '单',
|
||||
],
|
||||
[
|
||||
'title' => '待配送订单金额',
|
||||
'value' => $orderServices->sum($where + $order_where + ['status' => 2], 'pay_price', true),
|
||||
'key' => '元',
|
||||
],
|
||||
[
|
||||
'title' => '已配送订单',
|
||||
'value' => $orderServices->sum($where + $order_where + ['status' => 3], 'pay_price', true),
|
||||
'key' => '元',
|
||||
]
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店配送员订单统计
|
||||
* @param int $uid
|
||||
* @param int $store_id
|
||||
* @param string $time
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreData(int $uid, int $store_id, string $time = 'today')
|
||||
{
|
||||
$this->getDeliveryInfoByUid($uid, $store_id ? 1: 0, $store_id);
|
||||
$data = [];
|
||||
$where = ['delivery_uid' => $uid, 'time' => $time, 'paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3]];
|
||||
if ($store_id) {
|
||||
$where['store_id'] = $store_id;
|
||||
}
|
||||
/** @var BranchOrderServices $order */
|
||||
$order = app()->make(BranchOrderServices::class);
|
||||
$where['status'] = 2;
|
||||
$data['unsend'] = $order->count($where);
|
||||
$where['status'] = 9;
|
||||
$data['send'] = $order->count($where);
|
||||
$data['send_price'] = $order->sum($where, 'pay_price', true);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配送员列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getServiceList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getServiceList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配送员列表
|
||||
* @param int $type
|
||||
* @param int $store_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDeliveryList(int $type = 0, int $relation_id = 0)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$where = ['status' => 1, 'is_del' => 0, 'type' => $type, 'relation_id' => $relation_id];
|
||||
$list = $this->dao->getServiceList($where, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
if (!$item['nickname']) $item['nickname'] = $item['wx_name'];
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建配送员表单
|
||||
* @param array $formData
|
||||
* @return mixed
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createServiceForm(array $formData = [])
|
||||
{
|
||||
if ($formData) {
|
||||
$field[] = $this->builder->frameImage('avatar', '配送员头像:', $this->url('admin/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
// $field[] = $this->builder->frameImage('avatar', '用户头像', $this->url('admin/widget.images/index', array('fodder' => 'avatar')))->icon('ios-add')->width('50%')->height('396px');
|
||||
} 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', 0);
|
||||
$field[] = $this->builder->hidden('avatar', '');
|
||||
}
|
||||
$field[] = $this->builder->input('nickname', '配送员名称:', $formData['nickname'] ?? '')->required('请填写配送员名称')->col(24);
|
||||
$field[] = $this->builder->input('phone', '手机号码:', $formData['phone'] ?? '')->required('请填写电话')->col(24)->maxlength(11);
|
||||
$field[] = $this->builder->radio('status', '配送员状态:', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建配送员获取表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return create_form('添加配送员', $this->createServiceForm(), $this->url('/order/delivery/save'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑获取表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function edit(int $id)
|
||||
{
|
||||
$serviceInfo = $this->dao->get($id);
|
||||
if (!$serviceInfo) {
|
||||
throw new AdminException('数据不存在!');
|
||||
}
|
||||
return create_form('编辑配送员', $this->createServiceForm($serviceInfo->toArray()), $this->url('/order/delivery/update/' . $id), 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某人的聊天记录用户列表
|
||||
* @param int $uid
|
||||
* @return array|array[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getChatUser(int $uid)
|
||||
{
|
||||
/** @var StoreServiceLogServices $serviceLog */
|
||||
$serviceLog = app()->make(StoreServiceLogServices::class);
|
||||
/** @var UserServices $serviceUser */
|
||||
$serviceUser = app()->make(UserServices::class);
|
||||
$uids = $serviceLog->getChatUserIds($uid);
|
||||
if (!$uids) {
|
||||
return [];
|
||||
}
|
||||
return $serviceUser->getUserList(['uid' => $uids], 'nickname,uid,avatar as headimgurl');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否是配送员
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function checkoutIsService(int $uid)
|
||||
{
|
||||
return (bool)$this->dao->count(['uid' => $uid, 'status' => 1, 'is_del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加门店配送员
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createStoreDeliveryForm()
|
||||
{
|
||||
$field[] = $this->builder->frameImage('image', '商城用户', $this->url('store/system.User/list', ['fodder' => 'image'], true))->icon('ios-add')->width('960px')->height('430px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
|
||||
$field[] = $this->builder->hidden('uid', 0);
|
||||
$field[] = $this->builder->hidden('avatar', '');
|
||||
$field[] = $this->builder->input('nickname', '配送员名称')->required('请填写配送员名称')->col(24);
|
||||
$field[] = $this->builder->input('phone', '手机号码')->required('请填写电话')->col(24)->maxlength(11);
|
||||
$field[] = $this->builder->radio('status', '配送员状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
|
||||
return create_form('添加门店配送员', $field, $this->url('/staff/delivery'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑门店配送员
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function updateStoreDeliveryForm($id, $formData)
|
||||
{
|
||||
$field[] = $this->builder->input('nickname', '配送员名称:', $formData['nickname'] ?? '')->required('请填写配送员名称')->col(24);
|
||||
$field[] = $this->builder->frameImage('avatar', '配送员头像:', $this->url('store/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
$field[] = $this->builder->input('phone', '手机号码:', $formData['phone'] ?? '')->required('请填写电话')->col(24)->maxlength(11);
|
||||
$field[] = $this->builder->radio('status', '配送员状态:', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
|
||||
return create_form('编辑门店配送员', $field, $this->url('/staff/delivery/' . $id), 'put');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配送员select(Uid)
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSelectList($where = [])
|
||||
{
|
||||
$list = $this->dao->getSelectList($where);
|
||||
$menus = [];
|
||||
foreach ($list as $menu) {
|
||||
$menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
|
||||
}
|
||||
return $menus;
|
||||
}
|
||||
}
|
||||
228
app/services/store/LoginServices.php
Normal file
228
app/services/store/LoginServices.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\store;
|
||||
|
||||
use app\Request;
|
||||
use app\services\BaseServices;
|
||||
use app\dao\store\SystemStoreStaffDao;
|
||||
use app\services\system\SystemMenusServices;
|
||||
use app\services\system\SystemRoleServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\utils\ApiErrorCode;
|
||||
use crmeb\utils\JwtAuth;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LoginServices
|
||||
* @package app\services\user
|
||||
* @mixin SystemStoreStaffDao
|
||||
*/
|
||||
class LoginServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 当前门店权限缓存前缀
|
||||
*/
|
||||
const STORE_RULES_LEVEL = 'store_rules_level_';
|
||||
|
||||
/**
|
||||
* @var SystemStoreStaffDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemStoreStaffDao $dao;
|
||||
|
||||
/**
|
||||
* 获取登陆前的login等信息
|
||||
* @return array
|
||||
*/
|
||||
public function getLoginInfo()
|
||||
{
|
||||
return [
|
||||
'slide' => sys_data('admin_login_slide') ?? [],
|
||||
'logo_square' => sys_config('site_logo_square'),//透明
|
||||
'logo_rectangle' => sys_config('site_logo'),//方形
|
||||
'login_logo' => sys_config('start_login_logo'),//登陆
|
||||
'site_name' => sys_config('site_name'),
|
||||
'site_url' => sys_config('site_url'),
|
||||
'upload_file_size_max' => config('upload.filesize'),//文件上传大小kb
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* H5账号登陆
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function login($account, $password, $type)
|
||||
{
|
||||
$storeStaffInfo = $this->dao->getOne(['account' => $account, 'is_del' => 0]);
|
||||
|
||||
if (!$storeStaffInfo) {
|
||||
throw new AdminException('账号不存在!');
|
||||
}
|
||||
if ($password) {//平台还可以登录
|
||||
if (!$storeStaffInfo->status) {
|
||||
throw new AdminException('您已被禁止登录!');
|
||||
}
|
||||
if (!password_verify($password, $storeStaffInfo->pwd)) {
|
||||
throw new AdminException('账号或密码错误,请重新输入');
|
||||
}
|
||||
}
|
||||
$storeStaffInfo->last_time = time();
|
||||
$storeStaffInfo->last_ip = app('request')->ip();
|
||||
$storeStaffInfo->login_count++;
|
||||
$storeStaffInfo->save();
|
||||
|
||||
$tokenInfo = $this->createToken($storeStaffInfo->id, $type, $storeStaffInfo->pwd);
|
||||
/** @var SystemMenusServices $services */
|
||||
$services = app()->make(SystemMenusServices::class);
|
||||
[$menus, $uniqueAuth] = $services->getMenusList($storeStaffInfo->roles, (int)$storeStaffInfo['level'], 2);
|
||||
/** @var SystemStoreServices $storeServices */
|
||||
$storeServices = app()->make(SystemStoreServices::class);
|
||||
$store = $storeServices->get((int)$storeStaffInfo['store_id'], ['id', 'image']);
|
||||
return [
|
||||
'token' => $tokenInfo['token'],
|
||||
'expires_time' => $tokenInfo['params']['exp'],
|
||||
'menus' => $menus,
|
||||
'unique_auth' => $uniqueAuth,
|
||||
'user_info' => [
|
||||
'id' => $storeStaffInfo->getData('id'),
|
||||
'account' => $storeStaffInfo->getData('account'),
|
||||
'avatar' => $storeStaffInfo->getData('avatar'),
|
||||
],
|
||||
'logo' => $store && isset($store['image']) && $store['image'] ? $store['image'] : sys_config('site_logo'),
|
||||
'logo_square' => $store && isset($store['image']) && $store['image'] ? $store['image'] : sys_config('site_logo_square'),
|
||||
'version' => get_crmeb_version(),
|
||||
'newOrderAudioLink' => get_file_link(sys_config('new_order_audio_link', ''))
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @param $account
|
||||
* @param $password
|
||||
*/
|
||||
public function reset($account, $password)
|
||||
{
|
||||
$user = $this->dao->getOne(['account|phone' => $account]);
|
||||
if (!$user) {
|
||||
throw new ValidateException('用户不存在');
|
||||
}
|
||||
if (!$this->dao->update($user['uid'], ['pwd' => md5((string)$password)], 'uid')) {
|
||||
throw new ValidateException('修改密码失败');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Admin授权信息
|
||||
* @param string $token
|
||||
* @return array
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function parseToken(string $token): array
|
||||
{
|
||||
/** @var CacheService $cacheService */
|
||||
$cacheService = app()->make(CacheService::class);
|
||||
|
||||
if (!$token || $token === 'undefined') {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN);
|
||||
}
|
||||
//检测token是否过期
|
||||
$md5Token = md5($token);
|
||||
if (!$cacheService->hasToken($md5Token) || !($cacheToken = $cacheService->getTokenBucket($md5Token))) {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN);
|
||||
}
|
||||
//是否超出有效次数
|
||||
if (isset($cacheToken['invalidNum']) && $cacheToken['invalidNum'] >= 3) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
//设置解析token
|
||||
[$id, $type, $auth] = $jwtAuth->parseToken($token);
|
||||
//验证token
|
||||
try {
|
||||
$jwtAuth->verifyToken();
|
||||
$cacheService->setTokenBucket($md5Token, $cacheToken, $cacheToken['exp']);
|
||||
} catch (ExpiredException $e) {
|
||||
$cacheToken['invalidNum'] = isset($cacheToken['invalidNum']) ? $cacheToken['invalidNum']++ : 1;
|
||||
$cacheService->setTokenBucket($md5Token, $cacheToken, $cacheToken['exp']);
|
||||
} catch (\Throwable $e) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
//获取管理员信息
|
||||
$storeStaffInfo = $this->dao->get($id);
|
||||
if (!$storeStaffInfo || !$storeStaffInfo->id || $storeStaffInfo->is_del) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
|
||||
}
|
||||
if ($auth !== md5($storeStaffInfo->pwd)) {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
|
||||
$storeStaffInfo->type = $type;
|
||||
return $storeStaffInfo->hidden(['pwd', 'is_del', 'status'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台验证权限
|
||||
* @param Request $request
|
||||
*/
|
||||
public function verifiAuth(Request $request)
|
||||
{
|
||||
$rule = str_replace('storeapi/', '', trim(strtolower($request->rule()->getRule())));
|
||||
if (in_array($rule, ['store/logout', 'menuslist'])) {
|
||||
return true;
|
||||
}
|
||||
$method = trim(strtolower($request->method()));
|
||||
/** @var SystemRoleServices $roleServices */
|
||||
$roleServices = app()->make(SystemRoleServices::class);
|
||||
$auth = $roleServices->getAllRoles(2, 2, self::STORE_RULES_LEVEL);
|
||||
//验证访问接口是否存在
|
||||
if ($auth && !in_array($method . '@@' . $rule, array_map(function ($item) {
|
||||
return trim(strtolower($item['methods'])) . '@@' . trim(strtolower(str_replace(' ', '', $item['api_url'])));
|
||||
}, $auth))) {
|
||||
return true;
|
||||
}
|
||||
$auth = $roleServices->getRolesByAuth($request->storeStaffInfo()['roles'], 2, 2, self::STORE_RULES_LEVEL);
|
||||
//验证访问接口是否有权限
|
||||
if ($auth && empty(array_filter($auth, function ($item) use ($rule, $method) {
|
||||
if (trim(strtolower($item['api_url'])) === $rule && $method === trim(strtolower($item['methods'])))
|
||||
return true;
|
||||
}))) {
|
||||
throw new AuthException(ApiErrorCode::ERR_AUTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
216
app/services/store/StoreConfigServices.php
Normal file
216
app/services/store/StoreConfigServices.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?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\StoreConfigDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\system\config\SystemConfigServices;
|
||||
use crmeb\form\Build;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class StoreConfigServices
|
||||
* @package app\services\store
|
||||
* @mixin StoreConfigDao
|
||||
*/
|
||||
class StoreConfigServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 表单数据切割符号
|
||||
* @var string
|
||||
*/
|
||||
protected $cuttingStr = '=>';
|
||||
|
||||
//打印机配置
|
||||
const PRINTER_KEY = [
|
||||
'store_printing_timing', 'store_terminal_number', 'store_printing_client_id',
|
||||
'store_printing_api_key', 'store_develop_id', 'store_pay_success_printing_switch',
|
||||
'store_print_type', 'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
|
||||
];
|
||||
//快递发货配置
|
||||
const EXPRESS_KEY = [
|
||||
'store_config_export_id', 'store_config_export_temp_id', 'store_config_export_to_name',
|
||||
'store_config_export_to_tel', 'store_config_export_to_address', 'store_config_export_siid', 'store_config_export_open'
|
||||
];
|
||||
|
||||
const CONFIG_TYPE = [
|
||||
'store_printing_deploy' => self::PRINTER_KEY,
|
||||
'store_electronic_sheet' => self::EXPRESS_KEY,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var StoreConfigDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreConfigDao $dao;
|
||||
|
||||
/**
|
||||
* 保存或者更新门店配置
|
||||
* @param array $data
|
||||
* @param int $storeId
|
||||
*/
|
||||
public function saveConfig(array $data, int $storeId)
|
||||
{
|
||||
$config = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if ($this->dao->count(['key_name' => $key, 'store_id' => $storeId])) {
|
||||
$this->dao->update(['key_name' => $key, 'store_id' => $storeId], ['value' => json_encode($value)]);
|
||||
} else {
|
||||
$config[] = [
|
||||
'key_name' => $key,
|
||||
'store_id' => $storeId,
|
||||
'value' => json_encode($value)
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($config) {
|
||||
$this->dao->saveAll($config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @param string $key
|
||||
* @param int $type
|
||||
* @param int $relation_id
|
||||
* @param $default
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getConfig(string $key, int $type = 0, int $relation_id = 0, $default = null)
|
||||
{
|
||||
$value = $this->dao->value(['key_name' => $key, 'type' => $type, 'relation_id' => $relation_id], 'value');
|
||||
return is_null($value) ? $default : json_decode($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店配置
|
||||
* @param int $storeId
|
||||
* @param array $keys
|
||||
*/
|
||||
public function getConfigAll(array $keys, int $type = 0, int $relation_id = 0)
|
||||
{
|
||||
$confing = $this->dao->searchs($keys, $type, $relation_id)->column('value', 'key_name');
|
||||
return array_map(function ($item) {
|
||||
return json_decode($item, true);
|
||||
}, $confing);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析配置参数生成选项列表
|
||||
* @param string $parameter 参数字符串
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(string $parameter)
|
||||
{
|
||||
$parameter = explode("\n", $parameter);
|
||||
$options = [];
|
||||
foreach ($parameter as $v) {
|
||||
if (strstr($v, $this->cuttingStr) !== false) {
|
||||
$pdata = explode($this->cuttingStr, $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configName
|
||||
* @param int $type
|
||||
* @param int $relation_id
|
||||
* @param int $group
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getConfigAllField(array $configName = [], int $type = 0, int $relation_id = 0, int $group = 0)
|
||||
{
|
||||
/** @var SystemConfigServices $systemConfigServices */
|
||||
$systemConfigServices = app()->make(SystemConfigServices::class);
|
||||
$list = $systemConfigServices->getConfigAllListByWhere(['menu_name' => $configName], $type, $relation_id, ['menu_name', 'info', 'type', 'value', 'desc', 'parameter']);
|
||||
if ($list) {
|
||||
foreach ($list as &$item) {
|
||||
if ($relation_id != 0) {
|
||||
$item['value'] = $item['store_value'] ?? '';
|
||||
}
|
||||
$item['value'] = json_decode($item['value'], true);
|
||||
}
|
||||
$list = array_combine(array_column($list, 'menu_name'), $list);
|
||||
}
|
||||
|
||||
$value = [];
|
||||
foreach ($configName as $key) {
|
||||
if ($group) {
|
||||
$value[$key] = $list[$key]['value'] ?? '';
|
||||
} else {
|
||||
$value[$key] = $list[$key] ?? ['info' => '', 'type' => 'text', 'value' => '', 'desc' => '', 'parameter' => ''];
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单
|
||||
* @param string $name
|
||||
* @param int $type
|
||||
* @param int $relation_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getFormBuildRule(string $name, int $type = 0, int $relation_id = 0)
|
||||
{
|
||||
switch ($name) {
|
||||
case 'third'://第三方
|
||||
$data = $this->thirdPartyFormBuild($type, $relation_id);
|
||||
break;
|
||||
default:
|
||||
throw new ValidateException('类型错误');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方配置
|
||||
* @return array
|
||||
*/
|
||||
public function thirdPartyFormBuild(int $type = 0, int $relation_id = 0)
|
||||
{
|
||||
$build = new Build();
|
||||
$build->url('system/config');
|
||||
if ($type == 1) {
|
||||
$data = $this->getConfigAllField([
|
||||
'store_pay_success_printing_switch', 'store_develop_id', 'store_printing_api_key', 'store_printing_client_id', 'store_terminal_number',
|
||||
'store_print_type', 'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
|
||||
'store_printing_timing',
|
||||
'store_config_export_open', 'store_config_export_siid', 'store_config_export_to_name', 'store_config_export_to_tel', 'store_config_export_to_address',
|
||||
], $type, $relation_id);
|
||||
|
||||
$build->rule([
|
||||
Build::tabs()->option('电子面单', [
|
||||
Build::radio('store_config_export_open', $data['store_config_export_open']['info'], (int)($data['store_config_export_open']['value'] ?? 0))->control(1, [
|
||||
Build::input('store_config_export_to_name', $data['store_config_export_to_name']['info'], $data['store_config_export_to_name']['value'])->info($data['store_config_export_to_name']['desc']),
|
||||
Build::input('store_config_export_to_tel', $data['store_config_export_to_tel']['info'], $data['store_config_export_to_tel']['value'])->info($data['store_config_export_to_tel']['desc']),
|
||||
Build::input('store_config_export_to_address', $data['store_config_export_to_address']['info'], $data['store_config_export_to_address']['value'])->info($data['store_config_export_to_address']['desc']),
|
||||
Build::input('store_config_export_siid', $data['store_config_export_siid']['info'], $data['store_config_export_siid']['value'])->info($data['store_config_export_siid']['desc']),
|
||||
])->options($this->getOptions($data['store_config_export_open']['parameter']))->info($data['store_config_export_open']['desc'])
|
||||
])
|
||||
]);
|
||||
}
|
||||
return $build->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
119
app/services/store/StoreUserServices.php
Normal file
119
app/services/store/StoreUserServices.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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\StoreUserDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\level\SystemUserLevelServices;
|
||||
use app\services\user\level\UserLevelServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 门店用户
|
||||
* Class StoreUser
|
||||
* @package app\services\store
|
||||
* @mixin StoreUserDao
|
||||
*/
|
||||
class StoreUserServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var StoreUserDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreUserDao $dao;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取门店用户列表
|
||||
* @param array $where 查询条件
|
||||
* @param int $store_id 门店ID
|
||||
* @return array
|
||||
*/
|
||||
public function index(array $where, int $store_id)
|
||||
{
|
||||
$where['store_id'] = $store_id;
|
||||
/** @var UserStoreUserServices $userStoreUserServices */
|
||||
$userStoreUserServices = app()->make(UserStoreUserServices::class);
|
||||
$fields = 'u.*';
|
||||
[$list, $count] = $userStoreUserServices->getWhereUserList($where, $fields);
|
||||
if ($list) {
|
||||
$uids = array_column($list, 'uid');
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userlabel = $userServices->getUserLablel($uids, $store_id);
|
||||
$levelName = app()->make(SystemUserLevelServices::class)->getUsersLevel(array_unique(array_column($list, 'level')));
|
||||
$userLevel = app()->make(UserLevelServices::class)->getUsersLevelInfo($uids);
|
||||
$spread_names = $userServices->getColumn([['uid', 'in', $uids]], 'nickname', 'uid');
|
||||
/** @var SystemStoreStaffServices $staffServices */
|
||||
$staffServices = app()->make(SystemStoreStaffServices::class);
|
||||
$staffNames = $staffServices->getColumn([['store_id', '=', $store_id], ['uid', 'in', array_column($list, 'uid')], ['is_del', '=', 0]], 'uid,staff_name', 'uid');
|
||||
foreach ($list as &$item) {
|
||||
$item['status'] = ($item['status'] == 1) ? '正常' : '禁止';
|
||||
// $item['birthday'] = $item['birthday'] ? date('Y-m-d', (int)$item['birthday']) : '';
|
||||
$item['spread_uid_nickname'] = $item['spread_uid'] ? ($spread_names[$item['spread_uid']] ?? '') . '/' . $item['spread_uid'] : '无';
|
||||
$item['staff_name'] = $staffNames[$item['uid']]['staff_name'] ?? '';
|
||||
//用户类型
|
||||
if ($item['user_type'] == 'routine') {
|
||||
$item['user_type'] = '小程序';
|
||||
} else if ($item['user_type'] == 'wechat') {
|
||||
$item['user_type'] = '公众号';
|
||||
} else if ($item['user_type'] == 'h5') {
|
||||
$item['user_type'] = 'H5';
|
||||
} else if ($item['user_type'] == 'pc') {
|
||||
$item['user_type'] = 'PC';
|
||||
} else if ($item['user_type'] == 'app') {
|
||||
$item['user_type'] = 'APP';
|
||||
} else $item['user_type'] = '其他';
|
||||
//等级名称
|
||||
$item['level'] = $levelName[$item['level']] ?? '无';
|
||||
//用户等级
|
||||
$item['vip_name'] = false;
|
||||
$levelinfo = $userLevel[$item['uid']] ?? null;
|
||||
if ($levelinfo) {
|
||||
if ($levelinfo && ($levelinfo['is_forever'] || time() < $levelinfo['valid_time'])) {
|
||||
$item['vip_name'] = $item['level'] != '无' ? $item['level'] : false;
|
||||
}
|
||||
}
|
||||
$item['labels'] = $userlabel[$item['uid']] ?? '';
|
||||
$item['isMember'] = $item['is_money_level'] > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步写入门店用户
|
||||
* @param int $uid
|
||||
* @param int $store_id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setStoreUser(int $uid, int $store_id)
|
||||
{
|
||||
$storeUser = $this->dao->getOne(['uid' => $uid, 'store_id' => $store_id]);
|
||||
if (!$storeUser) {
|
||||
if (!$this->dao->save(['uid' => $uid, 'store_id' => $store_id, 'add_time' => time()])) {
|
||||
throw new ValidateException('新增门店用户失败');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
378
app/services/store/SystemStoreServices.php
Normal file
378
app/services/store/SystemStoreServices.php
Normal file
@@ -0,0 +1,378 @@
|
||||
<?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\SystemStoreDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\erp\Erp;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 自提点
|
||||
* Class SystemStoreServices
|
||||
* @package app\services\system\store
|
||||
* @mixin SystemStoreDao
|
||||
*/
|
||||
class SystemStoreServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 创建form表单
|
||||
* @var FormBuilder
|
||||
*/
|
||||
#[Inject]
|
||||
protected FormBuilder $builder;
|
||||
|
||||
/**
|
||||
* @var SystemStoreDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemStoreDao $dao;
|
||||
|
||||
/**
|
||||
* 获取单个自提点信息
|
||||
* @param int $id
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getStoreInfo(int $id = 0)
|
||||
{
|
||||
if ($id) {
|
||||
$storeInfo = $this->dao->getOne(['id' => $id, 'is_del' => 0]);
|
||||
} else {
|
||||
$storeList = $this->dao->getStoreList(['is_del' => 0], ['*'], 0, 1);
|
||||
$storeInfo = $storeList[0] ?? [];
|
||||
}
|
||||
if (!$storeInfo) {
|
||||
return [];
|
||||
}
|
||||
$storeInfo['day_time'] = $storeInfo['day_time'] ? explode('-', $storeInfo['day_time']) : [];
|
||||
return is_object($storeInfo) ? $storeInfo->toArray() : $storeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附近自提点
|
||||
* @param array $where
|
||||
* @param string $latitude
|
||||
* @param string $longitude
|
||||
* @param string $ip
|
||||
* @param int $limit
|
||||
* @return array|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNearbyStore(array $where, string $latitude, string $longitude, string $ip = '', int $limit = 0)
|
||||
{
|
||||
$where = array_merge($where, ['type' => 0]);
|
||||
if ($limit) {
|
||||
$page = 1;
|
||||
} else {
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
}
|
||||
//默认附近自提点
|
||||
$store_type = $where['store_type'] ?? 1;
|
||||
$uid = $where['uid'] ?? 0;
|
||||
unset($where['store_type'], $where['uid']);
|
||||
if ($store_type != 1) {//常用自提点
|
||||
if ($uid) {
|
||||
/** @var StoreUserServices $storeUserServices */
|
||||
$storeUserServices = app()->make(StoreUserServices::class);
|
||||
$ids = $storeUserServices->getColumn(['uid' => $uid], 'store_id');
|
||||
if (!$ids) {
|
||||
return [];
|
||||
}
|
||||
$where['ids'] = $ids;
|
||||
} else {//没登录,无常用自提点
|
||||
return [];
|
||||
}
|
||||
}
|
||||
$storeList = [];
|
||||
if (isset($where['id']) && $where['id']) {
|
||||
$storeList = $this->dao->getStoreList($where, ['*'], $page, $limit, $latitude, $longitude, $latitude && $longitude ? 1 : 0);
|
||||
} elseif ($latitude && $longitude) {
|
||||
$storeList = $this->dao->getStoreList($where, ['*'], $page, $limit, $latitude, $longitude, 1);
|
||||
} elseif ($ip) {
|
||||
$addressArr = $this->addressHandle($this->convertIp($ip));
|
||||
$city = $addressArr['city'] ?? '';
|
||||
if ($city) {
|
||||
$storeList = $this->dao->getStoreByAddressInfo($city, $where, '*', $page, $limit);
|
||||
}
|
||||
$province = $addressArr['province'] ?? '';
|
||||
if (!$storeList && $province) {
|
||||
$storeList = $this->dao->getStoreByAddressInfo($province, $where, '*', $page, $limit);
|
||||
}
|
||||
}
|
||||
//上面条件都没获取到自提点
|
||||
if (!$storeList) {
|
||||
$storeList = $this->dao->getStoreList($where, ['*'], $page, $limit);
|
||||
}
|
||||
if ($storeList) {
|
||||
foreach ($storeList as &$item) {
|
||||
$item['range'] = 0;
|
||||
if (isset($item['distance'])) {
|
||||
$item['range'] = bcdiv($item['distance'], '1000', 1);
|
||||
} else {
|
||||
$item['range'] = 0;
|
||||
}
|
||||
if (isset($item['is_show']) && $item['is_show'] == 1) {
|
||||
$item['status_name'] = '营业中';
|
||||
} else {
|
||||
$item['status_name'] = '已停业';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $limit == 1 ? ($storeList[0] ?? []) : $storeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提货点列表
|
||||
* @param array $where
|
||||
* @param array $field
|
||||
* @param string $latitude
|
||||
* @param string $longitude
|
||||
* @param int $product_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getStoreList(array $where, array $field = ['*'], string $latitude = '', string $longitude = '', int $product_id = 0)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$order = 0;
|
||||
if (isset($where['order_id']) && $where['order_id']) {
|
||||
/** @var StoreOrderServices $storeOrderServices */
|
||||
$storeOrderServices = app()->make(StoreOrderServices::class);
|
||||
$user_location = $storeOrderServices->value(['id' => $where['order_id']], 'user_location');
|
||||
[$longitude, $latitude] = explode(' ', $user_location);
|
||||
}
|
||||
if ($longitude && $latitude) {
|
||||
$order = 1;
|
||||
}
|
||||
$oid = (int)($where['order_id'] ?? 0);
|
||||
unset($where['order_id']);
|
||||
$storeList = $this->dao->getStoreList($where, $field, $page, $limit, $latitude, $longitude, $order);
|
||||
$list = [];
|
||||
foreach ($storeList as &$item) {
|
||||
if (isset($item['distance'])) {
|
||||
$item['range'] = $item['distance'] < 1000 ? $item['distance'] . "m" : bcdiv($item['distance'], '1000', 1) . "km";
|
||||
} else {
|
||||
$item['range'] = "0";
|
||||
}
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['status_name'] = '营业中';
|
||||
} else {
|
||||
$item['status_name'] = '已停业';
|
||||
}
|
||||
$list[] = $item;
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提货点头部统计信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStoreData()
|
||||
{
|
||||
$data['show'] = [
|
||||
'name' => '显示中的提货点',
|
||||
'num' => $this->dao->count(['type' => 0]),
|
||||
];
|
||||
$data['hide'] = [
|
||||
'name' => '隐藏中的提货点',
|
||||
'num' => $this->dao->count(['type' => 1]),
|
||||
];
|
||||
$data['recycle'] = [
|
||||
'name' => '回收站的提货点',
|
||||
'num' => $this->dao->count(['type' => 2])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自提点重置账号密码表单
|
||||
* @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 storeAdminAccountForm(int $id)
|
||||
{
|
||||
$storeInfo = $this->getStoreInfo($id);
|
||||
/** @var SystemStoreStaffServices $staffServices */
|
||||
$staffServices = app()->make(SystemStoreStaffServices::class);
|
||||
$staffInfo = $staffServices->getOne(['store_id' => $storeInfo['id'], 'level' => 0, 'is_admin' => 1, 'is_manager' => 1, 'is_del' => 0]);
|
||||
$field[] = $this->builder->hidden('staff_id', $staffInfo['id'] ?? 0);
|
||||
$field[] = $this->builder->input('account', '登录账号', $staffInfo['account'] ?? '')->col(24)->required('请输入账号');
|
||||
$field[] = $this->builder->input('password', '登录密码')->type('password')->col(24)->required('请输入密码');
|
||||
$field[] = $this->builder->input('true_password', '确认密码')->type('password')->col(24)->required('请再次确认密码');
|
||||
return create_form('自提点重置账号密码', $field, $this->url('/store/store/reset_admin/' . $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取erp自提点列表
|
||||
* @return array|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function erpShopList()
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
if (!sys_config('erp_open')) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
/** @var Erp $erpService */
|
||||
$erpService = app()->make(Erp::class);
|
||||
$res = Cache::tag('erp_shop')->remember('list_' . $page . '_' . $limit, function () use ($page, $limit, $erpService) {
|
||||
return $erpService->serviceDriver('Comment')->getShopList($page, $limit);
|
||||
}, 60);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error(
|
||||
json_encode([
|
||||
'message' => '读取ERP自提点信息失败',
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine()
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
||||
);
|
||||
}
|
||||
|
||||
return $res['data']['datas'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或修改自提点
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @param array $staff_data
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function saveStore(int $id, array $data, array $staff_data = [])
|
||||
{
|
||||
$id = $this->transaction(function () use ($id, $data, $staff_data) {
|
||||
if ($id) {
|
||||
if (!$this->dao->update($id, $data)) {
|
||||
throw new AdminException('修改失败或者您没有修改什么!');
|
||||
}
|
||||
} else {
|
||||
$data['add_time'] = time();
|
||||
if ($res = $this->dao->save($data)) {
|
||||
$id = $res->id;
|
||||
} else {
|
||||
throw new AdminException('保存失败!');
|
||||
}
|
||||
}
|
||||
return $id;
|
||||
});
|
||||
$info = $this->dao->get((int)$id);
|
||||
$this->dao->cacheUpdate($info->toArray(), $id);
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自提点缓存
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/21
|
||||
*/
|
||||
public function getStoreDisposeCache(int $id, string $felid = '')
|
||||
{
|
||||
$storeInfo = $this->dao->cacheRemember($id, function () use ($id) {
|
||||
$storeInfo = $this->dao->get($id);
|
||||
return $storeInfo ? $storeInfo->toArray() : null;
|
||||
});
|
||||
|
||||
if ($felid) {
|
||||
return $storeInfo[$felid] ?? null;
|
||||
}
|
||||
|
||||
if ($storeInfo) {
|
||||
$storeInfo['latlng'] = $storeInfo['latitude'] . ',' . $storeInfo['longitude'];
|
||||
$storeInfo['dataVal'] = $storeInfo['valid_time'] ? (is_array($storeInfo['valid_time']) ? $storeInfo['valid_time'] : explode(' - ', $storeInfo['valid_time'])) : [];
|
||||
$storeInfo['timeVal'] = $storeInfo['day_time'] ? (is_array($storeInfo['day_time']) ? $storeInfo['day_time'] : explode(' - ', $storeInfo['day_time'])) : [];
|
||||
$storeInfo['address2'] = $storeInfo['address'] ? (is_array($storeInfo['address']) ? $storeInfo['address'] : explode(' - ', $storeInfo['address'])) : [];
|
||||
return $storeInfo;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台获取提货点详情
|
||||
* @param int $id
|
||||
* @param string $felid
|
||||
* @return array|false|mixed|string|string[]|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getStoreDispose(int $id, string $felid = '')
|
||||
{
|
||||
if ($felid) {
|
||||
return $this->dao->value(['id' => $id], $felid);
|
||||
} else {
|
||||
$storeInfo = $this->dao->get($id);
|
||||
if ($storeInfo) {
|
||||
$storeInfo['latlng'] = $storeInfo['latitude'] . ',' . $storeInfo['longitude'];
|
||||
$storeInfo['dataVal'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
|
||||
$storeInfo['timeVal'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
|
||||
$storeInfo['address2'] = $storeInfo['address2'] ? explode(',', $storeInfo['address2']) : [];
|
||||
return $storeInfo;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自提点不分页
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getStore()
|
||||
{
|
||||
return $this->dao->getStore(['type' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得导出店员列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getExportData(array $where)
|
||||
{
|
||||
return $this->dao->getStoreList($where, ['*']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
689
app/services/store/SystemStoreStaffServices.php
Normal file
689
app/services/store/SystemStoreStaffServices.php
Normal file
@@ -0,0 +1,689 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
||||
84
app/services/store/UserStoreUserServices.php
Normal file
84
app/services/store/UserStoreUserServices.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\store;
|
||||
|
||||
use app\dao\store\UserStoreUserDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class UserStoreUserServices
|
||||
* @package app\services\store
|
||||
* @mixin UserStoreUserDao
|
||||
*/
|
||||
class UserStoreUserServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var UserStoreUserDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserStoreUserDao $dao;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义简单查询总数
|
||||
* @param array $where
|
||||
* @return int
|
||||
*/
|
||||
public function getCount(array $where): int
|
||||
{
|
||||
return $this->dao->getCount($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂条件搜索列表
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getWhereUserList(array $where, string $field): array
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$order_string = '';
|
||||
$order_arr = ['asc', 'desc'];
|
||||
if (isset($where['now_money']) && in_array($where['now_money'], $order_arr)) {
|
||||
$order_string = 'now_money ' . $where['now_money'];
|
||||
}
|
||||
$list = $this->dao->getListByModel($where, $field, $order_string, $page, $limit);
|
||||
$count = $this->dao->getCountByWhere($where);
|
||||
return [$list, $count];
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店搜索用户
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function storeSearch(array $data)
|
||||
{
|
||||
$where = [];
|
||||
if ($data['field_key']) {
|
||||
$where['u.' . $data['field_key']] = $data['keyword'];
|
||||
} else {
|
||||
$where['u.uid|u.phone'] = $data['keyword'];
|
||||
}
|
||||
$fields = 'u.*,w.country,w.province,w.city,w.sex,w.unionid,w.openid,w.user_type as w_user_type,w.groupid,w.tagid_list,w.subscribe,w.subscribe_time';
|
||||
$list = $this->dao->getList($where, $fields);
|
||||
$count = $this->dao->getCount($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user