AdminIndexController.php 7.7 KB
<?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 app\user\model\ScoreLogModel;
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()
    {
        $data = $this->request->param();
        $return = $this->adminIndex($data);
        $page_arr = $return['page_arr'];

        $where_member['status'] = array('neq',9);
        $where_member = $return['where_arr'];
        if(!empty($data['name'])){
            $where_member['name'] = array('like','%'.$data['name'].'%');
            $this->assign('name', $data['name']);
            $page_arr['name'] = $data['name'];
        }
        if(!empty($data['up'])){
            if($data['up'] == 1){
                $order['all_score'] = 'asc';
            }else if($data['up'] == 2){
                $order['all_score'] = 'desc';
            }
            $page_arr['all_score'] = $data['up'];
        }else{
            $order['create_time'] = 'desc';
        }

        $where_member['type'] = 1;
        $list = Db::name('Member')->where($where_member)->order($order)->paginate(1,false,['query'=>$page_arr]);
        // 获取分页显示
        $page = $list->render();
        $this->assign('lists', $list);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }

    /**查看详情
     *
     * @adminMenu(
     *     'name'   => '查看详情',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '查看详情',
     *     'param'  => ''
     * )
     */
    public function detail()
    {
        $data = $this->request->param();
        $where_member['status'] = array('neq',9);
        $where_member['type'] = 1;
        $where_member['id'] = $data['id'];
        $list = Db::name('Member')->where($where_member)->find();
        $this->assign('list', $list);
        // 渲染模板输出
        return $this->fetch();
    }

    /**修改用户昵称、积分
     *
     * @adminMenu(
     *     'name'   => '修改用户昵称、积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '修改用户昵称、积分',
     *     'param'  => ''
     * )
     */
    public function changeUser()
    {
        $data = $this->request->param();
        $where_member['id'] = $data['id'];
        $up['all_score'] = $data['all_score'];
        $up['name'] = $data['name'];
        $up['update_time'] = time();
        $list = Db::name('Member')->where($where_member)->update($up);
        if($list){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }


    /**积分详情列表
     *
     * @adminMenu(
     *     'name'   => '积分详情列表',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '积分详情列表',
     *     'param'  => ''
     * )
     */
    public function in()
    {
        $data = $this->request->param();
        $return = $this->adminIndex($data);
        $page_arr = $return['page_arr'];
        $where_score = $return['where_arr'];
        $where_score['status'] = array('neq',9);
        if(!empty($data['score'])){
            $where_score['status'] = $data['score'];
            $this->assign('score',$data['score']);
            $page_arr['score'] = $data['score'];
        }
        $page_arr['id'] = $data['id'];
        $where_member['status'] = array('neq',9);
        $where_member['type'] = 1;
        $where_member['id'] = $data['id'];
        $list = Db::name('Member')->where($where_member)->find();
        $this->assign('user',$list);
        $this->assign('uid',$data['id']);


        $where_score['user_id'] = $data['id'];
        $list = Db::name('ScoreLog')->where($where_score)->order('create_time desc')->paginate(2,false,['query'=>$page_arr]);
        $page = $list->render();
        $this->assign('page',$page);
        $this->assign('lists',$list);
        return $this->fetch();
    }


    /**删除积分记录
     *
     * @adminMenu(
     *     'name'   => '删除积分记录',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除积分记录',
     *     'param'  => ''
     * )
     */
    public function scoreDel()
    {
        $model = new ScoreLogModel();
        $this->adminDel($model);
    }

    /**减积分
     *
     * @adminMenu(
     *     'name'   => '减积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '减积分',
     *     'param'  => ''
     * )
     */
    public function sallScore()
    {
        $data = $this->request->param();
        $where_member['status'] = array('neq',9);
        $where_member['id'] = $data['id'];
        $list = Db::name('Member')->where($where_member)->find();
        if($this->request->isPost()){
            $model = new  ScoreLogModel();
            if($data['score'] > $list['all_score']){
                $this->error('当前用户积分不足');
            }
            if(floatval($data['score']) == 0 && strpos($data['score'],'.') === false){
                $this->error('积分只能为整数');
            }
            $data['user_id'] = $data['id'];
            $data['old_score'] = $list['all_score'];
            $data['now_score'] = $list['all_score'] - $data['score'];
            $data['type'] = 1;
            $data['status'] = 3;
            unset($data['id']);
            $res = $model->save($data);
            if($res){
                $sall = Db::name('Member')->where($where_member)->setDec('all_score',$data['score']);
                if($sall){
                    $this->success('操作成功',url('index'));
                }else{
                    $this->error('操作失败');
                }
            }else{
                $this->error('操作失败');
            }
        }else{

            $this->assign('list', $list);
            // 渲染模板输出
            return $this->fetch('sall');
        }

    }

}