Quellcode durchsuchen

Merge branch 'version1.5' into dev_wf

wufeng vor 2 Jahren
Ursprung
Commit
f578308f3c

+ 107 - 0
app/admin/controller/Base.php

@@ -112,4 +112,111 @@ class Base extends \app\BaseController
         $action['action_conllect']=implode(",",array_unique(explode(",",$action['action_conllect'])));
         return $action;
     }
+
+    /**
+	* @param $good
+	* @param $isZx
+	* @param string $thNo
+	 * @return mixed|string
+	* @throws \think\Exception
+	 */
+    public function CheckGood($good,$isZx,$thNo=''){
+  	    $spuCode= makeNo("SKU");
+  	    //查询是否存在转库存品记录 存在则返回库存编号
+  	    $newCode= Db::name("good_change_log")->where(["oldCode"=>$good['spuCode']])->value("newCode",'');
+  	    if($newCode==''){
+  	    	 $log=["oldCode"=>$good['spuCode'],
+		        "order_source"=>$isZx,
+		        "newCode"=>$spuCode,
+		        "thCode"=>$thNo,
+		        "createrid"=>$this->uid,
+		        "creater"=>$this->uname,
+		        "addtime"=>date("Y-m-d H:i:s")
+  	        ];
+  	    }else{
+  	    	return $newCode;
+  	    }
+
+  	    if($isZx==1){
+  	    	  $supplier =Db::name("supplier")->where(["code"=>$good['supplierNo']])->findOrEmpty();
+        if(empty($supplier)) throw new \Exception('非库存商品转库存失败');
+  	    	$good = [
+                    'spuCode' => $spuCode,
+                    'good_code' => $good['good_code'],
+                    'good_name' => $good['good_name'],
+                    'cat_id' => $good['cat_id'],
+                    'brand_id' => $good['brand_id'],
+                    'companyNo' => $good['companyNo'],
+                    'good_unit' => $good['good_unit'],
+                    'good_type' => $good['good_type'],
+                    'moq' => $good['moq'],
+                    'customized' => $good['customized'],
+                    'tax' => $good['tax'],
+                    'supplierNo' => $good['supplierNo'],
+                    'is_auth' => $good['is_auth'],
+                    'auth_img' => $good['auth_img'],
+                    'after_sales' => '',
+                    'craft_desc' => $good['craft_desc'],
+                    'good_remark' => $good['good_remark'],
+                    'weight' => $good['weight'],
+                    'packing_way' => '',
+                    'packing_size' => '',
+                    'packing_spec' => '',
+                    'packing_list' => '',
+                    'packing_weight' => '',
+                    'good_bar' => '',
+                    'supply_area' => $good['supply_area'],
+                    'delivery_place' => '',
+                    'origin_place' => '',
+                    'delivery_day' => '',
+                    'lead_time' => '',
+                    'sample_day' => '',
+                    'sample_fee' => '',
+                    'good_img' => '',//$good['good_img'],
+                    'good_thumb_img' => $good['good_thumb_img'],
+                    'good_info_img' => $good['good_img'],//商品主图对应到商品详情
+                    'cert_fee' => '',
+                    'packing_fee' => '',
+                    'cost_fee' => '',
+                    'mark_fee' => '',
+                    'demo_fee' => '',
+                    'open_fee' => '',
+                    'noble_metal' => $good['noble_metal'],
+                    'noble_weight' => $good['good_weight'],
+                    'is_gold_price' => $good['is_gold_price'],
+                    'cgd_gold_price' => '',
+                    'market_price' => '',
+                    'nake_price' => '',
+                    'is_step' => '',
+                    'is_online' => '0',
+                    'status' =>7,//咨询商品待编辑
+                    'createrid' =>$good['createrid'],
+                    'creater' => $good['creater'],
+                    'field_change' => '',
+                    'is_del' => 0,
+                    'is_support_stock' => 0,
+                    'addtime' => date('Y-m-d H:i:s'),
+                    'updatetime' => date('Y-m-d H:i:s'),
+                    'is_diff' => $good['is_diff'],
+                    'config' => $good['config'],
+                    'other_config' => $good['other_config'],
+                     'chargerid'=>$supplier['personid']??$good['createrid'],
+                      'charger'=>$supplier['person']??$good['creater'],//负责人跟创建人一致
+                ];
+  	    }else{
+			$good['id']=null;
+			$good['spuCode']=$spuCode;
+			$good['is_stock']=1;
+			$good['is_support_stock']=0;
+			$good['status']=7;
+			$good['addtime']=date("Y-m-d H:i:s");
+			$good['updatetime']=date("Y-m-d H:i:s");
+  	    }
+  	    $insert =Db::name("good_basic")->insert($good);
+  	    if($insert==false) throw new \Exception("非库存商品转库存失败",1005);
+  	    $newAdd=Db::name("good_change_log")->insert($log);
+  	    if($newAdd==false) throw new \Exception("非库存商品转库存失败",1005);
+  	    return $spuCode;
+
+    }
 }

