feat: 添加阿里云短信服务支持并优化验证码逻辑

- 引入 alibabacloud/dysmsapi-20170525 依赖,集成阿里云短信服务
- 将短信验证码从6位改为4位,优化用户体验
- 添加聚水潭商品按时间范围同步功能,支持分页拉取
- 增强Cron任务异常处理,添加错误日志记录
- 修复系统附件服务中图片路径处理逻辑
- 更新阿里云SDK相关组件至最新版本
- 添加think-trace调试扩展,便于问题排查
- 优化跨域中间件,使用str_contains替代strpos
This commit is contained in:
2026-04-30 15:19:40 +08:00
parent 0334fef6c1
commit c7f85ffbda
565 changed files with 59742 additions and 3391 deletions

View File

@@ -14,10 +14,14 @@ namespace app\services\other\export;
use app\model\product\stock\StockRecord;
use app\services\BaseServices;
use app\jobs\system\ExportExcelJob;
use app\model\order\StoreOrderRefund;
use app\model\order\StoreOrderStatus;
use app\services\order\StoreOrderServices;
use app\services\pay\PayServices;
use app\services\product\label\StoreProductLabelServices;
use app\services\product\product\StoreDescriptionServices;
use app\services\product\sku\StoreProductAttrResultServices;
use app\services\supplier\SystemSupplierServices;
use app\services\user\UserServices;
use crmeb\services\SpreadsheetExcelService;
@@ -729,9 +733,11 @@ class ExportServices extends BaseServices
$header = ['订单ID', '订单编号', '性别', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息', '商品总数',
'总价格', '实际支付', '邮费', '会员优惠金额', '优惠卷金额', '积分抵扣金额', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注'];
$header = [
'订单号', '订单类型', '订单状态', '下单时间', '买家姓名(uid)', '买家手机号', '收货地址', '商品名称', '商品数量', '商品金额合计', '邮费',
'会员优惠', '优惠券优惠', '积分抵扣', '活动优惠', '首单优惠', '改价优惠', '实付金额', '实付邮费', '支付方式',
'订单号', '订单类型', '订单状态', '下单时间', '买家姓名(uid)', '用户名称', '买家手机号', '收货地址',
'商品名称', '商品标签', 'SPU', '款式编码', '商品编号', '商品规格', '商品数量', '商品金额合计', '结算价', '商品来源',
'邮费', '会员优惠', '优惠券优惠', '积分抵扣', '活动优惠', '首单优惠', '改价优惠', '实付金额', '实付邮费', '支付方式',
'支付状态', '支付时间', '订单配送方式', '快递公司(单号)/送货人姓名(手机号)',
'退款状态', '退款金额', '分销员', '分销佣金', '订单发货时间',
// '售后状态', '售后类型', '售后件数', '退款金额', '退款时间', '退货备注'
];
$title = ['订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
@@ -744,6 +750,96 @@ class ExportServices extends BaseServices
$export = [];
$filekey = [];
if (!empty($data)) {
$userList = [];
$spreadList = [];
$orderStatusTime = [];
$refundCartMap = [];
$supplierList = [];
$labelNameMap = [];
if (!$type) {
$userServices = app()->make(UserServices::class);
$uids = array_values(array_unique(array_column($data, 'uid')));
$userList = $uids ? $userServices->getColumn([['uid', 'IN', $uids]], 'uid,nickname,spread_uid', 'uid') : [];
$spreadUids = $userList ? array_values(array_filter(array_unique(array_column($userList, 'spread_uid')))) : [];
$spreadList = $spreadUids ? $userServices->getColumn([['uid', 'IN', $spreadUids]], 'uid,nickname', 'uid') : [];
$orderIds = array_values(array_unique(array_column($data, 'id')));
$statusRows = StoreOrderStatus::whereIn('oid', $orderIds)
->whereIn('change_type', ['delivery', 'delivery_goods', 'delivery_part_split', 'delivery_split', 'delivery_fictitious'])
->field(['oid', 'change_type', 'change_time'])
->order('change_time desc')
->select()
->toArray();
foreach ($statusRows as $row) {
$oid = (int)$row['oid'];
$changeType = (string)$row['change_type'];
if (!isset($orderStatusTime[$oid][$changeType])) {
$orderStatusTime[$oid][$changeType] = (int)$row['change_time'];
}
}
$refundRows = StoreOrderRefund::whereIn('store_order_id', $orderIds)
->where('is_cancel', 0)
->where('is_del', 0)
->whereIn('refund_type', [0, 1, 2, 4, 5, 6])
->field(['store_order_id', 'refund_type', 'cart_info'])
->select()
->toArray();
foreach ($refundRows as $refund) {
$oid = (int)$refund['store_order_id'];
$refundType = (int)$refund['refund_type'];
$cartInfo = $refund['cart_info'] ?? [];
foreach ($cartInfo as $cart) {
$cartId = (int)($cart['id'] ?? 0);
$qty = (int)($cart['cart_num'] ?? 0);
if (!$cartId || !$qty) {
continue;
}
if (!isset($refundCartMap[$oid][$cartId])) {
$refundCartMap[$oid][$cartId] = ['refunding_qty' => 0, 'refunded_qty' => 0];
}
if ($refundType === 6) {
$refundCartMap[$oid][$cartId]['refunded_qty'] += $qty;
} else {
$refundCartMap[$oid][$cartId]['refunding_qty'] += $qty;
}
}
}
$supplierIds = [];
$labelIds = [];
foreach ($data as $o) {
foreach ($o['_info'] ?? [] as $cart) {
$productInfo = $cart['productInfo'] ?? [];
$supplierId = (int)($productInfo['supplier_id'] ?? 0);
if ($supplierId > 0) {
$supplierIds[$supplierId] = $supplierId;
} elseif ((int)($cart['_relation_type'] ?? 0) === 2 && (int)($cart['_relation_id'] ?? 0) > 0) {
$supplierId = (int)$cart['_relation_id'];
$supplierIds[$supplierId] = $supplierId;
}
$storeLabelId = $productInfo['store_label_id'] ?? [];
$storeLabelId = is_string($storeLabelId) ? array_map('intval', array_filter(explode(',', $storeLabelId))) : (is_array($storeLabelId) ? $storeLabelId : []);
foreach ($storeLabelId as $lid) {
$lid = (int)$lid;
if ($lid > 0) {
$labelIds[$lid] = $lid;
}
}
}
}
$supplierService = app()->make(SystemSupplierServices::class);
$supplierList = $supplierIds ? $supplierService->getColumn([['id', 'IN', array_values($supplierIds)]], 'id,supplier_name', 'id') : [];
$labelService = app()->make(StoreProductLabelServices::class);
$labelList = $labelIds ? $labelService->getLabelCache(array_values($labelIds), ['id', 'label_name'], false) : [];
foreach ($labelList as $label) {
if (isset($label['id'])) {
$labelNameMap[(int)$label['id']] = (string)($label['label_name'] ?? '');
}
}
}
$i = 0;
foreach ($data as $item) {
if (!$type) {
@@ -805,24 +901,9 @@ class ExportServices extends BaseServices
} else if ($item['paid'] == 1 && $item['refund_status'] == 3) {
$item['status_name'] = '部分退款';
}
$goodsName = [];
$vip_sum_price = 0;
foreach ($item['_info'] as $k => $v) {
$suk = '';
if (isset($v['productInfo']['attrInfo'])) {
if (isset($v['productInfo']['attrInfo']['suk'])) {
$suk = '(' . $v['productInfo']['attrInfo']['suk'] . ')';
}
}
if (isset($v['productInfo']['store_name'])) {
$goodsName[] = implode(' ',
[
$v['productInfo']['store_name'],
$suk,
"[{$v['cart_num']} * {$v['truePrice']}]",
]);
}
$vip_sum_price = bcadd((string)$vip_sum_price, bcmul($v['vip_truePrice'], $v['cart_num'] ? $v['cart_num'] : 1, 4), 2);
foreach ($item['_info'] as $v) {
$vip_sum_price = bcadd((string)$vip_sum_price, bcmul((string)($v['vip_truePrice'] ?? 0), (string)($v['cart_num'] ? $v['cart_num'] : 1), 4), 2);
}
// if ($item['sex'] == 1) $sex_name = '男';
// else if ($item['sex'] == 2) $sex_name = '女';
@@ -856,32 +937,134 @@ class ExportServices extends BaseServices
'send' => '配送',
default => '暂无',
};
$one_data = [
'order_id' => $item['order_id'],
'order_type' => $item['pink_name'] ?? '普通订单',
'status_name' => $item['status_name'] ?? '未知状态',
'add_time' => empty($item['add_time']) ? '' : date('Y-m-d H:i:s', (int)$item['add_time']),
'real_name' => $item['real_name'] . '(' . $item['uid'] . ')',
'user_phone' => $item['user_phone'],
'user_address' => $item['user_address'],
'goods_name' => $goodsName ? implode("\n", $goodsName) : '',
'total_num' => $item['total_num'],
'total_price' => $item['total_price'],
'total_postage' => $item['total_postage'],
'vip_sum_price' => $vip_sum_price,
'coupon_price' => $item['coupon_price'],
'deduction_price' => $item['deduction_price'] ?? 0,
'promotions_price' => $item['promotions_price'] ?? 0,
'first_order_price' => $item['first_order_price'] ?? 0,
'change_price' => $item['change_price'] ?? 0,
'pay_price' => $item['pay_price'],
'pay_postage' => $item['pay_postage'],
'pay_type_name' => $item['pay_type_name'],
'pay_status' => $item['paid'] ? '已支付' : '未支付',
'pay_time' => empty($item['pay_time']) ? '' : date('Y-m-d H:i:s', (int)$item['pay_time']),
'delivery_type' => $delivery_type,
'delivery_info' => $item['delivery_name'] . '(' . $item['delivery_id'] . ')',
];
$orderLevelDeliveryTime = '';
$oid = (int)$item['id'];
$timeMap = $orderStatusTime[$oid] ?? [];
$deliveryTime = $timeMap['delivery'] ?? ($timeMap['delivery_goods'] ?? ($timeMap['delivery_part_split'] ?? ($timeMap['delivery_split'] ?? ($timeMap['delivery_fictitious'] ?? 0))));
if ($deliveryTime) {
$orderLevelDeliveryTime = date('Y-m-d H:i:s', $deliveryTime);
}
$currentUser = $userList[(int)$item['uid']] ?? [];
$userNickname = (string)($currentUser['nickname'] ?? '');
$spreadUid = (int)($currentUser['spread_uid'] ?? 0);
$spreadNickname = $spreadUid ? (string)($spreadList[$spreadUid]['nickname'] ?? '') : '';
if ($spreadUid && $spreadUid === (int)$item['uid'] && $spreadNickname !== '') {
$spreadNickname .= '(自购)';
}
foreach ($item['_info'] as $v) {
$productInfo = $v['productInfo'] ?? [];
$attrInfo = $productInfo['attrInfo'] ?? [];
$storeName = (string)($productInfo['store_name'] ?? '');
$suk = (string)($attrInfo['suk'] ?? '');
$productLabelNames = [];
if (!empty($productInfo['store_label']) && is_array($productInfo['store_label'])) {
foreach ($productInfo['store_label'] as $label) {
$name = (string)($label['label_name'] ?? ($label['label'] ?? ''));
if ($name !== '') {
$productLabelNames[] = $name;
}
}
} else {
$storeLabelId = $productInfo['store_label_id'] ?? [];
$storeLabelId = is_string($storeLabelId) ? array_map('intval', array_filter(explode(',', $storeLabelId))) : (is_array($storeLabelId) ? $storeLabelId : []);
foreach ($storeLabelId as $lid) {
$name = $labelNameMap[(int)$lid] ?? '';
if ($name !== '') {
$productLabelNames[] = $name;
}
}
}
$productLabelText = $productLabelNames ? implode(',', array_values(array_unique($productLabelNames))) : '';
$supplierId = (int)($productInfo['supplier_id'] ?? 0);
if (!$supplierId && (int)($v['_relation_type'] ?? 0) === 2) {
$supplierId = (int)($v['_relation_id'] ?? 0);
}
$productSource = $supplierId ? (string)($supplierList[$supplierId]['supplier_name'] ?? '') : '平台';
$cartId = (int)($v['cart_id'] ?? 0);
$refundedQty = (int)($refundCartMap[$oid][$cartId]['refunded_qty'] ?? 0);
$refundingQty = (int)($refundCartMap[$oid][$cartId]['refunding_qty'] ?? 0);
$refundQty = $refundedQty + $refundingQty;
$cartNum = (int)($v['cart_num'] ?? 0);
$truePrice = (string)($v['truePrice'] ?? 0);
$productAmount = bcmul($truePrice, (string)$cartNum, 2);
$refundStatus = '';
if ($refundQty > 0) {
if ($refundingQty > 0) {
$refundStatus = '退款中';
} else {
$refundStatus = $refundQty >= $cartNum ? '退款成功(全额退款)' : '退款成功(部分退款)';
}
}
$refundAmount = $refundQty > 0 ? bcmul($truePrice, (string)$refundQty, 2) : '';
$settlePrice = (string)($attrInfo['settle_price'] ?? 0);
$oneBrokerage = $v['one_brokerage'] ?? null;
if ($oneBrokerage === null) {
$oneBrokerage = bcmul((string)($attrInfo['brokerage'] ?? 0), (string)$cartNum, 2);
}
$twoBrokerage = $v['two_brokerage'] ?? null;
if ($twoBrokerage === null) {
$twoBrokerage = bcmul((string)($attrInfo['brokerage_two'] ?? 0), (string)$cartNum, 2);
}
$commission = bcadd((string)$oneBrokerage, (string)$twoBrokerage, 2);
$one_data = [
'order_id' => $item['order_id'],
'order_type' => $item['pink_name'] ?? '普通订单',
'status_name' => $item['status_name'] ?? '未知状态',
'add_time' => empty($item['add_time']) ? '' : date('Y-m-d H:i:s', (int)$item['add_time']),
'real_name' => $item['real_name'] . '(' . $item['uid'] . ')',
'user_nickname' => $userNickname,
'user_phone' => $item['user_phone'],
'user_address' => $item['user_address'],
'goods_name' => $storeName,
'goods_label' => $productLabelText,
'spu' => (string)($productInfo['spu'] ?? ''),
'style_code' => (string)($productInfo['code'] ?? ''),
'sku_code' => (string)($attrInfo['code'] ?? ''),
'goods_suk' => $suk,
'cart_num' => $cartNum,
'product_amount' => $productAmount,
'settle_price' => $settlePrice,
'product_source' => $productSource,
'total_postage' => $item['total_postage'],
'vip_sum_price' => $vip_sum_price,
'coupon_price' => $item['coupon_price'],
'deduction_price' => $item['deduction_price'] ?? 0,
'promotions_price' => $item['promotions_price'] ?? 0,
'first_order_price' => $item['first_order_price'] ?? 0,
'change_price' => $item['change_price'] ?? 0,
'pay_price' => $item['pay_price'],
'pay_postage' => $item['pay_postage'],
'pay_type_name' => $item['pay_type_name'],
'pay_status' => $item['paid'] ? '已支付' : '未支付',
'pay_time' => empty($item['pay_time']) ? '' : date('Y-m-d H:i:s', (int)$item['pay_time']),
'delivery_type' => $delivery_type,
'delivery_info' => $item['delivery_name'] . '(' . $item['delivery_id'] . ')',
'refund_status' => $refundStatus,
'refund_amount' => $refundAmount,
'spread_nickname' => $spreadNickname,
'spread_commission' => $commission,
'delivery_time' => $orderLevelDeliveryTime,
];
if ($export_type == 1) {
$export[] = $one_data;
if ($i == 0) {
$filekey = array_keys($one_data);
}
} else {
$export[] = array_values($one_data);
}
$i++;
}
} else {
if (isset($item['pinkStatus']) && $item['pinkStatus'] != 2) {
continue;
@@ -937,15 +1120,17 @@ class ExportServices extends BaseServices
'pay_time' => $item['pay_time'] ? date('Y-m-d H:i:s', (int)$item['pay_time']) : '暂无',
];
}
if ($export_type == 1) {
$export[] = $one_data;
if ($i == 0) {
$filekey = array_keys($one_data);
if ($type) {
if ($export_type == 1) {
$export[] = $one_data;
if ($i == 0) {
$filekey = array_keys($one_data);
}
} else {
$export[] = array_values($one_data);
}
} else {
$export[] = array_values($one_data);
$i++;
}
$i++;
}
}
if ($export_type == 1) {