|
|
@@ -15,7 +15,41 @@ class LiveOrderClass extends BaseClass
|
|
|
|
|
|
public static function updateCustom($customData, $live)
|
|
|
{
|
|
|
- print_r($customData);
|
|
|
+ $orderSn = $live->orderSn ?? '';
|
|
|
+ $mainId = $live->mainId ?? 0;
|
|
|
+ $customMap = [];
|
|
|
+ $ids = [];
|
|
|
+ foreach ($customData as $key => $val) {
|
|
|
+ $customId = $val['customId'] ?? 0;
|
|
|
+ $customMap[$customId] = $val;
|
|
|
+ $ids[] = $customId;
|
|
|
+ }
|
|
|
+ $currentList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
+ if (!empty($currentList)) {
|
|
|
+ foreach ($currentList as $current) {
|
|
|
+ if ($current->ownMainId != $mainId) {
|
|
|
+ util::fail('不是你的客户');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (empty($customList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $totalNum = 0;
|
|
|
+ foreach ($customList as $k => $info) {
|
|
|
+ $customId = $info->customId ?? 0;
|
|
|
+ $num = isset($customMap[$customId]) && isset($customMap[$customId]['num']) ? $customMap[$customId]['num'] : 0;
|
|
|
+ $unitPrice = isset($customMap[$customId]) && isset($customMap[$customId]['unitPrice']) ? $customMap[$customId]['unitPrice'] : 0;
|
|
|
+ $price = bcmul($num, $unitPrice, 2);
|
|
|
+ $info->num = $num;
|
|
|
+ $info->unitPrice = $unitPrice;
|
|
|
+ $info->price = $price;
|
|
|
+ $info->save();
|
|
|
+ $totalNum = bcadd($totalNum, $num);
|
|
|
+ }
|
|
|
+ $live->itemNum = $totalNum;
|
|
|
+ $live->save();
|
|
|
}
|
|
|
|
|
|
public static function delCustom($custom, $live)
|