Maintain.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Maintain as Maintainmodel;
  5. use think\Db;
  6. /**
  7. * 保修
  8. */
  9. class Maintain extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //报修
  14. public function addone()
  15. {
  16. $info = input('info','');
  17. $filedata = input('filedata','','htmlspecialchars_decode');
  18. $mobile = input('mobile','');
  19. $address = input('address','');
  20. //视频类型追加缩略图
  21. $filedata = json_decode($filedata,true);
  22. foreach($filedata as $key => $file){
  23. if($file['type'] == 'video'){
  24. $file_url = explode('.', $file['url']);
  25. unset($file_url[count($file_url) - 1]);
  26. $file['images_thumb'] = implode('.', $file_url) . '_0.jpg';
  27. }else{
  28. $file['images_thumb'] = $file['url'];
  29. }
  30. $filedata[$key] = $file;
  31. }
  32. $filedata = json_encode($filedata);
  33. $nowtime = time();
  34. //写入
  35. $data = [
  36. 'orderno' => createUniqueNo('',''),
  37. 'user_id' => $this->auth->id,
  38. 'company_id' => $this->auth->company_id,
  39. 'createtime' => $nowtime,
  40. 'updatetime' => $nowtime,
  41. 'info' => $info,
  42. 'filedata' => $filedata,
  43. 'mobile' => $mobile,
  44. 'address' => $address,
  45. 'status' => 0,
  46. ];
  47. $order_id = Db::name('maintain')->insertGetId($data);
  48. $this->success('提交成功', $order_id);
  49. }
  50. //列表
  51. public function lists(){
  52. $status = input('status',0); //默认待审核
  53. $map = [
  54. 'user_id' => $this->auth->id,
  55. 'status' => $status,
  56. ];
  57. $field = ['id','orderno','createtime','info','filedata','status','eva_time'];
  58. $list = Db::name('maintain')->field($field)
  59. ->where($map)->order('id desc')
  60. ->autopage()->select();
  61. if(!empty($list)){
  62. //负责人的电话
  63. $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');
  64. $maintain_model = new Maintainmodel();
  65. foreach($list as $key => $val){
  66. $list[$key]['header_mobile'] = $header_mobile;
  67. $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
  68. }
  69. }
  70. $this->success(1,$list);
  71. }
  72. //详情
  73. public function info(){
  74. $id = input('id',0);
  75. $map = [
  76. 'user_id' => $this->auth->id,
  77. 'id' => $id,
  78. ];
  79. $field = ['id','orderno','createtime','info','filedata','mobile','address','status','finishtime','worker_id','shangmen_time','eva_info','eva_time','eva_score','weixiu_id'];
  80. $info = Db::name('maintain')->field($field)
  81. ->where($map)
  82. ->find();
  83. $maintain_model = new Maintainmodel();
  84. $info['status_text'] = $maintain_model->status_data($info['status']);
  85. //负责人的电话
  86. $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');
  87. $info['header_mobile'] = $header_mobile;
  88. //追加维修师傅
  89. $info['worker_info'] = [];
  90. if($info['worker_id'] != 0){
  91. $worker_info = Db::name('worker')->field('avatar,truename,mobile')->where('id',$info['worker_id'])->find();
  92. if(!empty($worker_info)){
  93. $worker_info['avatar'] = localpath_to_netpath($worker_info['avatar']);
  94. $info['worker_info'] = $worker_info;
  95. }
  96. }
  97. //追加进度
  98. $info['jindu_list'] = [];
  99. if($info['weixiu_id'] > 0){
  100. $jindu_list = Db::name('maintain_jindu')->field('id,title,images,createtime')->where('weixiu_id',$info['weixiu_id'])->order('id desc')->select();
  101. if(!empty($jindu_list)){
  102. $jindu_list = list_domain_image($jindu_list,['images']);
  103. $info['jindu_list'] = $jindu_list;
  104. }
  105. }
  106. $this->success(1, $info);
  107. }
  108. //取消上报
  109. public function cancel(){
  110. $id = input('id',0);
  111. $map = [
  112. 'user_id' => $this->auth->id,
  113. 'id' => $id,
  114. ];
  115. $info = Db::name('maintain')
  116. ->where($map)
  117. ->find();
  118. if(empty($info)){
  119. $this->error('不存在的订单');
  120. }
  121. if($info['status'] >= 40){ //报价都审核过了,可派师傅了
  122. $this->error('现在已经不能取消了');
  123. }
  124. $nowtime = time();
  125. $update = [
  126. 'status' => 2,
  127. 'canceltime' => $nowtime, //取消时间
  128. 'finishtime' => $nowtime,
  129. 'updatetime' => $nowtime,
  130. ];
  131. $rs = Db::name('maintain')
  132. ->where($map)->update($update);
  133. $this->success('取消成功');
  134. }
  135. //报价详情
  136. public function baojia_info(){
  137. $order_id = input('order_id',0);
  138. //找出最新报价日志
  139. $baojia_log = Db::name('maintain_baojia')->field('id,baojia_filename,baojia_file')->where('order_id',$order_id)->where('status',30)->order('id desc')->find();
  140. $baojia_log = info_domain_image($baojia_log,['baojia_file']);
  141. $this->success(1,$baojia_log);
  142. }
  143. //报价确认
  144. public function baojia_confirm(){
  145. $id = input('order_id',0);
  146. Db::startTrans();
  147. //检查订单
  148. $map = [
  149. 'user_id' => $this->auth->id,
  150. 'id' => $id,
  151. ];
  152. $info = Db::name('maintain')->where($map)->lock(true)->find();
  153. if(empty($info)){
  154. Db::rollback();
  155. $this->error('不存在的订单');
  156. }
  157. if($info['status'] != 30){ //用户待确认
  158. Db::rollback();
  159. $this->success('订单错误,请刷新重试');
  160. }
  161. //找出最新报价日志
  162. $baojia_log = Db::name('maintain_baojia')->where('order_id',$id)->where('status',30)->order('id desc')->find();
  163. $nowtime = time();
  164. //更新订单
  165. $update = [
  166. 'status' => 40,
  167. 'updatetime' => $nowtime,
  168. 'baojia_confirmtime' => $nowtime, //报价确认时间
  169. ];
  170. //更新报价记录
  171. $update_baojia = [
  172. 'status' => 40,
  173. 'updatetime' => $nowtime,
  174. 'baojia_useraudit_time' => $nowtime,
  175. ];
  176. $rs1 = Db::name('maintain')->where('id',$id)->update($update);
  177. if($rs1 === false){
  178. Db::rollback();
  179. $this->error('确认失败');
  180. }
  181. $rs2 = Db::name('maintain_baojia')->where('id',$baojia_log['id'])->update($update_baojia);
  182. if($rs2 === false){
  183. Db::rollback();
  184. $this->error('确认失败');
  185. }
  186. Db::commit();
  187. $this->success('报价已确认');
  188. }
  189. //验收
  190. public function yanshou(){
  191. $id = input('order_id',0);
  192. $status = input('status',2);//1=通过,2=拒绝
  193. $reason = input('reason','','trim');
  194. //必填
  195. if($status == 2 && empty($reason)){
  196. $this->error('请输入拒绝原因');
  197. }
  198. Db::startTrans();
  199. //检查订单
  200. $map = [
  201. 'user_id' => $this->auth->id,
  202. 'id' => $id,
  203. ];
  204. $info = Db::name('maintain')->where($map)->lock(true)->find();
  205. if(empty($info)){
  206. Db::rollback();
  207. $this->error('不存在的订单');
  208. }
  209. if($info['status'] != 90){ //师傅完成
  210. Db::rollback();
  211. $this->success('订单错误,请刷新重试');
  212. }
  213. $nowtime = time();
  214. //更新订单
  215. //更新维修
  216. if($status == 2){
  217. $update = [
  218. 'status' => 92, // '用户验收驳回'
  219. 'updatetime' => $nowtime,
  220. 'finishtime' => $nowtime,
  221. ];
  222. $update_weixiu = [
  223. 'status' => 92, // '用户验收驳回'
  224. 'updatetime' => $nowtime,
  225. 'audit_time' => $nowtime,
  226. 'audit_reason' => $reason,
  227. ];
  228. $remark = '验收已驳回';
  229. }else{
  230. $update = [
  231. 'status' => 100, //用户验收通过
  232. 'updatetime' => $nowtime,
  233. 'finishtime' => $nowtime,
  234. ];
  235. $update_weixiu = [
  236. 'status' => 100, //用户验收通过
  237. 'updatetime' => $nowtime,
  238. 'audit_time' => $nowtime,
  239. ];
  240. $remark = '验收已通过';
  241. }
  242. //最后一个轮回,追加验收进度
  243. $jindu = [
  244. 'order_id' => $info['id'],
  245. 'company_id' => $info['company_id'],
  246. 'user_id' => $info['user_id'],
  247. 'worker_id' => $info['worker_id'],
  248. 'weixiu_times' => $info['weixiu_times'],
  249. 'weixiu_id' => $info['weixiu_id'],
  250. 'title' => $remark,
  251. 'createtime' => $nowtime,
  252. ];
  253. $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu);
  254. if(!$jindu_id){
  255. Db::rollback();
  256. $this->error('验收失败');
  257. }
  258. $rs1 = Db::name('maintain')->where('id',$id)->update($update);
  259. if($rs1 === false){
  260. Db::rollback();
  261. $this->error('验收失败');
  262. }
  263. $rs2 = Db::name('maintain_weixiu')->where('id',$info['weixiu_id'])->update($update_weixiu);
  264. if($rs2 === false){
  265. Db::rollback();
  266. $this->error('验收失败');
  267. }
  268. Db::commit();
  269. $this->success($remark);
  270. }
  271. //评价
  272. public function evaluate(){
  273. $id = input('order_id',0);
  274. $eva_info = input('eva_info','');
  275. $eva_score = input('eva_score',5);
  276. //检查订单
  277. $map = [
  278. 'user_id' => $this->auth->id,
  279. 'id' => $id,
  280. ];
  281. $info = Db::name('maintain')->where($map)->find();
  282. if(empty($info)){
  283. $this->error('不存在的订单');
  284. }
  285. if($info['status'] != 100){
  286. $this->success('订单未验收通过,请刷新重试');
  287. }
  288. if($info['eva_time'] != 0){
  289. $this->success('订单已评价,无需重复评价');
  290. }
  291. //更新
  292. $update = [
  293. 'eva_info' => $eva_info,
  294. 'eva_score' => $eva_score,
  295. 'eva_time' => time(),
  296. ];
  297. $rs1 = Db::name('maintain')->where('id',$id)->update($update);
  298. //维保公司的平均分修改
  299. $this->success('评价完成');
  300. }
  301. }