Maintain.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. use app\common\model\Maintain as Maintainmodel;
  6. /**
  7. * 维保流程
  8. */
  9. class Maintain extends Apic
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['index','info'];
  13. protected $table = 'maintain';
  14. //待处理数量
  15. public function count(){
  16. $map = [
  17. 'company_id' => $this->auth->company_id,
  18. 'status' => 0,
  19. ];
  20. if($this->auth->company_id == 1){
  21. $map = [
  22. 'status' => 0,
  23. 'liuzhuan_status' => 1,
  24. ];
  25. }
  26. $count = Db::name($this->table)
  27. ->where($map)->count();
  28. $this->success(1,$count);
  29. }
  30. //待审核 0
  31. //报价评估 20,22
  32. //报价审核 30
  33. //待处理 40,50,60,70,80,90,92
  34. //已完成 100
  35. //首页统计
  36. public function index(){
  37. if($this->auth->company_id == 1){
  38. return $this->liuzhuan_index();
  39. }
  40. $rs = [
  41. 'status_0' => 0,
  42. 'status_20' => 0,
  43. 'status_30' => 0,
  44. 'status_40' => 0,
  45. 'status_100' => 0,
  46. 'score' => 5,
  47. ];
  48. $list = Db::name($this->table)->field('status,count(id) as number')
  49. // ->where('status','NEQ',2)
  50. ->where('company_id',$this->auth->company_id)->group('status')->select();
  51. if(!empty($list)){
  52. foreach($list as $key => $val){
  53. if($val['status'] == 0){
  54. $rs['status_0'] = $val['number'];
  55. }
  56. if(in_array($val['status'],[20,22])){
  57. $rs['status_20'] += $val['number'];
  58. }
  59. if($val['status'] == 30){
  60. $rs['status_30'] = $val['number'];
  61. }
  62. if(in_array($val['status'],[40,50,60,70,80,90,92])){
  63. $rs['status_40'] += $val['number'];
  64. }
  65. /*if($val['status'] == 100){
  66. $rs['status_100'] = $val['number'];
  67. }*/
  68. if(in_array($val['status'],[2,100])){
  69. $rs['status_100'] += $val['number'];
  70. }
  71. }
  72. }
  73. //本周服务评分
  74. $score = Db::name($this->table)
  75. ->where('status',100)
  76. ->where('company_id',$this->auth->company_id)
  77. ->whereTime('eva_time','week')
  78. /*->select(false);echo $score;exit;*/
  79. ->avg('eva_score');
  80. $rs['score'] = $score;
  81. $this->success(1,$rs);
  82. }
  83. //首页统计
  84. public function liuzhuan_index(){
  85. $rs = [
  86. 'status_0' => 0,
  87. 'status_20' => 0,
  88. 'status_30' => 0,
  89. 'status_40' => 0,
  90. 'status_100' => 0,
  91. 'score' => 5,
  92. ];
  93. $list = Db::name($this->table)->field('status,count(id) as number')
  94. ->where('liuzhuan_status',1)->group('status')->select();
  95. if(!empty($list)){
  96. foreach($list as $key => $val){
  97. if($val['status'] == 0){
  98. $rs['status_0'] = $val['number'];
  99. }
  100. if(in_array($val['status'],[20,22])){
  101. $rs['status_20'] += $val['number'];
  102. }
  103. if($val['status'] == 30){
  104. $rs['status_30'] = $val['number'];
  105. }
  106. if(in_array($val['status'],[40,50,60,70,80,90,92])){
  107. $rs['status_40'] += $val['number'];
  108. }
  109. /*if($val['status'] == 100){
  110. $rs['status_100'] = $val['number'];
  111. }*/
  112. if(in_array($val['status'],[2,100])){
  113. $rs['status_100'] += $val['number'];
  114. }
  115. }
  116. }
  117. //本周服务评分
  118. $score = Db::name($this->table)
  119. ->where('status',100)
  120. ->where('liuzhuan_status',1)
  121. ->whereTime('eva_time','week')
  122. /*->select(false);echo $score;exit;*/
  123. ->avg('eva_score');
  124. $rs['score'] = $score;
  125. $this->success(1,$rs);
  126. }
  127. //列表
  128. public function lists(){
  129. if($this->auth->company_id == 1){
  130. return $this->liuzhuan_lists();
  131. }
  132. $orderno = input('orderno','');
  133. $projectname = input('projectname','');
  134. $header = input('header','');
  135. $status = input('status','ALL'); //默认ALL
  136. $map = [
  137. 'mt.company_id' => $this->auth->company_id,
  138. ];
  139. if(!empty($orderno)){
  140. $map['mt.orderno'] = $orderno;
  141. }
  142. if(!empty($projectname)){
  143. $map['uc.projectname'] = ['LIKE','%'.$projectname.'%'];
  144. }
  145. if(!empty($header)){
  146. $map['uc.header'] = ['LIKE','%'.$header.'%'];
  147. }
  148. if($status != 'ALL'){
  149. $map['mt.status'] = $status;
  150. if($status == 20){
  151. $map['mt.status'] = ['IN',[20,22]];
  152. }
  153. if($status == 40){
  154. $map['mt.status'] = ['IN',[40,50,60,70,80,90,92]];
  155. }
  156. if($status == 100){
  157. $map['mt.status'] = ['IN',[2,100]];
  158. }
  159. }
  160. $field = ['mt.id','mt.orderno','uc.projectname','mt.info','uc.header','mt.status','mt.price','mt.liuzhuan_status','company.companyname'];
  161. $list = Db::name($this->table)->alias('mt')
  162. ->join('user_company uc','mt.uc_id = uc.id','LEFT')
  163. ->join('company','mt.company_id = company.id','LEFT')
  164. ->field($field)
  165. ->where($map)->order('mt.id desc')
  166. ->paginate();
  167. $total = $list->total();
  168. $list = $list->items();
  169. if(!empty($list)){
  170. $maintain_model = new Maintainmodel();
  171. foreach($list as $key => $val){
  172. $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
  173. //pc用户,已流转订单,直接显示流转中
  174. if($this->auth->company_id != 1 && in_array($val['status'],[0,20,22,30,40]) && $val['liuzhuan_status'] == 1){
  175. $list[$key]['status_text'] = '流转中';
  176. }
  177. $list[$key]['status_colorType'] = $maintain_model->status_colorType($val['status']);
  178. //假状态
  179. $list[$key]['fake_status'] = $this->fake_status($val['status']);
  180. $list[$key]['fake_status_text'] = $this->fake_status_data($val['status']);
  181. }
  182. }
  183. $rs = [
  184. 'list' => $list,
  185. 'total'=> $total,
  186. ];
  187. $this->success(1,$rs);
  188. }
  189. //流转列表
  190. public function liuzhuan_lists(){
  191. $orderno = input('orderno','');
  192. $projectname = input('projectname','');
  193. $header = input('header','');
  194. $status = input('status','ALL'); //默认ALL
  195. $map = [
  196. 'mt.liuzhuan_status' => 1,
  197. ];
  198. if(!empty($orderno)){
  199. $map['mt.orderno'] = $orderno;
  200. }
  201. if(!empty($projectname)){
  202. $map['uc.projectname'] = ['LIKE','%'.$projectname.'%'];
  203. }
  204. if(!empty($header)){
  205. $map['uc.header'] = ['LIKE','%'.$header.'%'];
  206. }
  207. if($status != 'ALL'){
  208. $map['mt.status'] = $status;
  209. if($status == 20){
  210. $map['mt.status'] = ['IN',[20,22]];
  211. }
  212. if($status == 40){
  213. $map['mt.status'] = ['IN',[40,50,60,70,80,90,92]];
  214. }
  215. if($status == 100){
  216. $map['mt.status'] = ['IN',[2,100]];
  217. }
  218. }
  219. $field = ['mt.id','mt.orderno','uc.projectname','mt.info','uc.header','mt.status','mt.price','mt.liuzhuan_status','company.companyname'];
  220. $list = Db::name($this->table)->alias('mt')
  221. ->join('user_company uc','mt.uc_id = uc.id','LEFT')
  222. ->join('company','mt.company_id = company.id','LEFT')
  223. ->field($field)
  224. ->where($map)->order('mt.id desc')
  225. ->paginate();
  226. $total = $list->total();
  227. $list = $list->items();
  228. if(!empty($list)){
  229. $maintain_model = new Maintainmodel();
  230. foreach($list as $key => $val){
  231. $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
  232. $list[$key]['status_colorType'] = $maintain_model->status_colorType($val['status']);
  233. //假状态
  234. $list[$key]['fake_status'] = $this->fake_status($val['status']);
  235. $list[$key]['fake_status_text'] = $this->fake_status_data($val['status']);
  236. }
  237. }
  238. $rs = [
  239. 'list' => $list,
  240. 'total'=> $total,
  241. ];
  242. $this->success(1,$rs);
  243. }
  244. /**
  245. * 查看导出
  246. */
  247. public function showinfo(){
  248. $id = input('id',0);
  249. $info = Db::name('maintain')->alias('mt')
  250. ->join('user_company uc','mt.uc_id = uc.id','LEFT')
  251. ->join('user','mt.user_id = user.id','LEFT')
  252. ->join('worker','mt.worker_id = worker.id','LEFT')
  253. ->join('company','mt.company_id = company.id','LEFT')
  254. ->field('mt.*,uc.projectname,uc.header,uc.header_mobile,uc.projectaddress,user.nickname as user_nickname,user.mobile as user_mobile,worker.truename as worker_truename,worker.mobile as worker_mobile,company.companyname')
  255. ->where('mt.id',$id)
  256. ->find();
  257. if(empty($info)){
  258. echo '没找到订单';
  259. exit;
  260. }
  261. if($info['company_id'] != $this->auth->company_id){
  262. echo '没找到订单';
  263. exit;
  264. }
  265. $maintain_model = new Maintainmodel();
  266. $info['status_text'] = $maintain_model->status_data($info['status']);
  267. //pc用户,已流转订单,直接显示流转中
  268. if($info['company_id'] != 1 && in_array($info['status'],[0,20,22,30,40]) && $info['liuzhuan_status'] == 1){
  269. $info['status_text'] = '流转中';
  270. }
  271. $info['status_colorType'] = $maintain_model->status_colorType($info['status']);
  272. //假状态
  273. $info['fake_status'] = $this->fake_status($info['status']);
  274. $info['fake_status_text'] = $this->fake_status_data($info['status']);
  275. $info['filedata'] = json_decode($info['filedata'],true);
  276. //追加报价历史
  277. $baojia = Db::name('maintain_baojia')->alias('bj')
  278. ->field('bj.*,admin.nickname as baojia_nickname,audit.nickname as baojia_audit_nickname')
  279. ->join('pc_admin admin','bj.baojia_staffid = admin.id','LEFT')
  280. ->join('pc_admin audit','bj.baojia_audit_staffid = audit.id','LEFT')
  281. ->where('order_id',$id)->order('id desc')->select();
  282. if(!empty($baojia)){
  283. foreach($baojia as $key => $val){
  284. $baojia[$key]['status_text'] = $maintain_model->baojia_status_data($val['status']);
  285. }
  286. }
  287. $info['baojia_list'] = $baojia;
  288. //追加材料列表
  289. $info['cailiao_list'] = Db::name('maintain_cailiao')->field('id,name,number,danwei,images')->where('order_id',$id)->order('id desc')->select();
  290. //追加多次维修+对应进度历史
  291. $last_jindulist = [];
  292. $new_jindulist = [];
  293. $jindu_list = Db::name('maintain_jindu')->alias('jd')
  294. ->join('worker','jd.worker_id = worker.id','LEFT')
  295. ->field('jd.id,jd.worker_id,jd.weixiu_times,jd.title,jd.images,jd.createtime,worker.avatar,worker.truename')
  296. ->where('jd.order_id',$id)
  297. ->order('jd.id desc')->select();
  298. if(!empty($jindu_list)){
  299. for($i=$jindu_list[0]['weixiu_times'];$i>=1;$i--){
  300. foreach($jindu_list as $key => $val){
  301. if($i == $val['weixiu_times']){
  302. $new_jindulist[$i][] = $val;
  303. }
  304. }
  305. }
  306. foreach($new_jindulist as $key => $val){
  307. $last_jindulist[] = [
  308. 'title' => '第'.$val[0]['weixiu_times'].'次',
  309. 'child' => $val
  310. ];
  311. }
  312. }
  313. $info['jindu'] = $last_jindulist;
  314. $this->assign('info', $info);
  315. // dump($info);exit;
  316. return $this->fetch();
  317. // $this->view->assign('info','ffff');
  318. // return $this->view->fetch();
  319. }
  320. //整合过的状态
  321. private function fake_status_data($status){
  322. $data = [
  323. 0 => '待报价',
  324. 2 => '已取消',
  325. 20 => '评估报价',
  326. 22 => '评估报价',
  327. 30 => '用户待确认',
  328. 40 => '待处理',
  329. 50 => '待处理',
  330. 60 => '待处理',
  331. 70 => '待处理',
  332. 80 => '待处理',
  333. 90 => '待处理',
  334. 92 => '待处理',
  335. 100 => '已完成',
  336. ];
  337. return isset($data[$status]) ? $data[$status] : $status;
  338. }
  339. //整合过的状态
  340. private function fake_status($status){
  341. $data = [
  342. 0 => 0,
  343. 2 => 2,
  344. 20 => 20,
  345. 22 => 20,
  346. 30 => 30,
  347. 40 => 40,
  348. 50 => 40,
  349. 60 => 40,
  350. 70 => 40,
  351. 80 => 40,
  352. 90 => 40,
  353. 92 => 40,
  354. 100 => 100,
  355. ];
  356. return isset($data[$status]) ? $data[$status] : $status;
  357. }
  358. //详情
  359. public function info(){
  360. $id = input('id',0);
  361. $info = Db::name($this->table)->alias('mt')
  362. ->join('user_company uc','mt.uc_id = uc.id','LEFT')
  363. ->join('user','mt.user_id = user.id','LEFT')
  364. ->join('worker','mt.worker_id = worker.id','LEFT')
  365. ->join('company','mt.company_id = company.id','LEFT')
  366. ->field('mt.*,uc.projectname,uc.header,uc.header_mobile,uc.projectaddress,user.nickname as user_nickname,user.mobile as user_mobile,worker.truename as worker_truename,worker.mobile as worker_mobile,company.companyname')
  367. ->where('mt.id',$id)
  368. ->find();
  369. if($info['company_id'] != $this->auth->company_id){
  370. $this->error('没找到订单');
  371. }
  372. $maintain_model = new Maintainmodel();
  373. $info['status_text'] = $maintain_model->status_data($info['status']);
  374. //pc用户,已流转订单,直接显示流转中
  375. if($info['company_id'] != 1 && in_array($info['status'],[0,20,22,30,40]) && $info['liuzhuan_status'] == 1){
  376. $info['status_text'] = '流转中';
  377. }
  378. $info['status_colorType'] = $maintain_model->status_colorType($info['status']);
  379. //假状态
  380. $info['fake_status'] = $this->fake_status($info['status']);
  381. $info['fake_status_text'] = $this->fake_status_data($info['status']);
  382. $info['filedata'] = json_decode($info['filedata'],true);
  383. //追加报价历史
  384. $baojia = Db::name('maintain_baojia')->alias('bj')
  385. ->field('bj.*,admin.nickname as baojia_nickname,audit.nickname as baojia_audit_nickname')
  386. ->join('pc_admin admin','bj.baojia_staffid = admin.id','LEFT')
  387. ->join('pc_admin audit','bj.baojia_audit_staffid = audit.id','LEFT')
  388. ->where('order_id',$id)->order('id desc')->select();
  389. if(!empty($baojia)){
  390. foreach($baojia as $key => $val){
  391. $baojia[$key]['status_text'] = $maintain_model->baojia_status_data($val['status']);
  392. }
  393. }
  394. $info['baojia_list'] = $baojia;
  395. //追加材料列表
  396. $cailiao_list = Db::name('maintain_cailiao')->field('id,name,number,danwei,images,createtime')->where('order_id',$id)->order('id desc')->select();
  397. $info['cailiao_list'] = list_domain_image($cailiao_list,['images']);
  398. //追加多次维修+对应进度历史
  399. $last_jindulist = [];
  400. $new_jindulist = [];
  401. $jindu_list = Db::name('maintain_jindu')->alias('jd')
  402. ->join('worker','jd.worker_id = worker.id','LEFT')
  403. ->field('jd.id,jd.worker_id,jd.weixiu_times,jd.title,jd.images,jd.createtime,worker.avatar,worker.truename')
  404. ->where('jd.order_id',$id)
  405. ->order('jd.id desc')->select();
  406. if(!empty($jindu_list)){
  407. for($i=$jindu_list[0]['weixiu_times'];$i>=1;$i--){
  408. foreach($jindu_list as $key => $val){
  409. if($i == $val['weixiu_times']){
  410. $new_jindulist[$i][] = $val;
  411. }
  412. }
  413. }
  414. foreach($new_jindulist as $key => $val){
  415. $last_jindulist[] = [
  416. 'title' => '第'.$val[0]['weixiu_times'].'次',
  417. 'child' => $val
  418. ];
  419. }
  420. }
  421. $info['jindu'] = $last_jindulist;
  422. $this->success(1,$info);
  423. }
  424. //提交报价
  425. public function baojia(){
  426. $id = input('id',0);
  427. $baojia_file = input('baojia_file','');
  428. $baojia_filename = input('baojia_filename','');
  429. if(empty($baojia_file) || empty($baojia_filename)){
  430. $this->error();
  431. }
  432. Db::startTrans();
  433. $info = Db::name($this->table)->where('id',$id)->lock(true)->find();
  434. if(empty($info)){
  435. Db::rollback();
  436. $this->error('没找到该信息,请刷新重试');
  437. }
  438. if($info['company_id'] != $this->auth->company_id){
  439. Db::rollback();
  440. $this->error('没找到该信息,请刷新重试');
  441. }
  442. if($info['status'] == 20){
  443. Db::rollback();
  444. $this->error('当前订单报价正在审核中');
  445. }
  446. if($info['status'] != 22 && $info['status'] != 0){
  447. Db::rollback();
  448. $this->error('当前订单不能报价');
  449. }
  450. //报价
  451. $nowtime = time();
  452. $baojia_data = [
  453. 'order_id' => $info['id'],
  454. 'company_id' => $info['company_id'],
  455. 'user_id' => $info['user_id'],
  456. 'baojia_staffid' => $this->auth->id,
  457. 'baojia_time' => $nowtime,
  458. 'baojia_filename' => $baojia_filename,
  459. 'baojia_file' => $baojia_file,
  460. 'status' => 20,
  461. 'updatetime' => $nowtime,
  462. ];
  463. $baojia_id = Db::name('maintain_baojia')->insertGetId($baojia_data);
  464. if(!$baojia_id){
  465. Db::rollback();
  466. $this->error('报价失败,请重试');
  467. }
  468. //
  469. $update = [
  470. 'status' => 20,
  471. 'updatetime' => $nowtime,
  472. ];
  473. $rs_update = Db::name($this->table)->where('id',$id)->update($update);
  474. if($rs_update === false){
  475. Db::rollback();
  476. $this->error('报价失败,请重试');
  477. }
  478. //
  479. Db::commit();
  480. $this->success();
  481. }
  482. //审核报价
  483. public function baojia_audit(){
  484. $baojia_id = input('baojia_id',0);
  485. $status = input('status',2);
  486. $reason = input('reason','');
  487. Db::startTrans();
  488. $nowtime = time();
  489. $baojia_info = Db::name('maintain_baojia')->where('id',$baojia_id)->lock(true)->find();
  490. if(empty($baojia_info)){
  491. Db::rollback();
  492. $this->error('没找到该信息,请刷新重试');
  493. }
  494. $info = Db::name($this->table)->where('id',$baojia_info['order_id'])->lock(true)->find();
  495. if(empty($info)){
  496. Db::rollback();
  497. $this->error('没找到该信息,请刷新重试');
  498. }
  499. if($info['company_id'] != $this->auth->company_id){
  500. Db::rollback();
  501. $this->error('没找到该信息,请刷新重试');
  502. }
  503. if($baojia_info['status'] != 20){
  504. Db::rollback();
  505. $this->error('状态错误不能审核,请刷新重试');
  506. }
  507. if($info['status'] != 20){
  508. Db::rollback();
  509. $this->error('状态错误不能审核,请刷新重试');
  510. }
  511. if($status == 1){
  512. //通过
  513. $baojia_update = [
  514. 'status' => 30,
  515. 'baojia_audit_staffid' => $this->auth->id,
  516. 'baojia_audit_time' => $nowtime,
  517. 'updatetime' => $nowtime,
  518. ];
  519. }else{
  520. //驳回
  521. $baojia_update = [
  522. 'status' => 22,
  523. 'baojia_audit_staffid' => $this->auth->id,
  524. 'baojia_audit_time' => $nowtime,
  525. 'baojia_audit_reason' => $reason,
  526. 'updatetime' => $nowtime,
  527. ];
  528. }
  529. $rs_audit = Db::name('maintain_baojia')->where('id',$baojia_id)->update($baojia_update);
  530. if($rs_audit === false){
  531. Db::rollback();
  532. $this->error('审核失败,请重试');
  533. }
  534. //订单
  535. $update = [
  536. 'status' => $baojia_update['status'],
  537. 'updatetime' => $nowtime,
  538. ];
  539. $rs_update = Db::name($this->table)->where('id',$baojia_info['order_id'])->update($update);
  540. if($rs_update === false){
  541. Db::rollback();
  542. $this->error('审核失败,请重试');
  543. }
  544. //
  545. Db::commit();
  546. $this->success();
  547. }
  548. //流转到总公司
  549. public function liuzhuan(){
  550. $id = input('id',0);
  551. Db::startTrans();
  552. $info = Db::name($this->table)->where('id',$id)->lock(true)->find();
  553. if(empty($info)){
  554. Db::rollback();
  555. $this->error('没找到该信息,请刷新重试');
  556. }
  557. if($info['company_id'] != $this->auth->company_id){
  558. Db::rollback();
  559. $this->error('没找到该信息,请刷新重试');
  560. }
  561. if(!in_array($info['status'],[0,20,22,30,40])){
  562. Db::rollback();
  563. $this->error('当前订单状态,不能流转');
  564. }
  565. if(!empty($info['worker_id'])){
  566. Db::rollback();
  567. $this->error('已经指派了师傅,不能流转了');
  568. }
  569. //
  570. $update = [
  571. 'liuzhuan_status' => 1,
  572. 'updatetime' => time(),
  573. ];
  574. $rs_update = Db::name($this->table)->where('id',$id)->update($update);
  575. if($rs_update === false){
  576. Db::rollback();
  577. $this->error('流转失败,请重试');
  578. }
  579. //
  580. Db::commit();
  581. $this->success();
  582. }
  583. //指派师傅
  584. public function zhipai(){
  585. //检查师傅
  586. $worker_id = input('worker_id',0);
  587. $worker = Db::name('worker')->where('id',$worker_id)->where('status',1)->where('company_id',$this->auth->company_id)->find();
  588. if(empty($worker)){
  589. $this->error('没找到该师傅');
  590. }
  591. //检查订单
  592. $id = input('id',0);
  593. Db::startTrans();
  594. $info = Db::name($this->table)->where('id',$id)->lock(true)->find();
  595. if(empty($info)){
  596. Db::rollback();
  597. $this->error('没找到该信息,请刷新重试');
  598. }
  599. if($this->auth->company_id != 1 && $info['company_id'] != $this->auth->company_id){
  600. Db::rollback();
  601. $this->error('没找到该信息,请刷新重试');
  602. }
  603. /*if(in_array($info['status'],[20,22,30])){
  604. Db::rollback();
  605. $this->error('报价未确认,还不能指派师傅');
  606. }
  607. if($info['status'] != 0 && $info['status'] != 40 ){
  608. Db::rollback();
  609. $this->error('当前订单状态,不能指派师傅');
  610. }*/
  611. if(!in_array($info['status'],[0,20,22,30,40])){
  612. Db::rollback();
  613. $this->error('当前订单状态,不能指派师傅');
  614. }
  615. if(!empty($info['worker_id'])){
  616. Db::rollback();
  617. $this->error('已经指派了师傅');
  618. }
  619. //
  620. $update = [
  621. 'worker_id' => $worker_id,
  622. 'status' => 50,
  623. 'updatetime' => time(),
  624. ];
  625. $rs_update = Db::name($this->table)->where('id',$id)->update($update);
  626. if($rs_update === false){
  627. Db::rollback();
  628. $this->error('指派失败,请重试');
  629. }
  630. //
  631. Db::commit();
  632. $this->success();
  633. }
  634. //修改报价金额
  635. public function set_price(){
  636. $id = input('id',0);
  637. $price = input('price',0);
  638. $update = [
  639. 'price' => $price,
  640. 'updatetime' => time(),
  641. ];
  642. $rs_update = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->update($update);
  643. $this->success();
  644. }
  645. }