|
|
@@ -0,0 +1,63 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace console\controllers;
|
|
|
+
|
|
|
+use biz\shop\classes\ShopClass;
|
|
|
+use biz\stat\classes\StatWastClass;
|
|
|
+use bizGhs\order\classes\StockWastageOrderClass;
|
|
|
+use bizGhs\order\classes\StockWastageOrderItemClass;
|
|
|
+use yii\console\Controller;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class WastController extends Controller
|
|
|
+{
|
|
|
+
|
|
|
+ //报损数据更新 ./yii wast/update
|
|
|
+ public function actionUpdate()
|
|
|
+ {
|
|
|
+ $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true);
|
|
|
+ if (!empty($list)) {
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $orderSn = $item->orderSn ?? '';
|
|
|
+ $shopId = $item->shopId ?? 0;
|
|
|
+ $addTime = $item->addTime ?? '';
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $shop = ShopClass::getLockById($shopId);
|
|
|
+ if (empty($shop)) {
|
|
|
+ echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $productList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (!empty($productList)) {
|
|
|
+ $wast = 0;
|
|
|
+ foreach ($productList as $product) {
|
|
|
+ $num = $product->itemNum ?? 0;
|
|
|
+ $cost = $product->itemCost ?? 0;
|
|
|
+ $amount = bcmul($num, $cost, 2);
|
|
|
+ $wast = bcadd($amount, $wast, 2);
|
|
|
+ }
|
|
|
+ $totalWast = bcadd($wast, $shop->totalWast, 2);
|
|
|
+ $shop->totalWast = $totalWast;
|
|
|
+ $shop->save();
|
|
|
+ $date = date("Ymd", strtotime($addTime));
|
|
|
+ StatWastClass::replace($shop, $wast, $date);
|
|
|
+ }
|
|
|
+
|
|
|
+ $transaction->commit();
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ $msg = $e->getMessage();
|
|
|
+ echo "报错了:" . $msg . "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|