Browse Source

库存同步

sunhao 5 years ago
parent
commit
032b2db806

+ 9 - 0
app/Console/Commands/SyncOrderToMj.php

7
 use App\OrderScript;
7
 use App\OrderScript;
8
 use App\FxOrder;
8
 use App\FxOrder;
9
 use App\GoodsSkus;
9
 use App\GoodsSkus;
10
+use App\OrderGoodsSkus;
10
 use App\Goods;
11
 use App\Goods;
11
 
12
 
12
 class SyncOrderToMj extends Command {
13
 class SyncOrderToMj extends Command {
43
                 if($mjOrder['status'] == '已取消'){
44
                 if($mjOrder['status'] == '已取消'){
44
                     $res = $this->updateOrderToMj($id);
45
                     $res = $this->updateOrderToMj($id);
45
                     echo "\n订单ID:".$id." 卖家取消订单重新更新";
46
                     echo "\n订单ID:".$id." 卖家取消订单重新更新";
47
+                    #同步到卖家云,更新order_goods_skus状态
48
+                    $mj_status = array();
49
+                    $mj_status['mj_status'] = 1;
50
+                    OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
46
                 }
51
                 }
47
             }else{
52
             }else{
48
                 $res = $this->syncOrderToMj($id);
53
                 $res = $this->syncOrderToMj($id);
49
                 if(!$res){
54
                 if(!$res){
50
                     echo "\n订单ID:".$id." 同步失败";
55
                     echo "\n订单ID:".$id." 同步失败";
51
                 }else{
56
                 }else{
57
+                    #同步到卖家云,更新order_goods_skus状态
58
+                    $mj_status = array();
59
+                    $mj_status['mj_status'] = 1;
60
+                    OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
52
                     echo "\n订单ID:".$id." 同步成功";
61
                     echo "\n订单ID:".$id." 同步成功";
53
                 }
62
                 }
54
             }
63
             }

+ 5 - 0
app/Http/Controllers/Admin/GoodsController.php

382
         $name = trim($request->input('name'));
382
         $name = trim($request->input('name'));
383
         $result = Goods::select('gs.id as sku_id', 'goods.id as goods_id', 'goods.name', 'gs.propsName', 'gs.price', 'gs.is_weigh', 'gs.quantity', 'gs.is_white')->leftJoin('goods_skus as gs', 'gs.goodsCode', '=', 'goods.id')->where('goods.name', 'like', '%'.$name.'%')->where('goods.is_del', 0)->where('gs.is_del', 0)->orderBy('goods.id', 'desc')->get();
383
         $result = Goods::select('gs.id as sku_id', 'goods.id as goods_id', 'goods.name', 'gs.propsName', 'gs.price', 'gs.is_weigh', 'gs.quantity', 'gs.is_white')->leftJoin('goods_skus as gs', 'gs.goodsCode', '=', 'goods.id')->where('goods.name', 'like', '%'.$name.'%')->where('goods.is_del', 0)->where('gs.is_del', 0)->orderBy('goods.id', 'desc')->get();
384
         $result = json_decode(json_encode($result), true);
384
         $result = json_decode(json_encode($result), true);
385
+        foreach($result as $k=>&$v){
386
+            //计算实际库存 -还未到卖家云的量
387
+            $w_num = DB::table('order_goods_skus')->where('sku_id', $v['sku_id'])->where('is_del',0)->where('mj_status',0)->sum('num');
388
+            $v['quantity'] = $v['quantity'] - $w_num;
389
+        }
385
 
390
 
386
         if(empty($result)) exit('0');
391
         if(empty($result)) exit('0');
387
         exit(json_encode($result));
392
         exit(json_encode($result));

+ 19 - 2
app/Http/Controllers/Admin/OrderController.php

532
 
532
 
533
         //redis防重复数据
533
         //redis防重复数据
534
         $phone = $request->input('receiverMobile');
534
         $phone = $request->input('receiverMobile');
