Todo.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\common\model\Config;
  5. use app\hander\HelpHander;
  6. use think\App;
  7. use think\Db;
  8. use think\exception\Handle;
  9. class Todo extends Base
  10. {
  11. public function __construct(App $app = null) {
  12. parent::__construct($app);
  13. $this->model = new \app\common\model\Todo();
  14. }
  15. //工单列表
  16. public function lists(){
  17. $page =input('page',1);
  18. $size =input('size',10);
  19. $type =input('type',0);
  20. $list = $this->model->lists($page,$size,$this->userId,$this->orgId,$type);
  21. HelpHander::success($list);
  22. }
  23. //工单详情
  24. public function detail(){
  25. $todoId =input('todoId',0);
  26. $info = $this->model->apiDetail($todoId);
  27. HelpHander::success($info);
  28. }
  29. // 处理驳回工单
  30. public function createNtbo(){
  31. $todoId = input('todoId');
  32. $toUserIdArray =input('toUserIdArray');
  33. $todoContent = input('todoContent');
  34. $typeId = input('typeId/d',0);
  35. $addressId = input('addressId/d',0);
  36. if(!$toUserIdArray){
  37. HelpHander::error('未选择执行人');
  38. }
  39. $ret = $this->model->createNtbo($todoId,$toUserIdArray,$todoContent,$this->userId,$typeId,$addressId);
  40. if(!$ret){
  41. HelpHander::error($this->model->getError());
  42. }
  43. HelpHander::success([],'操作成功');
  44. }
  45. // 修改状态 2=员工已经接单 4=被驳回 6=调度取消
  46. public function updateState(){
  47. $todoId = input('todoId/d',0);
  48. if($todoId <= 0){
  49. HelpHander::error('参数错误');
  50. }
  51. $todoMode =input('todoMode',0);
  52. if(!in_array($todoMode,[2,4,6])){
  53. HelpHander::error('参数错误');
  54. }
  55. $nodoReason = input('nodoReason','');
  56. if($todoMode == 6 && !$nodoReason){
  57. HelpHander::error('取消原因必需填写');
  58. }
  59. $rejectVoice = input('rejectVoice','');
  60. $ret = $this->model->updateState($todoId,$todoMode,$nodoReason,$this->userId,$rejectVoice);
  61. if(!$ret){
  62. HelpHander::error($this->model->getError());
  63. }
  64. HelpHander::success([],'操作成功');
  65. }
  66. //工单完成
  67. public function finishTodo(){
  68. $todoId =input('todoId/d');
  69. if($todoId <= 0){
  70. HelpHander::error('参数错误');
  71. }
  72. $todoMode = input('todoMode');
  73. if(!in_array($todoMode,[3,5])){
  74. HelpHander::error('参数错误');
  75. }
  76. $content = input('content');
  77. $consItems = input('consItems');
  78. $sign = input('sign');
  79. $images = input('img');
  80. if(!$content){
  81. HelpHander::error('未填写备注');
  82. }
  83. $ret = $this->model->finishTodo($todoId,$todoMode,$content,$this->userId,$images,$consItems,$sign);
  84. if(!$ret){
  85. HelpHander::error($this->model->getError());
  86. }
  87. HelpHander::success([],'操作成功');
  88. }
  89. //获取物品列表
  90. public function getMateGoods(){
  91. $page =input('page',1);
  92. $size =input('size',10);
  93. $title =input('title','','trim');
  94. $list = $this->model->getMateGoods($this->orgId,$this->userId,$title,$page,$size);
  95. HelpHander::success($list,'操作成功');
  96. }
  97. //收藏/取消收藏物品
  98. public function favGoods(){
  99. $type = input('type/d',0);
  100. $goodsId = input('goodsId/d',0);
  101. if(empty($goodsId)){
  102. HelpHander::error('物品不能为空');
  103. }
  104. $res = $this->model->favGoods($this->userId,$type,$goodsId);
  105. $res?HelpHander::success([],'操作成功'):HelpHander::error('操作失败');
  106. }
  107. //收藏列表
  108. public function favList(){
  109. $title =input('title','','trim');
  110. $list = $this->model->favList($this->userId,$title);
  111. HelpHander::success($list,'操作成功');
  112. }
  113. // 工单挂起
  114. public function pause(){
  115. $id = input('id/d',0);
  116. $reason = input('reason','','trim');
  117. if($id <= 0){
  118. HelpHander::error('参数错误');
  119. }
  120. if(!$reason){
  121. HelpHander::error('未填写挂起原因');
  122. }
  123. $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
  124. if(!$todo||$todo['to_user_id'] != $this->userId){
  125. HelpHander::error('工单不存在');
  126. }
  127. if($todo['todo_mode'] != 2){
  128. HelpHander::error('该状态不能挂起');
  129. }
  130. if($todo['work_type_mode'] != 1){
  131. HelpHander::error('该订单不能挂起');
  132. }
  133. if($todo['pause'] == 1){
  134. HelpHander::error('该订单已挂起');
  135. }
  136. $data = [
  137. 'pause' => 1,
  138. 'pause_time' => date('Y-m-d H:i:s'),
  139. 'pause_reason' => $reason
  140. ];
  141. if($todo['pause_time']){
  142. unset($data['pause_time']);
  143. }
  144. $ret = Db::name('todo')->where('id',$id)->update($data);
  145. // Db::name('todo_puase')
  146. // ->insert([
  147. // 'todo_id'=>$id,
  148. // 'reason'=>$reason,
  149. // 'create_time'=>getTime(),
  150. // ]);
  151. if(!$ret){
  152. HelpHander::error('操作失败');
  153. }
  154. HelpHander::success([],'操作成功');
  155. }
  156. //添加挂起进度
  157. public function addTodoPuase(){
  158. $id = input('id/d',0);
  159. $reason = input('reason','','trim');
  160. if($id <= 0){
  161. HelpHander::error('参数错误');
  162. }
  163. if(!$reason){
  164. HelpHander::error('未填写挂起原因');
  165. }
  166. $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
  167. if(!$todo||$todo['to_user_id'] != $this->userId){
  168. HelpHander::error('工单不存在');
  169. }
  170. if($todo['work_type_mode'] != 1){
  171. HelpHander::error('该订单不能挂起');
  172. }
  173. if($todo['pause'] != 1){
  174. HelpHander::error('该订单未挂起');
  175. }
  176. $ret = Db::name('todo_puase')
  177. ->insert([
  178. 'todo_id'=>$id,
  179. 'reason'=>$reason,
  180. 'create_time'=>getTime(),
  181. ]);
  182. if(!$ret){
  183. HelpHander::error('操作失败');
  184. }
  185. HelpHander::success([],'操作成功');
  186. }
  187. //获取待处理已完成已评价工单数量
  188. public function getOrdersCount(){
  189. $task = Db::name('task')
  190. ->where('user_id', $this->userId)
  191. ->where('org_id', $this->orgId)
  192. ->where('type',1)
  193. ->order('id','desc')
  194. ->select();
  195. $list = [];
  196. foreach ($task as $k => $value) {
  197. if ($value['type'] == 1) {//工单
  198. $todoInfo = Db::name('todo')
  199. ->where('id', $value['bus_id'])
  200. ->find();
  201. if (!empty($todoInfo)) {
  202. $list[] = $todoInfo;
  203. }
  204. } elseif($value['type'] == 2) {//巡更巡检
  205. $patrolInfo = Db::name('patrol_task')
  206. ->where('id', $value['bus_id'])
  207. ->find();
  208. if (!empty($patrolInfo)) {
  209. $list[] = $patrolInfo;
  210. }
  211. }elseif ($value['type'] == 3){ // 日常工作
  212. $dailyInfo = Db::name('daily_task')
  213. ->where('id', $value['bus_id'])
  214. ->find();
  215. if (!empty($dailyInfo)) {
  216. $list[] = $dailyInfo;
  217. }
  218. }elseif ($value['type'] == 4){ // 设备台账
  219. $deviceInfo = Db::name('device_task')
  220. ->where('id', $value['bus_id'])
  221. ->find();
  222. if (!empty($deviceInfo)) {
  223. $list[] = $deviceInfo;
  224. }
  225. }
  226. }
  227. $dcl = count($list);
  228. $map[] = ['to_user_id','=',$this->userId];
  229. $map[] = ['org_id','=',$this->orgId];
  230. $map[] = ['del','=',0];
  231. $a1 = Db::name('todo')
  232. ->where($map)
  233. ->where('todo_mode',3)
  234. ->count();
  235. $ywc = $a1?$a1:0;
  236. $ypj = Db::name('todo')
  237. ->alias('a')
  238. ->join('orders b','b.id=a.order_id','left')
  239. ->where('a.to_user_id',$this->userId)
  240. ->where('a.del',0)
  241. ->where('b.del',0)
  242. ->where('a.org_id',$this->orgId)
  243. ->where('b.order_mode',6)
  244. ->count();
  245. $data = [
  246. 'dcl'=>$dcl,
  247. 'ywc'=>$ywc,
  248. 'ypj'=>$ypj,
  249. 'pfdd'=>model('Orders')->orderCount($this->userId,$this->orgId,0),
  250. ];
  251. HelpHander::success($data);
  252. }
  253. //工单挂起结束
  254. public function pauseEnd(){
  255. $id = input('id/d',0);
  256. if($id <= 0){
  257. HelpHander::error('参数错误');
  258. }
  259. $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
  260. if(!$todo||$todo['to_user_id'] != $this->userId){
  261. HelpHander::error('工单不存在');
  262. }
  263. if($todo['todo_mode'] != 2){
  264. HelpHander::error('该状态不能挂起');
  265. }
  266. if($todo['work_type_mode'] != 1){
  267. HelpHander::error('该订单不能挂起');
  268. }
  269. if($todo['pause'] != 1){
  270. HelpHander::error('该订单未挂起不能结束');
  271. }
  272. $ret = Db::name('todo')->where('id',$id)->update([
  273. 'pause' => 2,
  274. 'pause_end' => date('Y-m-d H:i:s'),
  275. ]);
  276. Db::name('todo_puase')
  277. ->insert([
  278. 'todo_id'=>$id,
  279. 'reason'=>'挂起结束',
  280. 'create_time'=>getTime(),
  281. ]);
  282. if(!$ret){
  283. HelpHander::error('操作失败');
  284. }
  285. HelpHander::success([],'操作成功');
  286. }
  287. }