|
|
@@ -53,17 +53,70 @@ class PurchaseClass extends BaseClass
|
|
|
public static function arrival($cg, $data)
|
|
|
{
|
|
|
if ($cg->stockChange == 1) {
|
|
|
- util::fail('重复操作');
|
|
|
+ util::fail('您已操作过了');
|
|
|
}
|
|
|
$product = $data['product'] ?? '';
|
|
|
if (empty($product)) {
|
|
|
util::fail('请填写成本价和到货数量');
|
|
|
}
|
|
|
- $product = json_decode($product, true);
|
|
|
- if (empty($product)) {
|
|
|
- util::fail('没有填写成本价和到货数量');
|
|
|
+ $orderSn = $cg->orderSn ?? '';
|
|
|
+ $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (empty($list)) {
|
|
|
+ util::fail('没有找到花材哦');
|
|
|
+ }
|
|
|
+ $weight = 0;
|
|
|
+ $itemPrice = 0;
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $productId = $val->productId ?? 0;
|
|
|
+ if (isset($product[$productId]) == false) {
|
|
|
+ util::fail('没有找到对应采购花材');
|
|
|
+ }
|
|
|
+ $num = $product[$productId]['num'] ?? 0;
|
|
|
+ $price = $product[$productId]['price'] ?? 0;
|
|
|
+ $totalPrice = bcmul($num, $price, 2);
|
|
|
+ $itemPrice = bcadd($itemPrice, $totalPrice, 2);
|
|
|
+ $val->price = $price;
|
|
|
+ $val->itemNum = $num;
|
|
|
+ $val->preTotalPrice = $totalPrice;
|
|
|
+ $val->totalPrice = $totalPrice;
|
|
|
+ $val->save();
|
|
|
+ $unitWeight = $val->unitWeight ?? 0;
|
|
|
+ $currentWeight = bcmul($num, $unitWeight, 2);
|
|
|
+ $weight = bcadd($weight, $currentWeight, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $cg->itemPrice = $itemPrice;
|
|
|
+ $sendCost = 0;
|
|
|
+ $currentPrice = bcadd($itemPrice, $sendCost, 2);
|
|
|
+ $kiloFee = $data['kiloFee'] ?? 0;
|
|
|
+ $miniKilo = $data['miniKilo'] ?? 0;
|
|
|
+ $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
|
|
|
+ $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
|
|
|
+ $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
|
|
|
+ $cg->prePrice = $currentPrice;
|
|
|
+ $cg->orderPrice = $currentPrice;
|
|
|
+ $cg->actPrice = $currentPrice;
|
|
|
+ $cg->realPrice = $currentPrice;
|
|
|
+ $cg->stockChange = 1;
|
|
|
+ $cg->save();
|
|
|
+ $bookPrice = $cg->bookPrice ?? 0;
|
|
|
+ if ($bookPrice == $currentPrice) {
|
|
|
+ return true;
|
|
|
+ } elseif ($bookPrice > $currentPrice) {
|
|
|
+ //退款
|
|
|
+// $refundPrice = bcsub($bookPrice, $currentPrice, 2);
|
|
|
+// //退款
|
|
|
+// RefundOrderClass::add($data, true);
|
|
|
+// //门店余额减少
|
|
|
+// ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
|
|
|
+ } else {
|
|
|
+ //欠款
|
|
|
+ $currentDebt = bcsub($currentPrice, $bookPrice, 2);
|
|
|
+ $cg->debtPrice = $currentDebt;
|
|
|
+ $cg->remainDebtPrice = $currentDebt;
|
|
|
+ $cg->debt = PurchaseClass::DEBT_YES;
|
|
|
+ $cg->save();
|
|
|
}
|
|
|
- $info = ProductClass::getByIds($ids, null, 'id');
|
|
|
}
|
|
|
|
|
|
//添加采购 ssh 2021.1.18
|