model = model('Users'); $this->assign('statusList', $this->model->getStatusList()); $this->assign('typeList', $this->model->getTypeList()); } /** * 查看 */ 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('parent,agent') ->where($where)->where('users.is_delete', 0) ->order($sort, $order) ->paginate($limit); $in = model('MoneyIn'); $out = model('MoneyOut'); foreach ($list as &$item) { $item->recharge = $in::where('status', 200)->where('user_id', $item->id)->sum('amount'); $item->withdraw = $out::where('status', 200)->where('user_id', $item->id)->sum('amount'); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 余额 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function balance($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { $amount = $params['type'] == 1 ?-$params['amount']:$params['amount']; (new MoneyLog())->change($params['id'], $amount, MoneyLog::SystemChange, $this->auth->id, '后台操作'); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } $this->success(); } /** * 卡单 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function cardslip($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { // $task = json_decode($row->limit_task, true); // $row->which_start = $task['which_start']??''; // $row->min_amount = $task['min_amount']??''; // $row->max_amount = $task['max_amount']??''; // $row->income_multiple= $task['income_multiple']??''; $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { $result = $row->allowField(true)->save(['limit_task'=>$params['limit_task']]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 收款 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function collection($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $bank = json_decode($row->bank_info, true); $row->account_name = $bank['account_name']??''; $row->bank_name = $bank['bank_name']??''; $row->bank_card = $bank['bank_card']??''; $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { $addr = $params['usdt_address']; unset($params['id'],$params['usdt_address']); $result = $row->allowField(true)->save(['usdt_address'=> $addr, 'bank_info'=>json_encode($params)]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 清零 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function clear($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } $result = false; try { $result = $row->allowField(true)->save(['task_num'=>0]); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 编辑 * * @param $ids * @return string * @throws DbException * @throws \think\Exception */ 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) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; 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()->validate($validate); } if(!empty($params['login_pwd'])){ $params['salt'] = Random::alnum(); $params['login_pwd'] = $this->auth->getEncryptPassword($params['login_pwd'], $params['salt']); }else{ unset($params['login_pwd']); } if(!empty($params['fund_pwd'])){ $params['fund_pwd'] = md5($params['fund_pwd']); }else{ unset($params['fund_pwd']); } //修改代理 if($row->agent_id !=$params['agent_id'] && empty($row->is_agent)) { //伞下不是代理/代理是他的 $this->model->where('id','IN', UsersPath::where('parent_id', $ids)->column('user_id')) ->where('is_agent', 0) ->update(['agent_id'=>$params['agent_id']]); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 删除 * * @param $ids * @return void * @throws DbException * @throws DataNotFoundException * @throws ModelNotFoundException */ public function del($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } $result = false; try { $result = $row->allowField(true)->save(['is_delete'=>1]); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 批量更新 * @param $ids * @return void */ public function multi($ids = null) { if (false === $this->request->isPost()) { $this->error(__('Invalid parameters')); } $ids = $ids ?: $this->request->post('ids'); if (empty($ids)) { $this->error(__('Parameter %s can not be empty', 'ids')); } if (false === $this->request->has('params')) { $this->error(__('No rows were updated')); } parse_str($this->request->post('params'), $values); //$values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields))); if (empty($values)) { $this->error(__('You have no permission')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } $count = 0; Db::startTrans(); try { $row = $this->model->where($this->model->getPk(), '=', $ids)->find(); $key = key($values); //修改key if($key == 'is_agent'){ //默认开启:设置伞下当前会员所属代理id $map['agent_id'] = $values[$key] == 0? $row->agent_id: $ids; //伞下/代理是自己, 是agent_id = 自己user_id吗 $this->model->where('id','IN', UsersPath::where('parent_id', $ids)->column('user_id')) ->where('is_agent', 0) ->update($map); } $count = $row->allowField(true)->isUpdate(true)->save($values); Db::commit(); } catch (PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($count) { $this->success(); } $this->error(__('No rows were updated')); } }