AdminCostController.php 2.0 KB
<?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;
use think\Db;

/**
 * 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(){
        $data=Db::name('cost')
            ->alias('c')
            ->join('interval i','c.hospital=i.hospital')
            ->select();
        $this->assign('list',$data);
        return $this->fetch();
    }


    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();
        $this->assign('cost',$cost);
        $this->assign('interval',$interval);
        return $this->fetch();
    }

    public function editPost(){
        $param=$this->request->param();
        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=[
            'start_time' => $param['start_time'],
            'end_time' => $param['end_time'],
            'price' => $param['price'],
            'update_time' => time()
        ];
        try{
            Db::startTrans();
            Db::name('cost')->where('id',$param['id'])->update($cost);
            Db::name('interval')->where('id',$param['id'])->update($interval);
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('保存失败');
        }
        Db::commit();
        $this->success('保存成功');
    }
}