Sfoglia il codice sorgente

Merge branch 'master-new-dev-wf' of wugg/phpstock into master-new

wufeng 2 anni fa
parent
commit
8d51765ee6

+ 5 - 3
app/admin/controller/After.php

@@ -1423,9 +1423,10 @@ class After extends Base
 
                         //发货工单,有可能会有多个,要按照顺序扣减发货数
 //                        Db::name('order_out_child')
+//                        ->data(['updatetime' => date("Y-m-d H:i:s")])
 //                            ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
 //                            ->dec('num', $info['error_num'])
-//                            ->update(['updatetime' => date("Y-m-d H:i:s")]);
+//                            ->update();
 
                         $error_num = $info['error_num'];
                         $tmp_ooc = Db::name('order_out_child')
@@ -1437,9 +1438,10 @@ class After extends Base
 
                             if ($tmp['num'] >= $error_num) {
                                 Db::name('order_out_child')
+                                    ->data(['updatetime' => date("Y-m-d H:i:s")])
                                     ->where(['is_del' => 0, 'id' => $tmp["id"]])
                                     ->dec('num', $error_num)
-                                    ->update(['updatetime' => date("Y-m-d H:i:s")]);
+                                    ->update();
                                 $error_num = 0;
                             } else {
                                 Db::name('order_out_child')
@@ -1464,7 +1466,7 @@ class After extends Base
                                     ->where(['is_del' => 0, 'id' => $cgd_info['cgd_id']])
                                     ->inc('th_num', $info['error_num'])
                                     ->inc('th_fee', round($cgd_info['good_price'] * $info['error_num'], 2))
-                                    ->update(['updatetime' => date("Y-m-d H:i:s")]);
+                                    ->update();
                             }
                         }
 

+ 14 - 7
app/admin/controller/AfterChild.php

@@ -294,9 +294,10 @@ class AfterChild extends Base
 
                 //发货工单数量减少
                 Db::name('order_out_child')
+                    ->data(['updatetime' => $date])
                     ->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
                     ->dec('num', $info[$value['id']]['return_num'])
-                    ->update(['updatetime' => $date]);
+                    ->update();
             }
 
             $total = array_sum(array_column($param['list'], 'can_sell_num'));
@@ -430,9 +431,10 @@ class AfterChild extends Base
                     foreach ($child_bns as $child_bn) {
                         if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
                         Db::name('child_bn')
+                            ->data(['updatetime' => $date])
                             ->where(['id' => $child_bn['id']])
                             ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
-                            ->update(['updatetime' => $date]);
+                            ->update();
                         $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
                         if ($total == 0) break;
                     }
