Files
huangjingfen/pro_v3.5.1_副本/app/controller/kefu/Order.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

441 lines
16 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\kefu;
use app\Request;
use app\services\activity\coupon\StoreCouponIssueServices;
use app\services\activity\combination\StorePinkServices;
use app\services\order\StoreOrderWriteOffServices;
use FormBuilder\Exception\FormBuilderException;
use think\annotation\Inject;
use app\services\store\DeliveryServiceServices;
use app\services\order\StoreOrderPromotionsServices;
use app\services\product\product\StoreProductServices;
use app\services\serve\ServeServices;
use app\services\other\ExpressServices;
use app\services\user\UserServices;
use app\services\order\StoreOrderServices;
use app\services\order\StoreOrderRefundServices;
use app\services\order\StoreOrderDeliveryServices;
use app\services\store\SystemStoreServices;
use app\validate\admin\order\StoreOrderValidate;
use app\services\message\service\StoreServiceRecordServices;
use \app\common\controller\Order as CommonOrder;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
/**
* Class Order
* @package app\kefuapi\controller
*/
class Order extends AuthController
{
use CommonOrder;
/**
* @var StoreOrderServices
*/
#[Inject]
protected StoreOrderServices $services;
/**
* 获取订单列表
* @param Request $request
* @param StoreServiceRecordServices $services
* @param StoreOrderRefundServices $storeOrderRefundServices
* @param $uid
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getUserOrderList(Request $request, StoreServiceRecordServices $services, StoreOrderRefundServices $storeOrderRefundServices, $uid)
{
$where = $request->getMore([
['type', '', '', 'status'],
['search', '', '', 'real_name'],
]);
$where['uid'] = $uid;
$where['is_del'] = 0;
$where['is_system_del'] = 0;
$where['refund_type'] = [0, 1, 3, 6];
if (!$services->count(['to_uid' => $uid])) {
return $this->fail('用户uid不再当前聊天用户范围内');
}
if ($where['status'] == -1) {
$list = $storeOrderRefundServices->refundList(['uid' => $where['uid'], 'real_name' => $where['real_name'], 'refund_type' => [0, 1, 2, 4, 5]])['list'] ?? [];
} else {
$where['store_id'] = 0;
$list = $this->services->getOrderApiList($where + ['pid' => 0], ['*'], ['pink', 'invoice']);
}
return $this->success($list);
}
/**
* 订单发货
* @return mixed
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function delivery_keep(StoreOrderDeliveryServices $services, $id)
{
$data = $this->request->postMore([
['type', 1],
['delivery_name', ''],//快递公司名称
['delivery_id', ''],//快递单号
['delivery_code', ''],//快递公司编码
['express_record_type', 2],//发货记录类型
['express_temp_id', ""],//电子面单模板
['to_name', ''],//寄件人姓名
['to_tel', ''],//寄件人电话
['to_addr', ''],//寄件人地址
['sh_delivery_name', ''],//送货人姓名
['sh_delivery_id', ''],//送货人电话
['sh_delivery_uid', ''],//送货人ID
['fictitious_content', '']//虚拟发货内容
]);
$services->delivery((int)$id, $data);
return $this->success('发货成功!');
}
/**
* 修改支付金额等
* @param $id
* @return mixed|Json|void
* @throws FormBuilderException
*/
public function edit($id)
{
if (!$id) {
return $this->fail('Data does not exist!');
}
return $this->success($this->services->updateForm($id));
}
/**
* 修改订单
* @param $id
* @return mixed
* @throws \Exception
*/
public function update($id)
{
if (!$id) {
return $this->fail('Missing order ID');
}
$data = $this->request->postMore([
['order_id', ''],
['total_price', 0],
['total_postage', 0],
['pay_price', 0],
['pay_postage', 0],
['gain_integral', 0],
]);
validate(StoreOrderValidate::class)->check($data);
if ($data['total_price'] < 0) {
return $this->fail('Please enter the total price');
}
if ($data['pay_price'] < 0) {
return $this->fail('Please enter the actual payment amount');
}
$this->services->updateOrder((int)$id, $data);
return $this->success('Modified success');
}
/**
* 订单备注
* @param Request $request
* @return mixed
*/
public function remark(Request $request)
{
[$order_id, $remark] = $request->postMore([
['order_id', ''],
['remark', '']
], true);
$order = $this->services->getOne(['order_id' => $order_id], 'id,remark');
/** @var StoreOrderRefundServices $refundServices */
$refundServices = app()->make(StoreOrderRefundServices::class);
$order = $order ?: $refundServices->get(['order_id' => $order_id]);
if (!$order) {
return $this->fail('订单不存在');
}
if (!strlen(trim($remark))) {
return $this->fail('请填写备注内容');
}
$order->remark = $remark;
if (!$order->save()) {
return $this->fail('备注失败');
}
return $this->success('备注成功');
}
/**
* 退款表单生成
* @param StoreOrderRefundServices $services
* @param $id 订单id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function refundForm(StoreOrderRefundServices $services, $id)
{
if (!$id) {
return $this->fail('Data does not exist!');
}
return $this->success($services->refundOrderForm((int)$id));
}
/**
* 订单退款
* @param Request $request
* @param StoreOrderRefundServices $services
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function refundOld(Request $request, StoreOrderRefundServices $services)
{
[$orderId, $price, $type] = $request->postMore([
['order_id', ''],
['price', '0'],
['type', 1],
], true);
if (!strlen(trim($orderId))) return $this->fail('参数错误');
$orderRefund = $services->getOne(['order_id' => $orderId]);
if (!$orderRefund) {
return app('json')->fail('数据不存在!');
}
if ($orderRefund['is_cancel'] == 1) {
return app('json')->fail('用户已取消申请');
}
$orderInfo = $this->services->get((int)$orderRefund['store_order_id']);
if (!$orderInfo) {
return app('json')->fail('数据不存在');
}
if (!in_array($orderRefund['refund_type'], [0, 1, 2, 5]) && !($orderRefund['refund_type'] == 4 && $orderRefund['apply_type'] == 3)) {
return app('json')->fail('售后订单状态不支持该操作');
}
if ($type == 1) {
$data['refund_type'] = 6;
} else if ($type == 2) {
$data['refund_type'] = 3;
} else {
return app('json')->fail('退款修改状态错误');
}
$data['refunded_time'] = time();
//拒绝退款
if ($type == 2) {
$services->refuseRefund((int)$orderRefund['id'], $data, $orderRefund);
return $this->success('修改退款状态成功!');
} else {
if ($orderRefund['refund_price'] == $orderRefund['refunded_price']) return $this->fail('已退完支付金额!不能再退款了');
if (!$price) {
return $this->fail('请输入退款金额');
}
$data['refunded_price'] = bcadd($price, $orderRefund['refunded_price'], 2);
$bj = bccomp((float)$orderRefund['refund_price'], (float)$data['refunded_price'], 2);
if ($bj < 0) {
return $this->fail('退款金额大于支付金额,请修改退款金额');
}
$refundData['pay_price'] = $orderInfo['pay_price'];
$refundData['refund_price'] = $price;
//修改订单退款状态
if ($services->agreeRefund((int)$orderRefund['id'], $refundData)) {
$services->update((int)$orderRefund['id'], $data);
return $this->success('退款成功');
}
// else {
// $services->storeProductOrderRefundYFasle((int)$orderInfo['id'], $price);
// return $this->fail('退款失败');
// }
}
}
/**
* 订单详情
* @param StoreProductServices $productServices
* @param StoreOrderPromotionsServices $storeOrderPromotiosServices
* @param $id 订单id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function orderInfo(StoreProductServices $productServices, StoreOrderPromotionsServices $storeOrderPromotiosServices, $id)
{
if (!$id || !($orderInfo = $this->services->get($id))) {
return $this->fail('订单不存在');
}
/** @var UserServices $services */
$services = app()->make(UserServices::class);
$userInfo = $services->get($orderInfo['uid']);
if (!$userInfo) {
return $this->fail('用户信息不存在');
}
$userInfo = $userInfo->hidden(['pwd', 'add_ip', 'last_ip', 'login_type']);
$userInfo['spread_name'] = '';
if ($userInfo['spread_uid'])
$userInfo['spread_name'] = $services->value(['uid' => $userInfo['spread_uid']], 'nickname');
$orderInfo = $this->services->tidyOrder($orderInfo->toArray(), true);
/** @var StorePinkServices $pinkService */
$pinkService = app()->make(StorePinkServices::class);
$orderInfo['pinkStatus'] = $pinkService->value(['order_id' => $orderInfo['order_id']], 'status');
$productId = array_column($orderInfo['cartInfo'], 'product_id');
$cateData = $productServices->productIdByProductCateName($productId);
foreach ($orderInfo['cartInfo'] as &$item) {
$item['class_name'] = $cateData[$item['product_id']] ?? '';
}
if ($orderInfo['store_id'] && $orderInfo['shipping_type'] == 2) {
/** @var $storeServices */
$storeServices = app()->make(SystemStoreServices::class);
$orderInfo['_store_name'] = $storeServices->value(['id' => $orderInfo['store_id']], 'name');
} else {
$orderInfo['_store_name'] = '';
}
//核算优惠金额
$vipTruePrice = 0;
foreach ($orderInfo['cartInfo'] ?? [] as $cart) {
$vipTruePrice = bcadd((string)$vipTruePrice, (string)$cart['vip_sum_truePrice'], 2);
}
$orderInfo['vip_true_price'] = $vipTruePrice;
$orderInfo['total_price'] = bcadd((string)$orderInfo['total_price'], (string)$orderInfo['vip_true_price'], 2);
//优惠活动优惠详情
$orderInfo['promotions_detail'] = $storeOrderPromotiosServices->getOrderPromotionsDetail((int)$orderInfo['id']);
if ($orderInfo['give_coupon']) {
$couponIds = is_string($orderInfo['give_coupon']) ? explode(',', $orderInfo['give_coupon']) : $orderInfo['give_coupon'];
/** @var StoreCouponIssueServices $couponIssueService */
$couponIssueService = app()->make(StoreCouponIssueServices::class);
$orderInfo['give_coupon'] = $couponIssueService->getColumn([['id', 'IN', $couponIds]], 'id,coupon_title');
}
$userInfo = $userInfo->toArray();
return $this->success(compact('orderInfo', 'userInfo'));
}
/**
* 获取物流
* @param ExpressServices $services
* @return mixed
*/
public function export(ExpressServices $services)
{
[$status] = $this->request->getMore([
['status', ''],
], true);
if ($status != '') $data['status'] = $status;
$data['is_show'] = 1;
return $this->success($services->express($data));
}
/**
*
* 获取面单信息
* @param ServeServices $services
* @return mixed
*/
public function getExportTemp(ServeServices $services)
{
[$com] = $this->request->getMore([
['com', ''],
], true);
return $this->success($services->express()->temp($com));
}
/**
* 获取所有配送员列表
* @param DeliveryServiceServices $services
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getDeliveryAll(DeliveryServiceServices $services)
{
$list = $services->getDeliveryList();
return $this->success($list['list']);
}
/**
* 获取配置信息
* @return mixed
*/
public function getDeliveryInfo()
{
return $this->success([
'express_temp_id' => sys_config('config_export_temp_id'),
'to_name' => sys_config('config_export_to_name'),
'id' => sys_config('config_export_id'),
'to_tel' => sys_config('config_export_to_tel'),
'to_add' => sys_config('config_export_to_address')
]);
}
/**
* 门店核销
* @param StoreOrderWriteOffServices $services
* @param $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function order_verific(StoreOrderWriteOffServices $services, $id)
{
$orderInfo = $this->services->get(['id' => $id], ['verify_code', 'uid']);
if (!$orderInfo) {
return $this->fail('核销订单未查到');
}
if (!$orderInfo->verify_code) {
return $this->fail('Lack of write-off code');
}
$services->writeOffOrder($orderInfo->verify_code, 1, $orderInfo->uid);
return $this->success('Write off successfully');
}
/**
* 退款订单详情
* @param StoreOrderRefundServices $services
* @param UserServices $userServices
* @param $id
* @return mixed
*/
public function refundDetail(StoreOrderRefundServices $services, UserServices $userServices, $id)
{
$order = $services->get(['id' => $id], ['id', 'order_id', 'uid']);
$uni = $order['order_id'];
$data['orderInfo'] = $services->refundDetail($uni);
$userInfo = $userServices->get((int)$order['uid']);
if (!$userInfo) return app('json')->fail('用户信息不存在');
$userInfo = $userInfo->hidden(['pwd', 'add_ip', 'last_ip', 'login_type']);
$data['userInfo'] = $userInfo;
return app('json')->success($data);
}
}