Maintain.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 保修
  7. */
  8. class Maintain extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function addone()
  13. {
  14. $info = input('info','');
  15. $filedata = input('filedata','','htmlspecialchars_decode');
  16. $mobile = input('mobile','');
  17. $address = input('address','');
  18. //视频类型追加缩略图
  19. $filedata = json_decode($filedata,true);
  20. foreach($filedata as $key => $file){
  21. if($file['type'] == 'video'){
  22. $file_url = explode('.', $file['url']);
  23. unset($file_url[count($file_url) - 1]);
  24. $file['images_thumb'] = implode('.', $file_url) . '_0.jpg';
  25. }else{
  26. $file['images_thumb'] = $file['url'];
  27. }
  28. $filedata[$key] = $file;
  29. }
  30. $filedata = json_encode($filedata);
  31. //写入
  32. $data = [
  33. 'orderno' => createUniqueNo('',''),
  34. 'user_id' => $this->auth->id,
  35. 'company_id' => $this->auth->company_id,
  36. 'createtime' => time(),
  37. 'updatetime' => time(),
  38. 'info' => $info,
  39. 'filedata' => $filedata,
  40. 'mobile' => $mobile,
  41. 'address' => $address,
  42. 'status' => 0,
  43. ];
  44. $order_id = Db::name('maintain')->insertGetId($data);
  45. $this->success('保修成功请等待审核', $order_id);
  46. }
  47. public function lists(){
  48. $status = input('status',0); //默认待审核
  49. $map = [
  50. 'user_id' => $this->auth->id,
  51. 'status' => $status,
  52. ];
  53. $list = Db::name('maintain')->field('id,orderno,createtime,info,filedata,status,eva_time')
  54. ->where($map)->order('id desc')
  55. ->autopage()->select();
  56. if(!empty($list)){
  57. $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
  58. foreach($list as $key => $val){
  59. $list[$key]['header_mobile'] = $header_mobile;
  60. $list[$key]['status_text'] = $this->status_data($val['status']);
  61. }
  62. }
  63. $this->success(1,$list);
  64. }
  65. public function info(){
  66. $id = input('id',0);
  67. $map = [
  68. 'user_id' => $this->auth->id,
  69. 'id' => $id,
  70. ];
  71. $info = Db::name('maintain')
  72. ->where($map)
  73. ->find();
  74. $info['status_text'] = $this->status_data($info['status']);
  75. $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
  76. $info['header_mobile'] = $header_mobile;
  77. //追加维修师傅
  78. $worker = [
  79. 'avatar' => 'http://weibao.com/assets/img/avatar.png',
  80. 'truename' => '李师傅',
  81. 'mobile' => '17666666666',
  82. ];
  83. $info['worker_info'] = $worker;
  84. //追加进度
  85. $jindu = Db::name('maintain_jindu')->field('id,title,createtime')->where('order_id',$id)->order('id desc')->select();
  86. $info['jindu'] = $jindu;
  87. $this->success(1, $info);
  88. }
  89. //取消上报
  90. public function cancel(){
  91. $id = input('id',0);
  92. $map = [
  93. 'user_id' => $this->auth->id,
  94. 'id' => $id,
  95. ];
  96. $info = Db::name('maintain')
  97. ->where($map)
  98. ->find();
  99. if(empty($info)){
  100. $this->error('不存在的订单');
  101. }
  102. if($info['status'] != 0){
  103. $this->error('现在已经不能取消了');
  104. }
  105. $nowtime = time();
  106. $update = [
  107. 'status' => 3,
  108. 'canceltime' => $nowtime,
  109. 'finishtime' => $nowtime,
  110. 'updatetime' => $nowtime,
  111. ];
  112. $rs = Db::name('maintain')
  113. ->where($map)->update($update);
  114. $this->success('取消成功');
  115. }
  116. //报价详情
  117. public function baojia_info(){
  118. $order_id = input('order_id',0);
  119. //找出最新报价日志
  120. $baojia_log = Db::name('maintain_baojia')->where('order_id',$order_id)->where('status',30)->order('id desc')->find();
  121. $baojia_log['status_text'] = $this->status_data($baojia_log['status']);
  122. $this->success(1,$baojia_log);
  123. }
  124. //报价审核
  125. public function baojia_audit(){
  126. $id = input('order_id',0);
  127. $status = input('status',2);
  128. $reason = input('reason','','trim');
  129. //必填
  130. if($status == 2 && empty($reason)){
  131. $this->error('请输入拒绝原因');
  132. }
  133. //检查订单
  134. $map = [
  135. 'user_id' => $this->auth->id,
  136. 'id' => $id,
  137. ];
  138. $info = Db::name('maintain')->where($map)->find();
  139. if(empty($info)){
  140. $this->error('不存在的订单');
  141. }
  142. if($info['status'] != 30){
  143. $this->success('订单错误,请刷新重试');
  144. }
  145. //找出最新报价日志
  146. $baojia_log = Db::name('maintain_baojia')->where('order_id',$id)->where('status',30)->order('id desc')->find();
  147. //更新订单
  148. //更新报价记录
  149. if($status == 2){
  150. $update = [
  151. 'status' => 14, // '报价用户审核驳回', //等待重新报价
  152. 'updatetime' => time(),
  153. ];
  154. $update_baojia = [
  155. 'status' => 14, // '报价用户审核驳回', //等待重新报价
  156. 'updatetime' => time(),
  157. 'baojia_useraudit_reason' => $reason,
  158. ];
  159. $remark = '报价已拒绝,即将重新报价';
  160. }else{
  161. $update = [
  162. 'status' => 40,
  163. 'updatetime' => time(),
  164. ];
  165. $update_baojia = [
  166. 'status' => 40,
  167. 'updatetime' => time(),
  168. ];
  169. $remark = '报价已通过,即将委派师傅';
  170. }
  171. Db::startTrans();
  172. $rs1 = Db::name('maintain')->where('id',$id)->update($update);
  173. if($rs1 === false){
  174. Db::rollback();
  175. $this->error('审核失败');
  176. }
  177. $rs2 = Db::name('maintain_baojia')->where('id',$baojia_log['id'])->update($update_baojia);
  178. if($rs2 === false){
  179. Db::rollback();
  180. $this->error('审核失败');
  181. }
  182. Db::commit();
  183. $this->success($remark);
  184. }
  185. //验收
  186. public function yanshou(){
  187. }
  188. //评价
  189. public function evaluate(){
  190. $id = input('order_id',0);
  191. $eva_info = input('eva_info','');
  192. $eva_score = input('eva_score',5);
  193. //检查订单
  194. $map = [
  195. 'user_id' => $this->auth->id,
  196. 'id' => $id,
  197. ];
  198. $info = Db::name('maintain')->where($map)->find();
  199. if(empty($info)){
  200. $this->error('不存在的订单');
  201. }
  202. if($info['status'] != 60){
  203. $this->success('订单未完成,请刷新重试');
  204. }
  205. if($info['eva_time'] != 0){
  206. $this->success('订单已评价,无需重复评价');
  207. }
  208. //更新
  209. $update = [
  210. 'eva_info' => $eva_info,
  211. 'eva_score' => $eva_score,
  212. 'eva_time' => time(),
  213. ];
  214. $rs1 = Db::name('maintain')->where('id',$id)->update($update);
  215. //维保公司的平均分修改
  216. $this->success('评价完成');
  217. }
  218. //状态枚举
  219. private function status_data($status){
  220. //状态:0=待审核,2=已取消,4=审核未通过,10=待报价,20=报价待审,30=报价用户待审,40=待处理,41=选师傅,60=已完成
  221. $data = [
  222. 0 => '待审核',
  223. 2 => '已取消',
  224. 4 => '审核未通过',
  225. 10 => '待报价', //等待初次报价
  226. 12 => '报价审核驳回', //等待再次报价
  227. 14 => '报价用户审核驳回',//等待再次报价
  228. 20 => '报价待审', //通过就去30,驳回就到12
  229. 30 => '报价用户待审', //通过就去40,驳回就到14
  230. 40 => '待处理', //报价都审核过了,可派师傅了
  231. 50 => '已选师傅',
  232. 60 => '材料已申请待领取',
  233. 70 => '材料已领取待上门',
  234. 80 => '已上门',
  235. 90 => '维修进度',
  236. 100 => '已完成',
  237. ];
  238. return $data[$status];
  239. }
  240. }