model = new \app\admin\model\User; $this->view->assign("realStatusList", $this->model->getRealStatusList()); $this->view->assign("genderList", $this->model->getGenderList()); $this->view->assign("idcardStatusList", $this->model->getIdcardStatusList()); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("isKefuList", $this->model->getIsKefuList()); $this->view->assign("isRecommendList", $this->model->getIsRecommendList()); $this->view->assign("isAgentList", $this->model->getIsAgentList()); $this->view->assign("openMatchVideoList", $this->model->getOpenMatchVideoList()); $this->view->assign("openMatchAudioList", $this->model->getOpenMatchAudioList()); $this->view->assign("openMatchTypingList", $this->model->getOpenMatchTypingList()); $this->view->assign("freeVideoList", $this->model->getFreeVideoList()); $this->view->assign("freeAudioList", $this->model->getFreeAudioList()); $this->view->assign("freeTypingList", $this->model->getFreeTypingList()); $typeList = [ 'statusList' => $this->model->getStatusList(), ]; $this->view->assign($typeList); $this->assignconfig($typeList); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $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(['gonghui']) ->with(['wallet']) ->where($where) ->order($sort, $order) ->paginate($limit); $day = 1; // 一周的第一天 $wday = date('w'); // 星期几的数字表示 0(周日)到 6(周六) $wday_start = strtotime(date('Y-m-d', strtotime('-' . ($wday ? $wday - $day : 6) . ' day'))); // 本周开始日期 $week_map = [ 'log_type' => ['in', [21, 22, 23, 54, 60, 72, 82 ]] ]; $mt_user = Db::name('user'); $mt_user_money_log = Db::name('user_money_log'); $mt_pay_order = Db::name('pay_order'); $mt_user_wallet = Db::name('user_wallet'); $time = time(); foreach ($list as $row) { // $row->getRelation('gonghui')->visible(['id','name']); $row->getRelation('wallet')->visible(['pay_money', 'get_money','vip_endtime']); $week_map['user_id'] = $row['id']; //邀请人数 // $row['intro_total_num'] = $mt_user->where(['intro_uid' => $row['id']])->count('id'); //收益统计 // $row['total_profit'] = $mt_user_money_log->where($week_map)->sum('change_value'); //充值统计 // $row['pay_sum'] = $mt_pay_order->where(['user_id' => $row['id'], 'status' => 1])->sum('money'); //本周收益 $week_map['createtime'] = ['egt', $wday_start]; // $row['week_profit'] = $mt_user_money_log->where($week_map)->sum('change_value'); //上周收益 $week_map['createtime'] = ['between', [$wday_start - 86400 * 7, $wday_start]]; // $row['last_week_profit'] = $mt_user_money_log->where($week_map)->sum('change_value'); //本周邀请人数 // $row['week_count'] = $mt_user->where(['intro_uid' => $row['id'], 'invite_time' => ['egt', $wday_start]])->count('id'); //上周邀请人数 // $row['last_week_count'] = $mt_user->where(['intro_uid' => $row['id'], 'invite_time' => ['between', [$wday_start - 86400 * 7, $wday_start]]])->count('id'); //是否是会员 // $vip_endtime = $mt_user_wallet->where(['user_id' => $row['id']])->value('vip_endtime'); // if ($vip_endtime > $time) { // $row['vip_endtime'] = date('Y-m-d H:i:s', $vip_endtime); // } else { // $row['vip_endtime'] = ''; // } } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); $result = false; if ($params['mobile']) { $exists = db('user')->where('mobile', $params['mobile'])->where('id', '<>', $row['id'])->find(); if ($exists) { $this->error('手机号已经被其他人使用'); } } //推荐人查询 if (isset($params['intro_uid']) && $params['intro_uid'] != 0) { if ($params['intro_uid'] == $row['id']) { $this->error('推荐人ID不能填写自己'); } $intro_user = db('user')->field('id, intro_uid')->where('id', $params['intro_uid'])->find(); if(!$intro_user){ $this->error('不存在推荐人'); } if ($intro_user['intro_uid'] == $row['id']) { $this->error('不能填写下级邀请码作为推荐人'); } } Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException(true)->validate($validate); } $result = $row->allowField(true)->save($params); if ($params['status'] != 1 || (isset($params['frozentime']) && strtotime($params['frozentime']) > time())) { //置空token Token::clear($row['id']); } Db::commit(); } catch (ValidateException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were updated')); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } }