Forráskód Böngészése

Merge branch 'master-new-wgg' of wugg/phpstock into master-new

wugg 1 éve
szülő
commit
7ca368a223

+ 3 - 3
app/admin/controller/Consult.php

@@ -1416,8 +1416,8 @@ class Consult extends Base
                 "sale_price"=>$info['sale_price'],
                 "sale_price"=>$info['sale_price'],
                 "cost_before_price"=>$info['sale_cost_fee'],
                 "cost_before_price"=>$info['sale_cost_fee'],
                 "cost_after_price"=>$cost_price,
                 "cost_after_price"=>$cost_price,
-                "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
-                "after_rate"=>$bargain_price==0?-1:round(($bargain_price-$info['total_fee'])/$bargain_price,2),
+                "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],4),
+                "after_rate"=>$bargain_price==0?-1:round(($bargain_price-$info['total_fee'])/$bargain_price,4),
                 "after_price"=>$bargain_price,
                 "after_price"=>$bargain_price,
                 "exam_info"=>"",
                 "exam_info"=>"",
                 "status"=>0,
                 "status"=>0,
@@ -2350,7 +2350,7 @@ class Consult extends Base
     {
     {
         $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
         $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
         $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
         $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
-        $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
+        $where = [['cb.is_del', "=", 0]];//不要'取消转单'状态下的数据
         $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
         $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
         if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
         if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
 
 

+ 9 - 8
app/admin/controller/SaleReport.php

@@ -2337,9 +2337,8 @@ class SaleReport extends Base
 	    $count_row = Db::name('sale')
 	    $count_row = Db::name('sale')
 	               ->alias('a')
 	               ->alias('a')
 	               ->where($where)
 	               ->where($where)
-	               ->field(" a.good_num-th_num - IFNULL((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)  not_addr_address_good_num,count(a.id) as count")
-	               ->having("not_addr_address_good_num>0")
-	               ->find();
+	               ->where('a.good_num-a.th_num > ifnull((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)')
+	                ->count();
 	    $data = Db::name('sale')
 	    $data = Db::name('sale')
 	              ->alias('a')
 	              ->alias('a')
 	              ->field("a.id,
 	              ->field("a.id,
@@ -2360,7 +2359,8 @@ class SaleReport extends Base
 	              ->where($where)
 	              ->where($where)
 	              ->page($param['page'], $param['size'])
 	              ->page($param['page'], $param['size'])
 	              ->order("a.addtime desc")
 	              ->order("a.addtime desc")
-	              ->having("not_addr_address_good_num>0")
+	               ->where('a.good_num-a.th_num > ifnull((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)')
+	           
 	              ->select()
 	              ->select()
 	              ->toArray();
 	              ->toArray();
 	    $applyAr = array_unique(array_column($data,"apply_id")) ;
 	    $applyAr = array_unique(array_column($data,"apply_id")) ;
@@ -2369,7 +2369,7 @@ class SaleReport extends Base
 		    $value['name']=$depart[$value['apply_id']]??"";
 		    $value['name']=$depart[$value['apply_id']]??"";
 		    $value['month']=date("m",strtotime($value['addtime']));
 		    $value['month']=date("m",strtotime($value['addtime']));
 	    }
 	    }
-        return app_show(0, '请求成功', ['list' => $data, 'count' => $count_row['count']]);
+        return app_show(0, '请求成功', ['list' => $data, 'count' => $count_row]);
 
 
     }
     }
 
 
@@ -3408,10 +3408,10 @@ class SaleReport extends Base
         a.addrid,'' 收货地址,'' 收货联系人,'' 联系方式, d.cgdNo 采购单号,c.remark 备注,datediff(now(),a.addtime) 时效,b.contactor_name 仓库负责人,'' 供应商负责人")
         a.addrid,'' 收货地址,'' 收货联系人,'' 联系方式, d.cgdNo 采购单号,c.remark 备注,datediff(now(),a.addtime) 时效,b.contactor_name 仓库负责人,'' 供应商负责人")
         ->select()
         ->select()
         ->toArray();
         ->toArray();
-		$supArr =array_unique( array_column($list,'supplierNo'));
-		$platArr =array_unique(array_column($list,'platform_id'));
+		$supArr =array_unique( array_column($list,'供应商编号'));
+		$platArr =array_unique(array_column($list,'对接类型'));
 		$AddrArr =array_unique(array_column($list,'addrid'));
 		$AddrArr =array_unique(array_column($list,'addrid'));
