123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use app\api\controller\screen\Index;
- use think\Db;
- class Repair extends Index
- {
- public function todoCountData(){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('del',0)
- ->count();
- $count2 = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('del',0)
- ->where('todo_mode',3)
- ->count();
- $bl = 100;
- if($count > 0 ){
- $bl = round($count2/$count*100,1);
- }
- $user = model('WorkTypeMode')->getRolesUserApp(1,$this->orgId);
- $count3 = count($user);
- $count4 = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('del',0)
- ->where('todo_mode',3)
- ->avg('xy_time');
- $count5 = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('del',0)
- ->where('todo_mode',3)
- ->avg('wc_time');
- $data = [
- 'count'=>$count,
- 'count2'=>$count3,
- 'count3'=>round($count4/3600,1),
- 'count4'=>round($count5/3600,1),
- 'bl'=>$bl,
- ];
- HelpHander::success($data);
- }
- //维修订单数据状态分析、
- public function wxOrderStatus(){
- $orderMode = [
- ['name'=>'待派工','value'=>1],
- ['name'=>'已取消','value'=>[2,3]],
- ['name'=>'进行中','value'=>4],
- ['name'=>'已完成','value'=>5],
- ['name'=>'已评价','value'=>6],
- ];
- $list = [];
- foreach ($orderMode as $k=>$v){
- $list[$k]['name'] = $v['name'];
- $list[$k]['value'] = Db::name('orders')
- ->where('work_type_mode',1)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- // ->where('create_yyyymmdd',date('Ymd'))
- ->whereIn('order_mode',$v['value'])
- ->count();
- }
- HelpHander::success($list);
- }
- //维修工单周分析
- public function wxWeekTodo(){
- $dlist = [
- date('Ymd',strtotime('-6 days')),
- date('Ymd',strtotime('-5 days')),
- date('Ymd',strtotime('-4 days')),
- date('Ymd',strtotime('-3 days')),
- date('Ymd',strtotime('-2 days')),
- date('Ymd',strtotime('-1 days')),
- date('Ymd'),
- ];
- $title = $list = $list2 = [];
- foreach ($dlist as $k=>$v){
- $title[] = date('m-d',strtotime($v));
- $list[] = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('create_yyyymmdd',$v)
- ->count();
- $list2[] = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('create_yyyymmdd',$v)
- ->where('todo_mode',3)
- ->count();
- }
- $data = [
- 'title'=>$title,
- 'list'=>$list,
- 'list2'=>$list2,
- ];
- HelpHander::success($data);
- }
- public function wxUserStatus(){
- $lists = model('WorkTypeMode')->getRolesUserApp(1,$this->orgId);
- $curday = date('Ymd');
- $users = Db::name('todo')
- ->field('to_user_id')
- ->where('org_id',$this->orgId)
- ->whereIn('todo_mode',[1,2])
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('create_yyyymmdd',$curday)
- ->group('to_user_id')
- ->order('id desc')
- ->select();
- $users = $users?$users:[];
- $userIds = [];
- foreach ($users as $k=>$v){
- $userIds[] = $v['to_user_id'];
- }
- $nlists = $nlists2 = [];
- foreach ($lists as $k=>$v){
- if(!in_array($v['id'],$userIds)){
- $nlists[] = $v;
- }
- }
- $slist = $slist2 = [];
- foreach ($nlists as $k=>$v){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('to_user_id',$v['id'])
- ->whereIn('todo_mode',[1,2,3])
- ->where('del',0)
- ->where('create_yyyymmdd',$curday)
- ->where('work_type_mode',1)
- ->count();
- $addr = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','t.order_id=or.order_id')
- ->join('address a','a.id=or.address_id')
- ->where('t.to_user_id',$v['id'])
- ->whereIn('t.todo_mode',[1,2,3])
- ->where('t.del',0)
- ->where('t.create_yyyymmdd',$curday)
- ->where('t.work_type_mode',1)
- ->order('t.id desc')
- ->value('a.title');
- $slist[$k][] = '<span style="color: #FFE400">'.$v['real_name'].'</span>';
- $slist[$k][] = '<span style="color: #FFE400">'.$count.'</span>';
- $slist[$k][] = '<span style="color: #FFE400">'.$addr.'</span>';
- }
- foreach ($lists as $k=>$v){
- if(in_array($v['id'],$userIds)){
- $nlists2[] = $v;
- }
- }
- foreach ($nlists2 as $k=>$v){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('to_user_id',$v['id'])
- ->whereIn('todo_mode',[1,2,3])
- ->where('del',0)
- ->where('create_yyyymmdd',$curday)
- ->count();
- $addr = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','t.order_id=or.order_id')
- ->join('address a','a.id=or.address_id')
- ->where('t.to_user_id',$v['id'])
- ->whereIn('t.todo_mode',[1,2,3])
- ->where('t.del',0)
- ->where('t.create_yyyymmdd',$curday)
- ->where('t.work_type_mode',1)
- ->order('t.id desc')
- ->value('a.title');
- $slist2[$k][] = '<span style="color: #11E799">'.$v['real_name'].'</span>';
- $slist2[$k][] = '<span style="color: #11E799">'.$count.'</span>';
- $slist2[$k][] = '<span style="color: #11E799">'.$addr.'</span>';
- }
- $data = [
- 'list'=>[
- 'list'=>$slist,
- 'count'=>count($slist),
- ],
- 'list2'=>[
- 'list'=>$slist2,
- 'count'=>count($slist2),
- ],
- ];
- HelpHander::success($data);
- }
- public function wxTodoData(){
- $list = Db::name('todo')
- ->field('id,order_id,todo_mode,create_time,to_user_id')
- ->where('org_id',$this->orgId)
- ->whereIn('todo_mode',[1,2,3])
- ->where('del',0)
- // ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',1)
- ->limit(20)
- ->order('id desc')
- ->select();
- foreach ($list as $k=>$v){
- if($v['todo_mode'] == 1){
- $list[$k]['status'] = '新任务';
- }elseif ($v['todo_mode'] == 2){
- $list[$k]['status'] = '进行中';
- }elseif ($v['todo_mode'] == 3){
- $list[$k]['status'] = '已完成';
- }
- $repair = Db::name('order_type')
- ->alias('ot')
- ->field('ot.id,ot.title,ot.parent_id')
- ->join('order_repair or','or.type_id=ot.id')
- ->where('or.order_id',$v['order_id'])
- ->find();
- $list[$k]['cate_title'] = Db::name('order_type')->where('id',$repair['parent_id'])->value('title');
- $list[$k]['address'] = Db::name('address')
- ->alias('a')
- ->join('order_repair or','or.address_id=a.id')
- ->where('or.order_id',$v['order_id'])
- ->where('a.org_id',$this->orgId)
- ->value('a.title');
- $list[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
- $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- }
- $data = [];
- foreach ($list as $k=>$v){
- if($v['todo_mode'] == 1){
- $data[$k][] = $v['status'];
- $data[$k][] = $v['cate_title'];
- $data[$k][] = $v['address'];
- $data[$k][] = $v['create_time'];
- $data[$k][] = $v['user_name'];
- }elseif ($v['todo_mode'] == 2){
- $data[$k][] = '<span style="color:#0FC2DD;">'.$v['status'].'</span>';
- $data[$k][] = '<span style="color:#0FC2DD;">'.$v['cate_title'].'</span>';
- $data[$k][] = '<span style="color:#0FC2DD;">'.$v['address'].'</span>';
- $data[$k][] = '<span style="color:#0FC2DD;">'.$v['create_time'].'</span>';
- $data[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
- }elseif ($v['todo_mode'] == 3){
- $data[$k][] = '<span style="color:#2E73D1 ;">'.$v['status'].'</span>';
- $data[$k][] = '<span style="color:#2E73D1;">'.$v['cate_title'].'</span>';
- $data[$k][] = '<span style="color:#2E73D1;">'.$v['address'].'</span>';
- $data[$k][] = '<span style="color:#2E73D1;">'.$v['create_time'].'</span>';
- $data[$k][] = '<span style="color:#2E73D1;">'.$v['user_name'].'</span>';
- }
- }
- HelpHander::success($data);
- }
- public function wxCateData(){
- $type = Db::name('order_type')
- ->field('id,title as name')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('parent_id',0)
- ->select();
- foreach ($type as $k=>$v){
- //获取类型下的报修事项
- $cc = Db::name('order_type')
- ->where('parent_id',$v['id'])
- ->where('del',0)
- ->where('enable',1)
- ->column('id');
- $type[$k]['value'] = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->whereIn('or.type_id',$cc)
- ->where('t.del',0)
- ->where('t.org_id',$this->orgId)
- ->where('t.todo_mode',3)
- ->where('t.work_type_mode',1)
- ->where('t.create_yyyymmdd',date('Ymd'))
- ->count();
- unset($type[$k]['id']);
- }
- $list = array_slice(list_sort_by($type,'value','desc'),0,6);
- HelpHander::success($list);
- }
- public function wxMateItemData(){
- $type = input('type',1); // 1=月
- if($type == 1){
- $where[] = ['create_time','>=',date('Y-m').'-01 00:00:00'];
- $where[] = ['create_time','<=',date('Y-m').'-31 00:00:00'];
- }else{
- $where[] = ['create_time','>=',date('Y').'-01-01 00:00:00'];
- $where[] = ['create_time','<=',date('Y').'-12-31 00:00:00'];
- }
- $list = Db::name('mate_goods')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->limit(6)
- ->select();
- $title = $count = [];
- foreach ($list as $k=>$v){
- $title[]= $v['title'];
- $nums = Db::name('todo_mate_item')
- ->where('items_id',$v['id'])
- ->where($where)
- ->sum('total');
- $count[] = $nums;
- }
- $data = [
- 'list'=>$count,
- 'title'=>$title,
- ];
- HelpHander::success($data);
- }
- public function wxDepData(){
- $date = date('Ymd');
- $edate = date('Ymd',strtotime("-1 months",strtotime($date)));
- $dep = Db::name('dep')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->limit(6)
- ->select();
- $title = $count = $count2 = [];
- foreach ($dep as $k=>$v){
- $title[] =$v['title'];
- $count[] = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('o.dep_id',$v['id'])
- ->where('t.work_type_mode',1)
- ->where('t.create_yyyymmdd',$date)
- ->where('t.del',0)
- ->where('t.org_id',$this->orgId)
- ->count();
- $nums= Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('o.dep_id',$v['id'])
- ->where('t.work_type_mode',1)
- ->where('t.create_yyyymmdd','<=',$date)
- ->where('t.create_yyyymmdd','>=',$edate)
- ->where('t.del',0)
- ->where('t.org_id',$this->orgId)
- ->count();
- $count2[] = round($nums/30,1);
- }
- $data =[
- 'title' =>$title,
- 'list' =>$count,
- 'list2' =>$count2,
- ];
- HelpHander::success($data);
- }
- }
|