审查视图

app/user/controller/AdminIndexController.php 6.9 KB
lihan authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------

namespace app\user\controller;

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

/**
 * Class AdminIndexController
 * @package app\user\controller
 *
 * @adminMenuRoot(
 *     'name'   =>'用户管理',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 10,
 *     'icon'   =>'group',
 *     'remark' =>'用户管理'
 * )
 *
 * @adminMenuRoot(
 *     'name'   =>'用户组',
 *     'action' =>'default1',
 *     'parent' =>'user/AdminIndex/default',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   =>'',
 *     'remark' =>'用户组'
 * )
 */
class AdminIndexController extends AdminBaseController
{

    /**
     * 后台本站用户列表
     * @adminMenu(
     *     'name'   => '本站用户',
     *     'parent' => 'default1',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '本站用户',
     *     'param'  => ''
     * )
     */
    public function index()
    {
lihan authored
59 60 61
        $where = ['user_type' => 2];
        $where1 = [];
        $where3 = [];
lihan authored
62
        $param = request()->param();
lihan authored
63 64

徐治堂 authored
65 66 67
        $keywordComplex = [];
        if (!empty($param['keyword'])) {
            $keyword = $param['keyword'];
68
            $keywordComplex['mobile|id'] = $keyword;
徐治堂 authored
69
        }
lihan authored
70 71 72 73 74
        if (!empty($param['start_time'])) {
            $where['create_time'] = ['egt', strtotime($param['start_time'])];
        }
        if (!empty($param['end_time'])) {
            $where1['create_time'] = ['elt', strtotime($param['end_time'])];
徐治堂 authored
75
        }
lihan authored
76 77
        if (!empty($param['min'])) {
            $where['balance'] = ['egt', $param['min']];
徐治堂 authored
78
        }
lihan authored
79 80
        if (!empty($param['max'])) {
            $where1['balance'] = ['elt', $param['max']];
lihan authored
81
        }
lihan authored
82
lihan authored
83
        $uid = (isset($param['uid'])) ? $param['uid'] : null;
lihan authored
84
        //下级人员
lihan authored
85
        if ($uid) {
lihan authored
86
            $where3['parent_id'] = ['eq', $uid];
lihan authored
87 88
        }
lihan authored
89 90
        $usersQuery = Db::name('user');
lihan authored
91
        $list = $usersQuery->whereOr($keywordComplex)->where($where)->where($where1)->where($where3)->order("create_time DESC")->paginate(10);
lihan authored
92
        //获取订单数和会员专区金额统计
lihan authored
93 94 95
        foreach ($list as $k => $item) {
            $uid = $item['id'];
            $role = $item['role'];
lihan authored
96
            $data = [];
lihan authored
97
            //如果此人为普通会员,只统计其金额总和
lihan authored
98 99 100 101 102 103
            if ($role == 1) {
                $map = [
                    'uid' => ['eq', $item['id']],
                    'pay_type' => ['eq', 3],
                    'step' => ['neq', 1]
                ];
lihan authored
104
                $data = Db::name('zj_order')->where($map)->field('sum(whole) as whole,sum(whole_num) as whole_num')->select();
lihan authored
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
            } else {
                //先查此人的下级
                $son_arr = Db::name('user')->where(['parent_id' => $item['id']])->field('id')->select();
                if (!empty($son_arr)) {
                    $son_str = '';
                    foreach ($son_arr as $k => $v) {
                        if ($k == count($son_arr) - 1) {
                            $son_str .= $v['id'];
                        } else {
                            $son_str .= $v['id'] . ',';
                        }
                    }
                    $map = [
                        'uid' => ['in', $son_str],
                        'pay_type' => ['eq', 3],
                        'step' => ['neq', 1]
                    ];
                    $data = Db::name('zj_order')->where($map)->field('sum(whole) as whole,sum(whole_num) as whole_num')->select();
                }
lihan authored
124
            }
lihan authored
125 126
            $whole = $data[0]['whole'];
            $whole_num = $data[0]['whole_num'];
lihan authored
127
            echo $total = $whole - $whole_num;
lihan authored
128
            $item['total'] = 0;
lihan authored
129 130
            $list[$k] = $item;
        }
lihan authored
131 132

lihan authored
133
        // 获取分页显示
徐治堂 authored
134 135 136 137 138 139 140 141
        $list->appends($param);
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign('min', isset($param['min']) ? $param['min'] : '');
        $this->assign('max', isset($param['max']) ? $param['max'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('list', $list->items());
        $this->assign('page', $list->render());
lihan authored
142
        $this->assign('uid', $uid);
lihan authored
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        // 渲染模板输出
        return $this->fetch();
    }

    /**
     * 本站用户拉黑
     * @adminMenu(
     *     'name'   => '本站用户拉黑',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '本站用户拉黑',
     *     'param'  => ''
     * )
     */
    public function ban()
    {
        $id = input('param.id', 0, 'intval');
        if ($id) {
            $result = Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 0);
            if ($result) {
                $this->success("会员拉黑成功!", "adminIndex/index");
            } else {
                $this->error('会员拉黑失败,会员不存在,或者是管理员!');
            }
        } else {
            $this->error('数据传入失败!');
        }
    }

    /**
     * 本站用户启用
     * @adminMenu(
     *     'name'   => '本站用户启用',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '本站用户启用',
     *     'param'  => ''
     * )
     */
    public function cancelBan()
    {
        $id = input('param.id', 0, 'intval');
        if ($id) {
            Db::name("user")->where(["id" => $id, "user_type" => 2])->setField('user_status', 1);
            $this->success("会员启用成功!", '');
        } else {
            $this->error('数据传入失败!');
        }
    }
徐治堂 authored
198 199 200 201

    /**
     * 用户积分详情
     */
lihan authored
202 203 204 205 206 207 208
    public function balance()
    {
        if ($this->request->param()) {
            $id = input('param.id');
            $all = Db::name('zj_integral_log')->where('uid', $id)->paginate(20);
            $this->assign('list', $all);
            $this->assign('page', $all->render());
徐治堂 authored
209 210 211
            return $this->fetch();
        }
    }
lihan authored
212
}