|
|
@@ -105,17 +105,84 @@ class OrderClass extends BaseClass
|
|
|
|
|
|
public static function arrival($order, $data)
|
|
|
{
|
|
|
- //product [{"productId":"3674","num":0,"price":1}]
|
|
|
+ if ($order->stockChange == 1) {
|
|
|
+ util::fail('重复操作');
|
|
|
+ }
|
|
|
$product = $data['product'] ?? '';
|
|
|
if (empty($product)) {
|
|
|
- util::fail('请填写成本价和到货数量');
|
|
|
+ util::fail('没有花材?');
|
|
|
}
|
|
|
- $product = json_decode($product, true);
|
|
|
- if (empty($product)) {
|
|
|
- util::fail('没有填写成本价和到货数量');
|
|
|
+ $ids = [];
|
|
|
+ $format = [];
|
|
|
+ foreach ($product as $val) {
|
|
|
+ $productId = $val['productId'] ?? 0;
|
|
|
+ $ids[] = $productId;
|
|
|
+ $format[$productId] = $val;
|
|
|
}
|
|
|
- $ids = array_column($product, 'productId');
|
|
|
$info = ProductClass::getByIds($ids, null, 'id');
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+ $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (empty($list)) {
|
|
|
+ util::fail('没有找到订单的花材');
|
|
|
+ }
|
|
|
+
|
|
|
+ $itemPrice = 0;
|
|
|
+ $weight = 0;
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $productId = $val->productId ?? 0;
|
|
|
+ $num = $format[$productId]['num'] ?? 0;
|
|
|
+ $unitPrice = $format[$productId]['price'] ?? 0;
|
|
|
+ $price = bcmul($unitPrice, $num, 2);
|
|
|
+ $val->cost = $unitPrice;
|
|
|
+ $val->unitPrice = $unitPrice;
|
|
|
+ $val->price = $price;
|
|
|
+ $val->bigNum = $num;
|
|
|
+ $val->num = $num;
|
|
|
+ $val->save();
|
|
|
+
|
|
|
+ $price = bcmul($num, $unitPrice, 2);
|
|
|
+ $itemPrice = bcadd($itemPrice, $price, 2);
|
|
|
+
|
|
|
+ $productWeight = $info[$productId]['weight'] ?? 0;
|
|
|
+ $currentWeight = bcmul($productWeight, $num, 2);
|
|
|
+ $weight = bcadd($currentWeight, $weight, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['itemPrice'] = $itemPrice;
|
|
|
+ $sendCost = 0;
|
|
|
+ $currentPrice = bcadd($itemPrice, $sendCost, 2);
|
|
|
+
|
|
|
+ $shopId = $order->shopId ?? 0;
|
|
|
+ $shop = ShopClass::getById($shopId, true);
|
|
|
+ $kiloFee = $shop->kiloFee ?? 0;
|
|
|
+ $miniKilo = $shop->miniKilo ?? 0;
|
|
|
+ $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
|
|
|
+ $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
|
|
|
+ $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
|
|
|
+ $order->prePrice = $currentPrice;
|
|
|
+ $order->orderPrice = $currentPrice;
|
|
|
+ $order->actPrice = $currentPrice;
|
|
|
+ $order->realPrice = $currentPrice;
|
|
|
+ $order->stockChange = 1;
|
|
|
+ $order->save();
|
|
|
+ $bookPrice = $order->bookPrice ?? 0;
|
|
|
+ if ($bookPrice == $currentPrice) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ($bookPrice > $currentPrice) {
|
|
|
+ $refundPrice = bcsub($bookPrice, $currentPrice, 2);
|
|
|
+ //退款
|
|
|
+ RefundOrderClass::add($data, true);
|
|
|
+ //门店余额减少
|
|
|
+ ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
|
|
|
+ } else {
|
|
|
+ //欠款
|
|
|
+ $currentDebt = bcsub($currentPrice, $bookPrice, 2);
|
|
|
+ $order->debtPrice = $currentDebt;
|
|
|
+ $order->remainDebtPrice = $currentDebt;
|
|
|
+ $order->debt = OrderClass::DEBT_YES;
|
|
|
+ $order->save();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//添加订单 ssh 2019.12.5
|
|
|
@@ -135,8 +202,12 @@ class OrderClass extends BaseClass
|
|
|
//花材
|
|
|
$product = $data['product'];
|
|
|
$book = $data['book'] ?? 0;
|
|
|
- $stockLock = $book == 1 ? false : true;
|
|
|
- $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockLock);
|
|
|
+ $stockMayChange = true;
|
|
|
+ if ($book == 1) {
|
|
|
+ $stockMayChange = false;
|
|
|
+ $data['stockChange'] = 0;
|
|
|
+ }
|
|
|
+ $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange);
|
|
|
|
|
|
$sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
|
|
|
$data['sendCost'] = $sendCost;
|
|
|
@@ -357,6 +428,7 @@ class OrderClass extends BaseClass
|
|
|
$modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
|
|
|
$confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
|
|
|
$cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
|
|
|
+ $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '到货'];
|
|
|
|
|
|
if ($isList) {
|
|
|
//订单列表页显示的按钮
|
|
|
@@ -391,13 +463,18 @@ class OrderClass extends BaseClass
|
|
|
|
|
|
} else {
|
|
|
//订单详情页显示的按钮
|
|
|
+ if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
|
|
|
+ if ($order['status'] != self::ORDER_STATUS_UN_PAY && $order['status'] != self::ORDER_STATUS_CANCEL) {
|
|
|
+ $arrival['show'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//待确认订单显示延期付和已付款
|
|
|
if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
|
|
|
$debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
|
|
|
$hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
|
|
|
$confirm['disable'] = 0;
|
|
|
- return [$print, $debtPay, $hasPay, $confirm, $cancel];
|
|
|
+ return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
|
|
|
}
|
|
|
|
|
|
//待配送订单显示打印、发货和自取
|
|
|
@@ -405,16 +482,16 @@ class OrderClass extends BaseClass
|
|
|
$selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
|
|
|
$send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
|
|
|
if ($order['hasItem'] == 2) {
|
|
|
- return [$print, $selfGet, $send];
|
|
|
+ return [$print, $selfGet, $send, $arrival];
|
|
|
}
|
|
|
$selfGet['disable'] = 0;
|
|
|
$send['disable'] = 0;
|
|
|
- return [$print, $selfGet, $send];
|
|
|
+ return [$print, $selfGet, $send, $arrival];
|
|
|
}
|
|
|
//配送中显示按钮
|
|
|
if ($order['status'] == self::ORDER_STATUS_SENDING) {
|
|
|
$send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
|
|
|
- return [$print, $send];
|
|
|
+ return [$print, $send, $arrival];
|
|
|
}
|
|
|
//完成
|
|
|
if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
|
|
|
@@ -423,14 +500,14 @@ class OrderClass extends BaseClass
|
|
|
if ($order['sendType'] == self::SEND_TYPE_NO) {
|
|
|
$send['show'] = 0;
|
|
|
}
|
|
|
- return [$print, $send];
|
|
|
+ return [$print, $send, $arrival];
|
|
|
}
|
|
|
//取消订单置灰
|
|
|
if ($order['status'] == self::ORDER_STATUS_CANCEL) {
|
|
|
$selfGet['disable'] = 1;
|
|
|
$send['disable'] = 1;
|
|
|
$print['disable'] = 1;
|
|
|
- return [$modifyProduct];
|
|
|
+ return [$modifyProduct, $arrival];
|
|
|
}
|
|
|
return [];
|
|
|
}
|