|
|
@@ -48,8 +48,7 @@ $defaultProductIds = [27286, 27282];
|
|
|
|
|
|
$commonHeaders = [
|
|
|
'Connection: keep-alive',
|
|
|
- 'account: 12362',
|
|
|
- 'content-type: application/x-www-form-urlencoded;charset=UTF-8',
|
|
|
+ 'content-type: application/json;charset=UTF-8',
|
|
|
'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0.1 Mobile/21A360 Safari/604.1 wechatdevtools/2.01.2510260 MicroMessenger/8.0.5 Language/zh_CN webview/ hash/1237023557 sid/o7x10OLPfZ',
|
|
|
'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfOTMyIn0.eyJpc3MiOiJodHRwczpcL1wvYXBpLnNob3AuaHpnaGQuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5zaG9wLmh6Z2hkLmNvbSIsImp0aSI6IjBfOTMyIiwiaWF0IjoxNzc5Mjc1MzgxLCJuYmYiOjE3NzkyNzUzODEsImV4cCI6MTg3Mzg4MzM4MSwidW5pcXVlSWQiOjkzMiwic291cmNlSWQiOjB9.OVuQTjXMvklAFnYdIIRGVR2D5VK14Dp6QX5bDQAUHyE',
|
|
|
'appVersion: 2',
|
|
|
@@ -63,8 +62,7 @@ $commonHeaders = [
|
|
|
|
|
|
$hdHeaders = [
|
|
|
'Connection: keep-alive',
|
|
|
- 'account: 12362',
|
|
|
- 'content-type: application/x-www-form-urlencoded;charset=UTF-8',
|
|
|
+ 'content-type: application/json;charset=UTF-8',
|
|
|
'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/2.01.2510260 MicroMessenger/8.0.5 Language/zh_CN webview/ hash/1009552471 sid/xxB6sCFvvu',
|
|
|
'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfMTM5MSJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLnNob3AuaHVhbWwuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5zaG9wLmh1YW1sLmNvbSIsImp0aSI6IjBfMTM5MSIsImlhdCI6MTc4MDAzNzMxMSwibmJmIjoxNzgwMDM3MzExLCJleHAiOjE4NzQ2NDUzMTEsInVuaXF1ZUlkIjoiMTM5MSIsInNvdXJjZUlkIjowfQ.BgiDsxOd9cktOLsDe8Ud_hcFqzmVwSzKjCVwUdrSXKw',
|
|
|
'appVersion: 2',
|
|
|
@@ -76,16 +74,126 @@ $hdHeaders = [
|
|
|
'Accept-Language: zh-CN,zh;q=0.9',
|
|
|
];
|
|
|
|
|
|
-$orderBody = 'shopId=12986&shopName=&sendType=0&transType=4&sendDate=&sendTimeWant=&historyDate=&sendCost=&customSendCost=0&customId=914&packCost=&product=%5B%7B%22productId%22%3A%2227286%22%2C%22bigNum%22%3A2%2C%22smallNum%22%3A0%2C%22classId%22%3A%223322%22%2C%22itemId%22%3A%221009%22%2C%22price%22%3A%2227.00%22%2C%22remark%22%3A%22%22%7D%2C%7B%22productId%22%3A%2227282%22%2C%22bigNum%22%3A2%2C%22smallNum%22%3A0%2C%22classId%22%3A%223322%22%2C%22itemId%22%3A%221005%22%2C%22price%22%3A%220.30%22%2C%22remark%22%3A%22%22%7D%5D&remark=&payWay=0&needPrint=1&hasPay=2&getStaffId=0&getStaffName=&dealPrice=0&wlName=&reductionRule=0&callErrand=0&weight=1&deliveryRemark=&customName=%E5%BE%AE%E5%8D%87%E6%BC%AB%E8%8A%B1&modifyPrice=54.6&newVersion=1&book=0&xj=%22%22&treeData=%22%22';
|
|
|
-$stockOutBody = 'confirmIn=1&date=2026-05-25&remark=123&inShopId=37043&itemInfo=%5B%7B%22productId%22%3A%2227286%22%2C%22bigNum%22%3A1%2C%22smallNum%22%3A0%2C%22name%22%3A%22%E8%8B%8F%E9%86%92%22%7D%2C%7B%22productId%22%3A%2227282%22%2C%22bigNum%22%3A1%2C%22smallNum%22%3A0%2C%22name%22%3A%22%E6%B4%9B%E7%A5%9E%22%7D%5D&action=confirm';
|
|
|
-$hdPurchaseBody = 'getType=2&sendTimeWant=&sendType=0&transType=4&remark=&product=%5B%7B%22productId%22%3A%2227286%22%2C%22bigNum%22%3A1%2C%22smallNum%22%3A0%2C%22classId%22%3A%223322%22%2C%22itemId%22%3A%221009%22%2C%22weight%22%3A%221.20%22%2C%22name%22%3A%22%E8%8B%8F%E9%86%92%22%7D%5D&ghsId=932&hbId=0&wlName=&xj=%22%22&itemTotalAmount=27&version=10&direct=0';
|
|
|
-$wastageBody = http_build_query([
|
|
|
- 'remark' => 'concurrency-test',
|
|
|
- 'product' => json_encode([
|
|
|
- ['productId' => '27286', 'bigNum' => 1, 'smallNum' => 0, 'classId' => '3322', 'itemId' => '1009'],
|
|
|
- ['productId' => '27282', 'bigNum' => 1, 'smallNum' => 0, 'classId' => '3322', 'itemId' => '1005'],
|
|
|
- ], JSON_UNESCAPED_UNICODE),
|
|
|
-]);
|
|
|
+$orderBody = '{
|
|
|
+ "shopId": "12986",
|
|
|
+ "shopName": "",
|
|
|
+ "sendType": "0",
|
|
|
+ "transType": "4",
|
|
|
+ "sendDate": "",
|
|
|
+ "sendTimeWant": "",
|
|
|
+ "historyDate": "",
|
|
|
+ "sendCost": "",
|
|
|
+ "customSendCost": "0",
|
|
|
+ "customId": "914",
|
|
|
+ "packCost": "",
|
|
|
+ "product": [
|
|
|
+ {
|
|
|
+ "productId": "27286",
|
|
|
+ "bigNum": 2,
|
|
|
+ "smallNum": 0,
|
|
|
+ "classId": "3322",
|
|
|
+ "itemId": "1009",
|
|
|
+ "price": "27.00",
|
|
|
+ "remark": ""
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "productId": "27282",
|
|
|
+ "bigNum": 2,
|
|
|
+ "smallNum": 0,
|
|
|
+ "classId": "3322",
|
|
|
+ "itemId": "1005",
|
|
|
+ "price": "0.30",
|
|
|
+ "remark": ""
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "remark": "",
|
|
|
+ "payWay": "0",
|
|
|
+ "needPrint": "1",
|
|
|
+ "hasPay": "2",
|
|
|
+ "getStaffId": "0",
|
|
|
+ "getStaffName": "",
|
|
|
+ "dealPrice": "0",
|
|
|
+ "wlName": "",
|
|
|
+ "reductionRule": "0",
|
|
|
+ "callErrand": "0",
|
|
|
+ "weight": "1",
|
|
|
+ "deliveryRemark": "",
|
|
|
+ "customName": "微升漫花",
|
|
|
+ "modifyPrice": "54.6",
|
|
|
+ "newVersion": "1",
|
|
|
+ "book": "0",
|
|
|
+ "xj": "\"\"",
|
|
|
+ "treeData": "\"\""
|
|
|
+}';
|
|
|
+$stockOutBody = '{
|
|
|
+ "confirmIn": "1",
|
|
|
+ "date": "2026-05-25",
|
|
|
+ "remark": "123",
|
|
|
+ "inShopId": "37043",
|
|
|
+ "itemInfo": [
|
|
|
+ {
|
|
|
+ "productId": "27286",
|
|
|
+ "bigNum": 1,
|
|
|
+ "smallNum": 0,
|
|
|
+ "name": "苏醒"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "productId": "27282",
|
|
|
+ "bigNum": 1,
|
|
|
+ "smallNum": 0,
|
|
|
+ "name": "洛神"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "action": "confirm"
|
|
|
+}';
|
|
|
+$hdPurchaseBody = '{
|
|
|
+ "getType": "2",
|
|
|
+ "sendTimeWant": "",
|
|
|
+ "sendType": "0",
|
|
|
+ "transType": "4",
|
|
|
+ "remark": "",
|
|
|
+ "product": [
|
|
|
+ {
|
|
|
+ "productId": "27286",
|
|
|
+ "bigNum": 1,
|
|
|
+ "smallNum": 0,
|
|
|
+ "classId": "3322",
|
|
|
+ "itemId": "1009",
|
|
|
+ "weight": "1.20",
|
|
|
+ "name": "苏醒"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "ghsId": "932",
|
|
|
+ "hbId": "0",
|
|
|
+ "wlName": "",
|
|
|
+ "xj": "\"\"",
|
|
|
+ "itemTotalAmount": "27",
|
|
|
+ "version": "10",
|
|
|
+ "direct": "0"
|
|
|
+}';
|
|
|
+$wastageBody = '{
|
|
|
+ "remark": "concurrency-test",
|
|
|
+ "product": [
|
|
|
+ {
|
|
|
+ "productId": "27286",
|
|
|
+ "bigNum": 1,
|
|
|
+ "smallNum": 0,
|
|
|
+ "classId": "3322",
|
|
|
+ "itemId": "1009"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "productId": "27282",
|
|
|
+ "bigNum": 1,
|
|
|
+ "smallNum": 0,
|
|
|
+ "classId": "3322",
|
|
|
+ "itemId": "1005"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}';
|
|
|
+$orderBody = jsonBodyToJsonRequestBody($orderBody, ['product', 'xj', 'treeData']);
|
|
|
+$stockOutBody = jsonBodyToJsonRequestBody($stockOutBody, ['itemInfo']);
|
|
|
+$hdPurchaseBody = jsonBodyToJsonRequestBody($hdPurchaseBody, ['product', 'xj']);
|
|
|
+$wastageBody = jsonBodyToJsonRequestBody($wastageBody, ['product']);
|
|
|
|
|
|
$requestDefs = [
|
|
|
'order' => [
|
|
|
@@ -245,6 +353,27 @@ function normalizeNonNegativeInt($options, $key, $default)
|
|
|
return $value;
|
|
|
}
|
|
|
|
|
|
+function jsonBodyToJsonRequestBody($jsonBody, $jsonStringFields)
|
|
|
+{
|
|
|
+ $params = json_decode($jsonBody, true);
|
|
|
+ if (!is_array($params)) {
|
|
|
+ throw new RuntimeException('Invalid JSON request body: ' . json_last_error_msg());
|
|
|
+ }
|
|
|
+
|
|
|
+ return encodeJsonRequestBody($params, $jsonStringFields);
|
|
|
+}
|
|
|
+
|
|
|
+function encodeJsonRequestBody($params, $jsonStringFields)
|
|
|
+{
|
|
|
+ foreach ($jsonStringFields as $field) {
|
|
|
+ if (isset($params[$field]) && is_array($params[$field])) {
|
|
|
+ $params[$field] = json_encode($params[$field], JSON_UNESCAPED_UNICODE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
|
+}
|
|
|
+
|
|
|
function loadStocks($productIds)
|
|
|
{
|
|
|
$rows = Yii::$app->db->createCommand(
|
|
|
@@ -355,9 +484,18 @@ function collectProductIds($requestDefs, $defaultProductIds)
|
|
|
|
|
|
function refreshOrderBodyPrices($orderBody, &$summary)
|
|
|
{
|
|
|
- parse_str($orderBody, $params);
|
|
|
+ $isJsonBody = false;
|
|
|
+ $params = json_decode($orderBody, true);
|
|
|
+ if (is_array($params)) {
|
|
|
+ $isJsonBody = true;
|
|
|
+ } else {
|
|
|
+ parse_str($orderBody, $params);
|
|
|
+ }
|
|
|
+
|
|
|
$customId = isset($params['customId']) ? intval($params['customId']) : 0;
|
|
|
- $products = isset($params['product']) ? json_decode($params['product'], true) : [];
|
|
|
+ $products = isset($params['product']) && is_array($params['product'])
|
|
|
+ ? $params['product']
|
|
|
+ : (isset($params['product']) ? json_decode($params['product'], true) : []);
|
|
|
if (empty($customId) || empty($products) || !is_array($products)) {
|
|
|
$summary = 'keep original prices';
|
|
|
return $orderBody;
|
|
|
@@ -416,6 +554,9 @@ function refreshOrderBodyPrices($orderBody, &$summary)
|
|
|
$params['product'] = json_encode($products, JSON_UNESCAPED_UNICODE);
|
|
|
$params['modifyPrice'] = $modifyPrice;
|
|
|
$summary = implode('; ', $parts) . '; modifyPrice=' . $modifyPrice;
|
|
|
+ if ($isJsonBody) {
|
|
|
+ return encodeJsonRequestBody($params, ['product', 'xj', 'treeData']);
|
|
|
+ }
|
|
|
return http_build_query($params);
|
|
|
}
|
|
|
|