Maintain.php 11 KB

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