Maintain.php 7.8 KB

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