@@ -494,9 +496,10 @@ class AfterChild extends Base
                                 $total = $value['can_sell_num'];
                                 foreach ($child_bns as $child_bn) {
                                     Db::name('child_bn')
+                                        ->data(['updatetime' => $date])
                                         ->where(['id' => $child_bn['id']])
                                         ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
-                                        ->update(['updatetime' => $date]);
+                                        ->update();
 
                                     Db::name('good_stock_info')
                                         ->insert([
@@ -516,18 +519,20 @@ class AfterChild extends Base
                             } else {
                                 //维护记录
                                 Db::name('good_stock_info')
+                                    ->data(['updatetime' => $date])
                                     ->where(['id' => $good_stock_info['id']])
                                     ->inc('balance_num', $value['can_sell_num'])//可用数量增加
                                     ->dec('used_num', $value['can_sell_num'])//已用数量减少
-                                    ->update(['updatetime' => $date]);
+                                    ->update();
                             }
 
                             //维护good_stock
                             Db::name('good_stock')
+                                ->data(['updatetime' => $date])
                                 ->where(['is_del' => 0, 'id' => $stockids[$info[$value['id']]['return_wsm_code']]])
                                 ->inc('usable_stock', $value['can_sell_num'])
                                 ->inc('total_stock', $value['can_sell_num'])
-                                ->update(['updatetime' => $date]);
+                                ->update();
 
                         } else {
                             //新建good_stock和good_stock_info
@@ -558,9 +563,10 @@ class AfterChild extends Base
                             $total = $value['can_sell_num'];
                             foreach ($child_bns as $child_bn) {
                                 Db::name('child_bn')
+                                    ->data(['updatetime' => $date])
                                     ->where(['id' => $child_bn['id']])
                                     ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
-                                    ->update(['updatetime' => $date]);
+                                    ->update();
 
                                 Db::name('good_stock_info')
                                     ->insert([
@@ -583,9 +589,10 @@ class AfterChild extends Base
 
                     //维护商品层面的库存数
                     Db::name('good')
+                        ->data(['updatetime' => $date])
                         ->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
                         ->inc('usable_stock', array_sum(array_column($param['list'], 'can_sell_num')))
-                        ->update(['updatetime' => $date]);
+                        ->update();
 
                 }
             }

+ 2 - 2
app/admin/controller/Goodup.php

@@ -1626,8 +1626,8 @@ class Goodup extends Base
                 $create =Db::name("good_platform")->insert($tmp,true);
                 if($create>0){
 
-                    $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
-                    if($iso==false){
+                    $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->findOrEmpty();
+                    if(empty($iso)){
                         unset($value['id']);
                         $stock_num = Db::name('good_stock')->alias("a")
                         ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")

+ 2 - 1
app/admin/controller/OrderOutChild.php

@@ -577,9 +577,10 @@ class OrderOutChild extends Base
 
                 //库存
                 Db::name('good_stock')
+                    ->data(['updatetime' => $date])
                     ->where(['is_del' => 0, 'spuCode' => $sale[$child[$value['outChildCode']]['orderCode']]['good_code'], 'wsm_code' => $child[$value['outChildCode']]['wsm_code']])
                     ->dec('wait_out_stock', $child[$value['outChildCode']]['num'])
-                    ->update(['updatetime' => $date]);
+                    ->update();
 
             }
 

+ 13 - 9
app/admin/controller/Purchin.php

@@ -390,9 +390,10 @@ class Purchin extends Base
                         if($cgdinfo['order_type']==1){
                             //商品表里的'可用总库存数'增加
                             Db::name('good')
+                                ->data(['updatetime' => date('Y-m-d H:i:s')])
                                 ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
                                 ->inc('usable_stock', $send_num)
-                                ->update(['updatetime' => date('Y-m-d H:i:s')]);
+                                ->update();
                             
                         }
                         if($cgdinfo['send_status']==3 && $cgdinfo['order_type']!=1){
@@ -482,14 +483,16 @@ class Purchin extends Base
                                     }
                                 }
                             }
-					if($cgdinfo['order_type']==2)Db::name('good')
+                            if ($cgdinfo['order_type'] == 2) Db::name('good')
+                                ->data(['updatetime' => date('Y-m-d H:i:s')])
                                 ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
                                 ->inc('usable_stock', $send_num)
-                                ->update(['updatetime' => date('Y-m-d H:i:s')]);
-					else Db::name('good_zixun')
+                                ->update();
+                            else Db::name('good_zixun')
+                                ->data(['updatetime' => date('Y-m-d H:i:s')])
                                 ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
                                 ->inc('usable_stock', $send_num)
-                                ->update(['updatetime' => date('Y-m-d H:i:s')]);
+                                ->update();
                         }
 
                         ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo);
@@ -1970,10 +1973,11 @@ class Purchin extends Base
 				//商品表里的'可用总库存数'增加
 				$isGood= Db::name('good')->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])->findOrEmpty();
 				if(!empty($isGood)){
-					$upgood= Db::name('good')
-                                ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
-                                ->inc('usable_stock', $post['wsm_num'])
-                                ->update(['updatetime' => date('Y-m-d H:i:s')]);
+                    $upgood = Db::name('good')
+                        ->data(['updatetime' => date('Y-m-d H:i:s')])
+                        ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
+                        ->inc('usable_stock', $post['wsm_num'])
+                        ->update();
                     if($upgood ==false)  throw new \Exception("商品库存更新失败");
 				}
 

