Maintain.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. namespace app\api\controller\worker;
  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 lists(){
  14. $status = input('status',0);
  15. $map = [
  16. 'worker_id' => $this->auth->id,
  17. 'status' => $status,
  18. ];
  19. $list = Db::name('maintain')->field('id,orderno,createtime,info,filedata,status,eva_time')
  20. ->where($map)->order('id desc')
  21. ->autopage()->select();
  22. if(!empty($list)){
  23. $maintain_model = new Maintainmodel();
  24. foreach($list as $key => $val){
  25. $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
  26. }
  27. }
  28. $this->success(1,$list);
  29. }
  30. public function info(){
  31. $id = input('id',0);
  32. $map = [
  33. 'worker_id' => $this->auth->id,
  34. 'id' => $id,
  35. ];
  36. $info = Db::name('maintain')
  37. ->where($map)
  38. ->find();
  39. $maintain_model = new Maintain();
  40. $info['status_text'] = $maintain_model->status_data($info['status']);
  41. //追加进度
  42. $jindu = Db::name('maintain_jindu')->field('id,title,createtime')->where('order_id',$id)->order('id desc')->select();
  43. $info['jindu'] = $jindu;
  44. $this->success(1, $info);
  45. }
  46. //申请材料
  47. public function shenqingcailiao(){
  48. $order_id = input('order_id',0);
  49. $data = input('data','','htmlspecialchars_decode');
  50. $data = json_decode($data,true);
  51. if(empty($data)){
  52. $this->error();
  53. }
  54. //订单
  55. $map = [
  56. 'worker_id' => $this->auth->id,
  57. 'id' => $order_id,
  58. ];
  59. $info = Db::name('maintain')->where($map)->find();
  60. if(empty($info)){
  61. $this->error('不存在的订单');
  62. }
  63. if($info['status'] != 50){
  64. $this->error('状态不正确,请刷新重试');
  65. }
  66. //准备数据
  67. foreach($data as $key => $val){
  68. $val['order_id'] = $info['id'];
  69. $val['company_id'] = $info['company_id'];
  70. $val['user_id'] = $info['user_id'];
  71. $val['worker_id'] = $info['worker_id'];
  72. $val['createtime'] = time();
  73. $data[$key] = $val;
  74. }
  75. Db::startTrans();
  76. $id = Db::name('maintain_cailiao')->insertAll($data);
  77. if(!$id){
  78. Db::rollback();
  79. $this->error('申请失败');
  80. }
  81. $update = [
  82. 'status' => 60,
  83. 'updatetime' => time(),
  84. 'cailiao_time' => time(), //材料申请时间
  85. ];
  86. $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
  87. if($rs2 === false){
  88. Db::rollback();
  89. $this->error('申请失败');
  90. }
  91. Db::commit();
  92. $this->success('申请成功');
  93. }
  94. //材料计量单位
  95. public function cailiao_danwei(){
  96. $data = [
  97. '个',
  98. '把',
  99. '只',
  100. ];
  101. $this->success(1,$data);
  102. }
  103. //领取材料
  104. public function lingqucailiao(){
  105. $order_id = input('order_id',0);
  106. $images = input('images','','trim');
  107. if(empty($images)){
  108. $this->error();
  109. }
  110. //订单
  111. $map = [
  112. 'worker_id' => $this->auth->id,
  113. 'id' => $order_id,
  114. ];
  115. $info = Db::name('maintain')->where($map)->find();
  116. if(empty($info)){
  117. $this->error('不存在的订单');
  118. }
  119. if($info['status'] != 60){
  120. $this->error('状态不正确,请刷新重试');
  121. }
  122. //
  123. $update = [
  124. 'status' => 70,
  125. 'updatetime' => time(),
  126. 'lingqu_time' => time(), //材料申请时间
  127. 'lingqu_images' => $images,
  128. ];
  129. $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
  130. if($rs2 === false){
  131. $this->error('领取失败');
  132. }
  133. $this->success('领取成功');
  134. }
  135. //////////////////////////////循环开始///////////////////////
  136. //立即上门
  137. public function shangmen(){
  138. $order_id = input('order_id',0);
  139. Db::startTrans();
  140. //订单
  141. $map = [
  142. 'worker_id' => $this->auth->id,
  143. 'id' => $order_id,
  144. ];
  145. $info = Db::name('maintain')->where($map)->lock(true)->find();
  146. if(empty($info)){
  147. Db::rollback();
  148. $this->error('不存在的订单');
  149. }
  150. if(!in_array($info['status'],[50,70])){
  151. Db::rollback();
  152. $this->error('状态不正确,请刷新重试');
  153. }
  154. $nowtime = time();
  155. //开启一个新轮回
  156. $weixiu = [
  157. 'order_id' => $info['id'],
  158. 'company_id' => $info['company_id'],
  159. 'user_id' => $info['user_id'],
  160. 'worker_id' => $info['worker_id'],
  161. 'weixiu_times' => $info['weixiu_times'] + 1, //次数自增1
  162. 'shangmen_time' => $nowtime,
  163. 'status' => 80,
  164. 'updatetime' => $nowtime,
  165. ];
  166. $weixiu_id = Db::name('maintain_weixiu')->insertGetId($weixiu);
  167. if(!$weixiu_id){
  168. Db::rollback();
  169. $this->error('操作失败,重试一下吧');
  170. }
  171. //新轮回第一个进度
  172. $jindu = [
  173. 'order_id' => $info['id'],
  174. 'company_id' => $info['company_id'],
  175. 'user_id' => $info['user_id'],
  176. 'worker_id' => $info['worker_id'],
  177. 'weixiu_times' => $weixiu['weixiu_times'],
  178. 'weixiu_id' => $weixiu_id,
  179. 'title' => '已上门',
  180. 'createtime' => $nowtime,
  181. ];
  182. $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu);
  183. if(!$jindu_id){
  184. Db::rollback();
  185. $this->error('操作失败,重试一下吧');
  186. }
  187. //修改订单
  188. $update = [
  189. 'status' => 80,
  190. 'updatetime' => time(),
  191. 'shangmen_time' => time(), //上门时间
  192. 'weixiu_times' => $weixiu['weixiu_times'],
  193. 'weixiu_id' => $weixiu_id,
  194. ];
  195. $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
  196. if($rs2 === false){
  197. Db::rollback();
  198. $this->error('操作失败,重试一下吧');
  199. }
  200. Db::commit();
  201. $this->success('操作成功');
  202. }
  203. //新增维修进度
  204. public function jindu_add(){
  205. $order_id = input('order_id',0);
  206. $title = input('title','');
  207. $images = input('images','');
  208. if(empty($title)){
  209. $this->error();
  210. }
  211. //订单
  212. $map = [
  213. 'worker_id' => $this->auth->id,
  214. 'id' => $order_id,
  215. ];
  216. $info = Db::name('maintain')->where($map)->find();
  217. if(empty($info)){
  218. $this->error('不存在的订单');
  219. }
  220. if($info['status'] != 80){
  221. $this->error('状态不正确,请刷新重试');
  222. }
  223. $nowtime = time();
  224. //准备数据
  225. $jindu = [
  226. 'order_id' => $info['id'],
  227. 'company_id' => $info['company_id'],
  228. 'user_id' => $info['user_id'],
  229. 'worker_id' => $info['worker_id'],
  230. 'weixiu_times' => $info['weixiu_times'],
  231. 'weixiu_id' => $info['weixiu_id'],
  232. 'title' => $title,
  233. 'images' => $images,
  234. 'createtime' => $nowtime,
  235. ];
  236. $id = Db::name('maintain_jindu')->insertAll($jindu);
  237. if(!$id){
  238. $this->error('操作失败');
  239. }
  240. $this->success('操作成功');
  241. }
  242. //确认完成
  243. public function finish(){
  244. $order_id = input('order_id',0);
  245. Db::startTrans();
  246. //订单
  247. $map = [
  248. 'worker_id' => $this->auth->id,
  249. 'id' => $order_id,
  250. ];
  251. $info = Db::name('maintain')->where($map)->lock(true)->find();
  252. if(empty($info)){
  253. Db::rollback();
  254. $this->error('不存在的订单');
  255. }
  256. if($info['status'] != 80){
  257. Db::rollback();
  258. $this->error('状态不正确,请刷新重试');
  259. }
  260. $nowtime = time();
  261. //结束最后一个轮回
  262. $weixiu = [
  263. 'status' => 90, //待验收
  264. 'wancheng_time' => $nowtime,
  265. 'updatetime' => $nowtime,
  266. ];
  267. $weixiu_rs = Db::name('maintain_weixiu')->where('id',$info['weixiu_id'])->update($weixiu);
  268. if($weixiu_rs === false){
  269. Db::rollback();
  270. $this->error('操作失败,重试一下吧');
  271. }
  272. //最后一个轮回,最后一个进度
  273. $jindu = [
  274. 'order_id' => $info['id'],
  275. 'company_id' => $info['company_id'],
  276. 'user_id' => $info['user_id'],
  277. 'worker_id' => $info['worker_id'],
  278. 'weixiu_times' => $info['weixiu_times'],
  279. 'weixiu_id' => $info['weixiu_id'],
  280. 'title' => '已完成',
  281. 'createtime' => $nowtime,
  282. ];
  283. $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu);
  284. if(!$jindu_id){
  285. Db::rollback();
  286. $this->error('操作失败,重试一下吧');
  287. }
  288. //修改订单
  289. $update = [
  290. 'status' => 90,
  291. 'wancheng_time' => $nowtime,
  292. 'updatetime' => $nowtime,
  293. ];
  294. $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
  295. if($rs2 === false){
  296. Db::rollback();
  297. $this->error('操作失败,重试一下吧');
  298. }
  299. Db::commit();
  300. $this->success('操作成功');
  301. }
  302. //////////////////////////////循环结束///////////////////////
  303. }