123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\admin\controller\user;
- use app\common\controller\Backend;
- use app\common\library\Auth;
- use app\common\model\SysConfig;
- use app\common\service\DiscountService;
- /**
- * 会员管理
- *
- * @icon fa fa-user
- */
- class User extends Backend
- {
- protected $relationSearch = true;
- protected $searchFields = 'id,username,nickname';
- /**
- * @var \app\admin\model\User
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('User');
- $this->assign('levels',$this->model::getLevels());
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['group','admin'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $k => $v) {
- $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
- $v->hidden(['password', 'salt']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $this->token();
- }
- return parent::add();
- }
- /**
- * 编辑
- */
- public function edit($ids = null)
- {
- if ($this->request->isPost()) {
- $this->token();
- }
- $row = $this->model->get($ids);
- $this->modelValidate = true;
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
- return parent::edit($ids);
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if (!$this->request->isPost()) {
- $this->error(__("Invalid parameters"));
- }
- $ids = $ids ? $ids : $this->request->post("ids");
- $row = $this->model->get($ids);
- $this->modelValidate = true;
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- Auth::instance()->delete($row['id']);
- $this->success();
- }
- public function level_discount(){
- if ($this->request->isAjax()) {
- $levels=$this->model::getLevels();;
- $list=[];
- $config=DiscountService::getById();
- foreach ($levels as $id=>$level){
- $list[]=[
- 'id'=>$id,
- 'name'=>$level,
- 'discount'=>$config[$id]??'',
- ];
- }
- $result = array("total" => count($list), "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- public function level_discount_edit($ids){
- if($this->request->isGet()){
- $this->assign('row',DiscountService::getById($ids));
- $this->assign('id',$ids);
- return $this->fetch();
- }else{
- $data=input('row/a');
- $this->validate($data,[
- 'discount|折扣'=>['require','gt:0','lt:10'],
- ]);
- DiscountService::saveDiscount($ids,$data['discount']);
- $this->success();
- }
- }
- }
|