Maintain.php 10 KB

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