From d10cd97b2bde552c246eea36718779a20cc4a2aa Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Mon, 18 Mar 2024 00:35:55 +0800 Subject: [PATCH] 1 --- application/admin/controller/ScoreLog.php | 64 ++++++++++++++++++- .../admin/model/shopro/user/WalletLog.php | 5 ++ application/admin/view/score_log/index.html | 10 +-- public/assets/js/backend/score_log.js | 31 +++++---- 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/application/admin/controller/ScoreLog.php b/application/admin/controller/ScoreLog.php index 60af61f..e48aba8 100644 --- a/application/admin/controller/ScoreLog.php +++ b/application/admin/controller/ScoreLog.php @@ -2,8 +2,10 @@ namespace app\admin\controller; +use addons\shopro\library\Operator; +use app\admin\model\shopro\commission\Level as LevelModel; +use app\admin\model\shopro\user\WalletLog as WalletLogModel; use app\common\controller\Backend; - /** * 用户资金日志 * @@ -22,7 +24,58 @@ class ScoreLog extends Backend { parent::_initialize(); $this->model = new \app\admin\model\ScoreLog; +// var_dump((new Level())->getList()); + $this->assignconfig("levelList", $this->getList()); + + } + + public function index() + { + /*//设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result);*/ + //如果发送的来源是 Selectpage,则转发到 Selectpage + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $walletLogs = WalletLogModel::where($where) + ->with(['user.agent.levelInfo']) + ->score() + ->order($sort, $order) + ->paginate($limit); + + // 多态关联 oper + $morphs = [ + 'user' => \app\admin\model\shopro\user\User::class, + 'admin' => \app\admin\model\Admin::class, + 'system' => \app\admin\model\Admin::class, + ]; + $walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']); + $walletLogs = $walletLogs->toArray(); + // 解析操作人信息 + foreach ($walletLogs['data'] as &$log) { + $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null); + } + $result = ['total' => $walletLogs['total'], 'rows' => $walletLogs['data']]; + return json($result); } @@ -33,5 +86,14 @@ class ScoreLog extends Backend * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ + public function getList() { + $data = (new LevelModel())->field('level, name, image, commission_rules')->select(); + $new_data = []; + foreach ($data as $item) { + $new_data[$item['level']] = $item['name']; + } + return $new_data; + } + } diff --git a/application/admin/model/shopro/user/WalletLog.php b/application/admin/model/shopro/user/WalletLog.php index bfe6091..77c3aeb 100755 --- a/application/admin/model/shopro/user/WalletLog.php +++ b/application/admin/model/shopro/user/WalletLog.php @@ -76,4 +76,9 @@ class WalletLog extends Common { return $this->eventMap[$data['type']][$data['event']] ?? ''; } + + public function user() + { + return $this->belongsTo(User::class, 'user_id', 'id'); + } } diff --git a/application/admin/view/score_log/index.html b/application/admin/view/score_log/index.html index dd52780..c87d9d4 100644 --- a/application/admin/view/score_log/index.html +++ b/application/admin/view/score_log/index.html @@ -7,9 +7,9 @@
- {:__('Add')} - {:__('Edit')} - {:__('Delete')} + + + @@ -17,8 +17,8 @@
diff --git a/public/assets/js/backend/score_log.js b/public/assets/js/backend/score_log.js index 2683378..adff464 100644 --- a/public/assets/js/backend/score_log.js +++ b/public/assets/js/backend/score_log.js @@ -28,24 +28,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin [ {checkbox: true}, {field: 'id', title: __('Id')}, - {field: 'user_id', title: __('User_id')}, - {field: 'type', title: __('Type'), operate: 'LIKE'}, - {field: 'event', title: __('Event'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, - {field: 'amount', title: __('Amount'), operate:'BETWEEN'}, - {field: 'before', title: __('Before'), operate:'BETWEEN'}, - {field: 'after', title: __('After'), operate:'BETWEEN'}, - {field: 'memo', title: __('Memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, - {field: 'ext', title: __('Ext'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, - {field: 'oper_type', title: __('Oper_type'), operate: 'LIKE'}, - {field: 'oper_id', title: __('Oper_id')}, - {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + {field: 'user.nickname', title: '用户昵称',operate: 'LIKE'}, + {field: 'user.agent.level_info.name', title: '用户等级', searchList: Config.levelList}, + {field: 'user.mobile', title: '手机号',operate: 'LIKE'}, + {field: 'amount', title: '积分变动额度',operate:'BETWEEN'}, + {field: 'memo', title: '积分变动类型'}, + {field: 'after', title: '当前积分'}, + {field: 'createtime', title: '变动时间',operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, + // // {field: 'type', title: __('Type'), operate: 'LIKE'}, + // {field: 'event', title: __('Event'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + // {field: 'amount', title: __('Amount'), operate:'BETWEEN'}, + // {field: 'before', title: __('Before'), operate:'BETWEEN'}, + // {field: 'after', title: __('After'), operate:'BETWEEN'}, + // {field: 'memo', title: __('Memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + // {field: 'ext', title: __('Ext'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + // {field: 'oper_type', title: __('Oper_type'), operate: 'LIKE'}, + // {field: 'oper_id', title: __('Oper_id')}, + // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, + // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); + console.log(Config.levelList) }, add: function () { Controller.api.bindevent();