Maintain.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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')
  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. $this->success(1, $info);
  76. }
  77. //报价单里列表
  78. public function baojia_info(){
  79. $order_id = input('order_id',0);
  80. $lists = Db::name('maintain_baojia')
  81. ->field('id,name,price,number,price_total')
  82. ->where('order_id',$order_id)->order('id asc')->select();
  83. $baojia_sum = Db::name('maintain')
  84. ->where('id',$order_id)
  85. ->value('baojia_sum');
  86. $rs = [
  87. 'list' => $lists,
  88. 'baojia_sum' => $baojia_sum
  89. ];
  90. $this->success(1,$rs);
  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($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. private function status_data($status){
  118. $data = [
  119. 0 => '待审核',
  120. 3 => '已取消',
  121. 10 => '待报价',
  122. 20 => '报价审核',
  123. 30 => '待维修',
  124. 40 => '已完成',
  125. ];
  126. return $data[$status];
  127. }
  128. }