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
This commit is contained in:
146
pro_v3.5.1_副本/app/services/system/admin/AdminAuthServices.php
Normal file
146
pro_v3.5.1_副本/app/services/system/admin/AdminAuthServices.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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\system\admin;
|
||||
|
||||
|
||||
use app\dao\system\admin\AdminAuthDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\other\CacheServices;
|
||||
use app\services\supplier\SystemSupplierServices;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\utils\ApiErrorCode;
|
||||
use crmeb\utils\JwtAuth;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* admin授权service
|
||||
* Class AdminAuthServices
|
||||
* @package app\services\system\admin
|
||||
* @mixin AdminAuthDao
|
||||
*/
|
||||
class AdminAuthServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AdminAuthDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminAuthDao $dao;
|
||||
|
||||
/**
|
||||
* 获取Admin授权信息
|
||||
* @param string $token
|
||||
* @return array
|
||||
* @throws 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);
|
||||
}
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
//设置解析token
|
||||
[$id, $type, $auth] = $jwtAuth->parseToken($token);
|
||||
|
||||
//检测token是否过期
|
||||
$md5Token = md5($token);
|
||||
if (!$cacheService->hasToken($md5Token) || !($cacheToken = $cacheService->getTokenBucket($md5Token))) {
|
||||
$this->authFailAfter($id, $type);
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN);
|
||||
}
|
||||
//是否超出有效次数
|
||||
if (isset($cacheToken['invalidNum']) && $cacheToken['invalidNum'] >= 3) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
$this->authFailAfter($id, $type);
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
|
||||
|
||||
//验证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);
|
||||
}
|
||||
$this->authFailAfter($id, $type);
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
|
||||
//获取管理员信息
|
||||
$adminInfo = $this->dao->get($id);
|
||||
if (!$adminInfo || !$adminInfo->id || $adminInfo->status == 0 || $adminInfo->is_del == 1) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
$this->authFailAfter($id, $type);
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
|
||||
}
|
||||
//修改密码后token立刻过期
|
||||
if ($auth !== md5($adminInfo['pwd'])) {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
|
||||
}
|
||||
if($adminInfo['admin_type'] == 4){
|
||||
$adminInfo = app()->make(SystemSupplierServices::class)->getOne(['id' => (int)$adminInfo->relation_id, 'is_del' => 0], '*', ['admin']);
|
||||
if (!$adminInfo || !$adminInfo->account || $adminInfo->admin_is_del) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->clearToken($md5Token);
|
||||
}
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
|
||||
}
|
||||
}
|
||||
$adminInfo->type = $type;
|
||||
return $adminInfo->hidden(['pwd', 'is_del', 'status'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* token验证失败后事件
|
||||
*/
|
||||
protected function authFailAfter($id, $type)
|
||||
{
|
||||
try {
|
||||
$postData = request()->post();
|
||||
$rule = trim(strtolower(request()->rule()->getRule()));
|
||||
$method = trim(strtolower(request()->method()));
|
||||
//添加商品退出后事件
|
||||
if ($rule === 'product/product/<id>' && $method === 'post') {
|
||||
$this->saveProduct($id, $postData);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存提交数据
|
||||
* @param $adminId
|
||||
* @param $postData
|
||||
*/
|
||||
protected function saveProduct($adminId, $postData)
|
||||
{
|
||||
/** @var CacheServices $cacheService */
|
||||
$cacheService = app()->make(CacheServices::class);
|
||||
$cacheService->setDbCache($adminId . '_product_data', $postData, 68400);
|
||||
}
|
||||
}
|
||||
152
pro_v3.5.1_副本/app/services/system/admin/LoginAuthServices.php
Normal file
152
pro_v3.5.1_副本/app/services/system/admin/LoginAuthServices.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?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\system\admin;
|
||||
|
||||
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 密码、登录次数验证
|
||||
* Class AdminAuthServices
|
||||
* @package app\services\system\admin
|
||||
*/
|
||||
class LoginAuthServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证登录账号是否需要锁定
|
||||
* @param string $account
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function checkErrorLock(string $account, string $type = 'admin')
|
||||
{
|
||||
$loginErrorNum = $this->getErrorNum($account, $type);
|
||||
if ($loginErrorNum >= (int)sys_config('system_login_error_num', 3)) {
|
||||
throw new ValidateException('您输入的错误次数较多,已被暂时锁定,请稍后再试');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录错误次数
|
||||
* @param string $account
|
||||
* @param string $type
|
||||
* @return int
|
||||
*/
|
||||
public function getErrorNum(string $account, string $type = 'admin')
|
||||
{
|
||||
$errorKey = 'system_' . $type . '_login_error_num_' . $account;
|
||||
/** @var CacheService $cacheServices */
|
||||
$cacheServices = app()->make(CacheService::class);
|
||||
return (int)$cacheServices->get($errorKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置登录错误次数缓存
|
||||
* @param string $account
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function setErrorNum(string $account, string $type = 'admin')
|
||||
{
|
||||
$errorKey = 'system_' . $type . '_login_error_num_' . $account;
|
||||
$lockTime = (int)sys_config('system_login_lock_time', 5);
|
||||
/** @var CacheService $cacheServices */
|
||||
$cacheServices = app()->make(CacheService::class);
|
||||
$loginErrorNum = $this->getErrorNum($account, $type);
|
||||
$cacheServices::set($errorKey, $loginErrorNum + 1, $lockTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证输入密码
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public function validatePassword(string $password)
|
||||
{
|
||||
$type = (int)sys_config('system_password_type', 3);
|
||||
$length = (int)sys_config('system_password_length', 3);
|
||||
if (!$this->checkPassword($password, $type, $length)) {
|
||||
throw new ValidateException($this->getMessage($type, $length));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录密码
|
||||
* @param string $password
|
||||
* @param int $type
|
||||
* @param int $length
|
||||
* @return false|int
|
||||
*/
|
||||
function checkPassword(string $password, int $type = 3, int $length = 6)
|
||||
{
|
||||
switch ($type) {
|
||||
case 1:// 纯数字
|
||||
$regex = '/^\d{' . $length . ',}$/';
|
||||
break;
|
||||
case 2:// 纯字母
|
||||
$regex = '/^[A-Za-z]{' . $length . ',}$/';
|
||||
break;
|
||||
case 3:// 数字 + 纯字母
|
||||
$regex = '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{' . $length . ',}$/';
|
||||
break;
|
||||
case 4:// 数字 + 纯字母 + 特殊符号
|
||||
// 使用 [\W_] 匹配所有特殊字符和下划线
|
||||
$regex = '/^(?=.*[A-Za-z])(?=.*\d)(?=.*[\W_])[A-Za-z\d\W_]{' . $length . ',}$/';
|
||||
break;
|
||||
default:
|
||||
$regex = '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{' . $length . ',}$/';
|
||||
break;
|
||||
}
|
||||
return preg_match($regex, $password);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取验证密码提示语
|
||||
* @param int $type
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(int $type = 3, int $length = 6)
|
||||
{
|
||||
switch ($type) {
|
||||
case 1://纯数字
|
||||
$desc = '纯数字';
|
||||
break;
|
||||
case 2://纯字母
|
||||
$desc = '纯字母';
|
||||
break;
|
||||
case 3://数字+纯字母
|
||||
$desc = '数字+纯字母';
|
||||
break;
|
||||
case 4://数字+纯字母+特殊符号
|
||||
$desc = '数字+纯字母+特殊符号';
|
||||
break;
|
||||
default:
|
||||
$desc = '数字+纯字母';
|
||||
break;
|
||||
}
|
||||
return '密码必须由:' . $desc . '组成,最小' . $length . '位';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
479
pro_v3.5.1_副本/app/services/system/admin/SystemAdminServices.php
Normal file
479
pro_v3.5.1_副本/app/services/system/admin/SystemAdminServices.php
Normal file
@@ -0,0 +1,479 @@
|
||||
<?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\system\admin;
|
||||
|
||||
use app\jobs\notice\SocketPushJob;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\product\product\StoreProductReplyServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\user\UserExtractServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use app\dao\system\admin\SystemAdminDao;
|
||||
use app\services\system\SystemMenusServices;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\FormBuilder;
|
||||
use app\services\system\SystemRoleServices;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Cache;
|
||||
use function Symfony\Component\Translation\t;
|
||||
|
||||
/**
|
||||
* 管理员service
|
||||
* Class SystemAdminServices
|
||||
* @package app\services\system\admin
|
||||
* @mixin SystemAdminDao
|
||||
*/
|
||||
class SystemAdminServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* form表单创建
|
||||
* @var FormBuilder
|
||||
*/
|
||||
#[Inject]
|
||||
protected FormBuilder $builder;
|
||||
|
||||
/**
|
||||
* @var SystemAdminDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemAdminDao $dao;
|
||||
|
||||
/**
|
||||
* 管理员登陆
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @param bool $is_mobile
|
||||
* @param int $adminType
|
||||
* @return array|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function verifyLogin(string $account, string $password, bool $is_mobile = false, int $adminType = 1, bool $is_secure = false, bool $is_admin = false)
|
||||
{
|
||||
$key = $adminType == 1 ? 'login_captcha_' . $account : 'supplier_login_captcha_' . $account;
|
||||
/** @var LoginAuthServices $loginAuthServices */
|
||||
$loginAuthServices = app()->make(LoginAuthServices::class);
|
||||
//验证是否锁定
|
||||
$loginAuthServices->checkErrorLock($account, $adminType);
|
||||
if ($is_mobile) {
|
||||
$adminInfo = $this->dao->phoneByAdmin($account, $adminType);
|
||||
} else {
|
||||
$adminInfo = $this->dao->accountByAdmin($account, $adminType);
|
||||
}
|
||||
if (!$adminInfo) {
|
||||
Cache::inc($key);
|
||||
$loginAuthServices->setErrorNum($account, $adminType);
|
||||
throw new AdminException('账号密码错误!');
|
||||
}
|
||||
if (!$adminInfo->status) {
|
||||
Cache::inc($key);
|
||||
$loginAuthServices->setErrorNum($account, $adminType);
|
||||
throw new AdminException('您已被禁止登录!');
|
||||
}
|
||||
if (!$is_mobile && !password_verify($password, $adminInfo->pwd) && !$is_admin) {
|
||||
Cache::inc($key);
|
||||
$loginAuthServices->setErrorNum($account, $adminType);
|
||||
throw new AdminException('账号或密码错误,请重新输入');
|
||||
}
|
||||
if (!$is_secure) {
|
||||
$adminInfo->last_time = time();
|
||||
$adminInfo->last_ip = app('request')->ip();
|
||||
$adminInfo->login_count++;
|
||||
$adminInfo->save();
|
||||
}
|
||||
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全验证获取手机号
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/8/2 10:32
|
||||
*/
|
||||
public function secure(string $account, string $password)
|
||||
{
|
||||
$adminInfo = $this->verifyLogin($account, $password, false, 1, true);
|
||||
$phone = $adminInfo->phone;
|
||||
if (!$phone) {
|
||||
throw new AdminException('请先绑定手机号');
|
||||
}
|
||||
$phone = substr_replace($phone, '****', 3, 4);
|
||||
$secure_key = 'admin_secure_' . md5($adminInfo->id);
|
||||
CacheService::set($secure_key, $adminInfo->phone);
|
||||
return compact('phone', 'secure_key');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台登陆获取菜单获取token
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @param string $type
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function login(string $account, string $password, string $type, bool $is_mobile = false, bool $is_admin = false)
|
||||
{
|
||||
$admin_type = $type == 'admin' ? 1 : 4;
|
||||
$adminInfo = $this->verifyLogin($account, $password, $is_mobile, $admin_type, false, $is_admin);
|
||||
$tokenInfo = $this->createToken($adminInfo->id, $type, $adminInfo['pwd']);
|
||||
/** @var SystemMenusServices $services */
|
||||
$services = app()->make(SystemMenusServices::class);
|
||||
[$menus, $uniqueAuth] = $services->getMenusList($adminInfo->roles, (int)$adminInfo['level'], $admin_type);
|
||||
$data = SystemConfigService::more(['site_logo', 'site_logo_square', 'new_order_audio_link']);
|
||||
return [
|
||||
'token' => $tokenInfo['token'],
|
||||
'expires_time' => $tokenInfo['params']['exp'],
|
||||
'menus' => $menus,
|
||||
'unique_auth' => $uniqueAuth,
|
||||
'user_info' => [
|
||||
'id' => $adminInfo['id'],
|
||||
'account' => $adminInfo['account'],
|
||||
'head_pic' => $adminInfo['head_pic'],
|
||||
'division_id' => $adminInfo['division_id'],
|
||||
],
|
||||
'logo' => $data['site_logo'],
|
||||
'logo_square' => $data['site_logo_square'],
|
||||
'version' => get_crmeb_version(),
|
||||
'newOrderAudioLink' => get_file_link($data['new_order_audio_link'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登陆前的login等信息
|
||||
* @return array
|
||||
*/
|
||||
public function getLoginInfo()
|
||||
{
|
||||
$data = SystemConfigService::more(['admin_login_slide', 'site_logo_square', 'site_logo', 'login_logo']);
|
||||
return [
|
||||
'slide' => sys_config('admin_login_slide') ?? [],
|
||||
'system_secure_type' => (int)sys_config('system_secure_type') ?? 0,
|
||||
'logo_square' => $data['site_logo_square'] ?? '',//透明
|
||||
'logo_rectangle' => $data['site_logo'] ?? '',//方形
|
||||
'login_logo' => $data['login_logo'] ?? '',//登陆
|
||||
'version' => get_crmeb_version(),
|
||||
'upload_file_size_max' => config('upload.filesize'),//文件上传大小kb
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getAdminList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
|
||||
/** @var SystemRoleServices $service */
|
||||
$service = app()->make(SystemRoleServices::class);
|
||||
$allRole = $service->getRoleArray(['type' => 0]);
|
||||
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'] = '';
|
||||
}
|
||||
}
|
||||
$item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
||||
$item['_last_time'] = $item['last_time'] ? date('Y-m-d H:i:s', $item['last_time']) : '';
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建管理员表单
|
||||
* @param int $level
|
||||
* @param array $formData
|
||||
* @return mixed
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createAdminForm(int $level, array $formData = [], $supplierId = 0)
|
||||
{
|
||||
if (!$level) {
|
||||
$imgUrl = $supplierId ? '/supplier/widget.images/index' : '/admin/widget.images/index';
|
||||
$f[] = $this->builder->frameImage('head_pic', '头像:', $this->url($imgUrl, ['fodder' => 'head_pic'], true), $formData['head_pic'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
}
|
||||
|
||||
$f[] = $this->builder->input('account', '管理员账号:', $formData['account'] ?? '')->required('请填写管理员账号');
|
||||
if ($formData) {
|
||||
$f[] = $this->builder->input('pwd', '管理员密码:')->type('password')->placeholder('不修改密码请留空');
|
||||
$f[] = $this->builder->input('conf_pwd', '确认密码:')->type('password')->placeholder('不修改密码请留空');
|
||||
} else {
|
||||
$f[] = $this->builder->input('pwd', '管理员密码:')->type('password')->required('请填写管理员密码');
|
||||
$f[] = $this->builder->input('conf_pwd', '确认密码:')->type('password')->required('请输入确认密码');
|
||||
}
|
||||
|
||||
$f[] = $this->builder->input('real_name', '管理员姓名:', $formData['real_name'] ?? '')->required('请输入管理员姓名');
|
||||
$f[] = $this->builder->input('phone', '管理员电话:', $formData['phone'] ?? '')->required('请输入管理员电话');
|
||||
|
||||
/** @var SystemRoleServices $service */
|
||||
$service = app()->make(SystemRoleServices::class);
|
||||
$options = $service->getRoleFormSelect($level);
|
||||
$roles = [];
|
||||
if ($formData && ($formData['roles'] ?? [])) {
|
||||
foreach ($formData['roles'] as $role) {
|
||||
$roles[] = (int)$role;
|
||||
}
|
||||
}
|
||||
if ($level) {
|
||||
$f[] = $this->builder->select('roles', '管理员身份:', $roles)->setOptions(FormBuilder::setOptions($options))->multiple(true)->required('请选择管理员身份');
|
||||
}
|
||||
$f[] = $this->builder->radio('status', '状态:', $formData['status'] ?? 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
|
||||
return $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加管理员form表单获取
|
||||
* @param int $level
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm(int $level, string $url = '/setting/admin', int $supplierId = 0)
|
||||
{
|
||||
return create_form('管理员添加', $this->createAdminForm($level, [], $supplierId), $this->url($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建管理员
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
if ($data['conf_pwd'] != $data['pwd']) {
|
||||
throw new AdminException('两次输入的密码不相同');
|
||||
}
|
||||
unset($data['conf_pwd']);
|
||||
|
||||
if ($this->dao->count(['account' => $data['account'], 'admin_type' => $data['admin_type'] ?? 1, 'is_del' => 0])) {
|
||||
throw new AdminException('管理员账号已存在');
|
||||
}
|
||||
if ($this->dao->count(['phone' => $data['phone'], 'admin_type' => $data['admin_type'] ?? 1, 'is_del' => 0])) {
|
||||
throw new AdminException('管理员电话已存在');
|
||||
}
|
||||
|
||||
$data['pwd'] = $this->passwordHash($data['pwd']);
|
||||
$data['add_time'] = time();
|
||||
$data['roles'] = implode(',', $data['roles']);
|
||||
|
||||
return $this->transaction(function () use ($data) {
|
||||
if ($this->dao->save($data)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new AdminException('添加失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改管理员表单
|
||||
* @param int $level
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function updateForm(int $level, int $id, string $url = '/setting/admin/', $supplierId = 0)
|
||||
{
|
||||
$adminInfo = $this->dao->get($id);
|
||||
if (!$adminInfo) {
|
||||
throw new AdminException('管理员不存在!');
|
||||
}
|
||||
if ($adminInfo->is_del) {
|
||||
throw new AdminException('管理员已经删除');
|
||||
}
|
||||
return create_form('管理员修改', $this->createAdminForm($level, $adminInfo->toArray(), $supplierId), $this->url($url . $id), 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改管理员
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function save(int $id, array $data)
|
||||
{
|
||||
if (!$adminInfo = $this->dao->get($id)) {
|
||||
throw new AdminException('管理员不存在,无法修改');
|
||||
}
|
||||
if ($adminInfo->is_del) {
|
||||
throw new AdminException('管理员已经删除');
|
||||
}
|
||||
//修改密码
|
||||
if ($data['pwd']) {
|
||||
|
||||
if (!$data['conf_pwd']) {
|
||||
throw new AdminException('请输入确认密码');
|
||||
}
|
||||
|
||||
if ($data['conf_pwd'] != $data['pwd']) {
|
||||
throw new AdminException('上次输入的密码不相同');
|
||||
}
|
||||
$adminInfo->pwd = $this->passwordHash($data['pwd']);
|
||||
}
|
||||
//修改账号
|
||||
if (isset($data['account']) && $data['account'] != $adminInfo->account && $this->dao->isAccountUsable($data['account'], $id)) {
|
||||
throw new AdminException('管理员账号已存在');
|
||||
}
|
||||
if (isset($data['phone']) && $data['phone'] != $adminInfo->phone && $this->dao->count(['phone' => $data['phone'], 'admin_type' => 1, 'is_del' => 0])) {
|
||||
throw new AdminException('管理员电话已存在');
|
||||
}
|
||||
if (isset($data['roles'])) {
|
||||
$adminInfo->roles = implode(',', $data['roles']);
|
||||
}
|
||||
$adminInfo->real_name = $data['real_name'] ?? $adminInfo->real_name;
|
||||
$adminInfo->phone = $data['phone'] ?? $adminInfo->phone;
|
||||
$adminInfo->account = $data['account'] ?? $adminInfo->account;
|
||||
$adminInfo->head_pic = $data['head_pic'] ?? $adminInfo->head_pic;
|
||||
$adminInfo->status = $data['status'];
|
||||
if ($adminInfo->save()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前管理员信息
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAdmin(int $id, array $data)
|
||||
{
|
||||
$adminInfo = $this->dao->get($id);
|
||||
if (!$adminInfo)
|
||||
throw new AdminException('管理员信息未查到');
|
||||
if ($adminInfo->is_del) {
|
||||
throw new AdminException('管理员已经删除');
|
||||
}
|
||||
if ($data['head_pic'] != '') {
|
||||
$adminInfo->head_pic = $data['head_pic'];
|
||||
} elseif ($data['real_name'] != '') {
|
||||
$adminInfo->real_name = $data['real_name'];
|
||||
} elseif ($data['pwd'] != '') {
|
||||
if (!password_verify($data['pwd'], $adminInfo['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('两次输入的密码不一致');
|
||||
$adminInfo->pwd = $this->passwordHash($data['new_pwd']);
|
||||
} elseif ($data['phone'] != '') {
|
||||
$verifyCode = CacheService::get('code_' . $data['phone']);
|
||||
if (!$verifyCode)
|
||||
throw new AdminException('请先获取验证码');
|
||||
$verifyCode = substr($verifyCode, 0, 6);
|
||||
if ($verifyCode != $data['code']) {
|
||||
CacheService::delete('code_' . $data['phone']);
|
||||
throw new AdminException('验证码错误');
|
||||
}
|
||||
$adminInfo->phone = $data['phone'];
|
||||
}
|
||||
if ($adminInfo->save()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 后台订单下单,评论,支付成功,后台消息提醒
|
||||
*/
|
||||
public function adminNewPush()
|
||||
{
|
||||
try {
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$data['ordernum'] = $orderServices->count(['is_del' => 0, 'status' => 1, 'shipping_type' => 1]);
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$data['inventory'] = $productServices->count(['type' => 5]);
|
||||
/** @var StoreProductReplyServices $replyServices */
|
||||
$replyServices = app()->make(StoreProductReplyServices::class);
|
||||
$data['commentnum'] = $replyServices->count(['is_reply' => 0]);
|
||||
/** @var UserExtractServices $extractServices */
|
||||
$extractServices = app()->make(UserExtractServices::class);
|
||||
$data['reflectnum'] = $extractServices->getCount(['status' => 0]);//提现
|
||||
$data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);
|
||||
|
||||
SocketPushJob::dispatch(['', 'ADMIN_NEW_PUSH', $data, 'admin']);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信修改密码
|
||||
* @param $phone
|
||||
* @param $newPwd
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function resetPwd($phone, $newPwd)
|
||||
{
|
||||
$adminInfo = $this->dao->phoneByAdmin($phone);
|
||||
if ($adminInfo) {
|
||||
$adminInfo->pwd = $this->passwordHash($newPwd);
|
||||
$adminInfo->save();
|
||||
return true;
|
||||
} else {
|
||||
throw new AdminException('管理员不存在,请检查手机号码');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取供应商接收通知管理员
|
||||
* @param int $supplier_id
|
||||
* @param string $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNotifySupplierList(int $supplier_id, string $field = '*')
|
||||
{
|
||||
$where = [
|
||||
'relation_id' => $supplier_id,
|
||||
'status' => 1,
|
||||
'is_del' => 0
|
||||
];
|
||||
$list = $this->dao->getList($where, 0, 0, $field);
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user