123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- <?php
- namespace app\api\controller\worker;
- use app\common\controller\Apiw;
- use app\common\model\Maintain as Maintainmodel;
- use think\Db;
- /**
- * 保修
- */
- class Maintain extends Apiw
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //订单列表
- public function lists(){
- //待处理,50,60
- //进行中,70,80,92
- //待审核,90
- //已完成,100
- $status = input('status',0);
- $map = [
- 'm.worker_id' => $this->auth->id,
- 'm.status' => $status,
- ];
- if($status == 50){
- $map['m.status'] = ['IN',[50,60]];
- }
- if($status == 80){
- $map['m.status'] = ['IN',[70,80,92]];
- }
- $field = [
- 'm.id','m.orderno','m.info','m.filedata','m.mobile','m.address','m.status','m.cailiao_time','m.lingqu_time','m.shangmen_time','m.wancheng_time',
- 'user.contactname',
- 'uc.projectname'
- ];
- $list = Db::name('maintain')->alias('m')->field($field)
- ->join('user','m.user_id = user.id','LEFT')
- ->join('user_company uc','m.user_id = uc.user_id','LEFT')
- ->where($map)->order('m.id desc')
- ->autopage()->select();
- if(!empty($list)){
- $maintain_model = new Maintainmodel();
- foreach($list as $key => $val){
- $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
- $list[$key]['filedata'] = !empty($val['filedata']) ? json_decode($val['filedata'],true) : [];
- }
- }
- $this->success(1,$list);
- }
- //材料清单
- public function cailiao_list(){
- $id = input('order_id',0);
- $result = [];
- $list = Db::name('maintain_cailiao')->field('id,order_id,name,number,danwei,images')->where('order_id',$id)->order('id desc')->select();
- if(!empty($list)){
- $result = list_domain_image($list,['images']);
- }
- $this->success(1, $result);
- }
- //进度列表
- public function jindu_list(){
- $id = input('order_id',0);
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $id,
- ];
- $info = Db::name('maintain')
- ->where($map)
- ->find();
- //追加进度
- //追加多次维修+对应进度历史
- $last_jindulist = [];
- $new_jindulist = [];
- $jindu_list = Db::name('maintain_jindu')->alias('jd')
- ->join('worker','jd.worker_id = worker.id','LEFT')
- ->field('jd.id,jd.worker_id,jd.weixiu_times,jd.title,jd.images,jd.createtime,worker.avatar,worker.truename')
- ->where('jd.order_id',$id)
- ->order('jd.id desc')->select();
- $jindu_list = list_domain_image($jindu_list,['avatar','images']);
- if(!empty($jindu_list)){
- for($i=$jindu_list[0]['weixiu_times'];$i>=1;$i--){
- foreach($jindu_list as $key => $val){
- if($i == $val['weixiu_times']){
- $new_jindulist[$i][] = $val;
- }
- }
- }
- foreach($new_jindulist as $key => $val){
- $last_jindulist[] = [
- 'title' => '第'.$val[0]['weixiu_times'].'次',
- 'child' => $val
- ];
- }
- }
- $this->success(1, $last_jindulist);
- }
- //申请材料
- public function shenqingcailiao(){
- $order_id = input('order_id',0);
- $data = input('data','','htmlspecialchars_decode');
- $data = json_decode($data,true);
- if(empty($data)){
- $this->error();
- }
- Db::startTrans();
- //订单
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $order_id,
- ];
- $info = Db::name('maintain')->where($map)->lock(true)->find();
- if(empty($info)){
- Db::rollback();
- $this->error('不存在的订单');
- }
- if($info['status'] != 50){
- Db::rollback();
- $this->error('状态不正确,请刷新重试');
- }
- $nowtime = time();
- //准备数据
- foreach($data as $key => $val){
- $val['order_id'] = $info['id'];
- $val['company_id'] = $info['company_id'];
- $val['user_id'] = $info['user_id'];
- $val['worker_id'] = $info['worker_id'];
- $val['createtime'] = $nowtime;
- $data[$key] = $val;
- }
- $id = Db::name('maintain_cailiao')->insertAll($data);
- if(!$id){
- Db::rollback();
- $this->error('申请失败');
- }
- $update = [
- 'status' => 60,
- 'updatetime' => $nowtime,
- 'cailiao_time' => $nowtime, //材料申请时间
- ];
- $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
- if($rs2 === false){
- Db::rollback();
- $this->error('申请失败');
- }
- Db::commit();
- $this->success('申请成功');
- }
- //材料计量单位
- public function cailiao_danwei(){
- $data = [
- '个',
- '把',
- '只',
- ];
- $this->success(1,$data);
- }
- //领取材料
- public function lingqucailiao(){
- $order_id = input('order_id',0);
- $images = input('images','','trim');
- if(empty($images)){
- $this->error();
- }
- //订单
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $order_id,
- ];
- $info = Db::name('maintain')->where($map)->find();
- if(empty($info)){
- $this->error('不存在的订单');
- }
- if($info['status'] != 60){
- $this->error('状态不正确,请刷新重试');
- }
- $nowtime = time();
- //
- $update = [
- 'status' => 70,
- 'updatetime' => $nowtime,
- 'lingqu_time' => $nowtime, //材料申请时间
- 'lingqu_images' => $images,
- ];
- $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
- if($rs2 === false){
- $this->error('领取失败');
- }
- $this->success('领取成功');
- }
- //////////////////////////////循环开始///////////////////////
- //立即上门
- public function shangmen(){
- $order_id = input('order_id',0);
- Db::startTrans();
- //订单
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $order_id,
- ];
- $info = Db::name('maintain')->where($map)->lock(true)->find();
- if(empty($info)){
- Db::rollback();
- $this->error('不存在的订单');
- }
- if(!in_array($info['status'],[70,92])){
- Db::rollback();
- $this->error('状态不正确,请刷新重试');
- }
- $nowtime = time();
- //开启一个新轮回
- $weixiu = [
- 'order_id' => $info['id'],
- 'company_id' => $info['company_id'],
- 'user_id' => $info['user_id'],
- 'worker_id' => $info['worker_id'],
- 'weixiu_times' => $info['weixiu_times'] + 1, //次数自增1
- 'shangmen_time' => $nowtime,
- 'status' => 80,
- 'updatetime' => $nowtime,
- ];
- $weixiu_id = Db::name('maintain_weixiu')->insertGetId($weixiu);
- if(!$weixiu_id){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- //新轮回第一个进度
- $jindu = [
- 'order_id' => $info['id'],
- 'company_id' => $info['company_id'],
- 'user_id' => $info['user_id'],
- 'worker_id' => $info['worker_id'],
- 'weixiu_times' => $weixiu['weixiu_times'],
- 'weixiu_id' => $weixiu_id,
- 'title' => '已上门',
- 'createtime' => $nowtime,
- ];
- $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu);
- if(!$jindu_id){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- //修改订单
- $update = [
- 'status' => 80,
- 'updatetime' => $nowtime,
- 'shangmen_time' => $nowtime, //上门时间
- 'weixiu_times' => $weixiu['weixiu_times'],
- 'weixiu_id' => $weixiu_id,
- 'wancheng_time' => 0, //清空完成时间
- ];
- $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
- if($rs2 === false){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- Db::commit();
- $this->success('已上门');
- }
- //新增维修进度
- public function jindu_add(){
- $order_id = input('order_id',0);
- $title = input('title','');
- $images = input('images','');
- if(empty($title)){
- $this->error();
- }
- //订单
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $order_id,
- ];
- $info = Db::name('maintain')->where($map)->find();
- if(empty($info)){
- $this->error('不存在的订单');
- }
- if($info['status'] != 80){
- $this->error('状态不正确,请刷新重试');
- }
- $nowtime = time();
- //准备数据
- $jindu = [
- 'order_id' => $info['id'],
- 'company_id' => $info['company_id'],
- 'user_id' => $info['user_id'],
- 'worker_id' => $info['worker_id'],
- 'weixiu_times' => $info['weixiu_times'],
- 'weixiu_id' => $info['weixiu_id'],
- 'title' => $title,
- 'images' => $images,
- 'createtime' => $nowtime,
- ];
- $id = Db::name('maintain_jindu')->insertGetId($jindu);
- if(!$id){
- $this->error('记录失败');
- }
- $this->success('记录成功');
- }
- //确认完成
- public function wancheng(){
- $order_id = input('order_id',0);
- Db::startTrans();
- //订单
- $map = [
- 'worker_id' => $this->auth->id,
- 'id' => $order_id,
- ];
- $info = Db::name('maintain')->where($map)->lock(true)->find();
- if(empty($info)){
- Db::rollback();
- $this->error('不存在的订单');
- }
- if($info['status'] != 80){
- Db::rollback();
- $this->error('状态不正确,请刷新重试');
- }
- $nowtime = time();
- //结束最后一个轮回
- $weixiu = [
- 'status' => 90, //待验收
- 'wancheng_time' => $nowtime,
- 'updatetime' => $nowtime,
- ];
- $weixiu_rs = Db::name('maintain_weixiu')->where('id',$info['weixiu_id'])->update($weixiu);
- if($weixiu_rs === false){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- //最后一个轮回,追加完成进度
- $jindu = [
- 'order_id' => $info['id'],
- 'company_id' => $info['company_id'],
- 'user_id' => $info['user_id'],
- 'worker_id' => $info['worker_id'],
- 'weixiu_times' => $info['weixiu_times'],
- 'weixiu_id' => $info['weixiu_id'],
- 'title' => '已完成',
- 'createtime' => $nowtime,
- ];
- $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu);
- if(!$jindu_id){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- //修改订单
- $update = [
- 'status' => 90,
- 'wancheng_time' => $nowtime,
- 'updatetime' => $nowtime,
- ];
- $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
- if($rs2 === false){
- Db::rollback();
- $this->error('操作失败,重试一下吧');
- }
- Db::commit();
- $this->success('操作成功');
- }
- //////////////////////////////循环结束///////////////////////
- }
|