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:
258
pro_v3.5.1_副本/app/services/out/OutAccountServices.php
Normal file
258
pro_v3.5.1_副本/app/services/out/OutAccountServices.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?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\out;
|
||||
|
||||
|
||||
use app\dao\out\OutAccountDao;
|
||||
use crmeb\basic\BaseAuth;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\HttpService;
|
||||
use crmeb\utils\ApiErrorCode;
|
||||
use crmeb\utils\JwtAuth;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* Class LoginServices
|
||||
* @package app\services\kefu
|
||||
* @mixin OutAccountDao
|
||||
*/
|
||||
class OutAccountServices extends BaseServices
|
||||
{
|
||||
const FEPAORPL = 'OSeCVa';
|
||||
|
||||
/**
|
||||
* @var OutAccountDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected OutAccountDao $dao;
|
||||
|
||||
/**
|
||||
* 账号密码登录
|
||||
* @param string $appid
|
||||
* @param string|null $appsecret
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function authLogin(string $appid, string $appsecret = null)
|
||||
{
|
||||
$autInfo = $this->dao->get(['appid' => $appid, 'is_del' => 0]);
|
||||
if (!$autInfo) {
|
||||
throw new ValidateException('没有此用户');
|
||||
}
|
||||
if ($appsecret && !password_verify($appsecret, $autInfo->appsecret)) {
|
||||
throw new ValidateException('appid或appsecret错误');
|
||||
}
|
||||
if ($autInfo->status == 2) {
|
||||
throw new ValidateException('您已被禁止登录');
|
||||
}
|
||||
$token = $this->createToken($autInfo->id, 'out', $autInfo->appsecret);
|
||||
$data['last_time'] = time();
|
||||
$data['ip'] = request()->ip();
|
||||
$this->update($autInfo['id'], $data);
|
||||
return [
|
||||
'token' => $token['token'],
|
||||
'exp_time' => $token['params']['exp'],
|
||||
'autInfo' => $autInfo->hidden(['appsecret', 'ip', 'is_del', 'add_time', 'status', 'last_time'])->toArray()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析token
|
||||
* @param string $token
|
||||
* @return array
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function parseToken(string $token)
|
||||
{
|
||||
/** @var BaseAuth $services */
|
||||
$services = app()->make(BaseAuth::class);
|
||||
$adminInfo = $services->parseToken($token, function ($id) {
|
||||
return $this->dao->get($id);
|
||||
});
|
||||
if (isset($adminInfo->auth) && $adminInfo->auth !== md5($adminInfo->appsecret)) {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
return $adminInfo->hidden(['appsecret', 'ip', 'status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOne($where = [])
|
||||
{
|
||||
$info = $this->dao->getOne($where);
|
||||
return $info ? $info->toArray() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getList(array $where = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$where['is_del'] = 0;
|
||||
$list = $this->dao->getList((array)$where, (int)$page, (int)$limit);
|
||||
$count = $this->dao->count($where);
|
||||
if ($list) {
|
||||
foreach ($list as &$item) {
|
||||
$item['add_time'] = $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']) : '暂无';
|
||||
$item['rules'] = is_null($item['rules']) ? [] : json_decode($item['rules'], true);
|
||||
}
|
||||
}
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置推送接口
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function outSetUpSave($id, $data)
|
||||
{
|
||||
return $this->dao->update($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取token接口
|
||||
* @param $data
|
||||
* @return int[]|mixed
|
||||
*/
|
||||
public function textOutUrl($data)
|
||||
{
|
||||
if (!$data['push_account'] || !$data['push_password'] || !$data['push_token_url']) throw new AdminException(100100);
|
||||
$param = ['push_account' => $data['push_account'], 'push_password' => $data['push_password']];
|
||||
$res = HttpService::getRequest($data['push_token_url'], $param);
|
||||
$res = $res ? json_decode($res, true) : ['status' => 400];
|
||||
if ($res['status'] != 200) {
|
||||
throw new AdminException('测试失败');
|
||||
} else {
|
||||
return $res['data'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
* @param string $token
|
||||
* @return array
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function refresh(string $token): array
|
||||
{
|
||||
/** @var CacheService $cacheService */
|
||||
$cacheService = app()->make(CacheService::class);
|
||||
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
|
||||
//获取token信息
|
||||
[$md5Token, $id, $type] = $this->verifyToken($token, $jwtAuth, $cacheService);
|
||||
|
||||
//获取对外账号
|
||||
$authInfo = $this->dao->getOne(['id' => $id, 'is_del' => 0]);
|
||||
$this->checkAuth($authInfo, $md5Token, $cacheService);
|
||||
|
||||
$cacheService->delete($md5Token);
|
||||
|
||||
$token = $jwtAuth->createToken($id, $type);
|
||||
$data['last_time'] = time();
|
||||
$data['ip'] = request()->ip();
|
||||
$this->dao->update($id, $data);
|
||||
return [
|
||||
'access_token' => $token['token'],
|
||||
'exp_time' => $token['params']['exp'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* @param string $token
|
||||
* @param JwtAuth $jwtAuth
|
||||
* @param CacheService $cacheService
|
||||
* @return array
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
protected function verifyToken(string $token, JwtAuth $jwtAuth, CacheService $cacheService): array
|
||||
{
|
||||
if (!$token || $token === 'undefined') {
|
||||
throw new AuthException('登录失败');
|
||||
}
|
||||
|
||||
$md5Token = md5($token);
|
||||
|
||||
if (!$cacheService->has($md5Token) || !($cacheToken = $cacheService->get($md5Token, '', NULL, 'out'))) {
|
||||
throw new AuthException('登录已过期,请重新登录');
|
||||
}
|
||||
|
||||
//解析token
|
||||
[$id, $type] = $jwtAuth->parseToken($token);
|
||||
if (!$id || $type != 'out') {
|
||||
throw new AuthException('登录失败');
|
||||
}
|
||||
|
||||
try {
|
||||
$jwtAuth->verifyToken();
|
||||
} catch (\Throwable $e) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('登录失败');
|
||||
}
|
||||
|
||||
return [$md5Token, $id, $type];
|
||||
}
|
||||
|
||||
/**
|
||||
* 核对用户
|
||||
* @param $authInfo
|
||||
* @param string $md5Token
|
||||
* @param CacheService $cacheService
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkAuth($authInfo, string $md5Token, CacheService $cacheService): bool
|
||||
{
|
||||
if (!$authInfo) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('登录已过期,请重新登录');
|
||||
}
|
||||
|
||||
if ($authInfo->status == 2) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('您已被禁止登录');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
134
pro_v3.5.1_副本/app/services/out/OutInterfaceServices.php
Normal file
134
pro_v3.5.1_副本/app/services/out/OutInterfaceServices.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\out;
|
||||
|
||||
use app\dao\out\OutInterfaceDao;
|
||||
use app\Request;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
class OutInterfaceServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var OutInterfaceDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected OutInterfaceDao $dao;
|
||||
|
||||
/**
|
||||
* 获取接口列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function outInterfaceList()
|
||||
{
|
||||
$list = $this->dao->getInterfaceList(['is_del' => 0], 'id,pid,method,type,name,name as title');
|
||||
$data = [];
|
||||
foreach ($list as $key => $item) {
|
||||
if ($item['pid'] == 0) {
|
||||
$data[] = $item;
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
foreach ($data as &$item_p) {
|
||||
foreach ($list as $item_c) {
|
||||
if ($item_p['id'] == $item_c['pid']) {
|
||||
$item_p['children'][] = $item_c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证对外接口权限
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyAuth(Request $request)
|
||||
{
|
||||
$rule = trim(strtolower($request->rule()->getRule()));
|
||||
$method = trim(strtolower($request->method()));
|
||||
$authList = $this->dao->getColumn([['id', 'in', json_decode($request->outInfo()['rules'])]], 'method,url');
|
||||
$rolesAuth = [];
|
||||
foreach ($authList as $item) {
|
||||
$rolesAuth[trim(strtolower($item['method']))][] = trim(strtolower(str_replace(' ', '', $item['url'])));
|
||||
}
|
||||
$rule = str_replace('outapi', '', $rule);
|
||||
$rule = str_replace('<', '{', $rule);
|
||||
$rule = str_replace('>', '}', $rule);
|
||||
if (in_array($rule, $rolesAuth[$method] ?? [])) {
|
||||
return true;
|
||||
} else {
|
||||
throw new AuthException('暂无对应接口权限');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外接口文档
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function interfaceInfo($id)
|
||||
{
|
||||
if (!$id) throw new AdminException('参数错误');
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) throw new AdminException('数据不存在');
|
||||
$info = $info->toArray();
|
||||
$info['request_params'] = json_decode($info['request_params']);
|
||||
$info['return_params'] = json_decode($info['return_params']);
|
||||
$info['error_code'] = json_decode($info['error_code']);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增对外接口文档
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function saveInterface($id, $data)
|
||||
{
|
||||
$data['request_params'] = json_encode($data['request_params']);
|
||||
$data['return_params'] = json_encode($data['return_params']);
|
||||
$data['error_code'] = json_encode($data['error_code']);
|
||||
if ($id) {
|
||||
$res = $this->dao->update($id, $data);
|
||||
} else {
|
||||
$res = $this->dao->save($data);
|
||||
}
|
||||
if (!$res) throw new AdminException('保存失败');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口名称
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function editInterfaceName($data)
|
||||
{
|
||||
$res = $this->dao->update($data['id'], ['name' => $data['name']]);
|
||||
if (!$res) throw new AdminException('修改失败');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function delInterface($id)
|
||||
{
|
||||
$res = $this->dao->update($id, ['is_del' => 1]);
|
||||
if (!$res) throw new AdminException('删除失败');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
201
pro_v3.5.1_副本/app/services/out/OutStoreOrderRefundServices.php
Normal file
201
pro_v3.5.1_副本/app/services/out/OutStoreOrderRefundServices.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\out;
|
||||
|
||||
use app\dao\order\StoreOrderRefundDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\pay\PayServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\exceptions\ApiException;
|
||||
use app\services\order\StoreOrderRefundServices;
|
||||
use crmeb\services\HttpService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 售后单
|
||||
* Class OutStoreOrderRefundServices
|
||||
* @package app\services\order
|
||||
*/
|
||||
class OutStoreOrderRefundServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 订单services
|
||||
* @var OutStoreOrderServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected OutStoreOrderServices $storeOrderServices;
|
||||
|
||||
/**
|
||||
* @var StoreOrderRefundDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreOrderRefundDao $dao;
|
||||
|
||||
/**
|
||||
* 售后单列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function refundList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$field = 'id, store_order_id, uid, order_id, refund_type, refund_num, refund_price, refunded_price, refund_phone, refund_express, refund_express_name,
|
||||
refund_explain, refund_img, refund_reason, refuse_reason, remark, refunded_time, cart_info, is_cancel, is_del, add_time';
|
||||
$list = $this->dao->getRefundList($where, $field, [], $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
foreach ($list as $key => &$item) {
|
||||
$item['pay_price'] = $item['refund_price'];
|
||||
unset($item['refund_price']);
|
||||
$item['items'] = $this->tidyCartList($item['cart_info']);
|
||||
unset($list[$key]['cart_info']);
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化订单商品
|
||||
* @param array $carts
|
||||
* @return array
|
||||
*/
|
||||
public function tidyCartList(array $carts): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($carts as $cart) {
|
||||
$list[] = [
|
||||
'store_name' => $cart['productInfo']['store_name'] ?? '',
|
||||
'suk' => $cart['productInfo']['attrInfo']['suk'] ?? '',
|
||||
'image' => $cart['productInfo']['attrInfo']['image'] ?: $cart['productInfo']['image'],
|
||||
'price' => sprintf("%.2f", $cart['truePrice'] ?? '0.00'),
|
||||
'cart_num' => $cart['cart_num'] ?? 0
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 售后单生成
|
||||
* @param int $id
|
||||
* @param string $pushUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function refundCreatePush(int $id, string $pushUrl): bool
|
||||
{
|
||||
$refundInfo = $this->getInfo('', $id);
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$orderInfo = $orderServices->get($refundInfo['store_order_id'], ['id', 'order_id']);
|
||||
if (!$orderInfo) {
|
||||
throw new AdminException('订单不存在');
|
||||
}
|
||||
$refundInfo['order'] = $orderInfo->toArray();
|
||||
return $this->outPush($pushUrl, $refundInfo, '售后单');
|
||||
}
|
||||
|
||||
/**
|
||||
* 售后单取消
|
||||
* @param int $id
|
||||
* @param string $pushUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function cancelApplyPush(int $id, string $pushUrl): bool
|
||||
{
|
||||
$refundInfo = $this->getInfo('', $id);
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$orderInfo = $orderServices->get($refundInfo['store_order_id'], ['id', 'order_id']);
|
||||
if (!$orderInfo) {
|
||||
throw new AdminException('订单不存在');
|
||||
}
|
||||
$refundInfo['order'] = $orderInfo->toArray();
|
||||
return $this->outPush($pushUrl, $refundInfo, '取消售后单');
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认数据推送
|
||||
* @param string $pushUrl
|
||||
* @param array $data
|
||||
* @param string $tip
|
||||
* @return bool
|
||||
*/
|
||||
function outPush(string $pushUrl, array $data, string $tip = ''): bool
|
||||
{
|
||||
$param = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
|
||||
$res = $res ? json_decode($res, true) : [];
|
||||
if (!$res || !isset($res['code']) || $res['code'] != 0) {
|
||||
\think\facade\Log::error(json_encode(['msg' => $tip . '推送失败', 'data' => $res], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退款订单详情
|
||||
* @param string $orderId 售后单号
|
||||
* @param int $id 售后单ID
|
||||
* @return mixed
|
||||
*/
|
||||
public function getInfo(string $orderId = '', int $id = 0)
|
||||
{
|
||||
$field = ['id', 'store_order_id', 'order_id', 'uid', 'refund_type', 'refund_num', 'refund_price',
|
||||
'refunded_price', 'refund_phone', 'refund_express', 'refund_express_name', 'refund_explain',
|
||||
'refund_img', 'refund_reason', 'refuse_reason', 'remark', 'refunded_time', 'cart_info', 'is_cancel', 'is_del', 'add_time'];
|
||||
|
||||
if ($id > 0) {
|
||||
$where = $id;
|
||||
} else {
|
||||
$where = ['order_id' => $orderId];
|
||||
}
|
||||
$refund = $this->dao->get($where, $field, ['orderData']);
|
||||
if (!$refund) throw new ApiException(410173);
|
||||
$refund = $refund->toArray();
|
||||
|
||||
//核算优惠金额
|
||||
$totalPrice = 0;
|
||||
$vipTruePrice = 0;
|
||||
foreach ($refund['cart_info'] ?? [] as $key => &$cart) {
|
||||
$cart['sum_true_price'] = sprintf("%.2f", $cart['sum_true_price'] ?? bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2));
|
||||
$cart['vip_sum_truePrice'] = bcmul($cart['vip_truePrice'], $cart['cart_num'] ?: 1, 2);
|
||||
$vipTruePrice = bcadd((string)$vipTruePrice, $cart['vip_sum_truePrice'], 2);
|
||||
if (isset($order['split']) && $order['split']) {
|
||||
$refund['cart_info'][$key]['cart_num'] = $cart['surplus_num'];
|
||||
if (!$cart['surplus_num']) unset($refund['cart_info'][$key]);
|
||||
}
|
||||
$totalPrice = bcadd($totalPrice, $cart['sum_true_price'], 2);
|
||||
}
|
||||
$refund['vip_true_price'] = $vipTruePrice;
|
||||
|
||||
/** @var StoreOrderRefundServices $refundServices */
|
||||
$refundServices = app()->make(StoreOrderRefundServices::class);
|
||||
$refund['use_integral'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'use_integral', false);
|
||||
$refund['coupon_price'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'coupon_price', false);
|
||||
$refund['deduction_price'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'integral_price', false);
|
||||
$refund['pay_postage'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'postage_price', false);
|
||||
$refund['total_price'] = bcadd((string)$totalPrice, bcadd((string)$refund['deduction_price'], (string)$refund['coupon_price'], 2), 2);
|
||||
$refund['items'] = $this->tidyCartList($refund['cart_info']);
|
||||
if (in_array($refund['refund_type'], [0, 1, 2, 4, 5])) {
|
||||
$title = '申请退款中';
|
||||
} elseif ($refund['refund_type'] == 3) {
|
||||
$title = '拒绝退款';
|
||||
} else {
|
||||
$title = '已退款';
|
||||
}
|
||||
|
||||
$refund['refund_type_name'] = $title;
|
||||
$refund['pay_type_name'] = PayServices::PAY_TYPE[$refund['pay_type']] ?? '其他方式';
|
||||
unset($refund['cart_info']);
|
||||
return $refund;
|
||||
}
|
||||
|
||||
}
|
||||
285
pro_v3.5.1_副本/app/services/out/OutStoreOrderServices.php
Normal file
285
pro_v3.5.1_副本/app/services/out/OutStoreOrderServices.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\out;
|
||||
|
||||
use app\dao\order\StoreOrderDao;
|
||||
use app\services\activity\combination\StorePinkServices;
|
||||
use app\services\order\StoreOrderCartInfoServices;
|
||||
use app\services\BaseServices;
|
||||
use app\services\pay\PayServices;
|
||||
use crmeb\exceptions\ApiException;
|
||||
use crmeb\services\HttpService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class OutStoreOrderServices
|
||||
* @package app\services\order
|
||||
* @method getOrderIdsCount(array $ids) 获取订单id下没有删除的订单数量
|
||||
* @method StoreOrderDao getUserOrderDetail(string $key, int $uid, array $with) 获取订单详情
|
||||
* @method chartTimePrice($start, $stop) 获取当前时间到指定时间的支付金额 管理员
|
||||
* @method chartTimeNumber($start, $stop) 获取当前时间到指定时间的支付订单数 管理员
|
||||
* @method together(array $where, string $field, string $together = 'sum') 聚合查询
|
||||
* @method getBuyCount($uid, $type, $typeId) 获取用户已购买此活动商品的个数
|
||||
* @method getDistinctCount(array $where, $field, ?bool $search = true)
|
||||
* @method getTrendData($time, $type, $timeType, $str) 用户趋势
|
||||
* @method getRegion($time, $channelType) 地域统计
|
||||
* @method getProductTrend($time, $timeType, $field, $str) 商品趋势
|
||||
*/
|
||||
class OutStoreOrderServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 发货类型
|
||||
* @var string[]
|
||||
*/
|
||||
public array $deliveryType = ['send' => '商家配送', 'express' => '快递配送', 'fictitious' => '虚拟发货', 'delivery_part_split' => '拆分部分发货', 'delivery_split' => '拆分发货完成'];
|
||||
|
||||
/**
|
||||
* @var StoreOrderDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreOrderDao $dao;
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOrderList(array $where)
|
||||
{
|
||||
if (!is_numeric($where['paid'])) {
|
||||
$where['paid'] = -1;
|
||||
}
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$field = ['id', 'pid', 'order_id', 'trade_no', 'uid', 'freight_price', 'real_name', 'user_phone', 'user_address', 'total_num',
|
||||
'total_price', 'total_postage', 'pay_price', 'coupon_price', 'deduction_price', 'paid', 'pay_time', 'pay_type', 'add_time',
|
||||
'shipping_type', 'status', 'refund_status', 'delivery_name', 'delivery_code', 'delivery_id'];
|
||||
$data = $this->dao->getOutOrderList($where, $field, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
$list = $this->tidyOrderList($data);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据转换
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function tidyOrderList(array $data)
|
||||
{
|
||||
/** @var StoreOrderCartInfoServices $services */
|
||||
$services = app()->make(StoreOrderCartInfoServices::class);
|
||||
foreach ($data as &$item) {
|
||||
$list = [];
|
||||
$carts = $services->getOrderCartInfo((int)$item['id']);
|
||||
foreach ($carts as $key => $cart) {
|
||||
$list = $this->tidyCartList($cart['cart_info'], $list, $key);
|
||||
}
|
||||
$item['pay_type_name'] = PayServices::PAY_TYPE[$item['pay_type']] ?? '其他方式';
|
||||
$item['items'] = $list;
|
||||
unset($item['refund_status'], $item['shipping_type']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单推送
|
||||
* @param int $id
|
||||
* @param string $pushUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function orderCreatePush(int $id, string $pushUrl): bool
|
||||
{
|
||||
$orderInfo = $this->getInfo('', $id);
|
||||
return $this->outPush($pushUrl, $orderInfo, '订单');
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付推送
|
||||
* @param int $id
|
||||
* @param string $pushUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function paySuccessPush(int $id, string $pushUrl): bool
|
||||
{
|
||||
$orderInfo = $this->getInfo('', $id);
|
||||
return $this->outPush($pushUrl, $orderInfo, '订单支付');
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认数据推送
|
||||
* @param string $pushUrl
|
||||
* @param array $data
|
||||
* @param string $tip
|
||||
* @return bool
|
||||
*/
|
||||
function outPush(string $pushUrl, array $data, string $tip = ''): bool
|
||||
{
|
||||
$param = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
|
||||
$res = $res ? json_decode($res, true) : [];
|
||||
if (!$res || !isset($res['code']) || $res['code'] != 0) {
|
||||
\think\facade\Log::error(
|
||||
json_encode( ['msg' => $tip . '推送失败', 'data' => $res], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @param string $orderId 订单号
|
||||
* @param int $id 订单ID
|
||||
* @return mixed
|
||||
*/
|
||||
public function getInfo(string $orderId = '', int $id = 0)
|
||||
{
|
||||
$field = ['id', 'pid', 'order_id', 'trade_no', 'uid', 'freight_price', 'real_name', 'user_phone', 'user_address', 'total_num',
|
||||
'total_price', 'total_postage', 'pay_price', 'coupon_price', 'deduction_price', 'paid', 'pay_time', 'pay_type', 'add_time',
|
||||
'shipping_type', 'status', 'refund_status', 'delivery_name', 'delivery_code', 'delivery_id', 'refund_type', 'delivery_type', 'pink_id', 'use_integral', 'back_integral'];
|
||||
|
||||
if ($id > 0) {
|
||||
$where = $id;
|
||||
} else {
|
||||
$where = ['order_id' => $orderId];
|
||||
}
|
||||
|
||||
if (!$orderInfo = $this->dao->get($where, $field, ['invoice'])) {
|
||||
throw new ApiException(400118);
|
||||
}
|
||||
|
||||
if (!$orderInfo['invoice']) {
|
||||
$orderInfo['invoice'] = new \StdClass();
|
||||
} else {
|
||||
$orderInfo['invoice']->hidden(['uid', 'category', 'id', 'order_id', 'add_time']);
|
||||
}
|
||||
|
||||
$orderInfo = $this->tidyOrder($orderInfo->toArray(), true);
|
||||
//核算优惠金额
|
||||
$vipTruePrice = array_column($orderInfo['items'], 'vip_sum_truePrice');
|
||||
$vipTruePrice = round(array_sum($vipTruePrice), 2);
|
||||
$orderInfo['vip_true_price'] = sprintf("%.2f", $vipTruePrice ?: '0.00');
|
||||
$orderInfo['total_price'] = bcadd($orderInfo['total_price'], $orderInfo['vip_true_price'], 2);
|
||||
return $orderInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情数据格式化
|
||||
* @param $order
|
||||
* @param bool $detail 是否需要订单商品详情
|
||||
* @return mixed
|
||||
*/
|
||||
public function tidyOrder($order, bool $detail = false)
|
||||
{
|
||||
if ($detail == true && isset($order['id'])) {
|
||||
/** @var StoreOrderCartInfoServices $cartServices */
|
||||
$cartServices = app()->make(StoreOrderCartInfoServices::class);
|
||||
$carts = $cartServices->getOrderCartInfo((int)$order['id']);
|
||||
|
||||
$list = [];
|
||||
foreach ($carts as $key => $cart) {
|
||||
$list = $this->tidyCartList($cart['cart_info'], $list, $key);
|
||||
}
|
||||
$order['items'] = $list;
|
||||
}
|
||||
|
||||
$order['pay_type_name'] = PayServices::PAY_TYPE[$order['pay_type']] ?? '其他方式';
|
||||
|
||||
if (!$order['paid'] && $order['pay_type'] == 'offline' && !$order['status'] >= 2) {
|
||||
$order['status_name'] = '线下付款,未支付';
|
||||
} else if (!$order['paid']) {
|
||||
$order['status_name'] = '待付款';
|
||||
} else if ($order['status'] == 4) {
|
||||
if ($order['delivery_type'] == 'send') {
|
||||
$order['status_name'] = '待收货';
|
||||
} elseif ($order['delivery_type'] == 'express') {
|
||||
$order['status_name'] = '待收货';
|
||||
} elseif ($order['delivery_type'] == 'split') {//拆分发货
|
||||
$order['status_name'] = '待收货';
|
||||
} else {
|
||||
$order['status_name'] = '待收货';
|
||||
}
|
||||
} else if ($order['refund_status'] == 1) {
|
||||
if (in_array($order['refund_type'], [0, 1, 2])) {
|
||||
$order['status_name'] = '申请退款中';
|
||||
} elseif ($order['refund_type'] == 4) {
|
||||
$order['status_name'] = '申请退款中';
|
||||
} elseif ($order['refund_type'] == 5) {
|
||||
$order['status_name'] = '申请退款中';
|
||||
}
|
||||
} else if ($order['refund_status'] == 2 || $order['refund_type'] == 6) {
|
||||
$order['status_name'] = '已退款';
|
||||
} else if ($order['refund_status'] == 3) {
|
||||
$order['status_name'] = '部分退款(子订单)';
|
||||
} else if ($order['refund_status'] == 4) {
|
||||
$order['status_name'] = '子订单已全部申请退款中';
|
||||
} else if (!$order['status']) {
|
||||
if ($order['pink_id']) {
|
||||
/** @var StorePinkServices $pinkServices */
|
||||
$pinkServices = app()->make(StorePinkServices::class);
|
||||
if ($pinkServices->getCount(['id' => $order['pink_id'], 'status' => 1])) {
|
||||
$order['status_name'] = '拼团中';
|
||||
} else {
|
||||
$order['status_name'] = '未发货';
|
||||
}
|
||||
} else {
|
||||
if ($order['shipping_type'] === 1) {
|
||||
$order['status_name'] = '未发货';
|
||||
} else {
|
||||
$order['status_name'] = '待核销';
|
||||
}
|
||||
}
|
||||
} else if ($order['status'] == 1) {
|
||||
if ($order['delivery_type'] == 'send') {//TODO 送货
|
||||
$order['status_name'] = '待收货';
|
||||
} elseif ($order['delivery_type'] == 'express') {//TODO 发货
|
||||
$order['status_name'] = '待收货';
|
||||
} elseif ($order['delivery_type'] == 'split') {//拆分发货
|
||||
$order['status_name'] = '待收货';
|
||||
} else {
|
||||
$order['status_name'] = '待收货';
|
||||
}
|
||||
} else if ($order['status'] == 2) {
|
||||
$order['status_name'] = '待评价';
|
||||
} else if ($order['status'] == 3) {
|
||||
$order['status_name'] = '交易完成';
|
||||
}
|
||||
unset($order['pink_id'], $order['refund_type']);
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化订单商品
|
||||
* @param array $cartInfo
|
||||
* @param array $list
|
||||
* @return array
|
||||
*/
|
||||
public function tidyCartList(array $cartInfo, array $list, $cartId = 0): array
|
||||
{
|
||||
$list[] = [
|
||||
'cart_id' => $cartId,
|
||||
'store_name' => $cartInfo['productInfo']['store_name'] ?? '',
|
||||
'suk' => $cartInfo['productInfo']['attrInfo']['suk'] ?? '',
|
||||
'image' => $cartInfo['productInfo']['attrInfo']['image'] ?: $cartInfo['productInfo']['image'],
|
||||
'price' => sprintf("%.2f", $cartInfo['truePrice'] ?? '0.00'),
|
||||
'cart_num' => $cartInfo['cart_num'] ?? 0,
|
||||
'surplus_num' => $cartInfo['surplus_num'] ?? 0,
|
||||
'refund_num' => $cartInfo['refund_num'] ?? 0
|
||||
];
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user