审查视图

app/portal/controller/AdminCostController.php 3.5 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:58
 */

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 AdminCostController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'费用管理',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 1,
 *     'icon'   =>'th',
 *     'remark' =>'费用管理'
 * )
 */
class AdminCostController extends AdminBaseController{

    public function index(){
潘浩文 authored
32 33 34 35 36 37 38 39
        $data=Db::name('cost')
            ->alias('c')
            ->join('interval i','c.hospital=i.hospital')
            ->select();
        $this->assign('list',$data);
        return $this->fetch();
    }
潘浩文 authored
40 41 42 43 44 45 46 47 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
    public function add(){
        return $this->fetch();
    }


    public function addPost(){
        $param=$this->request->param();
        if (empty($param['free'])){
            $param['free']=0;
        }else{
            $param['free']=1;
        }
        $cost=[
            'hospital' =>$param['hospital'],
            'free' => $param['free'],
            'cost' => $param['cost'],
            'ceiling' => $param['ceiling'],
        ];
        $interval=[
            'hospital' =>$param['hospital'],
            'start_time' => $param['start_time'],
            'end_time' => $param['end_time'],
            'price' => $param['price'],
        ];

        $re1=Db::name('cost')->where('id',$param['hospital'])->find();
        $re2=Db::name('interval')->where('id',$param['hospital'])->find();
        if ($re1 || $re2){
            $this->error('医院重复');
        }

        try{
            Db::startTrans();
            Db::name('cost')->insert($cost);
            Db::name('interval')->insert($interval);
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('添加失败');
        }
        Db::commit();
        $this->success('添加成功');
    }
潘浩文 authored
83 84 85 86 87

    public function edit(){
        $param=$this->request->param();
        $cost=Db::name('cost')->where('id',$param['id'])->find();
        $interval = Db::name('interval')->where('id',$param['id'])->find();
董瑞恩 authored
88 89
        $this->assign('cost',$cost);
        $this->assign('interval',$interval);
董瑞恩 authored
90 91
        return $this->fetch();
    }
董瑞恩 authored
92 93 94

    public function editPost(){
        $param=$this->request->param();
董瑞恩 authored
95 96 97 98 99 100 101 102 103 104 105 106
        if (empty($param['free'])){
            $param['free']=0;
        }else{
            $param['free']=1;
        }
        $cost=[
            'free' => $param['free'],
            'cost' => $param['cost'],
            'ceiling' => $param['ceiling'],
            'update_time' => time()
        ];
        $interval=[
董瑞恩 authored
107 108
            'start_time' => $param['start_time'],
            'end_time' => $param['end_time'],
董瑞恩 authored
109 110 111 112 113
            'price' => $param['price'],
            'update_time' => time()
        ];
        try{
            Db::startTrans();
潘浩文 authored
114 115
            Db::name('cost')->where('id',$param['id'])->update($cost);
            Db::name('interval')->where('id',$param['id'])->update($interval);
董瑞恩 authored
116 117 118 119 120 121
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('保存失败');
        }
        Db::commit();
        $this->success('保存成功');
董瑞恩 authored
122
    }
潘浩文 authored
123 124 125 126 127 128 129 130


    public function delete(){
        $param=$this->request->param();
        Db::name('cost')->where('id',$param['id'])->delete();
        Db::name('interval')->where('id',$param['id'])->delete();
        $this->success('删除成功');
    }
董瑞恩 authored
131
}