123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- use think\exception\DbException;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- use Exception;
- use app\common\model\Maintain as Maintainmodel;
- /**
- * 维修单
- *
- * @icon fa fa-circle-o
- */
- class Maintain extends Backend
- {
- /**
- * Maintain模型对象
- * @var \app\admin\model\Maintain
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Maintain;
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['company','user','usercompany','worker'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
-
- $row->getRelation('company')->visible(['companyname']);
- $row->getRelation('user')->visible(['nickname','mobile']);
- $row->getRelation('usercompany')->visible(['projectname']);
- $row->getRelation('worker')->visible(['truename','mobile']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- *
- * @param $ids
- * @return string
- * @throws DbException
- * @throws \think\Exception
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- if (false === $this->request->isPost()) {
- //
- $row['filedata_array'] = json_decode($row['filedata'],true);
- //
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- /**
- * 总部指派
- * 复制pc端的指派,稍作调整
- */
- public function zhipai()
- {
- $id = input('id',0);
- $row = Db::name('maintain')->where('id',$id)->find();
- if(!$this->request->isPost()){
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- //检查师傅
- $worker_id = input('worker_id',0);
- $worker = Db::name('worker')->where('id',$worker_id)->where('status',1)->where('company_id',1)->find();
- if(empty($worker)){
- $this->error('没找到该师傅');
- }
- //检查订单
- $id = input('id',0);
- Db::startTrans();
- $info = Db::name('maintain')->where('id',$id)->lock(true)->find();
- if(empty($info)){
- Db::rollback();
- $this->error('没找到该信息,请刷新重试');
- }
- if(!in_array($info['status'],[0,20,22,30,40])){
- Db::rollback();
- $this->error('当前订单状态,不能指派师傅');
- }
- if(!empty($info['worker_id'])){
- Db::rollback();
- $this->error('已经指派了师傅');
- }
- //
- $update = [
- 'worker_id' => $worker_id,
- 'status' => 50,
- 'updatetime' => time(),
- ];
- $rs_update = Db::name('maintain')->where('id',$id)->update($update);
- if($rs_update === false){
- Db::rollback();
- $this->error('指派失败,请重试');
- }
- //
- Db::commit();
- $this->success();
- }
- /**
- * 查看导出
- */
- public function showinfo(){
- $id = input('id',0);
- $info = Db::name('maintain')->alias('mt')
- ->join('user_company uc','mt.uc_id = uc.id','LEFT')
- ->join('user','mt.user_id = user.id','LEFT')
- ->join('worker','mt.worker_id = worker.id','LEFT')
- ->join('company','mt.company_id = company.id','LEFT')
- ->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')
- ->where('mt.id',$id)
- ->find();
- $maintain_model = new Maintainmodel();
- $info['status_text'] = $maintain_model->status_data($info['status']);
- //pc用户,已流转订单,直接显示流转中
- if($info['company_id'] != 1 && in_array($info['status'],[0,20,22,30,40]) && $info['liuzhuan_status'] == 1){
- $info['status_text'] = '流转中';
- }
- $info['status_colorType'] = $maintain_model->status_colorType($info['status']);
- //假状态
- $info['fake_status'] = $this->fake_status($info['status']);
- $info['fake_status_text'] = $this->fake_status_data($info['status']);
- $info['filedata'] = json_decode($info['filedata'],true);
- //追加报价历史
- $baojia = Db::name('maintain_baojia')->alias('bj')
- ->field('bj.*,admin.nickname as baojia_nickname,audit.nickname as baojia_audit_nickname')
- ->join('pc_admin admin','bj.baojia_staffid = admin.id','LEFT')
- ->join('pc_admin audit','bj.baojia_audit_staffid = audit.id','LEFT')
- ->where('order_id',$id)->order('id desc')->select();
- if(!empty($baojia)){
- foreach($baojia as $key => $val){
- $baojia[$key]['status_text'] = $maintain_model->baojia_status_data($val['status']);
- }
- }
- $info['baojia_list'] = $baojia;
- //追加材料列表
- $info['cailiao_list'] = Db::name('maintain_cailiao')->field('id,name,number,danwei,images')->where('order_id',$id)->order('id desc')->select();
- //追加多次维修+对应进度历史
- $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();
- 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
- ];
- }
- }
- $info['jindu'] = $last_jindulist;
- $this->view->assign('info', $info);
- // dump($info);exit;
- $this->view->engine->layout(false);
- return $this->view->fetch();
- }
- //整合过的状态
- private function fake_status_data($status){
- $data = [
- 0 => '待报价',
- 2 => '已取消',
- 20 => '评估报价',
- 22 => '评估报价',
- 30 => '用户待确认',
- 40 => '待处理',
- 50 => '待处理',
- 60 => '待处理',
- 70 => '待处理',
- 80 => '待处理',
- 90 => '待处理',
- 92 => '待处理',
- 100 => '已完成',
- ];
- return isset($data[$status]) ? $data[$status] : $status;
- }
- //整合过的状态
- private function fake_status($status){
- $data = [
- 0 => 0,
- 2 => 2,
- 20 => 20,
- 22 => 20,
- 30 => 30,
- 40 => 40,
- 50 => 40,
- 60 => 40,
- 70 => 40,
- 80 => 40,
- 90 => 40,
- 92 => 40,
- 100 => 100,
- ];
- return isset($data[$status]) ? $data[$status] : $status;
- }
- }
|