Files
huangjingfen/pro_v3.5.1_副本/app/services/order/StoreOrderInvoiceServices.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

245 lines
9.4 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>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\services\order;
use app\services\BaseServices;
use think\annotation\Inject;
use think\exception\ValidateException;
use app\dao\order\StoreOrderInvoiceDao;
use app\services\user\UserInvoiceServices;
/**
* Class StoreOrderInvoiceServices
* @package app\services\order
* @mixin StoreOrderInvoiceDao
*/
class StoreOrderInvoiceServices extends BaseServices
{
/**
* @var StoreOrderInvoiceDao
*/
#[Inject]
protected StoreOrderInvoiceDao $dao;
/**
* @author 等风来
* @email 136327134@qq.com
* @date 2023/9/18
* @param array $where
* @return array
*/
public function chart(array $where)
{
//全部
$data['all'] = (string)$this->dao->count(['is_pay' => 1, 'is_del' => 0, 'time' => $where['time']]);
//待开
$data['noOpened'] = (string)$this->dao->count(['is_pay' => 1, 'is_del' => 0, 'time' => $where['time'], 'type' => 1]);
//已开
$data['opened'] = (string)$this->dao->count(['is_pay' => 1, 'is_del' => 0, 'time' => $where['time'], 'type' => 2]);
//退款
$data['refund'] = (string)$this->dao->count(['is_pay' => 1, 'is_del' => 0, 'time' => $where['time'], 'type' => 3]);
return $data;
}
/**
* 后台获取开票列表
* @param $where
* @return array
*/
public function getList(array $where)
{
[$page, $list] = $this->getPageValue();
$field = 'id as invoice_id,order_id,header_type,type,name,invoice_amount,duty_number,drawer_phone,email,tell,address,bank,card_number,is_invoice,invoice_number,remark as invoice_reamrk,invoice_time,add_time as invoice_add_time';
$where['is_pay'] = 1;
$where['is_del'] = 0;
$list = $this->dao->getList($where, $field, ['order' => function ($query) {
$query->field('id,order_id,pay_price,add_time,real_name,user_phone,status,refund_status');
}], 'add_time desc', $page, $list);
foreach ($list as &$item) {
$item['id'] = $item['order']['id'] ?? 0;
$item['order_id'] = $item['order']['order_id'] ?? '';
$item['pay_price'] = $item['order']['pay_price'] ?? 0.00;
$item['real_name'] = $item['order']['real_name'] ?? '';
$item['user_phone'] = $item['order']['user_phone'] ?? '';
$item['status'] = $item['order']['status'] ?? '';
$item['refund_status'] = $item['order']['refund_status'] ?? 0;
$item['add_time'] = date('Y-m-d H:i:s', $item['order']['add_time'] ?? $item['invoice_add_time'] ?? time());
$item['invoice_add_time'] = date('Y-m-d H:i:s', $item['invoice_add_time']);
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 前端获取开票列表(带商品信息)
* @param $where
* @return array
*/
public function getOrderInvoiceList(array $where)
{
[$page, $list] = $this->getPageValue();
$where['is_pay'] = 1;
$where['is_del'] = 0;
$where['is_refund'] = 0;
$list = $this->dao->getList($where, '*', ['order'], 'add_time desc', $page, $list);
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
foreach ($list as &$item) {
if (isset($item['order']) && $item['order']) {
$item['order'] = $storeOrderServices->tidyOrder($item['order'], true);
if (isset($item['order']['_status']['_type']) && $item['order']['_status']['_type'] == 3) {
foreach ($item['order']['cartInfo'] ?: [] as $key => $product) {
$item['order']['cartInfo'][$key]['add_time'] = isset($product['add_time']) ? date('Y-m-d H:i', (int)$product['add_time']) : '时间错误';
}
}
}
}
return $list;
}
/**
* 订单申请开票
* @param int $uid
* @param $order_id
* @param int $invoice_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function makeUp(int $uid, $order_id, int $invoice_id)
{
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
/** @var UserInvoiceServices $userInvoiceServices */
$userInvoiceServices = app()->make(UserInvoiceServices::class);
$order = $storeOrderServices->getOne(['order_id|id' => $order_id, 'is_del' => 0]);
if (!$order) {
throw new ValidateException('订单不存在');
}
if ($order['pay_price'] <= 0) {
throw new ValidateException('订单实际支付金额为0不能开发票');
}
//检测再带查询
$invoice = $userInvoiceServices->checkInvoice($invoice_id, $uid);
$info= $this->dao->getOne(['order_id' => $order['id'], 'uid' => $uid]);
if ($info && $info['is_invoice'] != -1) {
throw new ValidateException('发票已申请,正在审核打印中');
}
if ($order['refund_status'] == 2) {
throw new ValidateException('订单已退款');
}
if ($order['refund_status'] == 1) {
throw new ValidateException('正在申请退款中');
}
unset($invoice['id'], $invoice['add_time']);
$data = [];
$data['category'] = 'order';
$data['order_id'] = $order['id'];
$data['invoice_id'] = $invoice_id;
$data['add_time'] = time();
$data['is_pay'] = $order['paid'] == 1 ? 1 : 0;
$data = array_merge($data, $invoice);
if (!$re = $this->dao->save($data)) {
throw new ValidateException('申请失败,请稍后重试');
}
return ['id' => $re->id];
}
/**
* 设置处理发票
* @param int $id
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function setInvoice(int $id, array $data)
{
$orderInvoice = $this->dao->get($id);
if (!$orderInvoice) {
throw new ValidateException('数据不存在');
}
$data['invoice_time'] = time();
if (!$this->dao->update($id, $data, 'id')) {
throw new ValidateException('设置失败,请重试');
}
return true;
}
/**
* 根据订单id获取发票信息
* @param int $oid
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOneInvoice(int $oid)
{
$info = $this->dao->get(['order_id' => $oid]);
$info = $info ? $info->toArray() : [];
if (!$info) {
throw new ValidateException('数据不存在');
}
return $info;
}
/**
* 拆分订单同步拆分申请开票记录
* @param int $oid
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function splitOrderInvoice(int $oid)
{
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
$orderInfo = $storeOrderServices->getOne(['id' => $oid, 'is_del' => 0]);
if (!$orderInfo) {
throw new ValidateException('订单不存在');
}
$pid = $orderInfo['pid'] > 0 ? $orderInfo['pid'] : $orderInfo['id'];
//查询开票记录
$orderInvoice = $this->dao->get(['order_id' => $oid]);
//查询子订单
$spliteOrder = $storeOrderServices->getColumn(['pid' => $pid, 'is_system_del' => 0], 'id,order_id');
if ($spliteOrder && $orderInvoice) {
$data = $orderInvoice->toArray();
unset($data['id']);
$data['add_time'] = strtotime($data['add_time']);
$data_all = [];
foreach ($spliteOrder as $order) {
if (!$this->dao->count(['order_id' => $order['id']])) {
$data['order_id'] = $order['id'];
$data_all[] = $data;
}
}
if ($data_all) {
$this->transaction(function () use ($data_all, $orderInvoice, $orderInfo) {
$this->dao->saveAll($data_all);
if ($orderInfo['pid'] <= 0) {
$this->dao->delete(['id' => $orderInvoice['id']]);
}
});
}
}
return true;
}
}