123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace app\api\controller\ue;
- use app\common\model\EnergyParam;
- use app\hander\HelpHander;
- use think\Controller;
- use think\Db;
- class Order extends Base {
- // 首页统计
- public function sytj(){
- $day = date('Ymd');
- $bjCount = Db::name('orders')
- ->where('create_yyyymmdd',$day)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',2)
- ->count(); // 今日保洁总数
- $bxCount = Db::name('orders')
- ->where('create_yyyymmdd',$day)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',1)
- ->count(); // 今日报修总数
- $count = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode','in',[1,2])
- ->count(); // 今日报修和保洁总数
- $todo = Db::name('todo')
- ->where('create_yyyymmdd',$day)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode','in',[1,2])
- ->count(); // 今日工单总数
- $finishtodo = Db::name('todo')
- ->where('create_yyyymmdd',$day)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('todo_mode',3)
- ->where('work_type_mode','in',[1,2])
- ->count(); // 今日工单总数
- $bl = $todo > 0?round(($finishtodo/$todo)*100,1):0;
- $data = [
- 'count' => $count,
- 'bjCount' => $bjCount,
- 'bxCount' => $bxCount,
- 'todo' => $todo,
- 'bl' => $bl."%",
- ];
- HelpHander::success($data);
- }
- // 今日未完成的维修单
- public function wxorders(){
- $day = date('Ymd');
- $lists = Db::name('orders')
- ->alias('a')
- ->join('order_repair b','a.id = b.order_id')
- ->join('address c','c.id = b.address_id')
- ->where('a.create_yyyymmdd',$day)
- ->where('a.org_id',$this->orgId)
- ->where('a.del',0)
- ->where('b.address_id','>',0)
- ->whereNotNull('c.ueid')
- ->field('a.id,a.order_mode,a.content,a.images,c.ueid,c.title')
- ->order('a.id desc')
- ->select();
- $ueids = [];
- $nlist = [];
- $ordermodes = Db::name('order_mode')->select();
- foreach ($lists as $k=>$v){
- if(!in_array($v['ueid'],$ueids)){
- $ueids[] = $v['ueid'];
- // 获取状态
- $ordermodetext = "";
- foreach ($ordermodes as $ok=>$ov){
- if($ov['id'] == $v['order_mode']){
- $ordermodetext = $ov['out_content'];
- break;
- }
- }
- if($v['order_mode'] == 4){
- $todo = Db::name('todo')
- ->alias('a')
- ->join('user u','a.to_user_id = u.id')
- ->join('todo_mode b','a.todo_mode = b.id')
- ->where('a.order_id',$v['id'])
- ->where('a.todo_mode','in',[1,2,3,4])
- ->field('a.id,b.out_content,u.real_name')
- ->find();
- if($todo){
- $ordermodetext = "[".$todo['real_name']."]".$todo['out_content'];
- }
- }
- $v['order_mode_text'] = $ordermodetext;
- $v['images'] = empty($v['images'])?[]:explode(",",$v['images']);
- $nlist[] = $v;
- }
- }
- HelpHander::success($nlist);
- }
- // 项目任务数据分析
- public function ordertj(){
- $mode = input('mode/d',1); // 1=维修 2=保洁
- $type = input('type/d',1); // 1=日统计 2=月统计
- $eday = date("Y-m-d");
- $sday = date("Y-m-d",time() - 6*24*60*60);
- if($type == 1){
- $dates = getDateFromRange($sday, $eday);
- }else{
- $dates = get_month_last();
- }
- $x = [];
- $y1 = [];
- $y2 = [];
- foreach ($dates as $k=>$v){
- $map = [];
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['work_type_mode','=',$mode];
- if($type == 1){
- $d = date('Ymd',strtotime($v));
- $map[] = ['create_yyyymmdd','=',$d];
- $x[] = date('m-d',strtotime($v));
- }else{
- $d = date('Ym',strtotime($v));
- $map[] = ['create_yyyymm','=',$d];
- $x[] = date('Y-m',strtotime($v));
- }
- $map[] = ['del','=',0];
- $orders = Db::name('orders')->where($map)->count();
- $todos = Db::name('todo')->where($map)->count();
- $y1[] = $orders;
- $y2[] = $todos;
- }
- HelpHander::success(['x'=>$x,'y1'=>$y1,'y2'=>$y2]);
- }
- // 热点耗材数据分析
- public function mates(){
- $map[] = ['b.org_id','=',$this->orgId];
- $lists = Db::name('todo_mate_item')
- ->alias('a')
- ->join('todo_mate b','a.todo_mate_id = b.id')
- ->where($map)
- ->field('sum(a.total) as total,a.items_id')
- ->group('a.items_id')
- ->order('total desc')
- ->limit(4)
- ->select();
- $i = 1;
- foreach ($lists as $k=>$v){
- $lists[$k]['total'] = intval($v['total']);
- $title = Db::name('mate_items')->where('id',$v['items_id'])->value('title');
- $lists[$k]['title'] = $title?$title:'';
- $lists[$k]['rank'] = $i;
- $i++;
- }
- HelpHander::success($lists);
- }
- // 保洁网格化管理
- public function daily(){
- $map[] = ['enable', '=', 1];
- $map[] = ['org_id', '=', $this->orgId];
- $map[] = ['del', '=', 0];
- $lists = Db::name('daily')->where($map)->field('id,title')->orderRand()->limit(4)->select();
- $hours = model('Daily')->getTimeDaily($this->orgId);
- foreach ($lists as $k=>$v){
- $m = [];
- $m[] = ['org_id','=',$this->orgId];
- $m[] = ['daily_id','=',$v['id']];
- $m[] = ['create_time','>=',$hours['start']];
- $m[] = ['create_time','<',$hours['end']];
- $count = Db::name('daily_record')->where($m)->count();
- $lists[$k]['count'] = $count;
- }
- HelpHander::success($lists);
- }
- // 实时任务总览
- public function todos(){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['work_type_mode','in',[1,2]];
- $map[] = ['order_mode','in',[1,4]];
- $lists = Db::name('orders')->where($map)->limit(3)->order('id desc')->select();
- $nlist = [];
- foreach ($lists as $k=>$v){
- $work_text = $v['work_type_mode'] == 1?"维修任务":"保洁任务";
- $order_mode_text = "待处理";
- $users = "";
- if($v['order_mode'] == 4){
- $order_mode_text = "处理中";
- $ulist = Db::name('todo')
- ->alias('a')
- ->join('user b','a.to_user_id = b.id')
- ->where('a.order_id',$v['id'])
- ->where('a.todo_mode','in',[1,2,3,4])
- ->column('b.real_name');
- if($ulist){
- $users = implode(',',$ulist);
- }
- }
- $nlist[] = [
- 'work_text' => $work_text,
- 'order_mode_text' => $order_mode_text,
- 'users' => $users,
- 'content' => $v['content'],
- ];
- }
- HelpHander::success($nlist);
- }
- }
|