审查视图

app/portal/controller/AdminFaultAuditController.php 4.0 KB
董瑞恩 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
<?php
/**
 * Created by PhpStorm.
 * User: ruidiudiu
 * Date: 2018/11/23
 * Time: 11:57
 */

namespace app\portal\controller;


use app\portal\model\EquipmentModel;
use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class AdminFaultAuditController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'故障审核',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 1,
 *     'icon'   =>'th',
 *     'remark' =>'故障审核'
 * )
 */
class AdminFaultAuditController extends AdminBaseController{

    public function index(){
        $param=$this->request->param();
        $where=array();
        if (!empty($param['fault_type'])){
            $where['fault_type']=$param['fault_type'];
        }
        $data=Db::name('fault')
            ->alias('a')
潘浩文 authored
39
            ->field('a.*,b.serial_number,b.hospital,u.phone')
董瑞恩 authored
40
            ->join('equipment b','a.eq_name=b.name')
潘浩文 authored
41
            ->join('users u','a.users_id=u.id')
魏强 authored
42
            ->where('b.is_delete',0)
董瑞恩 authored
43 44 45 46
            ->where($where)
            ->order('a.state','ase')
            ->order('a.create_time','desc')
            ->paginate(10);
潘浩文 authored
47
        $this->assign('page',$data->render());
董瑞恩 authored
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        $this->assign('data',$data);
        $this->assign('fault_type', isset($param['fault_type']) ? $param['fault_type'] : '');
        return $this->fetch();
    }

    //保修
    public function warranty(){
        $id=$this->request->param('id');

        $fault=Db::name('fault')->where('id',$id)->find();

        try{
            Db::startTrans();
            Db::name('equipment')->where('name',$fault['eq_name'])->update(['state'=>2]);
            Db::name('fault')->where('id',$id)->update(['state'=>2]);
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('错误:'.$exception->getMessage());
        }
        Db::commit();
        $this->success('处理完成');

    }

    //恢复设备
    public function reply(){
        $id=$this->request->param('id');

        $fault=Db::name('fault')->where('id',$id)->find();

        try{
            Db::startTrans();
            Db::name('equipment')->where('name',$fault['eq_name'])->update(['state'=>1]);
            Db::name('fault')->where('id',$id)->update(['state'=>3]);
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('错误:'.$exception->getMessage());
        }
        Db::commit();
        $this->success('处理完成');

    }


    //结束计费
    public function bill_error(){
        $id=$this->request->param('id');

        $fault=Db::name('fault')->where('id',$id)->find();

        $order=Db::name('order')->where(['users_id'=>$fault['users_id'],'state'=>1])->find();
99
        $equipment=Db::name('equipment')->where(['name'=>$order['eq_name'],'is_delete'=>0])->find();
董瑞恩 authored
100 101 102 103 104
        if (empty($order)){
            $this->error('没有未完成订单');
        }else{
            $time=ceil(($fault['create_time']-$order['start_time'])/3600);
            $getPrice=new OrderController();
105
            $price=$getPrice->getPrice($fault['users_id'],$order['start_time'],$fault['create_time'],$equipment['hospital']);
董瑞恩 authored
106 107 108 109 110 111 112 113 114 115 116
            $data=[
                'end_time'=>$fault['create_time'],
                'time'=>$time,
                'price'=>$price,
                'state'=>2
            ];
            try{
                Db::startTrans();
                Db::name('users')->where('id',$fault['users_id'])->update(['is_use'=>0]);
                Db::name('order')->where('id',$order['id'])->update($data);
                Db::name('fault')->where('id',$id)->update(['state'=>3]);
潘浩文 authored
117
//                if (!Db::name('order')->where(['eq_name'=>$order['eq_name'],'state'=>1])->find()){
潘浩文 authored
118
                Db::name('equipment')->where('name',$order['eq_name'])->update(['use'=>0]);
潘浩文 authored
119
//                }
董瑞恩 authored
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
            }catch (\Exception $exception){
                Db::rollback();
                $this->error('错误:'.$exception->getMessage());
            }
            Db::commit();
            $this->success('处理完成');
        }
    }






}