'客服部@百辰荣达',53=>'项目部@普润心堂',56=>'网络部@泓源广诚',57=>'平台部@万宇恒通',59=>'财务部@万宇恒通']; // 客服部@百辰荣达, //项目部@普润心堂,网络部@泓源广诚,平台部@万宇恒通,财务部@万宇恒通 private $cgdDerpart=[58=>"万宇供应链资源部"];//万宇供应链资源部 public function __construct(App $app) {parent::__construct($app);} //咨询单 public function zxorder() { $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']]; $zxModel =new ConsultOrder(); $temp=[]; foreach ($this->saleDerpart as $departid=>$depart){ $uid =$this->GetDepartId($departid); $temp[$departid]["name"] =$depart; $temp[$departid]["num"] =$zxModel->alias("a")->leftJoin("consult_info b","wsm_consult_order.zxNo=b.zxNo") ->whereBetween('b.addtime',$time) ->whereIn('createrid',$uid) ->where(["a.is_del"=>0,"b.is_del"=>0]) ->count(); } $this->success("获取成功",array_values($temp)); } /** * 销售单. * * @return \think\Response */ public function saleOrder() { $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']]; $Model =new Sale(); $temp=[]; foreach ($this->saleDerpart as $departid=>$depart){ $uid =$this->GetDepartId($departid); $temp[$departid]['name'] =$depart; $temp[$departid]['result'] =$Model->group("order_type") ->whereBetween('addtime',$time) ->whereIn('apply_id',$uid) ->where(['is_del'=>0]) ->column("count(1) num,order_type","order_type"); } $this->success('获取成功',array_values($temp)); } /** * 报备单 * * @param \think\Request $request * @return \think\Response */ public function bkOrder() { $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']]; $Model =new Purchease(); $temp=[]; foreach ($this->saleDerpart as $departid=>$depart){ $uid =$this->GetDepartId($departid); $temp[$departid]['name'] =$depart; $temp[$departid]['num'] =$Model ->whereBetween('addtime',$time) ->whereIn('apply_id',$uid) ->where(['is_del'=>0,"status"=>[1,2]]) ->count(); } $this->success('获取成功',array_values($temp)); } /** * 采购部门采购情况 */ public function cgdOrder() { $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']]; $Model =new PurcheaseOrder(); $temp=[]; foreach ($this->cgdDerpart as $departid=>$depart){ $uid =$this->GetDepartId($departid); $temp[$departid]['name'] =$depart; $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("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") ->whereBetween('a.addtime',$time) ->whereIn('a.cgder_id',$uid) ->where('a.is_del',0) ->select(); $result=[]; foreach ($data as $key=>$val){ if(!isset($result[$val['cgder_id']])){ $result[$val['cgder_id']]= [ 'cgder'=>$val['cgder'], 'total_cgd' => 0,//订单总量 'tag_1' => 0,//库存品 'tag_2' => 0,//非库存品 'tag_zx' => 0,//咨询采反总数 'tag_c' => 0,//to C 'tag_b' => 0,//to B ]; } switch ($val['order_type']) { case 1: //库存品 if ($val['order_source'] == 0) { $result[$val['cgder_id']]['tag_1']+=$val['num']; } break; case 2: //非库存品 $result[$val['cgder_id']]['tag_2']+=$val['num']; break; case 3: //咨询采反 $result[$val['cgder_id']]['tag_zx']+=$val['num']; break; } switch ($val['use_type']) { case 1: //to B $result[$val['cgder_id']]['tag_b']+=$val['num']; break; case 2: //to C $result[$val['cgder_id']]['tag_c']+=$val['num']; break; } } $temp[$departid]['result'] =$result; } $this->success('获取成功',array_values($temp)); } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function bidsOrder() { $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']]; $model = new ConsultBids(); $temp=[]; foreach ($this->cgdDerpart as $departid=>$depart){ $uid =$this->GetDepartId($departid); $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(); $temp[$departid]['result'] =$list; } $this->success('获取成功',array_values($temp)); } /** * 咨询单空返数据 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function bidsFail() {$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']]; $model = new ConsultOrder(); $temp=[]; $uid = (new AccountItem())->GetUidByDepartId(array_keys($this->saleDerpart)); $list = $model->alias('a') ->leftJoin('consult_info b','wsm_consult_order.zxNo=b.zxNo') ->whereBetween('a.addtime',$time) ->whereIn('createrid',$uid) ->where(['a.is_del'=>0,'b.is_del'=>0]) ->where('b.status','<>',5) ->group('b.status') ->column('b.status,count(1) num','b.status'); $temp['result'] =$list; $this->success('获取成功',$temp); } /** * 发货工单 */ public function outChildOrder() { $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']]; $model = new OrderOutChild(); foreach ($this->saleDerpart as $departid=>$sale){ $uid = $this->GetDepartId($departid); $temp[$departid]['name'] =$sale; $build= $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code') ->whereBetween('a.addtime',$time) ->whereIn('a.apply_id',$uid) ->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') ->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; else return 6; })->select(); $tlist=[]; foreach ($build as $item){ if(!isset($tlist[$item['contactor']])){ $tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0]; } $tlist[$item['contactor']][$item['stage']]+=1; } $temp[$departid]['result'] =$tlist?:[]; } $this->success('获取成功',array_values($temp)); } /** 发货单数据统计 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function outOrder() { $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']]; $model = new OrderOut(); foreach ($this->saleDerpart as $departid=>$sale){ $uid = $this->GetDepartId($departid); $temp[$departid]['name'] =$sale; $build= $model->alias('a')->LeftJoin('warehouse_info b','a.wsm_code=b.wsm_code') ->whereBetween('a.addtime',$time) ->whereIn('a.apply_id',$uid) ->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') ->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; else return 6; })->select(); $tlist=[]; foreach ($build as $item){ if(!isset($tlist[$item['contactor']])){ $tlist[$item['contactor']]=[$item['contactor_name'],0,0,0,0,0,0]; } $tlist[$item['contactor']][$item["stage"]]+=1; } $temp[$departid]['result'] =$tlist; } $this->success('获取成功',array_values($temp)); } //未发货数据 public function wsendOrder(){ $temp=[]; $model =new Sale(); $userArr=[]; foreach ($this->saleDerpart as $departid=>$depart){ $uid = $this->GetDepartId($departid); $userArr=array_merge($userArr,$uid); $temp[$departid]["name"] = $depart; $start = 1; $end = date("m"); while ($start<=$end){ $list = $model->whereIn('status',[0,1]) ->whereIn("send_status",[1,2]) ->whereIn('apply_id',$uid) ->whereMonth('addtime',date('Y').'-'.$start) ->group('send_status')->column('sum(wsend_num) num,send_status','send_status'); $temp[$departid]['result'][$start]=$list; $start++; } } $noArr=[]; $noArr['name'] = "无地址订单"; $start = 1; $end = date('m'); while ($start<=$end){ // $month = $start; $list = $model->whereIn('status',[0,1]) ->whereIn('send_status',[1,2]) ->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); $start++; } $this->success('获取成功',["result"=>array_values($temp),"noAddr"=>$noArr]); } }