Files
douba_shop/app/services/order/StoreOrderStatusServices.php
Karlcarlo c9a98f342c chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
2026-03-06 20:14:23 +08:00

178 lines
6.8 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\services\order;
use app\dao\order\StoreOrderStatusDao;
use app\services\BaseServices;
use app\services\message\service\StoreServiceServices;
use app\services\store\SystemStoreStaffServices;
use app\services\system\admin\SystemAdminServices;
use app\services\user\UserServices;
use think\annotation\Inject;
use think\exception\ValidateException;
use think\facade\Log;
/**
* 订单状态
* Class StoreOrderStatusServices
* @package app\services\order
* @mixin StoreOrderStatusDao
*/
class StoreOrderStatusServices extends BaseServices
{
/**
* @var StoreOrderStatusDao
*/
#[Inject]
protected StoreOrderStatusDao $dao;
/**
* 订单状态分页
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStatusList(array $where)
{
$list = $this->dao->getStatusList($where);
foreach ($list as &$item) {
if (is_int($item['change_time'])) $item['change_time'] = date('Y-m-d H:i:s', $item['change_time']);
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 保存订单状态变更记录
* @param int $orderId 订单ID
* @param string $changeType 变更类型
* @param array $data 变更数据
* @param int $changeManagerId 操作人ID
* @param string $changeManagerType 操作人类型(user/admin/store/supplier/system)
* @return bool
*/
public function saveStatus(int $orderId, string $changeType = 'create', array $data = [], int $changeManagerId = 0, string $changeManagerType = 'user')
{
if (!$orderId || !$data) {
return true;
}
/** @var StoreOrderServices $orderService */
$orderService = app()->make(StoreOrderServices::class);
$orderInfo = $orderService->get($orderId);
if (!$orderInfo) {
return true;
}
$changeManagerId = !$changeManagerId && $changeManagerType == 'user' ? $orderInfo['uid'] : $changeManagerId;
$statusData = [
'oid' => $orderId,
'change_time' => time(),
'change_type' => $changeType,
'change_message' => $data['change_message'] ?? '',
'change_manager_type' => $changeManagerType,
'change_manager_id' => $changeManagerId
];
if ($changeManagerId) {
switch ($changeManagerType) {
case 'user':
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->getUserCacheInfo($changeManagerId);
if ($userInfo) {
$statusData['change_manager'] = $userInfo['nickname'] ?? '';
}
break;
case 'admin':
/** @var SystemAdminServices $adminServices */
$adminServices = app()->make(SystemAdminServices::class);
$adminInfo = $adminServices->get($changeManagerId);
if ($adminInfo) {
$statusData['change_manager'] = $adminInfo['real_name'] ?? 'system';
} else {
$statusData['change_manager'] = 'system';
}
break;
case 'store':
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->getUserCacheInfo($changeManagerId);
$statusData['change_manager'] = $userInfo['nickname'] ?? '';
break;
case 'supplier':
/** @var SystemAdminServices $systemAdminServices */
$systemAdminServices = app()->make(SystemAdminServices::class);
$supplierInfo = $systemAdminServices->get($changeManagerId);
if ($supplierInfo) {
$statusData['change_manager'] = $supplierInfo['real_name'] ?? '';
}
break;
case 'system':
$statusData['change_manager'] = '系统执行';
break;
default:
break;
}
}
$this->dao->save($statusData);
return true;
}
/**
* 保存订单记录
* @param $type
* @param $orderId
* @param $data
* @return bool
*/
public function saveStatusOld($type, $orderId, $data)
{
if (!$type || !$orderId) {
return true;
}
$statusData = ['oid' => $orderId, 'change_time' => time(), 'change_type' => ''];
switch ($type) {
case 'create'://创建
$statusData['change_type'] = 'cache_key_create_order';
$statusData['change_message'] = '订单生成';
if (isset($data['changePrice']) && $data['changePrice'] > 0) {//有改价
$this->saveStatus('edit', $orderId, $data);
}
break;
case 'edit'://改价
$statusData['change_type'] = 'order_edit';
$statusData['change_message'] = '商品总价为:' . ($data['totalPrice'] ?? 0) . ' 修改实际支付金额为:' . ($data['payPrice'] ?? 0);
break;
case 'pay'://支付
$statusData['change_type'] = 'pay_success';
$statusData['change_message'] = '用户付款成功';
break;
case 'delivery'://发货
break;
case 'take'://收货
break;
case 'reply'://评价
break;
default:
throw new ValidateException('未知订单类型记录');
break;
}
/** @var StoreOrderStatusServices $statusService */
$statusService = app()->make(StoreOrderStatusServices::class);
$statusService->save($statusData);
return true;
}
}