Maintain.php 12 KB

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