-		$applyArr =array_unique(array_column($list,'apply_id'));
+		$applyArr =array_unique(array_column($list,'申请人部门'));
 		$supp=checkHasAccountBySupplierNos($supArr);
 		$supp=checkHasAccountBySupplierNos($supArr);
 		$preson = get_personid_by_supplierNo($supArr,"person");
 		$preson = get_personid_by_supplierNo($supArr,"person");
 		$plafrom = Db::name("platform")->where("id","in",$platArr)->column("use_type","id");
 		$plafrom = Db::name("platform")->where("id","in",$platArr)->column("use_type","id");
@@ -3443,6 +3443,7 @@ class SaleReport extends Base
 				$value['联系方式'] =$addr[$value['addrid']]['mobile'];
 				$value['联系方式'] =$addr[$value['addrid']]['mobile'];
 			}
 			}
 			$value['申请人部门']=$depart[$value['申请人部门']]??"";
 			$value['申请人部门']=$depart[$value['申请人部门']]??"";
+			unset($value['addrid']);
 		}
 		}
 		if (empty($list)) $list[] = ['没有相关可导出的数据'];
 		if (empty($list)) $list[] = ['没有相关可导出的数据'];
         excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);
         excelSave('订单报表' . date('YmdHis'), array_keys($list[0]), $list);

+ 143 - 61
app/report/controller/Stats.php

@@ -3,11 +3,17 @@ declare (strict_types = 1);
 
 
 namespace app\report\controller;
 namespace app\report\controller;
 
 
-use app\model\AccountItem;use app\report\model\ConsultBids;use app\report\model\ConsultInfo;use app\report\model\ConsultOrder;
-use app\report\model\OrderOut;use app\report\model\OrderOutChild;use app\report\model\Purchease;
+use app\report\model\GoodBasic;
+use app\model\AccountItem;
+use app\report\model\ConsultBids;
+use app\report\model\ConsultInfo;
+use app\report\model\ConsultOrder;
+use app\report\model\GoodStock;use app\report\model\OrderOut;
+use app\report\model\OrderOutChild;
+use app\report\model\Purchease;
 use app\report\model\PurcheaseOrder;
 use app\report\model\PurcheaseOrder;
 use app\report\model\Sale;
 use app\report\model\Sale;
