Maintain.php 12 KB

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