AdminMoneyController.php 3.6 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class AdminMoneyController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'财务管理',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'财务管理'
 * )
 */
class AdminMoneyController extends AdminBaseController
{
    /**
     * 财务列表
     * @adminMenu(
     *     'name'   => '财务列表',
     *     'parent' => 'portal/AdminMoney/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '财务列表',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        //接收搜索参数
        $param = $this->request->param();
        //添加搜索条件
        $where=[];
        if (cmf_get_current_admin_id()!=1){
            $where['t.user_id']=cmf_get_current_admin_id();
        };
        $temple = empty($param['temple']) ? '' : $param['temple'];
        if (!empty($temple)) {
            $where['t.name'] = ['like', "%$temple%"];
        }

        $address=empty($param['address']) ? '' : $param['address'];
        if (!empty($address)) {
            $where['t.address'] = $address;
        }
        //所有地区
        $address_choose=Db::name('temple')->field('address')->distinct('address',true)->select();
        $this->assign('address_choose',$address_choose);

        //数据提取
        $data=Db::name('temple')->alias('t')->where($where)->paginate(10)->each(function ($item) {
//            $item['money'] = Db::name('light_order')->alias('lo')->join('light l','lo.light_id=l.id')->where('l.temple_id',$item['id'])->whereNotNull('lo.pay_time')->sum('lo.money');
            $item['real_money']=$item['money']*$item['percent'];
            return $item;
        });
        //向地址传参
        $data->appends($param);
        $this->assign('page',$data->render());
        $this->assign('address', isset($param['address']) ? $param['address'] : '');
        $this->assign('temple', isset($param['temple']) ? $param['temple'] : '');
        $this->assign('list', $data);
        return $this->fetch();
    }


    /**
     * 删除财务
     * @adminMenu(
     *     'name'   => '删除财务',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除财务',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $id = $this->request->param('id');
        $re=Db::name('light_order')
            ->alias('lo')
            ->join('light l','lo.light_id=l.id')
            ->where(['l.temple_id'=>$id,'lo.end_time'=>['>',time()]])
            ->find();
        if ($re){
            $this->error('该寺庙下有进行中的订单,不允许删除');
        }
        Db::name('temple')->where('id', $id)->delete();
        $this->success('删除成功');
    }

}