-use think\db\Query;use think\Request;
+
 use think\App;
 use think\App;
 class Stats extends Base
 class Stats extends Base
 {
 {
@@ -102,16 +108,16 @@ class Stats extends Base
     	    $data =$Model->alias("a")->leftJoin("order_num b","a.cgdNo=b.cgdNo")
     	    $data =$Model->alias("a")->leftJoin("order_num b","a.cgdNo=b.cgdNo")
     	    ->leftJoin("sale c","c.orderCode=b.orderCode and c.is_del=0")
     	    ->leftJoin("sale c","c.orderCode=b.orderCode and c.is_del=0")
     	    ->leftJoin("platform d","d.id=c.platform_id and d.is_del=0")
     	    ->leftJoin("platform d","d.id=c.platform_id and d.is_del=0")
-    	    ->field("a.cgder,a.cgder_id,a.order_type,d.use_type,count(1) num")
-    	    ->group("a.cgder,a.cgder_id,order_type,use_type")
+    	    ->field("a.companyNo,a.companyName,a.order_type,d.use_type,count(1) num")
+    	    ->group("a.companyNo,a.companyName,order_type,use_type")
     	     ->whereBetween('a.addtime',$time)
     	     ->whereBetween('a.addtime',$time)
-    	    ->whereIn('a.cgder_id',$uid)
+//    	    ->whereIn('a.cgder_id',$uid)
     	    ->where('a.is_del',0)
     	    ->where('a.is_del',0)
     	    ->select();
     	    ->select();
     	    $result=[];
     	    $result=[];
     	    foreach ($data as $key=>$val){
     	    foreach ($data as $key=>$val){
-    	    	if(!isset($result[$val['cgder_id']])){
-    	    		 $result[$val['cgder_id']]= [  'cgder'=>$val['cgder'],
+    	    	if(!isset($result[$val['companyNo']])){
+    	    		 $result[$val['companyNo']]= [  'cgder'=>$val['companyName'],
 	                    'total_cgd' => 0,//订单总量
 	                    'total_cgd' => 0,//订单总量
 	                    'tag_1' => 0,//库存品
 	                    'tag_1' => 0,//库存品
 	                    'tag_2' => 0,//非库存品
 	                    'tag_2' => 0,//非库存品
@@ -120,34 +126,35 @@ class Stats extends Base
 	                    'tag_b' => 0,//to B
 	                    'tag_b' => 0,//to B
                     ];
                     ];
     	    	}
     	    	}
+    	    	 $result[$val['companyNo']]['total_cgd']+=$val['num'];
     	    	switch ($val['order_type']) {
     	    	switch ($val['order_type']) {
 	                case 1:
 	                case 1:
 	                    //库存品
 	                    //库存品
-	                    if ($val['order_source'] == 0) {
-	                        $result[$val['cgder_id']]['tag_1']+=$val['num'];
-	                    }
+//	                    if ($val['order_source'] == 0) {
+	                        $result[$val['companyNo']]['tag_1']+=$val['num'];
+//	                    }
 	                    break;
 	                    break;
 	
 	
 	                case 2:
 	                case 2:
 	                    //非库存品
 	                    //非库存品
-	                 $result[$val['cgder_id']]['tag_2']+=$val['num'];
+	                 $result[$val['companyNo']]['tag_2']+=$val['num'];
 					break;
 					break;
 	                case 3:
 	                case 3:
 	                    //咨询采反
 	                    //咨询采反
-						$result[$val['cgder_id']]['tag_zx']+=$val['num'];
+						$result[$val['companyNo']]['tag_zx']+=$val['num'];
 	                    break;
 	                    break;
                 }
                 }
                 
                 
               switch ($val['use_type']) {
               switch ($val['use_type']) {
 	                case 1:
 	                case 1:
 	                    //to B
 	                    //to B
-	                    $result[$val['cgder_id']]['tag_b']+=$val['num'];
+	                    $result[$val['companyNo']]['tag_b']+=$val['num'];
 	                    
 	                    
 	                    break;
 	                    break;
 	
 	
 	                case 2:
 	                case 2:
 	                    //to C
 	                    //to C
-	                      $result[$val['cgder_id']]['tag_c']+=$val['num'];
+	                      $result[$val['companyNo']]['tag_c']+=$val['num'];
 	                    break;
 	                    break;
                 }
                 }
     	    }
     	    }
@@ -168,15 +175,19 @@ class Stats extends Base
      $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
      $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59')]);
      $time = [$param['start'],$param['end']];
      $time = [$param['start'],$param['end']];
      $model = new ConsultBids();
      $model = new ConsultBids();
+     $order =new ConsultInfo();
      $temp=[];
      $temp=[];
       foreach ($this->cgdDerpart as $departid=>$depart){
       foreach ($this->cgdDerpart as $departid=>$depart){
-            $uid =$this->GetDepartId($departid);
+//            $uid =$this->GetDepartId($departid);
     	    $temp[$departid]['name'] =$depart;
     	    $temp[$departid]['name'] =$depart;
-    	    $list = $model->whereBetween("addtime",$time)->whereIn("createrid",$uid)->where('is_del',0)->group("createrid,creater")->field
-    	    ("creater,createrid,count(1) num")->select();
+    	    $list = $model->whereBetween("addtime",$time)->where('is_del',0)->group("createrid,creater")->field
+    	    ("creater,createrid,count(1) num")->select()->toArray();
+    	    $list[]= ["creater"=>"竞价单总数","creater_id"=>"","num"=>$order->whereBetween('addtime',$time)->where('is_del',0)->count()];
+    	    
     	    $temp[$departid]['result'] =$list;
     	    $temp[$departid]['result'] =$list;
       }
       }
-          $this->success('获取成功',array_values($temp));
+      
+      $this->success('获取成功',array_values($temp));
     }
     }
 
 
     /**
     /**
@@ -191,13 +202,14 @@ class Stats extends Base
      $time = [$param['start'],$param['end']];
      $time = [$param['start'],$param['end']];
      $model = new ConsultOrder();
      $model = new ConsultOrder();
      $temp=[];
      $temp=[];
-     $uid =	 (new AccountItem())->GetUidByDepartId(array_keys($this->saleDerpart));
+//     $uid =	 (new AccountItem())->GetUidByDepartId(array_keys($this->saleDerpart));
      $list = $model->alias('a')
      $list = $model->alias('a')
     	    ->leftJoin('consult_info b','wsm_consult_order.zxNo=b.zxNo')
     	    ->leftJoin('consult_info b','wsm_consult_order.zxNo=b.zxNo')
+    	    ->leftJoin('consult_bids c','b.infoNo=c.infoNo')
     	    ->whereBetween('a.addtime',$time)
     	    ->whereBetween('a.addtime',$time)
-    	    ->whereIn('createrid',$uid)
+    	    ->whereNull("c.id")
     	    ->where(['a.is_del'=>0,'b.is_del'=>0])
     	    ->where(['a.is_del'=>0,'b.is_del'=>0])
-    	    ->where('b.status','<>',5)
+//    	    ->where('b.status','<>',5)
     	    ->group('b.status')
     	    ->group('b.status')
     	    ->column('b.status,count(1) num','b.status');
     	    ->column('b.status,count(1) num','b.status');
     	    $temp['result'] =$list;
     	    $temp['result'] =$list;
@@ -215,25 +227,27 @@ class Stats extends Base
       foreach ($this->saleDerpart as $departid=>$sale){
       foreach ($this->saleDerpart as $departid=>$sale){
       	$uid = $this->GetDepartId($departid);
       	$uid = $this->GetDepartId($departid);
       	 $temp[$departid]['name'] =$sale;
       	 $temp[$departid]['name'] =$sale;
-      	   $build=  $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code')
-      	 ->whereBetween('a.addtime',$time)
+      	   $build=  $model->alias('a')
+//      	 ->whereBetween('a.addtime',$time)
       	 ->whereIn('a.apply_id',$uid)
       	 ->whereIn('a.apply_id',$uid)
       	 ->where('a.is_del',0)
       	 ->where('a.is_del',0)
-      	 ->field('a.id,ifnull(b.contactor,"0") contactor,ifnull(b.contactor_name,"") as contactor_name ,a.addtime,DATEDIFF(ifnull( a.sendtime, NOW()), a.addtime ) as expire,"" stage')
+      	 	 ->whereIn('a.status',[0,1])
+      	 ->field('order_type,DATEDIFF(now(), a.addtime ) as expire,"" stage')
       	 ->withAttr('stage',function ($v,$row){
       	 ->withAttr('stage',function ($v,$row){
-      	 	if($row['expire']==0) return 1;
-      	 	elseif($row['expire']<2) return 2;
-      	 	elseif($row['expire']< 7) return 3;
-      	 	elseif($row['expire']< 14) return 4;
-      	 	elseif($row['expire']< 30) return 5;
+      	 	if($row['expire']>=0 && $row['expire']<=1) return 1;
+      	 	elseif($row['expire']<=2) return 2;
+      	 	elseif($row['expire']<=7) return 3;
+      	 	elseif($row['expire']<=14) return 4;
+      	 	elseif($row['expire']<=30) return 5;
       	 	else return 6;
       	 	else return 6;
       	 })->select();
       	 })->select();
       	  $tlist=[];
       	  $tlist=[];
+      	  $order_type_name = ["1"=>"库存品","2"=>"非库存品","3"=>"咨询采返",'4'=>'报备'];
       	foreach ($build as $item){
       	foreach ($build as $item){
-      	    if(!isset($tlist[$item['contactor']])){
-      	    	$tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0];
+      	    if(!isset($tlist[$item['order_type']])){
+      	    	$tlist[$item['order_type']]=[$order_type_name[$item['order_type']]?:"",0,0,0,0,0,0];
       	    }
       	    }
-      	    $tlist[$item['contactor']][$item['stage']]+=1;
+      	    $tlist[$item['order_type']][$item['stage']]+=1;
       	}
       	}
       	 $temp[$departid]['result'] =$tlist?:[];
       	 $temp[$departid]['result'] =$tlist?:[];
       }
       }
@@ -253,25 +267,27 @@ class Stats extends Base
       foreach ($this->saleDerpart as $departid=>$sale){
       foreach ($this->saleDerpart as $departid=>$sale){
       	$uid = $this->GetDepartId($departid);
       	$uid = $this->GetDepartId($departid);
       	 $temp[$departid]['name'] =$sale;
       	 $temp[$departid]['name'] =$sale;
-      	  $build=  $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code')
-      	 ->whereBetween('a.addtime',$time)
+      	  $build=  $model->alias('a')
+//      	 ->whereBetween('a.addtime',$time)
       	 ->whereIn('a.apply_id',$uid)
       	 ->whereIn('a.apply_id',$uid)
       	 ->where('a.is_del',0)
       	 ->where('a.is_del',0)
-      	 ->field('a.id,ifnull(b.contactor,"0") contactor,ifnull(b.contactor_name,"") as contactor_name ,a.addtime,DATEDIFF(ifnull( a.sendtime, NOW()), a.addtime ) as expire,"" stage')
+      	 ->where('a.status',"=",0)
+      	 ->field('order_type,DATEDIFF(ifnull( a.sendtime, NOW()), a.addtime ) as expire,"" stage')
       	 ->withAttr('stage',function ($v,$row){
       	 ->withAttr('stage',function ($v,$row){
-      	 	if($row['expire']==0) return 1;
-      	 	elseif($row['expire']<2) return 2;
-      	 	elseif($row['expire']< 7) return 3;
-      	 	elseif($row['expire']< 14) return 4;
-      	 	elseif($row['expire']< 30) return 5;
+      	 if($row['expire']>=0 && $row['expire']<=1) return 1;
+      	 	elseif($row['expire']<=2) return 2;
+      	 	elseif($row['expire']<=7) return 3;
+      	 	elseif($row['expire']<=14) return 4;
+      	 	elseif($row['expire']<=30) return 5;
       	 	else return 6;
       	 	else return 6;
       	 })->select();
       	 })->select();
       	  $tlist=[];
       	  $tlist=[];
-      	foreach ($build as $item){
-      	    if(!isset($tlist[$item['contactor']])){
-      	    	$tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0];
+      	   $order_type_name = ['1'=>'库存品','2'=>'非库存品','3'=>'咨询采返','4'=>'报备'];
+      		foreach ($build as $item){
+      	    if(!isset($tlist[$item['order_type']])){
+      	    	$tlist[$item['order_type']]=[$order_type_name[$item['order_type']]?:'',0,0,0,0,0,0];
       	    }
       	    }
-      	    $tlist[$item['contactor']][$item["stage"]]+=1;
+      	    $tlist[$item['order_type']][$item['stage']]+=1;
       	}
       	}
       	 $temp[$departid]['result'] =$tlist;
       	 $temp[$departid]['result'] =$tlist;
       }
       }
@@ -279,7 +295,7 @@ class Stats extends Base
     }
     }
     //未发货数据
     //未发货数据
     public function wsendOrder(){
     public function wsendOrder(){
-    	
+    	$param =$this->request->param(['start_y'=>date('Y')]);
     	$temp=[];
     	$temp=[];
     	$model =new Sale();
     	$model =new Sale();
 		$userArr=[];
 		$userArr=[];
@@ -288,13 +304,18 @@ class Stats extends Base
     		$userArr=array_merge($userArr,$uid);
     		$userArr=array_merge($userArr,$uid);
     		$temp[$departid]["name"] = $depart;
     		$temp[$departid]["name"] = $depart;
     	    $start = 1;
     	    $start = 1;
-    	    $end = date("m");
+    	    $end = $param['start_y']<date('Y')?12: date("m");
     		while ($start<=$end){
     		while ($start<=$end){
-    			$list = $model->whereIn('status',[0,1])
-    			->whereIn("send_status",[1,2])
+        	    $list = $model->alias('a')
+    	    	->whereIn('status',[0,1])
+    			->whereIn('send_status',[1,2])
+    			->where('is_del',0)
 	            ->whereIn('apply_id',$uid)
 	            ->whereIn('apply_id',$uid)
-	            ->whereMonth('addtime',date('Y').'-'.$start)
-	            ->group('send_status')->column('sum(wsend_num) num,send_status','send_status');
+	            ->whereMonth('addtime',$param['start_y'].'-'.str_pad($start.'' , 2,'0',0))
+	            ->where('good_num-th_num > ifnull((select sum(receipt_quantity) from wsm_order_addr where orderCode=a.orderCode and is_del=0),0)')
+	            ->group('send_status')
+	            ->column('count(1) num ,send_status','send_status');
+//        	 echo    $param['start'].'-'.str_pad($start.'' , 2,'0',0);
     			$temp[$departid]['result'][$start]=$list;
     			$temp[$departid]['result'][$start]=$list;
     			$start++;
     			$start++;
     		}
     		}
@@ -303,21 +324,82 @@ class Stats extends Base
     	$noArr=[];
     	$noArr=[];
     	$noArr['name'] = "无地址订单";
     	$noArr['name'] = "无地址订单";
     	 $start = 1;
     	 $start = 1;
-    	    $end = date('m');
+    	 $end = $param['start_y']<date('Y')?12: date('m');
     		while ($start<=$end){
     		while ($start<=$end){
-//    			$month = $start;
+//    			$month = $start;a
     			$list = $model->whereIn('status',[0,1])
     			$list = $model->whereIn('status',[0,1])
     			->whereIn('send_status',[1,2])
     			->whereIn('send_status',[1,2])
 	            ->whereIn('apply_id',$userArr)
 	            ->whereIn('apply_id',$userArr)
-	            ->whereMonth('addtime',date('Y').'-'.$start)
-	            ->field("sale_price,orderCode")
-	            ->append(["no_addr_num"=>function(Query $query,$data){
-	            	$query->name('order_addr')->where(['orderCode'=>$data['orderCode'],'is_del'=>0])->sum('receipt_quantity');
-	            }])
-	            ->find();
-    			$noArr['result'][$start]['total_price']=bcmul($list['sale_price'],$list['no_addr_num'].'',2);
+	            ->where('is_del',0)
+	            ->whereMonth('addtime',$param['start_y'].'-'.str_pad($start.'' , 2,'0',0))
+	            ->field('sale_price,orderCode,good_num,total_price,0 addr_num, 0 before_th')
+	            ->withAttr('addr_num',function($v,$data){
+	            	$num =  Sale::name('order_addr')->where(['orderCode'=>$data['orderCode'],'is_del'=>0])->sum
+	            	('receipt_quantity');
+	            	return bcmul($data['sale_price'],strval($num),2);
+	            })
+				->withAttr('before_th' , function ($v , $data) {
+					    $num= Sale::name('sale_return')->where(['orderCode'=>$data['orderCode'] , 'is_del'=>0,
+							    'status'=>4])->sum('num');
+					return bcmul($data['sale_price'],strval($num),2);
+				    }
+				    )
+	            ->select();
+				if($list->isEmpty())$noArr['result'][$start]['total_price']==0;
+				else{
+					$total =strval(array_sum(array_column($list->toArray() , 'total_price')));
+					$before_th =strval(array_sum(array_column($list->toArray() , 'before_th')));
+					$addr_num =strval(array_sum(array_column($list->toArray() , 'addr_num')));
+					$noArr['result'][$start]['total_price']=bcsub(bcsub($total,$before_th,2),$addr_num,2);
+				}
+
     			$start++;
     			$start++;
     		}
     		}
-    	  $this->success('获取成功',["result"=>array_values($temp),"noAddr"=>$noArr]);
+    	  $this->success('获取成功',["result"=>array_values($list)]);
+    }
+    
+    
+    
+    //发货单维度商品每日库存
+    public function goodStock(){
+    	$param =$this->request->param(['spuCode'=>'','good_name'=>'','companyNo'=>'','page'=>1,
+    	'size'=>10]);
+      $where=[["is_del","=",0]];
+      $param['spuCode']==''?: $where[]=["spuCode","like","%{$param['spuCode']}%"];
+      $param['good_name']==''?: $where[]=["good_name","like","%{$param['good_name']}%"];
+      $param['companyNo']==''?: $where[]=["companyNo","like","%{$param['companyNo']}%"];
+      $model = new GoodBasic();
+      $stock = new GoodStock();
+      $list=$model->where($where)->visible(["spuCode","good_name",'spec_info','cat_info','usable_stock',
+        'total_stock','wait_in_stock','wait_out_stock',"child"])->withAttr("child",function($v,$data) use($stock ){
+        return	$stock->withJoin(["wareinfo"],"left")
+        ->where("spuCode",$data['spuCode'])
+        ->column("wareinfo.name,contactor_name,supplierName,companyName,usable_stock+wait_out_stock total_stock,usable_stock,wait_out_stock,wait_in_stock");
+        
+        })->paginate(["list_rows"=>$param['size'], "page"=>$param["page"]]);
+        
+        $this->success('获取成功',['result'=>$list->items(),"count"=>$list->total()]);
+    }
+    
+    
+        //发货单维度商品每日库存
+    public function outChildStock(){
+        $param =$this->request->param(['start'=>date('Y-m-01 00:00:00'),'end'=>date('Y-m-t 23:59:59'),'page'=>1,
+    	'size'=>10]);
+      $time = [$param['start'],$param['end']];
+      $model = new OrderOutChild();
+      $list = $model
+      ->where(["status"=>2,"order_type"=>1,"is_del"=>0])
+      ->whereBetween("sendtime",$time)
+      ->field("spuCode,good_name,companyName,sum(num) num")
+      ->group('good_name,companyName,spuCode')
+      ->paginate(['list_rows'=>$param['size'], 'page'=>$param['page']]);
+	    foreach ($list->items() as &$value){
+	        $value['stock_num'] = (new GoodStock())->where('spuCode',$value['good_code'])->sum('usable_stock');
+			$value['good_price'] = (new PurcheaseOrder())->where(['spuCode'=>$value['good_code'],'order_source'=>0])->value('good_price',0);
+			$value['total_fee'] = bcmul(strval($value['good_price']),strval($value['good_num']),2);
+	      }
+       $this->success('获取成功',['result'=>$list->items(),'count'=>$list->total()]);
+      
     }
     }
 }
 }

+ 14 - 0
app/report/model/Brand.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Brand extends Model
+{
+    //
+}

+ 51 - 0
app/report/model/GoodBasic.php

@@ -0,0 +1,51 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\facade\Db;use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodBasic extends Model
+{
+	protected $append=["spec_info","cat_info","usable_stock","total_stock","wait_in_stock","wait_out_stock","child"];
+	
+	public function unit(){
+		return $this->belongsTo(Unit::class,"good_unit")->bind(["unit_name"=>"unit"]);
+	}
+	
+	public function brand(){
+		return $this->belongsTo(Brand::class,'brand_id')->bind(['brand_name']);
+	}
+	
+	public function getSpecInfoAttr($v,$row){
+		return (new GoodSpec())->with(["spec","specinfo"])->where(["spuCode"=>$row['spuCode']])->field("spec_id,spec_value_id")->select();
+		
+	}
+	public function getCatInfoAttr($v,$row){
+		
+		return made($row['cat_id']);
+	}
+	
+	public function getTotalStockAttr($v,$row){
+		return	(new GoodStock())->withJoin(['WareInfo'],"left")->where(['spuCode'=>$row['spuCode'],"wsm_type"=>[5,4]])
+		->sum(Db::raw("usable_stock+wait_out_stock"));
+	}
+	
+	public function getUsableStockAttr($v,$row){
+		return	(new GoodStock())->withJoin(['WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]])
+	->sum("usable_stock");
+	}
+	
+	public function getWaitInStockAttr($v,$row){
+		return	(new GoodStock())->withJoin(['WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]])
+	->sum('wait_in_stock');
+	}
+	
+	public function getWaitOutStockAttr($v,$row){
+		return	(new GoodStock())->withJoin([' WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]])
+	->sum('wait_out_stock');
+	}
+}

+ 22 - 0
app/report/model/GoodSpec.php

@@ -0,0 +1,22 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodSpec extends Model
+{
+//    protected $append=["spec_name",'spec_value_name'];
+
+	public function spec(){
+		return $this->belongsTo(Specs::class,"spec_id")->bind(["spec_name"]);
+	}
+	
+	public function SpecInfo(){
+		return $this->belongsTo(SpecValue::class,'spec_value_id')->bind(['spec_value_name'=>'spec_value']);
+	}
+}

+ 16 - 0
app/report/model/GoodStock.php

@@ -0,0 +1,16 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodStock extends Model
+{
+    public function WareInfo(){
+    	return $this->belongsTo(Ware::class,"wsm_code","wsm_code");
+    }
+}

+ 14 - 0
app/report/model/OrderAddr.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderAddr extends Model
+{
+    //
+}

+ 4 - 1
app/report/model/Sale.php

@@ -10,5 +10,8 @@ use think\Model;
  */
  */
 class Sale extends Model
 class Sale extends Model
 {
 {
-
+	protected $append=["addr_num"];
+	public function GetAddrNumAttr($v,$row){
+	    return (new OrderAddr())->where(["orderCode"=>$row["orderCode"],"is_del"=>0])->sum("receipt_quantity");
+	}
 }
 }

+ 14 - 0
app/report/model/SpecValue.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class SpecValue extends Model
+{
+    //
+}

+ 14 - 0
app/report/model/Specs.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Specs extends Model
+{
+    //
+}

+ 14 - 0
app/report/model/Unit.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\report\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Unit extends Model
+{
+    //
+}