123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- declare (strict_types = 1);
- 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\PurcheaseOrder;
- use app\report\model\Sale;
- use think\db\Query;use think\Request;
- use think\App;
- class Stats extends Base
- {
- private $saleDerpart=[52=>'客服部@百辰荣达',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("获取成功",$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('获取成功',$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('获取成功',$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('获取成功',$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('获取成功',$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('获取成功',$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('获取成功',$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');
- $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"=>$temp,"noAddr"=>$noArr]);
- }
- }
|