+ 8 - 4
app/admin/controller/ReorderChild.php

@@ -542,9 +542,10 @@ class ReorderChild extends Base
                     foreach ($child_bns as $child_bn) {
                         if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
                         Db::name('child_bn')
+                            ->data(['updatetime' => $date])
                             ->where(['id' => $child_bn['id']])
                             ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
-                            ->update(['updatetime' => $date]);
+                            ->update();
                         $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
                         if ($total == 0) break;
                     }
@@ -593,9 +594,10 @@ class ReorderChild extends Base
                     if (empty($has_good)) throw new Exception('未找到商品上线记录');
                     else {
                         Db::name('good')
+                            ->data(['updatetime' => $date])
                             ->where('id', $has_good['id'])
                             ->inc('usable_stock', $thnum)
-                            ->update(['updatetime' => $date]);
+                            ->update();
                     }
 
                 }
@@ -637,14 +639,16 @@ class ReorderChild extends Base
             if ($info['order_out_status'] == 1) {
                 //待发货,说明此时有库存,有bn号
                 Db::name('child_bn')
+                    ->data(['updatetime' => $date])
                     ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode'], 'childCode' => $info['outChildCode']])
                     ->inc('num', $info['return_num'])
-                    ->update(['updatetime' => $date]);
+                    ->update();
                 Db::name('good_stock')
+                    ->data(['updatetime' => $date])
                     ->where(['is_del' => 0, 'spuCode' => $info['spuCode'], 'wsm_code' => $info['return_wsm_code']])
                     ->inc('usable_stock', $info['return_num'])
                     ->dec('wait_out_stock', $info['return_num'])
-                    ->update(['updatetime' => $date]);
+                    ->update();
             }
 
 

+ 36 - 32
app/admin/controller/Sale.php

@@ -5157,14 +5157,13 @@ class Sale extends Base
 
 //                if ($sale['sale_status']!=0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
                 if ($sale['order_type'] == 1) {
-                   if ($sale['sale_status']!=0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
-                   	$good =Db::name("good")->where(["spuCode"=>$sale['good_code']])->findOrEmpty();
-                    if(empty($good))throw new Exception('未找到商品信息');
-                     $stock=Db::name("good")->where($good)->update(["usable_stock"=>$good['usable_stock']+$sale['wsend_num'],"updatetime"=>date("Y-m-d H:i:s")]);
-                     if ($stock == false) throw new Exception('商品库存更新失败');
-                } else {
-                    if (in_array($sale['cgd_status'], [0, 1]) == false) throw new \think\Exception($sale['orderCode'] . '采购单已入库,无法取消');
+                    if ($sale['sale_status'] != 0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
+                    $good = Db::name("good")->where(["spuCode" => $sale['good_code']])->findOrEmpty();
+                    if (empty($good)) throw new Exception('未找到商品信息');
+                    $stock = Db::name("good")->where($good)->update(["usable_stock" => $good['usable_stock'] + $sale['wsend_num'], "updatetime" => date("Y-m-d H:i:s")]);
+                    if ($stock == false) throw new Exception('商品库存更新失败');
                 }
+
                 //修改状态,添加待办
                 ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                     "order_code" => $sale['orderCode'],//销售单号
@@ -5182,21 +5181,24 @@ class Sale extends Base
                     'holder_id' => $sale['good_createrid'],
                 ]);
 
-                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_code" => $sale['cgdNo'],//销售单号
-                    "status" => $sale['cgd_status'],//这里的status是之前的值
-                    "action_remark" => '',//备注
-                    "action_type" => "status"//新建create,编辑edit,更改状态status
-                ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
+                if ($sale['cgdNo']) {
+                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+                        "order_code" => $sale['cgdNo'],//销售单号
+                        "status" => $sale['cgd_status'],//这里的status是之前的值
+                        "action_remark" => '',//备注
+                        "action_type" => "status"//新建create,编辑edit,更改状态status
+                    ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
+
+                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                        "order_type" => 'CGD',
+                        "order_code" => $sale['cgdNo'],
+                        "order_id" => $sale['cgd_id'],
+                        "order_status" => 4,
+                        "before_status" => $sale['cgd_status'],
+                        'holder_id' => $sale['cgder_id'],
+                    ]);
+                }
 
