Order.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. namespace app\api\controller\ue;
  3. use app\common\model\EnergyParam;
  4. use app\hander\HelpHander;
  5. use think\Controller;
  6. use think\Db;
  7. class Order extends Base {
  8. // 首页统计
  9. public function sytj(){
  10. $day = date('Ymd');
  11. $bjCount = Db::name('orders')
  12. ->where('create_yyyymmdd',$day)
  13. ->where('org_id',$this->orgId)
  14. ->where('del',0)
  15. ->where('work_type_mode',2)
  16. ->count(); // 今日保洁总数
  17. $bxCount = Db::name('orders')
  18. ->where('create_yyyymmdd',$day)
  19. ->where('org_id',$this->orgId)
  20. ->where('del',0)
  21. ->where('work_type_mode',1)
  22. ->count(); // 今日报修总数
  23. $count = Db::name('orders')
  24. ->where('org_id',$this->orgId)
  25. ->where('work_type_mode','in',[1,2])
  26. ->count(); // 今日报修和保洁总数
  27. $todo = Db::name('todo')
  28. ->where('create_yyyymmdd',$day)
  29. ->where('org_id',$this->orgId)
  30. ->where('del',0)
  31. ->where('work_type_mode','in',[1,2])
  32. ->count(); // 今日工单总数
  33. $finishtodo = Db::name('todo')
  34. ->where('create_yyyymmdd',$day)
  35. ->where('org_id',$this->orgId)
  36. ->where('del',0)
  37. ->where('todo_mode',3)
  38. ->where('work_type_mode','in',[1,2])
  39. ->count(); // 今日工单总数
  40. $bl = $todo > 0?round(($finishtodo/$todo)*100,1):0;
  41. $data = [
  42. 'count' => $count,
  43. 'bjCount' => $bjCount,
  44. 'bxCount' => $bxCount,
  45. 'todo' => $todo,
  46. 'bl' => $bl."%",
  47. ];
  48. HelpHander::success($data);
  49. }
  50. // 今日未完成的维修单
  51. public function wxorders(){
  52. $day = date('Ymd');
  53. $lists = Db::name('orders')
  54. ->alias('a')
  55. ->join('order_repair b','a.id = b.order_id')
  56. ->join('address c','c.id = b.address_id')
  57. ->where('a.create_yyyymmdd',$day)
  58. ->where('a.org_id',$this->orgId)
  59. ->where('a.del',0)
  60. ->where('b.address_id','>',0)
  61. ->whereNotNull('c.ueid')
  62. ->field('a.id,a.order_mode,a.content,a.images,c.ueid,c.title')
  63. ->order('a.id desc')
  64. ->select();
  65. $ueids = [];
  66. $nlist = [];
  67. $ordermodes = Db::name('order_mode')->select();
  68. foreach ($lists as $k=>$v){
  69. if(!in_array($v['ueid'],$ueids)){
  70. $ueids[] = $v['ueid'];
  71. // 获取状态
  72. $ordermodetext = "";
  73. foreach ($ordermodes as $ok=>$ov){
  74. if($ov['id'] == $v['order_mode']){
  75. $ordermodetext = $ov['out_content'];
  76. break;
  77. }
  78. }
  79. if($v['order_mode'] == 4){
  80. $todo = Db::name('todo')
  81. ->alias('a')
  82. ->join('user u','a.to_user_id = u.id')
  83. ->join('todo_mode b','a.todo_mode = b.id')
  84. ->where('a.order_id',$v['id'])
  85. ->where('a.todo_mode','in',[1,2,3,4])
  86. ->field('a.id,b.out_content,u.real_name')
  87. ->find();
  88. if($todo){
  89. $ordermodetext = "[".$todo['real_name']."]".$todo['out_content'];
  90. }
  91. }
  92. $v['order_mode_text'] = $ordermodetext;
  93. $v['images'] = empty($v['images'])?[]:explode(",",$v['images']);
  94. $nlist[] = $v;
  95. }
  96. }
  97. HelpHander::success($nlist);
  98. }
  99. // 项目任务数据分析
  100. public function ordertj(){
  101. $mode = input('mode/d',1); // 1=维修 2=保洁
  102. $type = input('type/d',1); // 1=日统计 2=月统计
  103. $eday = date("Y-m-d");
  104. $sday = date("Y-m-d",time() - 6*24*60*60);
  105. if($type == 1){
  106. $dates = getDateFromRange($sday, $eday);
  107. }else{
  108. $dates = get_month_last();
  109. }
  110. $x = [];
  111. $y1 = [];
  112. $y2 = [];
  113. foreach ($dates as $k=>$v){
  114. $map = [];
  115. $map[] = ['org_id','=',$this->orgId];
  116. $map[] = ['work_type_mode','=',$mode];
  117. if($type == 1){
  118. $d = date('Ymd',strtotime($v));
  119. $map[] = ['create_yyyymmdd','=',$d];
  120. $x[] = date('m-d',strtotime($v));
  121. }else{
  122. $d = date('Ym',strtotime($v));
  123. $map[] = ['create_yyyymm','=',$d];
  124. $x[] = date('Y-m',strtotime($v));
  125. }
  126. $map[] = ['del','=',0];
  127. $orders = Db::name('orders')->where($map)->count();
  128. $todos = Db::name('todo')->where($map)->count();
  129. $y1[] = $orders;
  130. $y2[] = $todos;
  131. }
  132. HelpHander::success(['x'=>$x,'y1'=>$y1,'y2'=>$y2]);
  133. }
  134. // 热点耗材数据分析
  135. public function mates(){
  136. $map[] = ['b.org_id','=',$this->orgId];
  137. $lists = Db::name('todo_mate_item')
  138. ->alias('a')
  139. ->join('todo_mate b','a.todo_mate_id = b.id')
  140. ->where($map)
  141. ->field('sum(a.total) as total,a.items_id')
  142. ->group('a.items_id')
  143. ->order('total desc')
  144. ->limit(4)
  145. ->select();
  146. $i = 1;
  147. foreach ($lists as $k=>$v){
  148. $lists[$k]['total'] = intval($v['total']);
  149. $title = Db::name('mate_items')->where('id',$v['items_id'])->value('title');
  150. $lists[$k]['title'] = $title?$title:'';
  151. $lists[$k]['rank'] = $i;
  152. $i++;
  153. }
  154. HelpHander::success($lists);
  155. }
  156. // 保洁网格化管理
  157. public function daily(){
  158. $map[] = ['enable', '=', 1];
  159. $map[] = ['org_id', '=', $this->orgId];
  160. $map[] = ['del', '=', 0];
  161. $lists = Db::name('daily')->where($map)->field('id,title')->orderRand()->limit(4)->select();
  162. $hours = model('Daily')->getTimeDaily($this->orgId);
  163. foreach ($lists as $k=>$v){
  164. $m = [];
  165. $m[] = ['org_id','=',$this->orgId];
  166. $m[] = ['daily_id','=',$v['id']];
  167. $m[] = ['create_time','>=',$hours['start']];
  168. $m[] = ['create_time','<',$hours['end']];
  169. $count = Db::name('daily_record')->where($m)->count();
  170. $lists[$k]['count'] = $count;
  171. }
  172. HelpHander::success($lists);
  173. }
  174. // 实时任务总览
  175. public function todos(){
  176. $map[] = ['org_id','=',$this->orgId];
  177. $map[] = ['del','=',0];
  178. $map[] = ['work_type_mode','in',[1,2]];
  179. $map[] = ['order_mode','in',[1,4]];
  180. $lists = Db::name('orders')->where($map)->limit(3)->order('id desc')->select();
  181. $nlist = [];
  182. foreach ($lists as $k=>$v){
  183. $work_text = $v['work_type_mode'] == 1?"维修任务":"保洁任务";
  184. $order_mode_text = "待处理";
  185. $users = "";
  186. if($v['order_mode'] == 4){
  187. $order_mode_text = "处理中";
  188. $ulist = Db::name('todo')
  189. ->alias('a')
  190. ->join('user b','a.to_user_id = b.id')
  191. ->where('a.order_id',$v['id'])
  192. ->where('a.todo_mode','in',[1,2,3,4])
  193. ->column('b.real_name');
  194. if($ulist){
  195. $users = implode(',',$ulist);
  196. }
  197. }
  198. $nlist[] = [
  199. 'work_text' => $work_text,
  200. 'order_mode_text' => $order_mode_text,
  201. 'users' => $users,
  202. 'content' => $v['content'],
  203. ];
  204. }
  205. HelpHander::success($nlist);
  206. }
  207. }