Browse Source

同步商品库存成本修改

shensong 5 years ago
parent
commit
5ed29122d9
1 changed files with 14 additions and 10 deletions
  1. 14 10
      app/Console/Commands/SyncMjWarehouse.php

+ 14 - 10
app/Console/Commands/SyncMjWarehouse.php

@@ -58,19 +58,23 @@ class SyncMjWarehouse extends Command {
58 58
             //2.更新商品库存总成本(有可能为空)
59 59
             //3.计算商品真实价格
60 60
             //4.计算商品外部价格
61
+            $cost = DB::table('goods_skus')->where('code', $code)->select('referenceCost', 'is_weigh')->first(); //获取规格成本/是否称重
62
+            if($cost){
63
+                $quantity = $cost->is_weigh == 1 ? $sku['quantity']/2 : $sku['quantity']; //对应规格数量
64
+                $up['quantity'] = $quantity;
65
+                $up['totalCost'] = isset($sku['totalCost']) ? $sku['totalCost'] : 0;
66
+                if($up['quantity'] != 0 ){
67
+                    $up['realPrice'] = $up['totalCost'] / $up['quantity'];
68
+                    $up['outPrice'] = ceil($up['realPrice'] * 1.1);
69
+                } else {
70
+                    $up['realPrice'] = 0;
71
+                    $up['outPrice'] = 0;
72
+                }
73
+                $up['cost'] = isset($sku['cost']) ? $sku['cost'] : 0;
61 74
 
62
-            $up['quantity'] = $sku['quantity'];
63
-            $up['totalCost'] = isset($sku['totalCost']) ? $sku['totalCost'] : 0;
64
-            if($up['quantity'] != 0 ){
65
-                $up['realPrice'] = $up['totalCost'] / $up['quantity'];
66
-                $up['outPrice'] = ceil($up['realPrice'] * 1.1);
67
-            } else {
68
-                $up['realPrice'] = 0;
69
-                $up['outPrice'] = 0;
75
+                $up_re = DB::table('goods_skus')->where('code', $code)->update($up);
70 76
             }
71
-            $up['cost'] = isset($sku['cost']) ? $sku['cost'] : 0;
72 77
 
73
-            $up_re = DB::table('goods_skus')->where('code', $code)->update($up);
74 78
         }
75 79
 
76 80
         return true;