Maintain.php 12 KB

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