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

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

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

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

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

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

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

340 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~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');
}
/**
* 获取配送员selectUid
* @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;
}
}