审查视图

app/portal/controller/AdminFaultController.php 2.0 KB
董瑞恩 authored
1 2 3 4 5 6 7 8 9 10 11 12 13
<?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;
董瑞恩 authored
14 15
use think\Db;
董瑞恩 authored
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/**
 * Class AdminFaultController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'故障统计',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 1,
 *     'icon'   =>'th',
 *     'remark' =>'故障统计'
 * )
 */
class AdminFaultController extends AdminBaseController{

    public function index(){
董瑞恩 authored
32 33
        $data=Db::name('fault')
            ->alias('a')
董瑞恩 authored
34
            ->field('a.*,b.serial_number,b.hospital')
董瑞恩 authored
35
            ->join('equipment b','a.eq_name=b.name')
董瑞恩 authored
36
            ->order('a.create_time','desc')
董瑞恩 authored
37
            ->paginate(10);
董瑞恩 authored
38 39 40
        $this->assign('data',$data);
        return $this->fetch();
    }
董瑞恩 authored
41 42 43 44 45



    //结束计费
    public function bill_error(){
董瑞恩 authored
46
        $id=$this->request->param('id');
董瑞恩 authored
47
董瑞恩 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
        $fault=Db::name('fault')->where('id',$id)->find();

        $order=Db::name('order')->where(['users_id'=>$fault['users_id'],'state'=>1])->find();
        if (empty($order)){
            $this->error('没有未完成订单');
        }else{
            $time=ceil(($fault['create_time']-$order['start_time'])/3600);
            $getPrice=new OrderController();
            $price=$getPrice->getPrice($order['start_time'],$fault['create_time']);
            $data=[
                'end_time'=>$fault['create_time'],
                'time'=>$time,
                'price'=>$price,
                'state'=>2
            ];
            try{
                Db::startTrans();
                Db::name('order')->where('id',$order['id'])->update($data);
                Db::name('fault')->where('id',$id)->update(['state'=>3]);
            }catch (\Exception $exception){
                Db::rollback();
                $this->error('错误:'.$exception->getMessage());
            }
            Db::commit();
            $this->success('处理完成');
        }
董瑞恩 authored
74 75 76 77 78 79 80
    }





董瑞恩 authored
81
}