Files
huangjingfen/pro_v3.5.1_副本/app/services/supplier/finance/SupplierFlowingWaterServices.php

251 lines
9.1 KiB
PHP
Raw Normal View History

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
<?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\supplier\finance;
use app\dao\supplier\finance\SupplierFlowingWaterDao;
use app\services\BaseServices;
use app\services\order\StoreOrderCreateServices;
use app\services\order\StoreOrderCartInfoServices;
use app\services\order\StoreOrderRefundServices;
use app\services\order\StoreOrderServices;
use think\annotation\Inject;
/**
* 供应商流水
* Class SupplierFlowingWaterServices
* @package app\services\supplier\finance
* @mixin SupplierFlowingWaterDao
*/
class SupplierFlowingWaterServices extends BaseServices
{
/**
* 支付类型
* @var string[]
*/
public array $pay_type = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'alipay' => '支付宝支付', 'cash' => '现金支付', 'automatic' => '自动转账', 'store' => '微信支付'];
/**
* 交易类型
* @var string[]
*/
public array $type = [
1 => '支付订单',
2 => '退款订单'
];
/**
* @var SupplierFlowingWaterDao
*/
#[Inject]
protected SupplierFlowingWaterDao $dao;
/**
* 显示资源列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, '*', $page, $limit, ['user', 'supplierName']);
foreach ($list as &$item) {
$item['type_name'] = isset($this->type[$item['type']]) ? $this->type[$item['type']] : '其他类型';
$item['pay_type_name'] = isset($this->pay_type[$item['pay_type']]) ? $this->pay_type[$item['pay_type']] : '其他方式';
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
$item['finish_time'] = $item['finish_time'] ? date('Y-m-d H:i:s', $item['finish_time']) : '';
$item['trade_time'] = $item['trade_time'] ? date('Y-m-d H:i:s', $item['trade_time']) : $item['add_time'];
$item['user_nickname'] = $item['user_nickname'] ?: '游客';
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 供应商账单
* @param $where
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFundRecord($where)
{
[$page, $limit] = $this->getPageValue();
$where['is_del'] = 0;
$data = $this->dao->getFundRecord($where, $page, $limit);
$i = 1;
foreach ($data['list'] as &$item) {
$item['id'] = $i;
$i++;
$item['entry_num'] = bcsub($item['income_num'], $item['exp_num'], 2);
switch ($where['timeType']) {
case "day" :
$item['title'] = "日账单";
$item['add_time'] = date('Y-m-d', $item['add_time']);
break;
case "week" :
$item['title'] = "周账单";
$item['add_time'] = '第' . $item['day'] . '周(' . date('m', $item['add_time']) . '月)';
break;
case "month" :
$item['title'] = "月账单";
$item['add_time'] = date('Y-m', $item['add_time']);
break;
}
}
return $data;
}
/**
* 获取百分比
* @param $num
* @return string|null
*/
public function getPercent($num)
{
return bcdiv($num, '100', 4);
}
/**
* 写入流水账单
* @param $oid
* @param $type
* @return bool|void
* @throws \Exception
*/
public function setSupplierFinance($oid, $type = 1)
{
/** @var SupplierTransactionsServices $transactionsServices */
$transactionsServices = app()->make(SupplierTransactionsServices::class);
/** @var StoreOrderCartInfoServices $cartInfoServices */
$cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
/** @var StoreOrderRefundServices $storeOrderRefundServices */
$storeOrderRefundServices = app()->make(StoreOrderRefundServices::class);
$order = $storeOrderServices->get($oid);
if (!$order) {
return true;
}
if ($order['supplier_id'] <= 0) return true;
$data = $cartInfoServices->getOrderCartInfoSettlePrice($order['id']);
$pay_postage = 0;
if (isset($order['shipping_type']) && !in_array($order['shipping_type'], [2, 4])) {
$pay_postage = floatval($storeOrderRefundServices->getOrderSumPrice($data['info'], 'postage_price', false));
}
if ($order['type'] == 8) {
$order['pay_price'] = $order['total_price'];
}
$append = [
'pay_price' => $order['pay_price'],
'pay_postage' => $pay_postage,
'total_price' => $order['total_price'],
];
switch ($type) {
case 1 ://支付
$number = bcadd((string)$data['settlePrice'], $pay_postage, 2);
//支付订单
$this->savaData($order, $number, 1, 1, $append);
//交易订单记录
$transactionsServices->savaData($order, 1, 1, $append);
break;
case 2://退款
$number = bcadd((string)$data['refundSettlePrice'], $pay_postage, 2);
$this->savaData($order, $number, 0, 2, $append);
//交易订单记录
$transactionsServices->savaData($order, 0, 2, $append);
break;
}
}
/**
* 写入数据
* @param $order
* @param $number
* @param $pm
* @param $type
* @param $trade_type
* @param array $append
* @throws \Exception
*/
public function savaData($order, $number, $pm, $type, array $append = [])
{
/** @var StoreOrderCreateServices $storeOrderCreateServices */
$storeOrderCreateServices = app()->make(StoreOrderCreateServices::class);
$order_id = $storeOrderCreateServices->getNewOrderId('ls');
$data = [
'supplier_id' => $order['supplier_id'] ?? 0,
'uid' => $order['uid'] ?? 0,
'order_id' => $order_id,
'link_id' => $order['order_id'] ?? '',
'pay_type' => $order['pay_type'] ?? '',
'trade_time' => $order['pay_time'] ?? $order['add_time'] ?? '',
'pm' => $pm,
'number' => $number ?: 0,
'type' => $type,
'add_time' => time()
];
if ($type == 2) {
$data['status'] = 1;
$data['finish_time'] = time();
//更改正常订单状态
$this->dao->update(['link_id' => $order['order_id'], 'type' => 1], ['status' => 1, 'finish_time' => time()]);
}
$data = array_merge($data, $append);
$this->dao->save($data);
}
/**
* 关联门店店员
* @param $link_id
* @param int $staff_id
* @return mixed
*/
public function setStaff($link_id, int $staff_id)
{
return $this->dao->update(['link_id' => $link_id], ['staff_id' => $staff_id]);
}
/**
* 可提现金额
* @param array $where
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSumFinance(array $where, array $whereData)
{
$field = 'sum(if(pm = 1,number,0)) as income_num,sum(if(pm = 0,number,0)) as exp_num';
$whereData['status'] = 1;
$data = $this->dao->getList($whereData, $field);
if (!$data) return 0;
$income_num = $data[0]['income_num'] ?? 0;
$exp_num = $data[0]['exp_num'] ?? 0;
$number = bcsub($income_num, $exp_num, 2);
//已提现金额
/** @var SupplierExtractServices $extractServices */
$extractServices = app()->make(SupplierExtractServices::class);
$where['not_status'] = -1;
$extract_price = $extractServices->getExtractMoneyByWhere($where, 'extract_price');
$price_not = bcsub((string)$number, (string)$extract_price, 2);
return $price_not;
}
}