审查视图

app/portal/controller/AdminCostController.php 1.7 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
        $cost=Db::name('cost')->where('id',1)->find();
        $interval = Db::name('interval')->where('id',1)->find();
        $this->assign('cost',$cost);
        $this->assign('interval',$interval);
董瑞恩 authored
36 37
        return $this->fetch();
    }
董瑞恩 authored
38 39 40

    public function editPost(){
        $param=$this->request->param();
董瑞恩 authored
41 42 43 44 45 46 47 48 49 50 51 52
        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
53 54
            'start_time' => $param['start_time'],
            'end_time' => $param['end_time'],
董瑞恩 authored
55 56 57 58 59 60 61 62 63 64 65 66 67
            'price' => $param['price'],
            'update_time' => time()
        ];
        try{
            Db::startTrans();
            Db::name('cost')->where('id',1)->update($cost);
            Db::name('interval')->where('id',1)->update($interval);
        }catch (\Exception $exception){
            Db::rollback();
            $this->error('保存失败');
        }
        Db::commit();
        $this->success('保存成功');
董瑞恩 authored
68
    }
董瑞恩 authored
69
}