+ 18 - 7
app/admin/controller/Orderback.php

@@ -426,7 +426,6 @@ class Orderback extends Base
         $val->extend('checkRemark', function ($val, $rule, $data) {
             return $data['status'] == 4 ? true : (empty($val) ? '请填写备注' : true);
         });
-
         if (!$val->check($param)) return error_show(1004, $val->getError());
         Db::startTrans();
         try {
@@ -442,6 +441,17 @@ class Orderback extends Base
                 Db::rollback();
                 return error_show(1004,"未找到销售单数据");
             }
+            $spuCode= $info['good_code'];
+            if($sale['order_type']!==1){
+              if($sale['order_type']==3){
+		          $goon = Db::name("good_zixun")->where(["spuCode"=>$sale['good_code'],"is_del"=>0])->find();
+		          $isZx=1;
+		      }else {
+		          $goon = Db::name('good_basic')->where(['spuCode' => $sale['good_code']])->find();
+		          $isZx=2;
+		      }
+              $spuCode = $this->CheckGood($goon,$isZx,$param['thNo']);
+            }
             $out =Db::name("order_out")->where(['outCode'=>$info['outCode']])->find();
             if($out==false){
                 Db::rollback();
@@ -457,10 +467,11 @@ class Orderback extends Base
                     if($sale['is_stock']==1){ //库存品退回原仓库 备库单释放数量 采购单
                         $param['can_sell_wsm'] = $out['wsm_code'];
                     }
-                    $stock = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['can_sell_wsm']])->find();
+                    $stock = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['can_sell_wsm']])
+                    ->find();
                     if(empty($stock)) {
                         $stock=[
-                            "spuCode"=>$info['good_code'],
+                            "spuCode"=>$spuCode,
                             "wsm_code"=>$param['can_sell_wsm'],
                             "usable_stock"=>0,
                             "wait_out_stock"=>0,
@@ -514,10 +525,10 @@ class Orderback extends Base
              }
 
             if($param['defective_num']!=0&& $param['defective_wsm']!=''){
-                $defective = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['defective_wsm']])->find();
+                $defective = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['defective_wsm']])->find();
                 if(empty($defective)) {
                     $defective=[
-                        "spuCode"=>$info['good_code'],
+                        "spuCode"=>$spuCode,
                         "wsm_code"=>$param['defective_wsm'],
                         "usable_stock"=>0,
                         "wait_out_stock"=>0,
@@ -526,9 +537,9 @@ class Orderback extends Base
                         "addtime"=>date("Y-m-d H:i:s"),
                         "updatetime"=>date("Y-m-d H:i:s"),
                     ];
-                    $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
+                    $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"create"];
                 }else{
-                    $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                    $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
                 }
                 $defective['usable_stock']+=$param['defective_num'];
                 $defective['updatetime'] = date("Y-m-d H:i:s");