535
-    
535
+        
536
         $redisKey = 'seafood.order_phone_add.'.$phone;
536
         $redisKey = 'seafood.order_phone_add.'.$phone;
537
         $res = RedisModel::setnx($redisKey, 1);
537
         $res = RedisModel::setnx($redisKey, 1);
538
         if( $res == 0 ){
538
         if( $res == 0 ){
767
 
767
 
768
         $skus = array_keys($order_skus);
768
         $skus = array_keys($order_skus);
769
         if(!empty($skus)){
769
         if(!empty($skus)){
770
-            $goods = Goods::select('gs.id as sku_id', 'goods.id as goods_id', 'goods.name', 'gs.propsName as props_name', 'gs.price', 'gs.is_weigh')->leftJoin('goods_skus as gs', 'gs.goodsCode', '=', 'goods.id')->whereIn('gs.id', $skus)->orderBy('goods.id', 'desc')->get();
770
+            $goods = Goods::select('gs.id as sku_id', 'goods.id as goods_id', 'goods.name', 'gs.propsName as props_name', 'gs.price', 'gs.is_weigh', 'gs.is_white', 'gs.quantity')->leftJoin('goods_skus as gs', 'gs.goodsCode', '=', 'goods.id')->whereIn('gs.id', $skus)->orderBy('goods.id', 'desc')->get();
771
             $goods = json_decode(json_encode($goods),true);
771
             $goods = json_decode(json_encode($goods),true);
772
             foreach($goods as $k=>&$v){
772
             foreach($goods as $k=>&$v){
773
                 $v['num'] = $order_skus[$v['sku_id']];
773
                 $v['num'] = $order_skus[$v['sku_id']];
774
+                //计算实际库存 -还未到卖家云的量
775
+                $w_num = DB::table('order_goods_skus')->where('sku_id', $v['sku_id'])->where('is_del',0)->where('order_id','!=',$id)->where('mj_status',0)->sum('num');
776
+                $v['quantity'] = $v['quantity'] - $w_num;
774
             }
777
             }
775
             $order['goods'] = $goods;
778
             $order['goods'] = $goods;
776
         }
779
         }
1122
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1125
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1123
                 }
1126
                 }
1124
 
1127
 
1128
+                #更新order_goods_skus状态
1129
+                $mj_status = array();
1130
+                $mj_status['mj_status'] = 2;
1131
+                OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
1132
+
1125
                 #记录操作日志
1133
                 #记录操作日志
1126
                 $self_id = session('admin_id');
1134
                 $self_id = session('admin_id');
1127
                 $self_name = session('real_name');            
1135
                 $self_name = session('real_name');            
1188
                     $balance = $cust->balance + $order->receivedAmount;
1196
                     $balance = $cust->balance + $order->receivedAmount;
1189
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1197
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1190
                 }
1198
                 }
1199
+
1200
+                #更新order_goods_skus状态,退回库存
1201
+                $mj_status = array();
1202
+                $mj_status['mj_status'] = 2;
1203
+                OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
1191
                 
1204
                 
1192
                 #记录操作日志
1205
                 #记录操作日志
1193
                 $self_id = session('admin_id');
1206
                 $self_id = session('admin_id');
1272
                     if( $syncMj == false ){
1285
                     if( $syncMj == false ){
1273
                         throw new Exception("订单同步到卖家云失败");
1286
                         throw new Exception("订单同步到卖家云失败");
1274
                     }
1287
                     }
1288
+                    #同步到卖家云,更新order_goods_skus状态
1289
+                    $mj_status = array();
1290
+                    $mj_status['mj_status'] = 1;
1291
+                    OrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
1275
                 }
1292
                 }
1276
             }
1293
             }
1277
 
1294
 

File diff suppressed because it is too large
+ 22 - 9
resources/views/order/ordercreate.blade.php


File diff suppressed because it is too large
+ 17 - 4
resources/views/order/orderedit.blade.php