-                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                    "order_type" => 'CGD',
-                    "order_code" => $sale['cgdNo'],
-                    "order_id" => $sale['cgd_id'],
-                    "order_status" => 4,
-                    "before_status" => $sale['cgd_status'],
-                    'holder_id' => $sale['cgder_id'],
-                ]);
             }
             Db::name('sale')
                 ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
@@ -5212,7 +5214,6 @@ class Sale extends Base
                 ->toArray();
             if (!empty($out_list)) {
                 Db::name('order_out')
-                    ->field('id,outCode,status')
                     ->where(['is_del' => 0, 'orderCode' => $orderCode])
                     ->update(['status' => 5, 'updatetime' => $date]);
                 foreach ($out_list as $out) {
@@ -5244,16 +5245,19 @@ class Sale extends Base
                     ->where(['is_del' => 0, 'orderCode' => $orderCode])
                     ->update(['status' => 5, 'updatetime' => $date]);
                 foreach ($ooc_list as $ooc) {
-                	$stockinfo =Db::name("good_stock")->where(["spuCode"=>$ooc['spuCode'],"wsm_code"=>$ooc['wsm_code']])->findOrEmpty();
-                     if(empty($stockinfo))throw new Exception('未找到库存信息');
-                      $stockup =[
-                         "usable_stock"=>$stockinfo['usable_stock']+$ooc['num'],
-                         "wait_out_stock"=>$stockinfo['"wait_out_stock']- $ooc['num'],
-                         "updatetime" => $date
-                          ] ;
-                      $ysup =Db::name("good_stock")->where($stockinfo)->update($stockup);
-						if($ysup==false)throw new Exception('库存信息更新失败');
-						GoodStockInfo::ChildReturnBn($ooc['outChildCode'],$stockinfo['id'],$ooc['num']);//处理bn数据
+                    $stockinfo = Db::name("good_stock")->where(["spuCode" => $ooc['spuCode'], "wsm_code" => $ooc['wsm_code']])->findOrEmpty();
+                    if (empty($stockinfo)) throw new Exception('未找到库存信息');
+                    $stockup = [
+                        "usable_stock" => $stockinfo['usable_stock'] + $ooc['num'],
+                        "wait_out_stock" => $stockinfo['wait_out_stock'] - $ooc['num'],
+                        "updatetime" => $date
+                    ];
+
+                    $ysup = Db::name("good_stock")->where($stockinfo)->update($stockup);
+                    if ($ysup == false) throw new Exception('库存信息更新失败');
+
+                    GoodStockInfo::ChildReturnBn($ooc['outChildCode'], $stockinfo['id'], $ooc['num']);//处理bn数据
+
                     ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                         "order_code" => $ooc['outChildCode'],//销售单号
                         "status" => $ooc['status'],//这里的status是之前的值

+ 2 - 2
app/admin/model/GoodStockInfo.php

@@ -292,8 +292,8 @@ class GoodStockInfo extends Model
 				$bntmp['used_num']= $bninfo['used_num']-$num;
 				$num=0;
 			}
-			$up = self::name("child_bn")->update($temp,$value);
-			if($up==false)throw new \Exception("工单库存明细更新失败",1005);
+            $up = self::name("child_bn")->where('id',$value['id'])->update($temp);
+            if($up==false)throw new \Exception("工单库存明细更新失败",1005);
 			$bnup =self::update($bntmp,$bninfo)->getNumRows();
 			if($bnup==false) throw new \Exception("库存bn更新失败",1005);
 			if($num==0) break;