+ 35 - 14
app/admin/controller/Reorder.php

@@ -842,24 +842,35 @@ class Reorder extends Base
                                 Db::rollback();
                                 return error_show(1005, '未找到采购单数据');
                             }
-                            $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
+
+                            $stock = Db::name("good_stock")->where(["spuCode" =>  $orderinfo['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
                             if ($stock==false) {
                                 Db::rollback();
                                 return error_show(1005, '商品仓库未找到');
                             }
-                            if($stock['usable_stock']+$stock['wait_out_stock']<$info['num']){
-                                Db::rollback();
-                                return error_show(1005, '商品可用库存不足退回数量');
+                            if($info['is_all']==1){
+	                            if($stock['wait_in_stock']<$info['num']){
+	                                Db::rollback();
+	                                return error_show(1005, '商品可用库存不足退回数量');
+	                            }else{
+	                                    $stock['wait_in_stock']-= $info['num'];
+	                            }
                             }else{
+	                                if($stock['usable_stock']+$stock['wait_out_stock']<$info['num']){
+	                                Db::rollback();
+	                                return error_show(1005, '商品可用库存不足退回数量');
+	                            }else{
 
-                                if($stock['usable_stock']>$info['num']){
-                                    $stock['usable_stock'] -= $info['num'];
-                                }else{
-                                    $stock['usable_stock'] = 0;
-                                    $stock['wait_out_stock']-= $info['num']- $stock['usable_stock'] ;
-                                }
-                                $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
+	                                if($stock['usable_stock']>$info['num']){
+	                                    $stock['usable_stock'] -= $info['num'];
+	                                }else{
+	                                    $stock['usable_stock'] = 0;
+	                                    $stock['wait_out_stock']-= $info['num']- $stock['usable_stock'] ;
+	                                }
+	                                $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
+	                            }
                             }
+
                             $stock['updatetime'] = date("Y-m-d H:i:s");
                             $st_up = Db::name("good_stock")->save($stock);
                             if ($st_up == false) {
@@ -900,11 +911,21 @@ class Reorder extends Base
                             return error_show(1005, '未找到退货仓库');
                         }
                         //::todo 非库存品订单退货 采购单退货 虚拟仓如何减库存
-
-                        $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' => $wsmcode])->find();
+						$spuCode= $info['good_code'];
+				            if($orderinfo['order_type']!==1){
+				              if($orderinfo['order_type']==3){
+						          $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
+						          $isZx=1;
+						      }else {
+						          $goon = Db::name('good_basic')->where(['spuCode' => $orderinfo['good_code']])->find();
+						          $isZx=2;
+						      }
+				              $spuCode = $this->CheckGood($goon,$isZx,$code);
+				            }
+                        $stock = Db::name("good_stock")->where(["spuCode" => $spuCode, 'wsm_code' => $wsmcode])->find();
                         if (empty($stock)) {
                             $stock = [
-                                "spuCode" => $info['good_code'],
+                                "spuCode" => $spuCode,
                                 "wsm_code" => $wsmcode,
                                 "usable_stock" => 0,
                                 "wait_out_stock" => 0,

+ 8 - 5
app/command/NowReportHandle.php

@@ -317,7 +317,7 @@ class NowReportHandle extends Command
             ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
             ->where('woo.status',">=", 2)
             ->where('woo.is_del',"=", 0)
-            ->whereBetween('woo.addtime', [$start, $end])
+            ->whereBetween('woo.sendtime', [$start, $end])
             ->field(" year(`a`.`addtime`) AS `年`,
             month(`a`.`addtime`) AS `月`,
             dayofmonth(`a`.`addtime`) AS `日`,
@@ -378,7 +378,7 @@ class NowReportHandle extends Command
                 $value['单位']=Db::name("unit")->where(["id"=>$value['单位']])->value("unit",'');
                 if($value['是否库存品']==1){
                     $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b","a.cgdNo=b.cgdNo and b.is_del=0")
-                        ->where(["bkcode"=>$value['发货方式'],"order_type"=>1])->order("b.addtime desc")
+                        ->where(["bkcode"=>$value['发货方式'],"order_type"=>1,"order_source"=>0])->order("b.addtime desc")
                         ->value("b.sendtype",'');
                     $value['是否库存品']='是';
                 }else{
@@ -667,7 +667,7 @@ class NowReportHandle extends Command
             ->leftJoin("good_zixun wgz", "wgz.spuCode=wpo.spuCode")
             ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
             ->where('woo.status', ">=", 2)
-            ->whereBetween('woo.addtime', [$start, $end])
+            ->whereBetween('woo.sendtime', [$start, $end])
             ->field(" year(`a`.`addtime`) AS `年`,month(`a`.`addtime`) AS `月`,dayofmonth(`a`.`addtime`) AS `日`,a.supplierNo as '公司名称', a.apply_id '业务部门名称' ,a.apply_name as '业务人员',a.order_type as '订单类型',a.good_type as '商品类型',woo.outCode '发货编号',`woo`.`send_num` AS `本次发货数量`,`woo`.`sendtime` AS `本次发货时间`,`woo`.`orderCode` AS `确认单编号`,`a`.`good_code` AS `商品编号`,'' as '一级分类','' as '二级分类',a.cat_id as '三级分类','' as '财务核算编码',a.good_name as '商品名称',ifnull( `wgb`.`good_unit`, `wgz`.`good_unit` ) as '单位',`a`.`good_num` AS `下单数量`,`wpo`.`cgdNo` AS `采购单单号`,`wpo`.`cgder` AS `采购员`,`ws`.`name` AS `供应商名称`,`wgb`.`is_stock`  as '是否库存品',if (`wgb`.`is_stock`=1,wpo.bkcode,wpo.cgdNo) as '发货方式',ifnull( `wor`.`thNo`, '' ) AS `退货编号`,ifnull( `wor`.`return_num`, '' ) AS `退货数量`,'' as '售前退货数量'")
             ->cursor();
         $order_tyepe = ["库存销售", '非库存销售', '咨询销售', '项目销售', '平台库存销售', '平台非库存销售'];
@@ -685,7 +685,10 @@ class NowReportHandle extends Command
             $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
             $value['单位'] = Db::name("unit")->where(["id" => $value['单位']])->value("unit", '');
             if ($value['是否库存品'] == 1) {
-                $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")->where(["bkcode" => $value['发货方式'], "order_type" => 1])->order("b.addtime desc")->value("b.sendtype", '');
+                $sendtype = Db::name("purchease_order")->alias("a")
+                ->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")
+                ->where(["bkcode" => $value['发货方式'], "order_type" => 1,"order_source"=>0])
+                ->order("b.addtime desc")->value("b.sendtype", '');
                 $value['是否库存品'] = '是';
             } else {
                 $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")->where(["a.cgdNo" => $value['发货方式']])->order("b.addtime desc")->value("b.sendtype", '');
@@ -743,7 +746,7 @@ class NowReportHandle extends Command
             ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
             ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
             ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
-            ->where([['woo.status', ">=", 2],['woo.is_del',"=", 0],['a.order_type', "=", 1],['woo.addtime','between',[$start, $end]]])
+            ->where([['woo.status', ">=", 2],['woo.is_del',"=", 0],['a.order_type', "=", 1],['woo.sendtime','between',[$start, $end]]])
             ->field("wpo.companyNo '业务公司',bkcode '备库单号',woo.orderCode '销售单号',woo.outCode '出库单号',wpo.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wpo.good_name as '商品名称',woo.send_num'出库数量',woo.sendtime '本次出库时间',a.apply_id as '业务部门',a.apply_name as '业务员',wpo.cgder as '采购员',wor.return_num  '出库退货数量',wwi.wsm_type '仓库类型',ws.name '供应商名称',wwi.name '仓库名称'")
             ->cursor();
         $data = [];