feat: 添加阿里云短信服务支持并优化验证码逻辑
- 引入 alibabacloud/dysmsapi-20170525 依赖,集成阿里云短信服务 - 将短信验证码从6位改为4位,优化用户体验 - 添加聚水潭商品按时间范围同步功能,支持分页拉取 - 增强Cron任务异常处理,添加错误日志记录 - 修复系统附件服务中图片路径处理逻辑 - 更新阿里云SDK相关组件至最新版本 - 添加think-trace调试扩展,便于问题排查 - 优化跨域中间件,使用str_contains替代strpos
This commit is contained in:
@@ -135,6 +135,12 @@ class HaichaoJstServices extends HaichaoBridge
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::info('jst.orders_upload.request ' . json_encode([
|
||||
'api' => 'open/jushuitan/orders/upload',
|
||||
'oid' => $oid,
|
||||
'shop_status' => $status,
|
||||
'biz' => $biz,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
$num = 3;
|
||||
for ($i = $num; $i >= 0; $i--) {
|
||||
if ($i <= 0) {
|
||||
@@ -652,6 +658,26 @@ class HaichaoJstServices extends HaichaoBridge
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按时间范围获取聚水潭商品列表
|
||||
* @param string $startTime 开始时间 Y-m-d H:i:s
|
||||
* @param string $endTime 结束时间 Y-m-d H:i:s
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页数量
|
||||
* @return array
|
||||
*/
|
||||
public function getProductListByTime(string $startTime, string $endTime, int $pageIndex = 1, int $pageSize = 50): array
|
||||
{
|
||||
$data = $this->post('open/mall/item/query', [
|
||||
'modified_begin' => $startTime,
|
||||
'modified_end' => $endTime,
|
||||
'page_index' => $pageIndex,
|
||||
'page_size' => $pageSize,
|
||||
'date_field' => '',
|
||||
])['data'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProductListStand(): array
|
||||
{
|
||||
$time = 10;
|
||||
@@ -704,6 +730,94 @@ class HaichaoJstServices extends HaichaoBridge
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function uploadItemSku(array $items): array
|
||||
{
|
||||
return $this->post('open/jushuitan/itemsku/upload', [
|
||||
'items' => $items,
|
||||
]);
|
||||
}
|
||||
|
||||
public function uploadItemSkuByProductIds(array $productIds): array
|
||||
{
|
||||
$productIds = array_values(array_unique(array_map('intval', $productIds)));
|
||||
if (!$productIds) {
|
||||
throw new ValidateException('请选择商品');
|
||||
}
|
||||
|
||||
$products = \app\model\product\product\StoreProduct::whereIn('id', $productIds)
|
||||
->where('is_del', 0)
|
||||
->with(['attrValue'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$items = [];
|
||||
$errors = [];
|
||||
foreach ($products as $product) {
|
||||
$iId = trim((string)($product['code'] ?? ''));
|
||||
$productId = (int)($product['id'] ?? 0);
|
||||
if (!$iId) {
|
||||
$errors[] = [
|
||||
'product_id' => $productId,
|
||||
'msg' => '商品编码(code)为空',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$skuList = $product['attr_value'] ?? ($product['attrValue'] ?? []);
|
||||
if (!is_array($skuList) || !$skuList) {
|
||||
$errors[] = [
|
||||
'product_id' => $productId,
|
||||
'i_id' => $iId,
|
||||
'msg' => '商品规格为空',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$productImage = (string)($product['image'] ?? '');
|
||||
$productName = (string)($product['store_name'] ?? '');
|
||||
$enabled = ((int)($product['is_show'] ?? 0) === 1) ? 1 : -1;
|
||||
foreach ($skuList as $sku) {
|
||||
$skuId = trim((string)($sku['code'] ?? ''));
|
||||
if (!$skuId) {
|
||||
$errors[] = [
|
||||
'product_id' => $productId,
|
||||
'i_id' => $iId,
|
||||
'msg' => '规格编码(code)为空',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$skuImage = (string)($sku['image'] ?? $productImage);
|
||||
$propertiesValue = (string)($sku['suk'] ?? '');
|
||||
$propertiesValue = str_replace(',', ';', $propertiesValue);
|
||||
|
||||
$items[] = [
|
||||
'i_id' => $iId,
|
||||
'sku_id' => $skuId,
|
||||
'name' => $productName,
|
||||
'properties_value' => $propertiesValue,
|
||||
's_price' => (float)($sku['price'] ?? ($product['price'] ?? 0)),
|
||||
'market_price' => (float)($sku['ot_price'] ?? ($product['ot_price'] ?? 0)),
|
||||
'c_price' => (float)($sku['cost'] ?? ($product['cost'] ?? 0)),
|
||||
'pic' => $productImage,
|
||||
'pic_big' => $productImage,
|
||||
'sku_pic' => $skuImage,
|
||||
'enabled' => $enabled,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$items) {
|
||||
throw new ValidateException('没有可同步的商品规格');
|
||||
}
|
||||
|
||||
$rt = $this->uploadItemSku($items);
|
||||
return [
|
||||
'upload_count' => count($items),
|
||||
'errors' => $errors,
|
||||
'jst' => $rt,
|
||||
];
|
||||
}
|
||||
|
||||
public function getStork(string $ids): array
|
||||
{
|
||||
return $this->post('open/inventory/query', [
|
||||
@@ -758,28 +872,42 @@ class HaichaoJstServices extends HaichaoBridge
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getInneropenStockAndDetailList($styleCodes): array
|
||||
public function getInneropenStockAndDetailList(array|string $styleCodes, ?array &$stats = null): array
|
||||
{
|
||||
$rt = [];
|
||||
$i = 1;
|
||||
do {
|
||||
$result = $this->post('open/inventory/query', [
|
||||
'page_index' => $i++,
|
||||
'page_size' => 100,
|
||||
'sku_ids' => $styleCodes
|
||||
])['data']['inventorys'] ?? [];
|
||||
|
||||
// 适配原来的返回格式结构
|
||||
$formatResult = [];
|
||||
foreach ($result as $item) {
|
||||
$formatResult[] = [
|
||||
'item_code' => $item['sku_id'],
|
||||
'stock' => max(0, ($item['qty'] ?? 0) - ($item['order_lock'] ?? 0)) // 实际可用库存
|
||||
];
|
||||
$codeList = is_array($styleCodes) ? $styleCodes : explode(',', trim($styleCodes, ", \t\n\r\0\x0B"));
|
||||
$codeList = array_values(array_filter(array_map('trim', $codeList), static fn($v) => $v !== ''));
|
||||
|
||||
foreach (array_chunk($codeList, 100) as $chunkCodes) {
|
||||
if ($stats !== null) {
|
||||
$stats['chunk_count'] = (int)($stats['chunk_count'] ?? 0) + 1;
|
||||
$stats['request_sku_count'] = (int)($stats['request_sku_count'] ?? 0) + count($chunkCodes);
|
||||
}
|
||||
$rt = array_merge($formatResult, $rt);
|
||||
usleep(550);
|
||||
} while (count($result) == 100);
|
||||
$i = 1;
|
||||
do {
|
||||
if ($stats !== null) {
|
||||
$stats['api_call_count'] = (int)($stats['api_call_count'] ?? 0) + 1;
|
||||
}
|
||||
$result = $this->post('open/inventory/query', [
|
||||
'page_index' => $i++,
|
||||
'page_size' => 100,
|
||||
'sku_ids' => implode(',', $chunkCodes)
|
||||
])['data']['inventorys'] ?? [];
|
||||
if ($stats !== null) {
|
||||
$stats['api_resp_row_count'] = (int)($stats['api_resp_row_count'] ?? 0) + count($result);
|
||||
}
|
||||
|
||||
$formatResult = [];
|
||||
foreach ($result as $item) {
|
||||
$formatResult[] = [
|
||||
'item_code' => $item['sku_id'],
|
||||
'stock' => max(0, ($item['qty'] ?? 0) - ($item['order_lock'] ?? 0))
|
||||
];
|
||||
}
|
||||
$rt = array_merge($formatResult, $rt);
|
||||
usleep(550000);
|
||||
} while (count($result) == 100);
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user