From 19f6ea4bafcbb738c434981dc2d385b6672d2533 Mon Sep 17 00:00:00 2001
From: leo_xia <89232256@qq.com>
Date: Thu, 10 Feb 2022 20:15:55 +0800
Subject: [PATCH 0001/1004] saas base implement
---
.gitignore | 6 +
application/admin/command/Crud.php | 5 +
application/admin/controller/Command.php | 236 ++++++++++++
application/admin/lang/zh-cn/command.php | 16 +
application/admin/model/Command.php | 59 +++
application/admin/validate/Command.php | 27 ++
application/admin/view/command/add.html | 400 +++++++++++++++++++++
application/admin/view/command/detail.html | 42 +++
application/config.php | 6 +-
application/database.php | 6 +-
application/extra/queue.php | 14 +
application/extra/site.php | 80 +++--
public/{admin.php => LBTmCxRegc.php} | 0
public/assets/js/backend/command.js | 234 ++++++++++++
14 files changed, 1087 insertions(+), 44 deletions(-)
create mode 100644 application/admin/controller/Command.php
create mode 100644 application/admin/lang/zh-cn/command.php
create mode 100644 application/admin/model/Command.php
create mode 100644 application/admin/validate/Command.php
create mode 100644 application/admin/view/command/add.html
create mode 100644 application/admin/view/command/detail.html
create mode 100644 application/extra/queue.php
rename public/{admin.php => LBTmCxRegc.php} (100%)
create mode 100644 public/assets/js/backend/command.js
diff --git a/.gitignore b/.gitignore
index bc119718e..ecc83b808 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,9 @@ composer.lock
.svn
.vscode
node_modules
+.htaccess
+.well-known/
+404.html
+index.html
+public/.user.ini
+
diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php
index 4973a36aa..c49344e62 100755
--- a/application/admin/command/Crud.php
+++ b/application/admin/command/Crud.php
@@ -663,6 +663,11 @@ class Crud extends Command
$order = $priKey;
+ // 表检测是否存在company_id字段
+ if ($modelTableName!=="fa_company" && !key_exists('company_id', $fieldArr)) {
+ throw new Exception('table [' . $modelTableName . '] must be contain field [ company_id ]');
+ }
+
//如果是关联模型
foreach ($relations as $index => &$relation) {
if ($relation['relationMode'] == 'hasone') {
diff --git a/application/admin/controller/Command.php b/application/admin/controller/Command.php
new file mode 100644
index 000000000..8f8f76254
--- /dev/null
+++ b/application/admin/controller/Command.php
@@ -0,0 +1,236 @@
+model = model('Command');
+ $this->view->assign("statusList", $this->model->getStatusList());
+ }
+
+ /**
+ * 添加
+ */
+ public function add()
+ {
+
+ $tableList = [];
+ $list = \think\Db::query("SHOW TABLES");
+ foreach ($list as $key => $row) {
+ $tableList[reset($row)] = reset($row);
+ }
+
+ $this->view->assign("tableList", $tableList);
+ return $this->view->fetch();
+ }
+
+ /**
+ * 获取字段列表
+ * @internal
+ */
+ public function get_field_list()
+ {
+ $dbname = Config::get('database.database');
+ $prefix = Config::get('database.prefix');
+ $table = $this->request->request('table');
+ //从数据库中获取表字段信息
+ $sql = "SELECT * FROM `information_schema`.`columns` "
+ . "WHERE TABLE_SCHEMA = ? AND table_name = ? "
+ . "ORDER BY ORDINAL_POSITION";
+ //加载主表的列
+ $columnList = Db::query($sql, [$dbname, $table]);
+ $fieldlist = [];
+ foreach ($columnList as $index => $item) {
+ $fieldlist[] = $item['COLUMN_NAME'];
+ }
+ $this->success("", null, ['fieldlist' => $fieldlist]);
+ }
+
+ /**
+ * 获取控制器列表
+ * @internal
+ */
+ public function get_controller_list()
+ {
+ //搜索关键词,客户端输入以空格分开,这里接收为数组
+ $word = (array)$this->request->request("q_word/a");
+ $word = implode('', $word);
+
+ $adminPath = dirname(__DIR__) . DS;
+ $controllerDir = $adminPath . 'controller' . DS;
+ $files = new \RecursiveIteratorIterator(
+ new \RecursiveDirectoryIterator($controllerDir), \RecursiveIteratorIterator::LEAVES_ONLY
+ );
+ $list = [];
+ foreach ($files as $name => $file) {
+ if (!$file->isDir()) {
+ $filePath = $file->getRealPath();
+ $name = str_replace($controllerDir, '', $filePath);
+ $name = str_replace(DS, "/", $name);
+ if (!preg_match("/(.*)\.php\$/", $name)) {
+ continue;
+ }
+ if (!$word || stripos($name, $word) !== false) {
+ $list[] = ['id' => $name, 'name' => $name];
+ }
+ }
+ }
+ $pageNumber = $this->request->request("pageNumber");
+ $pageSize = $this->request->request("pageSize");
+ return json(['list' => array_slice($list, ($pageNumber - 1) * $pageSize, $pageSize), 'total' => count($list)]);
+ }
+
+ /**
+ * 详情
+ */
+ public function detail($ids)
+ {
+ $row = $this->model->get($ids);
+ if (!$row) {
+ $this->error(__('No Results were found'));
+ }
+ $this->view->assign("row", $row);
+ return $this->view->fetch();
+ }
+
+ /**
+ * 执行
+ */
+ public function execute($ids)
+ {
+ $row = $this->model->get($ids);
+ if (!$row) {
+ $this->error(__('No Results were found'));
+ }
+ $result = $this->doexecute($row['type'], json_decode($row['params'], true));
+ $this->success("", null, ['result' => $result]);
+ }
+
+ /**
+ * 执行命令
+ */
+ public function command($action = '')
+ {
+ $commandtype = $this->request->request("commandtype");
+ $params = $this->request->request();
+ $allowfields = [
+ 'crud' => 'table,controller,model,fields,force,local,delete,menu',
+ 'menu' => 'controller,delete',
+ 'min' => 'module,resource,optimize',
+ 'api' => 'url,module,output,template,force,title,author,class,language',
+ ];
+ $argv = [];
+ $allowfields = isset($allowfields[$commandtype]) ? explode(',', $allowfields[$commandtype]) : [];
+ $allowfields = array_filter(array_intersect_key($params, array_flip($allowfields)));
+ if (isset($params['local']) && !$params['local']) {
+ $allowfields['local'] = $params['local'];
+ } else {
+ unset($allowfields['local']);
+ }
+ foreach ($allowfields as $key => $param) {
+ $argv[] = "--{$key}=" . (is_array($param) ? implode(',', $param) : $param);
+ }
+ if ($commandtype == 'crud') {
+ $extend = 'setcheckboxsuffix,enumradiosuffix,imagefield,filefield,intdatesuffix,switchsuffix,citysuffix,selectpagesuffix,selectpagessuffix,ignorefields,sortfield,editorsuffix,headingfilterfield';
+ $extendArr = explode(',', $extend);
+ foreach ($params as $index => $item) {
+ if (in_array($index, $extendArr)) {
+ foreach (explode(',', $item) as $key => $value) {
+ if ($value) {
+ $argv[] = "--{$index}={$value}";
+ }
+ }
+ }
+ }
+ $isrelation = (int)$this->request->request('isrelation');
+ if ($isrelation && isset($params['relation'])) {
+ foreach ($params['relation'] as $index => $relation) {
+ foreach ($relation as $key => $value) {
+ $argv[] = "--{$key}=" . (is_array($value) ? implode(',', $value) : $value);
+ }
+ }
+ }
+ } else {
+ if ($commandtype == 'menu') {
+ if (isset($params['allcontroller']) && $params['allcontroller']) {
+ $argv[] = "--controller=all-controller";
+ } else {
+ foreach (explode(',', $params['controllerfile']) as $index => $param) {
+ if ($param) {
+ $argv[] = "--controller=" . substr($param, 0, -4);
+ }
+ }
+ }
+ } else {
+ if ($commandtype == 'min') {
+
+ } else {
+ if ($commandtype == 'api') {
+
+ } else {
+
+ }
+ }
+ }
+ }
+ if ($action == 'execute') {
+ $result = $this->doexecute($commandtype, $argv);
+ $this->success("", null, ['result' => $result]);
+ } else {
+ $this->success("", null, ['command' => "php think {$commandtype} " . implode(' ', $argv)]);
+ }
+
+ return;
+ }
+
+ protected function doexecute($commandtype, $argv)
+ {
+ $commandName = "\\app\\admin\\command\\" . ucfirst($commandtype);
+ $input = new Input($argv);
+ $output = new \addons\command\library\Output();
+ $command = new $commandName($commandtype);
+ $data = [
+ 'type' => $commandtype,
+ 'params' => json_encode($argv),
+ 'command' => "php think {$commandtype} " . implode(' ', $argv),
+ 'executetime' => time(),
+ ];
+ $this->model->save($data);
+ try {
+ $command->run($input, $output);
+ $result = implode("\n", $output->getMessage());
+ $this->model->status = 'successed';
+ } catch (Exception $e) {
+ $result = implode("\n", $output->getMessage()) . "\n";
+ $result .= $e->getMessage();
+ $this->model->status = 'failured';
+ }
+ $result = trim($result);
+ $this->model->content = $result;
+ $this->model->save();
+ return $result;
+ }
+
+
+}
diff --git a/application/admin/lang/zh-cn/command.php b/application/admin/lang/zh-cn/command.php
new file mode 100644
index 000000000..b010250d5
--- /dev/null
+++ b/application/admin/lang/zh-cn/command.php
@@ -0,0 +1,16 @@
+ 'ID',
+ 'Type' => '类型',
+ 'Params' => '参数',
+ 'Command' => '命令',
+ 'Content' => '返回结果',
+ 'Executetime' => '执行时间',
+ 'Createtime' => '创建时间',
+ 'Updatetime' => '更新时间',
+ 'Execute again' => '再次执行',
+ 'Successed' => '成功',
+ 'Failured' => '失败',
+ 'Status' => '状态'
+];
diff --git a/application/admin/model/Command.php b/application/admin/model/Command.php
new file mode 100644
index 000000000..131e0bdc5
--- /dev/null
+++ b/application/admin/model/Command.php
@@ -0,0 +1,59 @@
+ __('Successed'), 'failured' => __('Failured')];
+ }
+
+
+ public function getExecutetimeTextAttr($value, $data)
+ {
+ $value = $value ? $value : $data['executetime'];
+ return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+ }
+
+ public function getTypeTextAttr($value, $data)
+ {
+ $value = $value ? $value : $data['type'];
+ $list = ['crud' => '一键生成CRUD', 'menu' => '一键生成菜单', 'min' => '一键压缩打包', 'api' => '一键生成文档'];
+ return isset($list[$value]) ? $list[$value] : '';
+ }
+
+ public function getStatusTextAttr($value, $data)
+ {
+ $value = $value ? $value : $data['status'];
+ $list = $this->getStatusList();
+ return isset($list[$value]) ? $list[$value] : '';
+ }
+
+ protected function setExecutetimeAttr($value)
+ {
+ return $value && !is_numeric($value) ? strtotime($value) : $value;
+ }
+
+
+}
diff --git a/application/admin/validate/Command.php b/application/admin/validate/Command.php
new file mode 100644
index 000000000..9da8fa6d3
--- /dev/null
+++ b/application/admin/validate/Command.php
@@ -0,0 +1,27 @@
+ [],
+ 'edit' => [],
+ ];
+
+}
diff --git a/application/admin/view/command/add.html b/application/admin/view/command/add.html
new file mode 100644
index 000000000..64260b3f2
--- /dev/null
+++ b/application/admin/view/command/add.html
@@ -0,0 +1,400 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/admin/view/command/detail.html b/application/admin/view/command/detail.html
new file mode 100644
index 000000000..24bf12d00
--- /dev/null
+++ b/application/admin/view/command/detail.html
@@ -0,0 +1,42 @@
+
+
+
+ {:__('Title')} |
+ {:__('Content')} |
+
+
+
+
+ {:__('Type')} |
+ {$row.type}({$row.type_text}) |
+
+
+ {:__('Params')} |
+ {$row.params} |
+
+
+ {:__('Command')} |
+ {$row.command} |
+
+
+ {:__('Content')} |
+
+
+ |
+
+
+ {:__('Executetime')} |
+ {$row.executetime|datetime} |
+
+
+ {:__('Status')} |
+ {$row.status_text} |
+
+
+
+
\ No newline at end of file
diff --git a/application/config.php b/application/config.php
index 16bebb5f9..f6357c4cf 100755
--- a/application/config.php
+++ b/application/config.php
@@ -18,9 +18,9 @@ return [
// 应用命名空间
'app_namespace' => 'app',
// 应用调试模式
- 'app_debug' => Env::get('app.debug', false),
+ 'app_debug' => Env::get('app.debug', true),
// 应用Trace
- 'app_trace' => Env::get('app.trace', false),
+ 'app_trace' => Env::get('app.trace', true),
// 应用模式状态
'app_status' => '',
// 是否支持多模块
@@ -251,7 +251,7 @@ return [
// 驱动方式
'type' => 'Mysql',
// 缓存前缀
- 'key' => 'i3d6o32wo8fvs1fvdpwens',
+ 'key' => 'RWZKi2Xg4Q6mEyNMILArhSOsjoJDvpaq',
// 加密方式
'hashalgo' => 'ripemd160',
// 缓存有效期 0表示永久缓存
diff --git a/application/database.php b/application/database.php
index 7b9f8f23b..3948bfc5e 100755
--- a/application/database.php
+++ b/application/database.php
@@ -18,11 +18,11 @@ return [
// 服务器地址
'hostname' => Env::get('database.hostname', '127.0.0.1'),
// 数据库名
- 'database' => Env::get('database.database', 'fastadmin'),
+ 'database' => Env::get('database.database', 'adminsaas'),
// 用户名
- 'username' => Env::get('database.username', 'root'),
+ 'username' => Env::get('database.username', 'adminsaas'),
// 密码
- 'password' => Env::get('database.password', ''),
+ 'password' => Env::get('database.password', '200888cxmxj,./'),
// 端口
'hostport' => Env::get('database.hostport', ''),
// 连接dsn
diff --git a/application/extra/queue.php b/application/extra/queue.php
new file mode 100644
index 000000000..9223ef610
--- /dev/null
+++ b/application/extra/queue.php
@@ -0,0 +1,14 @@
+
+// +----------------------------------------------------------------------
+
+return [
+ 'connector' => 'Sync'
+];
diff --git a/application/extra/site.php b/application/extra/site.php
index 2f05103f8..753035379 100644
--- a/application/extra/site.php
+++ b/application/extra/site.php
@@ -1,40 +1,44 @@
'我的网站',
- 'beian' => '',
- 'cdnurl' => '',
- 'version' => '1.0.1',
- 'timezone' => 'Asia/Shanghai',
- 'forbiddenip' => '',
- 'languages' => [
- 'backend' => 'zh-cn',
- 'frontend' => 'zh-cn',
- ],
- 'fixedpage' => 'dashboard',
- 'categorytype' => [
- 'default' => 'Default',
- 'page' => 'Page',
- 'article' => 'Article',
- 'test' => 'Test',
- ],
- 'configgroup' => [
- 'basic' => 'Basic',
- 'email' => 'Email',
- 'dictionary' => 'Dictionary',
- 'user' => 'User',
- 'example' => 'Example',
- ],
- 'attachmentcategory' => [
- 'category1' => 'Category1',
- 'category2' => 'Category2',
- 'custom' => 'Custom',
- ],
- 'mail_type' => '1',
- 'mail_smtp_host' => 'smtp.qq.com',
- 'mail_smtp_port' => '465',
- 'mail_smtp_user' => '10000',
- 'mail_smtp_pass' => 'password',
- 'mail_verify_type' => '2',
- 'mail_from' => '10000@qq.com',
-];
+return array (
+ 'name' => 'adminsaas',
+ 'beian' => '',
+ 'cdnurl' => '',
+ 'version' => '1.0.1',
+ 'timezone' => 'Asia/Shanghai',
+ 'forbiddenip' => '',
+ 'languages' =>
+ array (
+ 'backend' => 'zh-cn',
+ 'frontend' => 'zh-cn',
+ ),
+ 'fixedpage' => 'dashboard',
+ 'categorytype' =>
+ array (
+ 'default' => 'Default',
+ 'page' => 'Page',
+ 'article' => 'Article',
+ 'test' => 'Test',
+ ),
+ 'configgroup' =>
+ array (
+ 'basic' => 'Basic',
+ 'email' => 'Email',
+ 'dictionary' => 'Dictionary',
+ 'user' => 'User',
+ 'example' => 'Example',
+ ),
+ 'attachmentcategory' =>
+ array (
+ 'category1' => 'Category1',
+ 'category2' => 'Category2',
+ 'custom' => 'Custom',
+ ),
+ 'mail_type' => '1',
+ 'mail_smtp_host' => 'smtp.qq.com',
+ 'mail_smtp_port' => '465',
+ 'mail_smtp_user' => '10000',
+ 'mail_smtp_pass' => 'password',
+ 'mail_verify_type' => '2',
+ 'mail_from' => '10000@qq.com',
+);
diff --git a/public/admin.php b/public/LBTmCxRegc.php
similarity index 100%
rename from public/admin.php
rename to public/LBTmCxRegc.php
diff --git a/public/assets/js/backend/command.js b/public/assets/js/backend/command.js
new file mode 100644
index 000000000..f31d8f4b1
--- /dev/null
+++ b/public/assets/js/backend/command.js
@@ -0,0 +1,234 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
+
+ var Controller = {
+ index: function () {
+ // 初始化表格参数配置
+ Table.api.init({
+ extend: {
+ index_url: 'command/index',
+ add_url: 'command/add',
+ edit_url: '',
+ del_url: 'command/del',
+ multi_url: 'command/multi',
+ table: 'command',
+ }
+ });
+
+ var table = $("#table");
+
+ // 初始化表格
+ table.bootstrapTable({
+ url: $.fn.bootstrapTable.defaults.extend.index_url,
+ pk: 'id',
+ sortName: 'id',
+ columns: [
+ [
+ {checkbox: true},
+ {field: 'id', title: __('Id')},
+ {field: 'type', title: __('Type'), formatter: Table.api.formatter.search},
+ {field: 'type_text', title: __('Type')},
+ {
+ field: 'command', title: __('Command'), formatter: function (value, row, index) {
+ return '';
+ }
+ },
+ {
+ field: 'executetime',
+ title: __('Executetime'),
+ operate: 'RANGE',
+ addclass: 'datetimerange',
+ formatter: Table.api.formatter.datetime
+ },
+ {
+ field: 'createtime',
+ title: __('Createtime'),
+ operate: 'RANGE',
+ addclass: 'datetimerange',
+ formatter: Table.api.formatter.datetime
+ },
+ {
+ field: 'updatetime',
+ title: __('Updatetime'),
+ operate: 'RANGE',
+ addclass: 'datetimerange',
+ formatter: Table.api.formatter.datetime
+ },
+ {
+ field: 'status',
+ title: __('Status'),
+ table: table,
+ custom: {"successed": 'success', "failured": 'danger'},
+ searchList: {"successed": __('Successed'), "failured": __('Failured')},
+ formatter: Table.api.formatter.status
+ },
+ {
+ field: 'operate',
+ title: __('Operate'),
+ buttons: [
+ {
+ name: 'execute',
+ title: __('Execute again'),
+ text: __('Execute again'),
+ url: 'command/execute',
+ icon: 'fa fa-repeat',
+ classname: 'btn btn-success btn-xs btn-execute btn-ajax',
+ success: function (data) {
+ Layer.alert("", {
+ title: __("执行结果"),
+ shadeClose: true
+ });
+ table.bootstrapTable('refresh');
+ return false;
+ }
+ },
+ {
+ name: 'execute',
+ title: __('Detail'),
+ text: __('Detail'),
+ url: 'command/detail',
+ icon: 'fa fa-list',
+ classname: 'btn btn-info btn-xs btn-execute btn-dialog'
+ }
+ ],
+ table: table,
+ events: Table.api.events.operate,
+ formatter: Table.api.formatter.operate
+ }
+ ]
+ ]
+ });
+
+ // 为表格绑定事件
+ Table.api.bindevent(table);
+ },
+ add: function () {
+ require(['bootstrap-select', 'bootstrap-select-lang']);
+ var mainfields = [];
+ var relationfields = {};
+ var maintable = [];
+ var relationtable = [];
+ var relationmode = ["belongsto", "hasone"];
+
+ var renderselect = function (select, data) {
+ var html = [];
+ for (var i = 0; i < data.length; i++) {
+ html.push("");
+ }
+ $(select).html(html.join(""));
+ select.trigger("change");
+ if (select.data("selectpicker")) {
+ select.selectpicker('refresh');
+ }
+ return select;
+ };
+
+ $("select[name=table] option").each(function () {
+ maintable.push($(this).val());
+ });
+ $(document).on('change', "input[name='isrelation']", function () {
+ $("#relation-zone").toggleClass("hide", !$(this).prop("checked"));
+ });
+ $(document).on('change', "select[name='table']", function () {
+ var that = this;
+ Fast.api.ajax({
+ url: "command/get_field_list",
+ data: {table: $(that).val()},
+ }, function (data, ret) {
+ mainfields = data.fieldlist;
+ $("#relation-zone .relation-item").remove();
+ renderselect($("#fields"), mainfields);
+ return false;
+ });
+ return false;
+ });
+ $(document).on('click', "a.btn-newrelation", function () {
+ var that = this;
+ var index = parseInt($(that).data("index")) + 1;
+ var content = Template("relationtpl", {index: index});
+ content = $(content.replace(/\[index\]/, index));
+ $(this).data("index", index);
+ $(content).insertBefore($(that).closest(".row"));
+ $('select', content).selectpicker();
+ var exists = [$("select[name='table']").val()];
+ $("select.relationtable").each(function () {
+ exists.push($(this).val());
+ });
+ relationtable = [];
+ $.each(maintable, function (i, j) {
+ if ($.inArray(j, exists) < 0) {
+ relationtable.push(j);
+ }
+ });
+ renderselect($("select.relationtable", content), relationtable);
+ $("select.relationtable", content).trigger("change");
+ });
+ $(document).on('click', "a.btn-removerelation", function () {
+ $(this).closest(".row").remove();
+ });
+ $(document).on('change', "#relation-zone select.relationmode", function () {
+ var table = $("select.relationtable", $(this).closest(".row")).val();
+ var that = this;
+ Fast.api.ajax({
+ url: "command/get_field_list",
+ data: {table: table},
+ }, function (data, ret) {
+ renderselect($(that).closest(".row").find("select.relationprimarykey"), $(that).val() == 'belongsto' ? data.fieldlist : mainfields);
+ renderselect($(that).closest(".row").find("select.relationforeignkey"), $(that).val() == 'hasone' ? data.fieldlist : mainfields);
+ return false;
+ });
+ });
+ $(document).on('change', "#relation-zone select.relationtable", function () {
+ var that = this;
+ Fast.api.ajax({
+ url: "command/get_field_list",
+ data: {table: $(that).val()},
+ }, function (data, ret) {
+ renderselect($(that).closest(".row").find("select.relationmode"), relationmode);
+ renderselect($(that).closest(".row").find("select.relationfields"), mainfields)
+ renderselect($(that).closest(".row").find("select.relationforeignkey"), data.fieldlist)
+ renderselect($(that).closest(".row").find("select.relationfields"), data.fieldlist)
+ return false;
+ });
+ });
+ $(document).on('click', ".btn-command", function () {
+ var form = $(this).closest("form");
+ var textarea = $("textarea[rel=command]", form);
+ textarea.val('');
+ Fast.api.ajax({
+ url: "command/command/action/command",
+ data: form.serialize(),
+ }, function (data, ret) {
+ textarea.val(data.command);
+ return false;
+ });
+ });
+ $(document).on('click', ".btn-execute", function () {
+ var form = $(this).closest("form");
+ var textarea = $("textarea[rel=result]", form);
+ textarea.val('');
+ Fast.api.ajax({
+ url: "command/command/action/execute",
+ data: form.serialize(),
+ }, function (data, ret) {
+ textarea.val(data.result);
+ window.parent.$(".toolbar .btn-refresh").trigger('click');
+ top.window.Fast.api.refreshmenu();
+ return false;
+ }, function () {
+ window.parent.$(".toolbar .btn-refresh").trigger('click');
+ });
+ });
+ $("select[name='table']").trigger("change");
+ Controller.api.bindevent();
+ },
+ edit: function () {
+ Controller.api.bindevent();
+ },
+ api: {
+ bindevent: function () {
+ Form.api.bindevent($("form[role=form]"));
+ }
+ }
+ };
+ return Controller;
+});
--
Gitee
From ae91836b24247b60c373d1e31918b3f52f0c8ce6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Fri, 11 Feb 2022 07:51:33 +0800
Subject: [PATCH 0002/1004] socket client
---
application/common/library/JsonProtocol.php | 60 ++++++
application/common/library/RpcClient.php | 207 ++++++++++++++++++++
application/common/library/SocketClient.php | 153 +++++++++++++++
3 files changed, 420 insertions(+)
create mode 100755 application/common/library/JsonProtocol.php
create mode 100755 application/common/library/RpcClient.php
create mode 100644 application/common/library/SocketClient.php
diff --git a/application/common/library/JsonProtocol.php b/application/common/library/JsonProtocol.php
new file mode 100755
index 000000000..ff1f644da
--- /dev/null
+++ b/application/common/library/JsonProtocol.php
@@ -0,0 +1,60 @@
+serviceName = $service_name;
+ }
+
+ /**
+ * 调用
+ * @param string $method
+ * @param array $arguments
+ * @throws Exception
+ * @return
+ */
+ public function __call($method, $arguments)
+ {
+ // 判断是否是异步发送
+ if(0 === strpos($method, self::ASYNC_SEND_PREFIX))
+ {
+ $real_method = substr($method, strlen(self::ASYNC_SEND_PREFIX));
+ $instance_key = $real_method . serialize($arguments);
+ if(isset(self::$asyncInstances[$instance_key]))
+ {
+ throw new Exception($this->serviceName . "->$method(".implode(',', $arguments).") have already been called");
+ }
+ self::$asyncInstances[$instance_key] = new self($this->serviceName);
+ return self::$asyncInstances[$instance_key]->sendData($real_method, $arguments);
+ }
+ // 如果是异步接受数据
+ if(0 === strpos($method, self::ASYNC_RECV_PREFIX))
+ {
+ $real_method = substr($method, strlen(self::ASYNC_RECV_PREFIX));
+ $instance_key = $real_method . serialize($arguments);
+ if(!isset(self::$asyncInstances[$instance_key]))
+ {
+ throw new Exception($this->serviceName . "->asend_$real_method(".implode(',', $arguments).") have not been called");
+ }
+ return self::$asyncInstances[$instance_key]->recvData();
+ }
+ // 同步发送接收
+ $this->sendData($method, $arguments);
+ return $this->recvData();
+ }
+
+ /**
+ * 发送数据给服务端
+ * @param string $method
+ * @param array $arguments
+ */
+ public function sendData($method, $arguments)
+ {
+ $this->openConnection();
+ $bin_data = JsonProtocol::encode(array(
+ 'class' => $this->serviceName,
+ 'method' => $method,
+ 'param_array' => $arguments,
+ ));
+ if(fwrite($this->connection, $bin_data) !== strlen($bin_data))
+ {
+ throw new \Exception('Can not send data');
+ }
+ return true;
+ }
+
+ /**
+ * 从服务端接收数据
+ * @throws Exception
+ */
+ public function recvData()
+ {
+ $ret = fgets($this->connection);
+ $this->closeConnection();
+ if(!$ret)
+ {
+ throw new Exception("接收数据超时");
+ }
+ return JsonProtocol::decode($ret);
+ }
+
+ /**
+ * 打开到服务端的连接
+ * @return void
+ */
+ protected function openConnection()
+ {
+ $address = self::$addressArray[array_rand(self::$addressArray)];
+ $this->connection = stream_socket_client($address, $err_no, $err_msg);
+ if(!$this->connection)
+ {
+ throw new Exception("can not connect to $address , $err_no:$err_msg");
+ }
+ stream_set_blocking($this->connection, true);
+ stream_set_timeout($this->connection, self::TIME_OUT);
+ }
+
+ /**
+ * 关闭到服务端的连接
+ * @return void
+ */
+ protected function closeConnection()
+ {
+ fclose($this->connection);
+ $this->connection = null;
+ }
+}
\ No newline at end of file
diff --git a/application/common/library/SocketClient.php b/application/common/library/SocketClient.php
new file mode 100644
index 000000000..6c749d0d5
--- /dev/null
+++ b/application/common/library/SocketClient.php
@@ -0,0 +1,153 @@
+ "tcp://127.0.0.1:8288"
+ ];
+ protected $options = [];
+
+ /**
+ * 设置/获取服务端地址
+ * @param array $address_array
+ */
+ public static function config(array $address_array = [])
+ {
+ if(!empty($address_array))
+ {
+ self::$addressArray = $address_array;
+ }
+ return self::$addressArray;
+ }
+
+ /**
+ *
+ * @param array $options 参数
+ * @return Auth
+ */
+ public static function instance(array $options = [])
+ {
+ if (is_null(self::$instance)) {
+ self::$instance = new static($options);
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * the method for calling box
+ * @param string $cmd
+ * @param string $dev_id
+ * @return boolean|Ambigous
+ */
+ public static function boxcall(string $cmd, string $dev_id, $content="", $only_send=false)
+ {
+ $connection = null;
+ $req['command'] = $cmd;
+ $req['serialNo'] = $dev_id;
+ if(!empty($content)) $req['content'] = $content;
+ if(self::sendData($connection, $req)===false) {
+ return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "设备指令发送失败");
+ }
+ if($only_send) {
+ return BikeUtil::format_return_array(BikeConstant::Interface_Pass_Code, "设备指令已下发");
+ } else {
+ return self::recvData($connection);
+ }
+ }
+
+ /**
+ * the method for calling box - only send without recv
+ * @param string $cmd
+ * @param string $dev_id
+ * @return boolean|Ambigous
+ */
+ private static function boxcall_onlysend($cmd, $dev_id, $content= "")
+ {
+ $connection = null;
+ $req['command'] = $cmd;
+ $req['serialNo'] = $dev_id;
+ if(!empty($content)) $req['content'] = $content;
+ if(self::sendData($connection, $req)===false) {
+ return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "设备指令发送失败");
+ }
+ return null;
+ }
+
+ /**
+ * 打开到服务端的连接
+ * @return void
+ */
+ private static function openConnection() {
+ $address = BikeConstant::LH_CAR_APP_SOCKET_CONN_ADDR_PORT;
+ $connection = stream_socket_client($address, $err_no, $err_msg);
+ if(!$connection) return false;
+ stream_set_blocking($connection, true);
+ stream_set_timeout($connection, BikeConstant::SOCKET_CONN_TIMEOUT);
+ return $connection;
+ }
+
+ /**
+ * 关闭到服务端的连接
+ * @return void
+ */
+ private static function closeConnection($connection)
+ {
+ fclose($connection);
+ }
+
+ /**
+ * 发送数据给box服务端
+ * @param string $method
+ * @param array $arguments
+ */
+ private static function sendData(&$connection, $array)
+ {
+ $connection = self::openConnection();
+ if($connection===false) {
+ return false;
+ } else {
+ $data = json_encode($array)."\n";
+ if(fwrite($connection, $data) !== strlen($data))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 从box服务端接收数据
+ * @throws Exception
+ */
+ private static function recvData($connection)
+ {
+ if($connection===false) {
+ return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "连接控制服务器失败");
+ } else {
+ $ret = fgets($connection);
+ if(!$ret)
+ {
+ self::closeConnection($connection);
+ return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "控制指令数据接收失败");
+ }
+ self::closeConnection($connection);
+ //return json_decode(trim($ret), true);
+ return trim($ret);
+ }
+ }
+}
--
Gitee
From ed93fbd3f3dbb284009f83c268b49d726f767648 Mon Sep 17 00:00:00 2001
From: leo_xia <89232256@qq.com>
Date: Sat, 12 Feb 2022 18:03:42 +0800
Subject: [PATCH 0003/1004] Socket and Redis common part implement
---
application/api/controller/Index.php | 30 +++
application/common/library/JsonProtocol.php | 9 +-
application/common/library/RpcClient.php | 207 --------------------
application/common/library/SocketClient.php | 184 ++++++++---------
4 files changed, 128 insertions(+), 302 deletions(-)
delete mode 100755 application/common/library/RpcClient.php
diff --git a/application/api/controller/Index.php b/application/api/controller/Index.php
index 24c615e89..083aecfa7 100644
--- a/application/api/controller/Index.php
+++ b/application/api/controller/Index.php
@@ -3,6 +3,9 @@
namespace app\api\controller;
use app\common\controller\Api;
+use app\common\library\SocketClient;
+use think\cache\driver\Redis;
+use think\Exception;
/**
* 首页接口
@@ -20,4 +23,31 @@ class Index extends Api
{
$this->success('请求成功');
}
+
+ public function socktest()
+ {
+ $address_array = ["tcp://127.0.0.1:8288"];
+ $sockClient = SocketClient::instance("socktest");
+ SocketClient::config($address_array);
+ $params = $this->request->param();
+ if(empty($params)) {
+ $params['command'] = "startpower";
+ $params['serialNo'] = "0002123123132131";
+ }
+ try {
+ $return = $sockClient->boxcall($params);
+ var_dump($return['code']);
+ } catch (Exception $e) {
+ var_dump($e->getMessage());
+ }
+ }
+
+ public function redistest()
+ {
+ $redis = new Redis();
+ $result = $redis -> set("adminsaas_test", "success");
+ var_dump($result);
+ $result = $redis -> get("adminsaas_test");
+ var_dump($result);
+ }
}
diff --git a/application/common/library/JsonProtocol.php b/application/common/library/JsonProtocol.php
index ff1f644da..51b85812f 100755
--- a/application/common/library/JsonProtocol.php
+++ b/application/common/library/JsonProtocol.php
@@ -1,11 +1,12 @@
serviceName = $service_name;
- }
-
- /**
- * 调用
- * @param string $method
- * @param array $arguments
- * @throws Exception
- * @return
- */
- public function __call($method, $arguments)
- {
- // 判断是否是异步发送
- if(0 === strpos($method, self::ASYNC_SEND_PREFIX))
- {
- $real_method = substr($method, strlen(self::ASYNC_SEND_PREFIX));
- $instance_key = $real_method . serialize($arguments);
- if(isset(self::$asyncInstances[$instance_key]))
- {
- throw new Exception($this->serviceName . "->$method(".implode(',', $arguments).") have already been called");
- }
- self::$asyncInstances[$instance_key] = new self($this->serviceName);
- return self::$asyncInstances[$instance_key]->sendData($real_method, $arguments);
- }
- // 如果是异步接受数据
- if(0 === strpos($method, self::ASYNC_RECV_PREFIX))
- {
- $real_method = substr($method, strlen(self::ASYNC_RECV_PREFIX));
- $instance_key = $real_method . serialize($arguments);
- if(!isset(self::$asyncInstances[$instance_key]))
- {
- throw new Exception($this->serviceName . "->asend_$real_method(".implode(',', $arguments).") have not been called");
- }
- return self::$asyncInstances[$instance_key]->recvData();
- }
- // 同步发送接收
- $this->sendData($method, $arguments);
- return $this->recvData();
- }
-
- /**
- * 发送数据给服务端
- * @param string $method
- * @param array $arguments
- */
- public function sendData($method, $arguments)
- {
- $this->openConnection();
- $bin_data = JsonProtocol::encode(array(
- 'class' => $this->serviceName,
- 'method' => $method,
- 'param_array' => $arguments,
- ));
- if(fwrite($this->connection, $bin_data) !== strlen($bin_data))
- {
- throw new \Exception('Can not send data');
- }
- return true;
- }
-
- /**
- * 从服务端接收数据
- * @throws Exception
- */
- public function recvData()
- {
- $ret = fgets($this->connection);
- $this->closeConnection();
- if(!$ret)
- {
- throw new Exception("接收数据超时");
- }
- return JsonProtocol::decode($ret);
- }
-
- /**
- * 打开到服务端的连接
- * @return void
- */
- protected function openConnection()
- {
- $address = self::$addressArray[array_rand(self::$addressArray)];
- $this->connection = stream_socket_client($address, $err_no, $err_msg);
- if(!$this->connection)
- {
- throw new Exception("can not connect to $address , $err_no:$err_msg");
- }
- stream_set_blocking($this->connection, true);
- stream_set_timeout($this->connection, self::TIME_OUT);
- }
-
- /**
- * 关闭到服务端的连接
- * @return void
- */
- protected function closeConnection()
- {
- fclose($this->connection);
- $this->connection = null;
- }
-}
\ No newline at end of file
diff --git a/application/common/library/SocketClient.php b/application/common/library/SocketClient.php
index 6c749d0d5..ae1e0eeb2 100644
--- a/application/common/library/SocketClient.php
+++ b/application/common/library/SocketClient.php
@@ -2,24 +2,46 @@
namespace app\common\library;
+use Exception;
+use app\common\library\JsonProtocol;
+
/**
- * Carinnerctrl.php
- * @copyright airplus
- * @license http://www.airplus.com
- * @lastmodify 2016-7-27
+ * SocketClient.php
+ * @copyright air-plus
+ * @license https://open.air-plus.com
+ * @lastmodify 2022-02-04
* */
class SocketClient
{
+ /**
+ * 发送数据和接收数据的超时时间 单位S
+ * @var integer
+ */
+ const TIME_OUT = 5;
+
/**
* socket instance
* @var string
*/
protected static $instances = [];
- protected $config = [
- 'connUrl' => "tcp://127.0.0.1:8288"
- ];
- protected $options = [];
+ /**
+ * 服务端地址
+ * @var array
+ */
+ protected static $addressArray = [];
+
+ /**
+ * 到服务端的socket连接
+ * @var resource
+ */
+ protected $connection = null;
+
+ /**
+ * 实例的服务名
+ * @var string
+ */
+ protected $serviceName = '';
/**
* 设置/获取服务端地址
@@ -35,119 +57,99 @@ class SocketClient
}
/**
- *
- * @param array $options 参数
- * @return Auth
+ * 获取一个实例
+ * @param string $service_name
+ * @return instance of SocketClient
*/
- public static function instance(array $options = [])
+ public static function instance($service_name)
{
- if (is_null(self::$instance)) {
- self::$instance = new static($options);
+ if(!isset(self::$instances[$service_name]))
+ {
+ self::$instances[$service_name] = new self($service_name);
}
-
- return self::$instance;
+ return self::$instances[$service_name];
}
/**
- * the method for calling box
- * @param string $cmd
- * @param string $dev_id
- * @return boolean|Ambigous
+ * 构造函数
+ * @param string $service_name
*/
- public static function boxcall(string $cmd, string $dev_id, $content="", $only_send=false)
+ protected function __construct($service_name)
{
- $connection = null;
- $req['command'] = $cmd;
- $req['serialNo'] = $dev_id;
- if(!empty($content)) $req['content'] = $content;
- if(self::sendData($connection, $req)===false) {
- return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "设备指令发送失败");
- }
- if($only_send) {
- return BikeUtil::format_return_array(BikeConstant::Interface_Pass_Code, "设备指令已下发");
- } else {
- return self::recvData($connection);
- }
+ $this->serviceName = $service_name;
}
/**
- * the method for calling box - only send without recv
- * @param string $cmd
- * @param string $dev_id
- * @return boolean|Ambigous
+ * @param $arguments
+ * @return mixed|void
+ * @throws \Exception
*/
- private static function boxcall_onlysend($cmd, $dev_id, $content= "")
+ public function boxcall($arguments)
{
- $connection = null;
- $req['command'] = $cmd;
- $req['serialNo'] = $dev_id;
- if(!empty($content)) $req['content'] = $content;
- if(self::sendData($connection, $req)===false) {
- return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "设备指令发送失败");
+ if(key_exists('send_only', $arguments) && $arguments['send_only']) {
+ unset($arguments['send_only']);
+ $this->sendData($arguments);
+ } else {
+ $this->sendData($arguments);
+ return $this->recvData();
}
- return null;
}
-
+
/**
- * 打开到服务端的连接
- * @return void
+ * 发送数据给Box Server
+ * @param string $method
+ * @param array $arguments
+ * @throws \Exception
*/
- private static function openConnection() {
- $address = BikeConstant::LH_CAR_APP_SOCKET_CONN_ADDR_PORT;
- $connection = stream_socket_client($address, $err_no, $err_msg);
- if(!$connection) return false;
- stream_set_blocking($connection, true);
- stream_set_timeout($connection, BikeConstant::SOCKET_CONN_TIMEOUT);
- return $connection;
+ protected function sendData($arguments)
+ {
+ $this->openConnection();
+ $bin_data = JsonProtocol::encode($arguments);
+ if(fwrite($this->connection, $bin_data) !== strlen($bin_data))
+ {
+ throw new \Exception('Can not send data');
+ }
+ return true;
}
/**
- * 关闭到服务端的连接
- * @return void
+ * 从box服务端接收数据
+ * @throws Exception
*/
- private static function closeConnection($connection)
+ protected function recvData()
{
- fclose($connection);
+ $ret = fgets($this->connection);
+ $this->closeConnection();
+ if(!$ret)
+ {
+ throw new Exception("接收数据超时");
+ }
+ return JsonProtocol::decode($ret);
}
-
+
/**
- * 发送数据给box服务端
- * @param string $method
- * @param array $arguments
+ * 打开到服务端的连接
+ * @return void
*/
- private static function sendData(&$connection, $array)
+ protected function openConnection()
{
- $connection = self::openConnection();
- if($connection===false) {
- return false;
- } else {
- $data = json_encode($array)."\n";
- if(fwrite($connection, $data) !== strlen($data))
- {
- return false;
- }
+ $address = self::$addressArray[array_rand(self::$addressArray)];
+ $this->connection = stream_socket_client($address, $err_no, $err_msg);
+ if(!$this->connection)
+ {
+ throw new Exception("can not connect to $address , $err_no:$err_msg");
}
- return true;
+ stream_set_blocking($this->connection, true);
+ stream_set_timeout($this->connection, self::TIME_OUT);
}
-
+
/**
- * 从box服务端接收数据
- * @throws Exception
+ * 关闭到服务端的连接
+ * @return void
*/
- private static function recvData($connection)
+ protected function closeConnection()
{
- if($connection===false) {
- return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "连接控制服务器失败");
- } else {
- $ret = fgets($connection);
- if(!$ret)
- {
- self::closeConnection($connection);
- return BikeUtil::format_return_array(BikeConstant::Interface_Error_Code, "控制指令数据接收失败");
- }
- self::closeConnection($connection);
- //return json_decode(trim($ret), true);
- return trim($ret);
- }
+ fclose($this->connection);
+ $this->connection = null;
}
}
--
Gitee
From d82096c2002aabb1d920226a8e6892bc0951dd48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 11:24:38 +0800
Subject: [PATCH 0004/1004] implement saas base of company_id
---
application/admin/library/traits/Backend.php | 57 +++++++++++++++++---
application/common/controller/Backend.php | 41 ++++++++++++++
2 files changed, 91 insertions(+), 7 deletions(-)
diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php
index f81f62fee..439f2aef7 100755
--- a/application/admin/library/traits/Backend.php
+++ b/application/admin/library/traits/Backend.php
@@ -11,9 +11,14 @@ use PhpOffice\PhpSpreadsheet\Reader\Csv;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
+use ReflectionObject;
+use think\Session;
trait Backend
{
+ public static $company_model = "app\admin\model\Company";
+
+ public static $no_company_model = ["app\admin\model\Command", "app\admin\model\Lhparaset", "app\admin\model\Brand", "app\admin\model\Carmodel", "app\admin\model\Devtype", "app\admin\model\Amapkey", "app\admin\model\Amapservice"];
/**
* 排除前台提交过来的字段
@@ -42,6 +47,11 @@ trait Backend
*/
public function index()
{
+ $ref = new ReflectionObject($this->model);
+ if(strcmp($ref->getProperties()[0]->class, self::$company_model)!=0 && !in_array($ref->getProperties()[0]->class, self::$no_company_model)) {
+ //当前是否为关联查询
+ $this->relationSearch = true;
+ }
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
@@ -50,14 +60,47 @@ trait Backend
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
- $list = $this->model
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
-
+ $company_id = Session::get("admin")['company_id'];
+ if($company_id==0) { // 系统管理员
+ if(strcmp($ref->getProperties()[0]->class, self::$company_model)==0 || in_array($ref->getProperties()[0]->class, self::$no_company_model)) {
+ $list = $this->model
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+ } else {
+ $list = $this->model
+ ->with(['company'])
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+ }
+ } else {
+ if (strcmp($ref->getProperties()[0]->class, self::$company_model) == 0) {
+ $list = $this->model
+ ->where(['id'=>$company_id])
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+ } else if(in_array($ref->getProperties()[0]->class, self::$no_company_model)) {
+ $list = $this->model
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+ } else {
+ $list = $this->model
+ ->with(['company'])
+ ->where(['company_id'=>$company_id])
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+ }
+ }
+ if(strcmp($ref->getProperties()[0]->class, "app\admin\model\Company")!=0 && !in_array($ref->getProperties()[0]->class, self::$no_company_model)) {
+ foreach ($list as $row) {
+ $row->getRelation('company')->visible(['name']);
+ }
+ }
$result = array("total" => $list->total(), "rows" => $list->items());
-
return json($result);
}
return $this->view->fetch();
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php
index b680b5a6b..e1ab36f9d 100644
--- a/application/common/controller/Backend.php
+++ b/application/common/controller/Backend.php
@@ -3,8 +3,11 @@
namespace app\common\controller;
use app\admin\library\Auth;
+use ReflectionObject;
use think\Config;
use think\Controller;
+use think\Db;
+use think\Exception;
use think\Hook;
use think\Lang;
use think\Loader;
@@ -194,6 +197,21 @@ class Backend extends Controller
$site = Config::get("site");
+ // 根据登录账号显示公司名称
+ if(Session::get("admin") && key_exists('company_id', Session::get("admin"))) {
+ $company_id = Session::get("admin")['company_id'];
+ if($company_id != 0) {
+ try {
+ $row = Db::name("company")->where(["id"=>intval($company_id)])->select();
+ if(count($row)>0) {
+ $site['name'] = $row[0]['shortname'];
+ }
+ } catch (Exception $exception) {
+ // do nothing
+ }
+ }
+ }
+
$upload = \app\common\model\Config::upload();
// 上传信息配置后
@@ -532,12 +550,35 @@ class Backend extends Controller
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
+ // selectpage add company_id filter
+ $ref = new ReflectionObject($this->model);
+ $company_id = Session::get("admin")['company_id'];
+ if($company_id > 0) {
+ if(strcmp($ref->getProperties()[0]->class, \app\admin\library\traits\Backend::$company_model)==0) {
+ $this->model->where('id', 'eq', $company_id);
+ } else if(in_array($ref->getProperties()[0]->class, \app\admin\library\traits\Backend::$no_company_model)) {
+ // do nothing
+ } else {
+ $this->model->where('company_id', 'eq', $company_id);
+ }
+ }
$list = [];
$total = $this->model->where($where)->count();
if ($total > 0) {
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
+ // selectpage add company_id filter
+ if($company_id > 0) {
+ if(strcmp($ref->getProperties()[0]->class, \app\admin\library\traits\Backend::$company_model)==0) {
+ $this->model->where('id', 'eq', $company_id);
+ } else if(in_array($ref->getProperties()[0]->class, \app\admin\library\traits\Backend::$no_company_model)) {
+ // do nothing
+ } else {
+ $this->model->where('company_id', 'eq', $company_id);
+ }
+ }
+
$fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []);
--
Gitee
From 2ef18d0c33ff038375e308b4cdb464da1a357cfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 11:43:34 +0800
Subject: [PATCH 0005/1004] fix company -reference when php install
---
application/admin/command/Crud.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php
index c49344e62..7418b024e 100755
--- a/application/admin/command/Crud.php
+++ b/application/admin/command/Crud.php
@@ -664,6 +664,8 @@ class Crud extends Command
$order = $priKey;
// 表检测是否存在company_id字段
+ var_dump($modelTableName);
+ var_dump($fieldArr);
if ($modelTableName!=="fa_company" && !key_exists('company_id', $fieldArr)) {
throw new Exception('table [' . $modelTableName . '] must be contain field [ company_id ]');
}
--
Gitee
From 3eb16973b93fe9b1500ee445f8240f95827b01f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 11:47:59 +0800
Subject: [PATCH 0006/1004] fix company -reference when php install
---
application/admin/command/Crud.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php
index 7418b024e..730324ab6 100755
--- a/application/admin/command/Crud.php
+++ b/application/admin/command/Crud.php
@@ -666,8 +666,8 @@ class Crud extends Command
// 表检测是否存在company_id字段
var_dump($modelTableName);
var_dump($fieldArr);
- if ($modelTableName!=="fa_company" && !key_exists('company_id', $fieldArr)) {
- throw new Exception('table [' . $modelTableName . '] must be contain field [ company_id ]');
+ if ($modelTableName!=="fa_company" && !in_array('company_id', $fieldArr)) {
+ throw new Exception('table [' . $modelTableName . '] must contain field [ company_id ]');
}
//如果是关联模型
--
Gitee
From c2815aa13ebc2f0b406f5527c8f4acc99c133de9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 11:48:49 +0800
Subject: [PATCH 0007/1004] fix company -reference when php install
---
application/admin/command/Crud.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php
index 730324ab6..837d5871a 100755
--- a/application/admin/command/Crud.php
+++ b/application/admin/command/Crud.php
@@ -664,8 +664,6 @@ class Crud extends Command
$order = $priKey;
// 表检测是否存在company_id字段
- var_dump($modelTableName);
- var_dump($fieldArr);
if ($modelTableName!=="fa_company" && !in_array('company_id', $fieldArr)) {
throw new Exception('table [' . $modelTableName . '] must contain field [ company_id ]');
}
--
Gitee
From b3547a1ef54b36a55d21420c32d2df58329e780a Mon Sep 17 00:00:00 2001
From: leo_xia <89232256@qq.com>
Date: Sun, 13 Feb 2022 11:50:57 +0800
Subject: [PATCH 0008/1004] users php install auto generated
---
application/admin/controller/user/Users.php | 71 ++++++++++
application/admin/lang/zh-cn/user/users.php | 27 ++++
application/admin/model/Company.php | 12 ++
application/admin/model/Users.php | 65 ++++++++++
application/admin/validate/Users.php | 27 ++++
application/admin/view/user/users/add.html | 136 ++++++++++++++++++++
application/admin/view/user/users/edit.html | 136 ++++++++++++++++++++
public/assets/js/backend/user/users.js | 74 +++++++++++
8 files changed, 548 insertions(+)
create mode 100644 application/admin/controller/user/Users.php
create mode 100644 application/admin/lang/zh-cn/user/users.php
create mode 100644 application/admin/model/Company.php
create mode 100644 application/admin/model/Users.php
create mode 100644 application/admin/validate/Users.php
create mode 100644 application/admin/view/user/users/add.html
create mode 100644 application/admin/view/user/users/edit.html
create mode 100644 public/assets/js/backend/user/users.js
diff --git a/application/admin/controller/user/Users.php b/application/admin/controller/user/Users.php
new file mode 100644
index 000000000..f2675a0fb
--- /dev/null
+++ b/application/admin/controller/user/Users.php
@@ -0,0 +1,71 @@
+model = new \app\admin\model\Users;
+
+ }
+
+
+
+ /**
+ * 默认生成的控制器所继承的父类中有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(['company'])
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+
+ foreach ($list as $row) {
+
+ $row->getRelation('company')->visible(['name']);
+ }
+
+ $result = array("total" => $list->total(), "rows" => $list->items());
+
+ return json($result);
+ }
+ return $this->view->fetch();
+ }
+
+}
diff --git a/application/admin/lang/zh-cn/user/users.php b/application/admin/lang/zh-cn/user/users.php
new file mode 100644
index 000000000..ad87876e3
--- /dev/null
+++ b/application/admin/lang/zh-cn/user/users.php
@@ -0,0 +1,27 @@
+ '用户id',
+ 'Open_id' => '微信openid(唯一标示)',
+ 'Nickname' => '微信昵称',
+ 'Avatarurl' => '微信头像',
+ 'Gender' => '性别',
+ 'Country' => '国家',
+ 'Province' => '省份',
+ 'City' => '城市',
+ 'Address_id' => '默认收货地址',
+ 'Balance' => '用户可用余额',
+ 'Powers' => '用户可用电力数',
+ 'Points' => '用户可用积分',
+ 'Pay_money' => '用户总支付的金额',
+ 'Expend_money' => '实际消费的金额(不含退款)',
+ 'Grade_id' => '会员等级id',
+ 'Is_dealer' => '是否代理',
+ 'Is_shopkeeper' => '是否店主',
+ 'Is_delete' => '是否删除',
+ 'Company_id' => '所属企业Id',
+ 'Create_time' => '创建时间',
+ 'Update_time' => '更新时间',
+ 'Status' => '用户状态',
+ 'Company.name' => '企业名称'
+];
diff --git a/application/admin/model/Company.php b/application/admin/model/Company.php
new file mode 100644
index 000000000..de55d4433
--- /dev/null
+++ b/application/admin/model/Company.php
@@ -0,0 +1,12 @@
+belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
+ }
+}
diff --git a/application/admin/validate/Users.php b/application/admin/validate/Users.php
new file mode 100644
index 000000000..c79284298
--- /dev/null
+++ b/application/admin/validate/Users.php
@@ -0,0 +1,27 @@
+ [],
+ 'edit' => [],
+ ];
+
+}
diff --git a/application/admin/view/user/users/add.html b/application/admin/view/user/users/add.html
new file mode 100644
index 000000000..45fa4f0cd
--- /dev/null
+++ b/application/admin/view/user/users/add.html
@@ -0,0 +1,136 @@
+
diff --git a/application/admin/view/user/users/edit.html b/application/admin/view/user/users/edit.html
new file mode 100644
index 000000000..ad6dabab1
--- /dev/null
+++ b/application/admin/view/user/users/edit.html
@@ -0,0 +1,136 @@
+
diff --git a/public/assets/js/backend/user/users.js b/public/assets/js/backend/user/users.js
new file mode 100644
index 000000000..110d37ea8
--- /dev/null
+++ b/public/assets/js/backend/user/users.js
@@ -0,0 +1,74 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+ var Controller = {
+ index: function () {
+ // 初始化表格参数配置
+ Table.api.init({
+ extend: {
+ index_url: 'user/users/index' + location.search,
+ add_url: 'user/users/add',
+ edit_url: 'user/users/edit',
+ del_url: 'user/users/del',
+ multi_url: 'user/users/multi',
+ import_url: 'user/users/import',
+ table: 'users',
+ }
+ });
+
+ var table = $("#table");
+
+ // 初始化表格
+ table.bootstrapTable({
+ url: $.fn.bootstrapTable.defaults.extend.index_url,
+ pk: 'id',
+ sortName: 'id',
+ fixedColumns: true,
+ fixedRightNumber: 1,
+ columns: [
+ [
+ {checkbox: true},
+ {field: 'id', title: __('Id')},
+ {field: 'open_id', title: __('Open_id'), operate: 'LIKE'},
+ {field: 'nickName', title: __('Nickname'), operate: 'LIKE'},
+ {field: 'avatarUrl', title: __('Avatarurl'), operate: 'LIKE', formatter: Table.api.formatter.url},
+ {field: 'gender', title: __('Gender')},
+ {field: 'country', title: __('Country'), operate: 'LIKE'},
+ {field: 'province', title: __('Province'), operate: 'LIKE'},
+ {field: 'city', title: __('City'), operate: 'LIKE'},
+ {field: 'address_id', title: __('Address_id')},
+ {field: 'balance', title: __('Balance'), operate:'BETWEEN'},
+ {field: 'powers', title: __('Powers')},
+ {field: 'points', title: __('Points')},
+ {field: 'pay_money', title: __('Pay_money'), operate:'BETWEEN'},
+ {field: 'expend_money', title: __('Expend_money'), operate:'BETWEEN'},
+ {field: 'grade_id', title: __('Grade_id')},
+ {field: 'is_dealer', title: __('Is_dealer')},
+ {field: 'is_shopkeeper', title: __('Is_shopkeeper')},
+ {field: 'is_delete', title: __('Is_delete')},
+ {field: 'company_id', title: __('Company_id')},
+ {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'status', title: __('Status')},
+ {field: 'company.name', title: __('Company.name')},
+ {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+ ]
+ ]
+ });
+
+ // 为表格绑定事件
+ Table.api.bindevent(table);
+ },
+ add: function () {
+ Controller.api.bindevent();
+ },
+ edit: function () {
+ Controller.api.bindevent();
+ },
+ api: {
+ bindevent: function () {
+ Form.api.bindevent($("form[role=form]"));
+ }
+ }
+ };
+ return Controller;
+});
--
Gitee
From d60bd90fa9307f976215f8da2b64f0f7f407fe8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 11:52:57 +0800
Subject: [PATCH 0009/1004] test users index used the traits backend
---
application/admin/controller/user/Users.php | 60 ++++++++++-----------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/application/admin/controller/user/Users.php b/application/admin/controller/user/Users.php
index f2675a0fb..19d1b0085 100644
--- a/application/admin/controller/user/Users.php
+++ b/application/admin/controller/user/Users.php
@@ -37,35 +37,35 @@ class Users extends Backend
/**
* 查看
*/
- 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(['company'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
-
- foreach ($list as $row) {
-
- $row->getRelation('company')->visible(['name']);
- }
-
- $result = array("total" => $list->total(), "rows" => $list->items());
-
- return json($result);
- }
- return $this->view->fetch();
- }
+// 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(['company'])
+// ->where($where)
+// ->order($sort, $order)
+// ->paginate($limit);
+//
+// foreach ($list as $row) {
+//
+// $row->getRelation('company')->visible(['name']);
+// }
+//
+// $result = array("total" => $list->total(), "rows" => $list->items());
+//
+// return json($result);
+// }
+// return $this->view->fetch();
+// }
}
--
Gitee
From 1031153598b7ad3f096e9ceb49d28d1bbebba48f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sun, 13 Feb 2022 21:30:29 +0800
Subject: [PATCH 0010/1004] users and dealer
---
application/api/controller/Users.php | 75 ++++++
application/api/model/Users.php | 232 ++++++++++++++++++
application/common.php | 93 +++++++
application/common/controller/Api.php | 22 ++
.../common/exception/BaseException.php | 33 +++
application/common/model/BaseModel.php | 143 +++++++++++
application/common/model/Users.php | 158 ++++++++++++
7 files changed, 756 insertions(+)
create mode 100644 application/api/controller/Users.php
create mode 100644 application/api/model/Users.php
create mode 100644 application/common/exception/BaseException.php
create mode 100644 application/common/model/BaseModel.php
create mode 100644 application/common/model/Users.php
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
new file mode 100644
index 000000000..6ca8c2db7
--- /dev/null
+++ b/application/api/controller/Users.php
@@ -0,0 +1,75 @@
+renderSuccess([
+ 'user_id' => $model->login($this->request->post()),
+ 'token' => $model->getToken()
+ ]);
+ }
+
+ /**
+ * 用户cloud云登录
+ * @return array
+ * @throws \app\common\exception\BaseException
+ * @throws \think\Exception
+ * @throws \think\exception\DbException
+ */
+ public function wxcloudlogin()
+ {
+ $model = new UserModel;
+ return $this->renderSuccess([
+ 'user_id' => $model->wxcloudlogin($this->request->post()),
+ 'token' => $model->getToken()
+ ]);
+ }
+
+ /**
+ * h5登录用于测试
+ * @return array
+ * @throws \app\common\exception\BaseException
+ * @throws \think\Exception
+ * @throws \think\exception\DbException
+ */
+ public function login2h5()
+ {
+ $model = new UserModel;
+ return $this->renderSuccess([
+ 'user_id' => $model->login2h5($this->request->post()),
+ 'token' => $model->getToken()
+ ]);
+ }
+ /**
+ * 当前用户详情
+ * @return array
+ * @throws \app\common\exception\BaseException
+ * @throws \think\exception\DbException
+ */
+ public function detail()
+ {
+ // 当前用户信息
+ $userInfo = $this->getUser();
+ return $this->renderSuccess(compact('userInfo'));
+ }
+
+}
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
new file mode 100644
index 000000000..cb458b7c6
--- /dev/null
+++ b/application/api/model/Users.php
@@ -0,0 +1,232 @@
+ $openId], ['address', 'addressDefault', 'grade']);
+ }
+
+ /**
+ * 用户登录
+ * @param array $post
+ * @return string
+ * @throws BaseException
+ * @throws \think\Exception
+ * @throws \think\exception\DbException
+ */
+ public function login($post)
+ {
+ // 微信登录 获取session_key
+ $session = $this->wxlogin($post['code']);
+ // 自动注册用户
+// $refereeId = isset($post['referee_id']) ? $post['referee_id'] : null;
+ // 用户注册时候不绑定referee关系
+ $refereeId = null;
+ $userInfo = json_decode(htmlspecialchars_decode($post['user_info']), true);
+ $user_id = $this->register($session['openid'], $userInfo, $refereeId);
+ // 生成token (session3rd)
+ $this->token = $this->token($session['openid']);
+ // 记录缓存, 7天
+ Cache::set($this->token, $session, 86400 * 7);
+ return $user_id;
+ }
+
+ /**
+ * 用户cloud登录
+ * @param array $post
+ * @return string
+ * @throws BaseException
+ * @throws \think\Exception
+ * @throws \think\exception\DbException
+ */
+ public function wxcloudlogin($post)
+ {
+ // 微信登录 获取session_key
+ $session = $this->wxlogin($post['code']);
+ // 自动注册用户
+// $refereeId = isset($post['referee_id']) ? $post['referee_id'] : null;
+ // 用户注册时候不绑定referee关系
+ $refereeId = null;
+ $userInfo = json_decode(htmlspecialchars_decode($post['user_info']), true);
+ $user_id = $this->register($session['openid'], $userInfo, $refereeId);
+ // 生成token (session3rd)
+ $this->token = $this->token($session['openid']);
+ // 记录缓存, 7天
+ Cache::set($this->token, $session, 86400 * 7);
+ return $user_id;
+ }
+
+ /**
+ * 获取token
+ * @return mixed
+ */
+ public function getToken()
+ {
+ return $this->token;
+ }
+
+ /**
+ * 微信登录
+ * @param $code
+ * @return array|mixed
+ * @throws BaseException
+ * @throws \think\exception\DbException
+ */
+ private function wxlogin($code)
+ {
+ // 获取当前小程序信息
+ $wxConfig = Wxapp::getWxappCache();
+ // 验证appid和appsecret是否填写
+ if (empty($wxConfig['app_id']) || empty($wxConfig['app_secret'])) {
+ throw new BaseException(['msg' => '请到 [后台-小程序设置] 填写appid 和 appsecret']);
+ }
+ // 微信登录 (获取session_key)
+ $WxUser = new WxUser($wxConfig['app_id'], $wxConfig['app_secret']);
+ if (!$session = $WxUser->sessionKey($code)) {
+ throw new BaseException(['msg' => $WxUser->getError()]);
+ }
+ return $session;
+ }
+
+ /**
+ * 生成用户认证的token
+ * @param $openid
+ * @return string
+ */
+ private function token($openid)
+ {
+ $wxapp_id = self::$wxapp_id;
+ // 生成一个不会重复的随机字符串
+ $guid = \getGuidV4();
+ // 当前时间戳 (精确到毫秒)
+ $timeStamp = microtime(true);
+ // 自定义一个盐
+ $salt = 'token_salt';
+ return md5("{$wxapp_id}_{$timeStamp}_{$openid}_{$guid}_{$salt}");
+ }
+
+ /**
+ * 自动注册用户
+ * @param $open_id
+ * @param $data
+ * @param int $refereeId
+ * @return mixed
+ * @throws \Exception
+ * @throws \think\exception\DbException
+ */
+ private function register($open_id, $data, $refereeId = null)
+ {
+ // 查询用户是否已存在
+ $user = self::detail(['open_id' => $open_id]);
+ $model = $user ?: $this;
+ $this->startTrans();
+ try {
+ // 保存/更新用户记录
+ if (!$model->allowField(true)->save(array_merge($data, [
+ 'open_id' => $open_id,
+ 'wxapp_id' => self::$wxapp_id
+ ]))) {
+ throw new BaseException(['msg' => '用户注册失败']);
+ }
+ // 记录推荐人关系
+ if (!$user && $refereeId > 0) {
+ RefereeModel::createRelation($model['user_id'], $refereeId);
+ }
+ $this->commit();
+ } catch (\Exception $e) {
+ $this->rollback();
+ throw new BaseException(['msg' => $e->getMessage()]);
+ }
+ return $model['user_id'];
+ }
+
+ /**
+ * 个人中心菜单列表
+ * @return array
+ */
+ public function getMenus()
+ {
+ $menus = [
+ 'coupon' => [
+ 'name' => '会员中心',
+ 'url' => 'pages/coupon/coupon',
+ 'icon' => 'vip'
+ ],
+ 'my_coupon' => [
+ 'name' => '优惠券',
+ 'url' => 'pages/user/coupon/coupon',
+ 'icon' => 'coupon'
+ ],
+ 'dealer' => [
+ 'name' => '分销中心',
+ 'url' => 'pages/dealer/index/index',
+ 'icon' => 'branch-one'
+ ],
+ 'address' => [
+ 'name' => '收货地址',
+ 'url' => 'pages/address/index',
+ 'icon' => 'local'
+ ],
+// 'sharing_order' => [
+// 'name' => '拼团订单',
+// 'url' => 'pages/sharing/order/index',
+// 'icon' => 'pintuan'
+// ],
+// 'my_bargain' => [
+// 'name' => '我的砍价',
+// 'url' => 'pages/bargain/index/index?tab=1',
+// 'icon' => 'kanjia'
+// ],
+// 'help' => [
+// 'name' => '我的帮助',
+// 'url' => 'pages/user/help/index',
+// 'icon' => 'help'
+// ],
+ ];
+ // 判断分销功能是否开启
+ if (DealerSettingModel::isOpen()) {
+ $menus['dealer']['name'] = DealerSettingModel::getDealerTitle();
+ } else {
+ unset($menus['dealer']);
+ }
+ return $menus;
+ }
+
+}
diff --git a/application/common.php b/application/common.php
index a014f80bb..ec68e6d03 100755
--- a/application/common.php
+++ b/application/common.php
@@ -512,3 +512,96 @@ EOT;
return $icon;
}
}
+
+/**
+ * 获取全局唯一标识符
+ * @param bool $trim
+ * @return string
+ */
+if (!function_exists('getGuidV4')) {
+ function getGuidV4($trim = true)
+ {
+ // Windows
+ if (function_exists('com_create_guid') === true) {
+ $charid = com_create_guid();
+ return $trim == true ? trim($charid, '{}') : $charid;
+ }
+ // OSX/Linux
+ if (function_exists('openssl_random_pseudo_bytes') === true) {
+ $data = openssl_random_pseudo_bytes(16);
+ $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
+ $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
+ return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
+ }
+ // Fallback (PHP 4.2+)
+ mt_srand((double)microtime() * 10000);
+ $charid = strtolower(md5(uniqid(rand(), true)));
+ $hyphen = chr(45); // "-"
+ $lbrace = $trim ? "" : chr(123); // "{"
+ $rbrace = $trim ? "" : chr(125); // "}"
+ $guidv4 = $lbrace .
+ substr($charid, 0, 8) . $hyphen .
+ substr($charid, 8, 4) . $hyphen .
+ substr($charid, 12, 4) . $hyphen .
+ substr($charid, 16, 4) . $hyphen .
+ substr($charid, 20, 12) .
+ $rbrace;
+ return $guidv4;
+ }
+}
+
+/**
+ * 时间戳转换日期
+ * @param $timeStamp
+ * @return false|string
+ */
+if (!function_exists('format_time')) {
+ function format_time($timeStamp)
+ {
+ return date('Y-m-d H:i:s', $timeStamp);
+ }
+}
+
+/**
+ * 左侧填充0
+ * @param $value
+ * @param int $padLength
+ * @return string
+ */
+if (!function_exists('pad_left')) {
+ function pad_left($value, $padLength = 2)
+ {
+ return \str_pad($value, $padLength, "0", STR_PAD_LEFT);
+ }
+}
+
+/**
+ * 过滤emoji表情
+ * @param $text
+ * @return null|string|string[]
+ */
+if (!function_exists('filter_emoji')) {
+ function filter_emoji($text)
+ {
+ // 此处的preg_replace用于过滤emoji表情
+ // 如需支持emoji表情, 需将mysql的编码改为utf8mb4
+ return preg_replace('/[\xf0-\xf7].{3}/', '', $text);
+ }
+}
+
+/**
+ * 获取当前域名及根路径
+ * @return string
+ */
+if (!function_exists('base_url')) {
+ function base_url()
+ {
+ static $baseUrl = '';
+ if (empty($baseUrl)) {
+ $request = Request::instance();
+ $subDir = str_replace('\\', '/', dirname($request->server('PHP_SELF')));
+ $baseUrl = $request->scheme() . '://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/');
+ }
+ return $baseUrl;
+ }
+}
\ No newline at end of file
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index 87e9c6f74..82d9f3aea 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -2,6 +2,8 @@
namespace app\common\controller;
+use app\api\model\User as UserModel;
+use app\common\exception\BaseException;
use app\common\library\Auth;
use think\Config;
use think\exception\HttpResponseException;
@@ -324,4 +326,24 @@ class Api
//刷新Token
$this->request->token();
}
+
+ /**
+ * 获取当前用户信息
+ * @param bool $is_force
+ * @return UserModel|bool|null
+ * @throws BaseException
+ * @throws \think\exception\DbException
+ */
+ protected function getUser($is_force = true)
+ {
+ if (!$token = $this->request->param('token')) {
+ $is_force && $this->throwError('缺少必要的参数:token', -1);
+ return false;
+ }
+ if (!$user = UserModel::getUser($token)) {
+ $is_force && $this->throwError('没有找到用户信息', -1);
+ return false;
+ }
+ return $user;
+ }
}
diff --git a/application/common/exception/BaseException.php b/application/common/exception/BaseException.php
new file mode 100644
index 000000000..2cb378eb3
--- /dev/null
+++ b/application/common/exception/BaseException.php
@@ -0,0 +1,33 @@
+code = $params['code'];
+ }
+ if (array_key_exists('msg', $params)) {
+ $this->message = $params['msg'];
+ }
+ }
+}
+
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
new file mode 100644
index 000000000..942b94a58
--- /dev/null
+++ b/application/common/model/BaseModel.php
@@ -0,0 +1,143 @@
+param('wxapp_id');
+ }
+
+ /**
+ * 定义全局的查询范围
+ * @param \think\db\Query $query
+ */
+ protected function base($query)
+ {
+ if (self::$wxapp_id > 0) {
+ $query->where($query->getTable() . '.wxapp_id', self::$wxapp_id);
+ }
+ }
+
+ /**
+ * 设置默认的检索数据
+ * @param $query
+ * @param array $default
+ * @return array
+ */
+ protected function setQueryDefaultValue(&$query, $default = [])
+ {
+ $data = array_merge($default, $query);
+ foreach ($query as $key => $val) {
+ if (empty($val) && isset($default[$key])) {
+ $data[$key] = $default[$key];
+ }
+ }
+ return $data;
+ }
+
+ /**
+ * 设置基础查询条件(用于简化基础alias和field)
+ * @test 2019-4-25
+ * @param string $alias
+ * @param array $join
+ * @return BaseModel
+ */
+ public function setBaseQuery($alias = '', $join = [])
+ {
+ // 设置别名
+ $aliasValue = $alias ?: $this->alias;
+ $model = $this->alias($aliasValue)->field("{$aliasValue}.*");
+ // join条件
+ if (!empty($join)) : foreach ($join as $item):
+ $model->join($item[0], "{$item[0]}.{$item[1]}={$aliasValue}."
+ . (isset($item[2]) ? $item[2] : $item[1]));
+ endforeach; endif;
+ return $model;
+ }
+
+ /**
+ * 批量更新数据(支持带where条件)
+ * @param array $data [0 => ['data'=>[], 'where'=>[]]]
+ * @return \think\Collection
+ */
+ public function updateAll($data)
+ {
+ return $this->transaction(function () use ($data) {
+ $result = [];
+ foreach ($data as $key => $item) {
+ $result[$key] = self::update($item['data'], $item['where']);
+ }
+ return $this->toCollection($result);
+ });
+ }
+
+}
diff --git a/application/common/model/Users.php b/application/common/model/Users.php
new file mode 100644
index 000000000..8b3b9f1c7
--- /dev/null
+++ b/application/common/model/Users.php
@@ -0,0 +1,158 @@
+belongsTo("app\\{$module}\\model\\user\\Grade");
+ }
+
+ /**
+ * 关联收货地址表
+ * @return \think\model\relation\HasMany
+ */
+ public function address()
+ {
+ return $this->hasMany('UserAddress');
+ }
+
+ /**
+ * 关联收货地址表 (默认地址)
+ * @return \think\model\relation\BelongsTo
+ */
+ public function addressDefault()
+ {
+ return $this->belongsTo('UserAddress', 'address_id');
+ }
+
+ /**
+ * 显示性别
+ * @param $value
+ * @return mixed
+ */
+ public function getGenderAttr($value)
+ {
+ return $this->gender[$value];
+ }
+
+ /**
+ * 获取用户信息
+ * @param $where
+ * @param $with
+ * @return null|static
+ * @throws \think\exception\DbException
+ */
+ public static function detail($where, $with = ['address', 'addressDefault'])
+ {
+ $filter = ['is_delete' => 0];
+ if (is_array($where)) {
+ $filter = array_merge($filter, $where);
+ } else {
+ $filter['user_id'] = (int)$where;
+ }
+ return static::get($filter, $with);
+ }
+
+ /**
+ * 累积用户的实际消费金额
+ * @param $userId
+ * @param $expendMoney
+ * @return int|true
+ * @throws \think\Exception
+ */
+ public function setIncUserExpend($userId, $expendMoney)
+ {
+ return $this->where(['user_id' => $userId])->setInc('expend_money', $expendMoney);
+ }
+
+ /**
+ * 指定会员等级下是否存在用户
+ * @param $gradeId
+ * @return bool
+ */
+ public static function checkExistByGradeId($gradeId)
+ {
+ $model = new static;
+ return !!$model->where('grade_id', '=', (int)$gradeId)
+ ->where('is_delete', '=', 0)
+ ->value('user_id');
+ }
+
+ /**
+ * 累积用户总消费金额
+ * @param $money
+ * @return int|true
+ * @throws \think\Exception
+ */
+ public function setIncPayMoney($money)
+ {
+ return $this->setInc('pay_money', $money);
+ }
+
+ /**
+ * 累积用户实际消费的金额 (批量)
+ * @param $data
+ * @return array|false
+ * @throws \Exception
+ */
+ public function onBatchIncExpendMoney($data)
+ {
+ foreach ($data as $userId => $expendMoney) {
+ $this->where(['user_id' => $userId])->setInc('expend_money', $expendMoney);
+ }
+ return true;
+ }
+
+ /**
+ * 累积用户的可用积分数量 (批量)
+ * @param $data
+ * @return array|false
+ * @throws \Exception
+ */
+ public function onBatchIncPoints($data)
+ {
+ foreach ($data as $userId => $expendMoney) {
+ $this->where(['user_id' => $userId])->setInc('points', $expendMoney);
+ }
+ return true;
+ }
+
+ /**
+ * 累积用户的可用积分
+ * @param $points
+ * @param $describe
+ * @return int|true
+ * @throws \think\Exception
+ */
+ public function setIncPoints($points, $describe)
+ {
+ // 新增积分变动明细
+ PointsLogModel::add([
+ 'user_id' => $this['user_id'],
+ 'value' => $points,
+ 'describe' => $describe,
+ ]);
+ // 更新用户可用积分
+ return $this->setInc('points', $points);
+ }
+
+}
--
Gitee
From b9cf344064e1d0b604ec48b0baa06305b57cafaa Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:04:07 +0800
Subject: [PATCH 0011/1004] client user login implement
---
application/api/model/Users.php | 102 +++++-------------------
application/common/controller/Api.php | 52 ++++++++++++
application/common/library/RedisKey.php | 35 ++++++++
application/common/model/BaseModel.php | 2 +-
application/common/model/Company.php | 75 +++++++++++++++++
application/common/model/Users.php | 4 +-
application/common/model/Wxapp.php | 76 ++++++++++++++++++
7 files changed, 261 insertions(+), 85 deletions(-)
create mode 100644 application/common/library/RedisKey.php
create mode 100644 application/common/model/Company.php
create mode 100644 application/common/model/Wxapp.php
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index cb458b7c6..bf3981aed 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -2,12 +2,11 @@
namespace app\api\model;
-use think\Cache;
-use app\common\library\wechat\WxUser;
use app\common\exception\BaseException;
+use app\common\library\RedisKey;
use app\common\model\Users as UserModel;
-use app\api\model\dealer\Referee as RefereeModel;
-use app\api\model\dealer\Setting as DealerSettingModel;
+use app\common\model\Company as CompanyModel;
+use app\common\model\Wxapp as WxappModel;
/**
* 用户模型类
@@ -37,35 +36,11 @@ class Users extends UserModel
*/
public static function getUser($token)
{
- $cache = Cache::get($token);
- $openId = "";
- if($cache) $openId = Cache::get($token)['openid'];
- return self::detail(['open_id' => $openId], ['address', 'addressDefault', 'grade']);
- }
-
- /**
- * 用户登录
- * @param array $post
- * @return string
- * @throws BaseException
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function login($post)
- {
- // 微信登录 获取session_key
- $session = $this->wxlogin($post['code']);
- // 自动注册用户
-// $refereeId = isset($post['referee_id']) ? $post['referee_id'] : null;
- // 用户注册时候不绑定referee关系
- $refereeId = null;
- $userInfo = json_decode(htmlspecialchars_decode($post['user_info']), true);
- $user_id = $this->register($session['openid'], $userInfo, $refereeId);
- // 生成token (session3rd)
- $this->token = $this->token($session['openid']);
- // 记录缓存, 7天
- Cache::set($this->token, $session, 86400 * 7);
- return $user_id;
+ $user_id = Cache::get($token);
+// $openId = "";
+// if($cache) $openId = Cache::get($token)['openid'];
+// return self::detail(['open_id' => $openId], ['address', 'addressDefault', 'grade']);
+ return self::detail($user_id);
}
/**
@@ -76,20 +51,13 @@ class Users extends UserModel
* @throws \think\Exception
* @throws \think\exception\DbException
*/
- public function wxcloudlogin($post)
+ public function login($post)
{
- // 微信登录 获取session_key
- $session = $this->wxlogin($post['code']);
- // 自动注册用户
-// $refereeId = isset($post['referee_id']) ? $post['referee_id'] : null;
- // 用户注册时候不绑定referee关系
- $refereeId = null;
- $userInfo = json_decode(htmlspecialchars_decode($post['user_info']), true);
- $user_id = $this->register($session['openid'], $userInfo, $refereeId);
+ $user_id = $this->register($post);
// 生成token (session3rd)
- $this->token = $this->token($session['openid']);
+ $this->token = $this->token($post['open_id']);
// 记录缓存, 7天
- Cache::set($this->token, $session, 86400 * 7);
+ Cache::set($this->token, $user_id, 86400 * 7);
return $user_id;
}
@@ -102,29 +70,6 @@ class Users extends UserModel
return $this->token;
}
- /**
- * 微信登录
- * @param $code
- * @return array|mixed
- * @throws BaseException
- * @throws \think\exception\DbException
- */
- private function wxlogin($code)
- {
- // 获取当前小程序信息
- $wxConfig = Wxapp::getWxappCache();
- // 验证appid和appsecret是否填写
- if (empty($wxConfig['app_id']) || empty($wxConfig['app_secret'])) {
- throw new BaseException(['msg' => '请到 [后台-小程序设置] 填写appid 和 appsecret']);
- }
- // 微信登录 (获取session_key)
- $WxUser = new WxUser($wxConfig['app_id'], $wxConfig['app_secret']);
- if (!$session = $WxUser->sessionKey($code)) {
- throw new BaseException(['msg' => $WxUser->getError()]);
- }
- return $session;
- }
-
/**
* 生成用户认证的token
* @param $openid
@@ -138,43 +83,36 @@ class Users extends UserModel
// 当前时间戳 (精确到毫秒)
$timeStamp = microtime(true);
// 自定义一个盐
- $salt = 'token_salt';
+ $salt = RedisKey::PROJECT_NAME_PREFIX;
return md5("{$wxapp_id}_{$timeStamp}_{$openid}_{$guid}_{$salt}");
}
/**
* 自动注册用户
- * @param $open_id
* @param $data
- * @param int $refereeId
- * @return mixed
* @throws \Exception
* @throws \think\exception\DbException
*/
- private function register($open_id, $data, $refereeId = null)
+ private function register($data)
{
// 查询用户是否已存在
- $user = self::detail(['open_id' => $open_id]);
+ $user = self::detail(['open_id' => $data['open_id']]);
$model = $user ?: $this;
$this->startTrans();
try {
+ $wxapp_id = WxappModel::getMappingWxappId(['app_id'=>$data['app_id']]);
+ $wxapp_arr = WxappModel::getWxappCache($wxapp_id);
// 保存/更新用户记录
+ unset($data['app_id']);
if (!$model->allowField(true)->save(array_merge($data, [
- 'open_id' => $open_id,
- 'wxapp_id' => self::$wxapp_id
+ 'company_id' => $wxapp_arr['company_id']
]))) {
throw new BaseException(['msg' => '用户注册失败']);
}
- // 记录推荐人关系
- if (!$user && $refereeId > 0) {
- RefereeModel::createRelation($model['user_id'], $refereeId);
- }
- $this->commit();
} catch (\Exception $e) {
- $this->rollback();
throw new BaseException(['msg' => $e->getMessage()]);
}
- return $model['user_id'];
+ return $model['id'];
}
/**
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index 82d9f3aea..2700a2055 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -22,6 +22,13 @@ use think\Validate;
class Api
{
+ const JSON_SUCCESS_STATUS = 1;
+
+ const JSON_ERROR_STATUS = 0;
+
+ /* @ver $client_id 商户client id */
+ protected $client_id;
+
/**
* @var Request Request 实例
*/
@@ -346,4 +353,49 @@ class Api
}
return $user;
}
+
+ /**
+ * 输出错误信息
+ * @param int $code
+ * @param $msg
+ * @throws BaseException
+ */
+ protected function throwError($msg, $code = 0)
+ {
+ throw new BaseException(['code' => $code, 'msg' => $msg]);
+ }
+
+ /**
+ * 返回封装后的 API 数据到客户端
+ * @param int $code
+ * @param string $msg
+ * @param array $data
+ * @return array
+ */
+ protected function renderJson($code = self::JSON_SUCCESS_STATUS, $msg = '', $data = [])
+ {
+ return compact('code', 'msg', 'data');
+ }
+
+ /**
+ * 返回操作成功json
+ * @param array $data
+ * @param string|array $msg
+ * @return array
+ */
+ protected function renderSuccess($data = [], $msg = 'success')
+ {
+ return $this->renderJson(self::JSON_SUCCESS_STATUS, $msg, $data);
+ }
+
+ /**
+ * 返回操作失败json
+ * @param string $msg
+ * @param array $data
+ * @return array
+ */
+ protected function renderError($msg = 'error', $data = [])
+ {
+ return $this->renderJson(self::JSON_ERROR_STATUS, $msg, $data);
+ }
}
diff --git a/application/common/library/RedisKey.php b/application/common/library/RedisKey.php
new file mode 100644
index 000000000..34afa36ac
--- /dev/null
+++ b/application/common/library/RedisKey.php
@@ -0,0 +1,35 @@
+param('wxapp_id');
+ self::$wxapp_id = Wxapp::getMappingWxappId(['app_id' => $request->param('app_id')]);
}
/**
diff --git a/application/common/model/Company.php b/application/common/model/Company.php
new file mode 100644
index 000000000..3aacec65a
--- /dev/null
+++ b/application/common/model/Company.php
@@ -0,0 +1,75 @@
+ 'id不可为空']);
+ }
+ if (!$data = Redis::hGet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id)) {
+ $data = self::detail($company_id);
+ if (empty($data)) throw new BaseException(['msg' => '未找到当前企业信息']);
+ Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
+ }
+ return $data;
+ }
+
+ /**
+ * 根据企业表其他字段获取企业Id
+ * @param array
+ * @return mixed|null|static
+ * @throws BaseException
+ * @throws \think\exception\DbException
+ */
+ public static function getMappingCompanyId($where = [])
+ {
+ if (empty($where)) {
+ throw new BaseException(['msg' => '企业Id Mapping条件为空']);
+ }
+ if (count($where) > 0) {
+ throw new BaseException(['msg' => '企业Id Mapping条件超限']);
+ }
+ $mapping_key = array_values($where)[0];
+ if (!$company_id = Redis::hGet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key)) {
+ $data = self::get($where);
+ if (empty($data)) throw new BaseException(['msg' => '未找到企业信息']);
+ $company_id = $data['id'];
+ Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
+ Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key, $company_id);
+ }
+ return $company_id;
+ }
+
+}
diff --git a/application/common/model/Users.php b/application/common/model/Users.php
index 8b3b9f1c7..cc6b1fea2 100644
--- a/application/common/model/Users.php
+++ b/application/common/model/Users.php
@@ -61,13 +61,13 @@ class Users extends BaseModel
* @return null|static
* @throws \think\exception\DbException
*/
- public static function detail($where, $with = ['address', 'addressDefault'])
+ public static function detail($where, $with = [])
{
$filter = ['is_delete' => 0];
if (is_array($where)) {
$filter = array_merge($filter, $where);
} else {
- $filter['user_id'] = (int)$where;
+ $filter['id'] = (int)$where;
}
return static::get($filter, $with);
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
new file mode 100644
index 000000000..9a5fd89f4
--- /dev/null
+++ b/application/common/model/Wxapp.php
@@ -0,0 +1,76 @@
+ 'id不可为空']);
+ }
+ if (!$data = Redis::hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
+ $data = self::detail($id);
+ if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
+ Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ }
+ return $data;
+ }
+ /**
+ * 根据小程序表其他字段获取小程序表Id
+ * @param array
+ * @return mixed|null|static
+ * @throws BaseException
+ * @throws \think\exception\DbException
+ */
+ public static function getMappingWxappId($where = [])
+ {
+ if (empty($where)) {
+ throw new BaseException(['msg' => '小程序Id Mapping条件为空']);
+ }
+ if (count($where) > 0) {
+ throw new BaseException(['msg' => '小程序Id Mapping条件超限']);
+ }
+ $mapping_key = array_values($where)[0];
+ if (!$id = Redis::hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
+ $data = self::get($where);
+ if (empty($data)) throw new BaseException(['msg' => '未找到企业信息']);
+ $id = $data['id'];
+ Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
+ }
+ return $id;
+ }
+
+
+}
--
Gitee
From c983008053589f575ff160dbfb676a24187d76f6 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:05:44 +0800
Subject: [PATCH 0012/1004] client user login implement
---
application/common/library/RedisKey.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/application/common/library/RedisKey.php b/application/common/library/RedisKey.php
index 34afa36ac..c16574f48 100644
--- a/application/common/library/RedisKey.php
+++ b/application/common/library/RedisKey.php
@@ -30,6 +30,4 @@ class RedisKey
const AIRPLUS_HASH_USERS_INFO = self::PROJECT_NAME_PREFIX . "hash_users_info";
- const AIRPLUS_HASH_USERS_INFO = self::PROJECT_NAME_PREFIX . "hash_users_info";
-
}
--
Gitee
From 41fa7428f9790bcfd275b2819242b2166bc65b7f Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:07:33 +0800
Subject: [PATCH 0013/1004] client user login implement
---
application/api/controller/Users.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 6ca8c2db7..9f6df68ce 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -12,6 +12,9 @@ use app\common\controller\Api;
*/
class Users extends Api
{
+ protected $noNeedLogin = ['login'];
+ protected $noNeedRight = '*';
+
/**
* 用户自动登录
* @return array
--
Gitee
From 32865e3525467597f43934c98443302adb6b22cc Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:08:36 +0800
Subject: [PATCH 0014/1004] client user login implement
---
application/common.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/common.php b/application/common.php
index ec68e6d03..636d37f52 100755
--- a/application/common.php
+++ b/application/common.php
@@ -5,6 +5,7 @@
use Symfony\Component\VarExporter\VarExporter;
use think\exception\HttpResponseException;
use think\Response;
+use think\Request;
if (!function_exists('__')) {
--
Gitee
From 8113438b9f9a59e8f14ea541920be776bb39fd63 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:11:43 +0800
Subject: [PATCH 0015/1004] client user login implement
---
application/common/model/Wxapp.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 9a5fd89f4..aaffc11f0 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -55,6 +55,7 @@ class Wxapp extends BaseModel
*/
public static function getMappingWxappId($where = [])
{
+ var_dump($where);
if (empty($where)) {
throw new BaseException(['msg' => '小程序Id Mapping条件为空']);
}
--
Gitee
From b2dd469625ace8bf9ab2754abef635fdc6bd9d10 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:14:50 +0800
Subject: [PATCH 0016/1004] client user login implement
---
application/common/model/Company.php | 2 +-
application/common/model/Wxapp.php | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/application/common/model/Company.php b/application/common/model/Company.php
index 3aacec65a..bef08a34b 100644
--- a/application/common/model/Company.php
+++ b/application/common/model/Company.php
@@ -58,7 +58,7 @@ class Company extends BaseModel
if (empty($where)) {
throw new BaseException(['msg' => '企业Id Mapping条件为空']);
}
- if (count($where) > 0) {
+ if (count($where) > 1) {
throw new BaseException(['msg' => '企业Id Mapping条件超限']);
}
$mapping_key = array_values($where)[0];
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index aaffc11f0..b48762c57 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -55,11 +55,10 @@ class Wxapp extends BaseModel
*/
public static function getMappingWxappId($where = [])
{
- var_dump($where);
if (empty($where)) {
throw new BaseException(['msg' => '小程序Id Mapping条件为空']);
}
- if (count($where) > 0) {
+ if (count($where) > 1) {
throw new BaseException(['msg' => '小程序Id Mapping条件超限']);
}
$mapping_key = array_values($where)[0];
--
Gitee
From d6099a948a08c8fd33c418c4789a4a77f934e783 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:16:20 +0800
Subject: [PATCH 0017/1004] client user login implement
---
application/common/model/Wxapp.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index b48762c57..5b64ed59f 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -4,8 +4,7 @@ namespace app\common\model;
use app\common\exception\BaseException;
use app\common\library\RedisKey;
-use think\Cache;
-use think\Db;
+use Redis;
/**
* 微信小程序模型
--
Gitee
From ea187becbd5717f7171f1638a853d3e36e548159 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:20:23 +0800
Subject: [PATCH 0018/1004] client user login implement
---
application/common/model/BaseModel.php | 4 ++++
application/common/model/Company.php | 10 +++++-----
application/common/model/Wxapp.php | 10 +++++-----
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 3de80de50..bd281f9e4 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -2,6 +2,7 @@
namespace app\common\model;
+use app\common\library\token\driver\Redis;
use think\Model;
use think\Request;
use think\Session;
@@ -13,6 +14,7 @@ use think\Session;
*/
class BaseModel extends Model
{
+ public static $redis;
public static $wxapp_id;
public static $base_url;
@@ -24,6 +26,8 @@ class BaseModel extends Model
public static function init()
{
parent::init();
+ // 初始化redis
+ self::$redis = new Redis();
// 获取当前域名
self::$base_url = base_url();
// 后期静态绑定wxapp_id
diff --git a/application/common/model/Company.php b/application/common/model/Company.php
index bef08a34b..f07d7c92b 100644
--- a/application/common/model/Company.php
+++ b/application/common/model/Company.php
@@ -38,10 +38,10 @@ class Company extends BaseModel
if (is_null($company_id)) {
throw new BaseException(['msg' => 'id不可为空']);
}
- if (!$data = Redis::hGet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id)) {
+ if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id)) {
$data = self::detail($company_id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前企业信息']);
- Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
}
return $data;
}
@@ -62,12 +62,12 @@ class Company extends BaseModel
throw new BaseException(['msg' => '企业Id Mapping条件超限']);
}
$mapping_key = array_values($where)[0];
- if (!$company_id = Redis::hGet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key)) {
+ if (!$company_id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key)) {
$data = self::get($where);
if (empty($data)) throw new BaseException(['msg' => '未找到企业信息']);
$company_id = $data['id'];
- Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
- Redis::hSet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key, $company_id);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_COMPANY_INFO, $company_id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_COMPANY_FIELD_MAPPING_COMPANY_ID, $mapping_key, $company_id);
}
return $company_id;
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 5b64ed59f..5eb57ac05 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -38,10 +38,10 @@ class Wxapp extends BaseModel
if (is_null($id)) {
throw new BaseException(['msg' => 'id不可为空']);
}
- if (!$data = Redis::hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
+ if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
}
return $data;
}
@@ -61,12 +61,12 @@ class Wxapp extends BaseModel
throw new BaseException(['msg' => '小程序Id Mapping条件超限']);
}
$mapping_key = array_values($where)[0];
- if (!$id = Redis::hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
+ if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::get($where);
if (empty($data)) throw new BaseException(['msg' => '未找到企业信息']);
$id = $data['id'];
- Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
- Redis::hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
}
return $id;
}
--
Gitee
From 60a4d558a4be813ce2a6ec1e405f83091e01f2aa Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:21:50 +0800
Subject: [PATCH 0019/1004] client user login implement
---
application/api/model/Users.php | 1 -
application/common/model/BaseModel.php | 2 +-
application/common/model/Company.php | 1 -
application/common/model/Wxapp.php | 1 -
4 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index bf3981aed..fe41d2169 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -5,7 +5,6 @@ namespace app\api\model;
use app\common\exception\BaseException;
use app\common\library\RedisKey;
use app\common\model\Users as UserModel;
-use app\common\model\Company as CompanyModel;
use app\common\model\Wxapp as WxappModel;
/**
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index bd281f9e4..05e411d51 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -2,10 +2,10 @@
namespace app\common\model;
-use app\common\library\token\driver\Redis;
use think\Model;
use think\Request;
use think\Session;
+use Redis;
/**
* 模型基类
diff --git a/application/common/model/Company.php b/application/common/model/Company.php
index f07d7c92b..924732705 100644
--- a/application/common/model/Company.php
+++ b/application/common/model/Company.php
@@ -4,7 +4,6 @@ namespace app\common\model;
use app\common\exception\BaseException;
use app\common\library\RedisKey;
-use Redis;
/**
* 企业模型
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 5eb57ac05..855131323 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -4,7 +4,6 @@ namespace app\common\model;
use app\common\exception\BaseException;
use app\common\library\RedisKey;
-use Redis;
/**
* 微信小程序模型
--
Gitee
From 708b925e1a7994bca7ab60f487a4a0647adf4c60 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:23:39 +0800
Subject: [PATCH 0020/1004] client user login implement
---
application/common/model/BaseModel.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 05e411d51..7ab165113 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -5,7 +5,7 @@ namespace app\common\model;
use think\Model;
use think\Request;
use think\Session;
-use Redis;
+use think\cache\driver\Redis;
/**
* 模型基类
--
Gitee
From 4fd101239d7e6c1af03322989838fe9b5b4ffc13 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:33:41 +0800
Subject: [PATCH 0021/1004] fix redis
---
application/common/model/BaseModel.php | 2 +-
composer.json | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 7ab165113..05e411d51 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -5,7 +5,7 @@ namespace app\common\model;
use think\Model;
use think\Request;
use think\Session;
-use think\cache\driver\Redis;
+use Redis;
/**
* 模型基类
diff --git a/composer.json b/composer.json
index bacfc9d4c..e2d968e7a 100755
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,8 @@
"ext-curl": "*",
"ext-pdo": "*",
"ext-bcmath": "*",
- "txthinking/mailer": "^2.0"
+ "txthinking/mailer": "^2.0",
+ "ext-redis": "*"
},
"config": {
"preferred-install": "dist"
--
Gitee
From 7ce064f699164d720fc4bea9fa7ea1cd9e349018 Mon Sep 17 00:00:00 2001
From: leo_xia <89232256@qq.com>
Date: Thu, 17 Feb 2022 14:34:49 +0800
Subject: [PATCH 0022/1004] fix redis
---
composer.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.json b/composer.json
index e2d968e7a..ee2e75639 100755
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,7 @@
"ext-pdo": "*",
"ext-bcmath": "*",
"txthinking/mailer": "^2.0",
- "ext-redis": "*"
+ "ext-redis": "^5.3"
},
"config": {
"preferred-install": "dist"
--
Gitee
From a397268f1ab21831a38d68d50d69f830ad88bd4b Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 14:42:52 +0800
Subject: [PATCH 0023/1004] fix redis
---
application/common/model/BaseModel.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 05e411d51..6f7c68299 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -28,6 +28,7 @@ class BaseModel extends Model
parent::init();
// 初始化redis
self::$redis = new Redis();
+ self::$redis -> pconnect("127.0.0.1");
// 获取当前域名
self::$base_url = base_url();
// 后期静态绑定wxapp_id
--
Gitee
From f5f0562572f96a67313444cd69495ee3bff5e116 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 16:51:39 +0800
Subject: [PATCH 0024/1004] fix redis
---
application/api/controller/Users.php | 35 +++++++++++-----------------
application/common/model/Wxapp.php | 2 +-
2 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 9f6df68ce..2e03b638d 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -4,6 +4,7 @@ namespace app\api\controller;
use app\api\model\Users as UserModel;
use app\common\controller\Api;
+use think\Exception;
/**
* 用户管理
@@ -25,26 +26,14 @@ class Users extends Api
public function login()
{
$model = new UserModel;
- return $this->renderSuccess([
- 'user_id' => $model->login($this->request->post()),
- 'token' => $model->getToken()
- ]);
- }
-
- /**
- * 用户cloud云登录
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function wxcloudlogin()
- {
- $model = new UserModel;
- return $this->renderSuccess([
- 'user_id' => $model->wxcloudlogin($this->request->post()),
- 'token' => $model->getToken()
- ]);
+ try {
+ return $this->renderSuccess([
+ 'user_id' => $model->login($this->request->post()),
+ 'token' => $model->getToken()
+ ]);
+ } catch (Exception $e) {
+ return $this->renderError($e->getMessage());
+ }
}
/**
@@ -71,7 +60,11 @@ class Users extends Api
public function detail()
{
// 当前用户信息
- $userInfo = $this->getUser();
+ try {
+ $userInfo = $this->getUser();
+ } catch (Exception $e) {
+ return $this->renderError($e->getMessage());
+ }
return $this->renderSuccess(compact('userInfo'));
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 855131323..76be623fe 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -62,7 +62,7 @@ class Wxapp extends BaseModel
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::get($where);
- if (empty($data)) throw new BaseException(['msg' => '未找到企业信息']);
+ if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
--
Gitee
From 2e9b21c22829db8e73bc1638595dcaeb9f707b4f Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 16:54:21 +0800
Subject: [PATCH 0025/1004] login implement
---
application/api/controller/Users.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 2e03b638d..1549028d0 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -4,6 +4,7 @@ namespace app\api\controller;
use app\api\model\Users as UserModel;
use app\common\controller\Api;
+use app\common\exception\BaseException;
use think\Exception;
/**
@@ -31,7 +32,7 @@ class Users extends Api
'user_id' => $model->login($this->request->post()),
'token' => $model->getToken()
]);
- } catch (Exception $e) {
+ } catch (BaseException $e) {
return $this->renderError($e->getMessage());
}
}
@@ -62,7 +63,7 @@ class Users extends Api
// 当前用户信息
try {
$userInfo = $this->getUser();
- } catch (Exception $e) {
+ } catch (BaseException $e) {
return $this->renderError($e->getMessage());
}
return $this->renderSuccess(compact('userInfo'));
--
Gitee
From 7c8be2309bf98a5f35156473e4a8ed0310d7ffd6 Mon Sep 17 00:00:00 2001
From: Leo
Date: Thu, 17 Feb 2022 17:05:50 +0800
Subject: [PATCH 0026/1004] login implement
---
application/api/controller/Users.php | 7 +------
application/api/model/Users.php | 1 -
2 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 1549028d0..30849e751 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -4,7 +4,6 @@ namespace app\api\controller;
use app\api\model\Users as UserModel;
use app\common\controller\Api;
-use app\common\exception\BaseException;
use think\Exception;
/**
@@ -20,9 +19,7 @@ class Users extends Api
/**
* 用户自动登录
* @return array
- * @throws \app\common\exception\BaseException
* @throws \think\Exception
- * @throws \think\exception\DbException
*/
public function login()
{
@@ -32,7 +29,7 @@ class Users extends Api
'user_id' => $model->login($this->request->post()),
'token' => $model->getToken()
]);
- } catch (BaseException $e) {
+ } catch (Exception $e) {
return $this->renderError($e->getMessage());
}
}
@@ -40,9 +37,7 @@ class Users extends Api
/**
* h5登录用于测试
* @return array
- * @throws \app\common\exception\BaseException
* @throws \think\Exception
- * @throws \think\exception\DbException
*/
public function login2h5()
{
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index fe41d2169..4a65d644e 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -97,7 +97,6 @@ class Users extends UserModel
// 查询用户是否已存在
$user = self::detail(['open_id' => $data['open_id']]);
$model = $user ?: $this;
- $this->startTrans();
try {
$wxapp_id = WxappModel::getMappingWxappId(['app_id'=>$data['app_id']]);
$wxapp_arr = WxappModel::getWxappCache($wxapp_id);
--
Gitee
From 743b167dc1cbde6a11c15c596d80aef2df25eec6 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 09:04:19 +0800
Subject: [PATCH 0027/1004] rmv admin company model
---
application/admin/model/Company.php | 12 ------------
1 file changed, 12 deletions(-)
delete mode 100644 application/admin/model/Company.php
diff --git a/application/admin/model/Company.php b/application/admin/model/Company.php
deleted file mode 100644
index de55d4433..000000000
--- a/application/admin/model/Company.php
+++ /dev/null
@@ -1,12 +0,0 @@
-
Date: Fri, 18 Feb 2022 09:24:35 +0800
Subject: [PATCH 0028/1004] generate company & wxapp mvc
---
application/admin/controller/auth/Company.php | 37 ++++++++
.../admin/controller/miniprogram/Wxapp.php | 71 ++++++++++++++
application/admin/lang/zh-cn/auth/company.php | 16 ++++
.../admin/lang/zh-cn/miniprogram/wxapp.php | 20 ++++
application/admin/model/Company.php | 40 ++++++++
application/admin/model/Wxapp.php | 65 +++++++++++++
application/admin/validate/Company.php | 27 ++++++
application/admin/validate/Wxapp.php | 27 ++++++
application/admin/view/auth/company/add.html | 72 ++++++++++++++
application/admin/view/auth/company/edit.html | 72 ++++++++++++++
.../admin/view/miniprogram/wxapp/add.html | 94 +++++++++++++++++++
.../admin/view/miniprogram/wxapp/edit.html | 94 +++++++++++++++++++
public/assets/js/backend/auth/company.js | 63 +++++++++++++
public/assets/js/backend/miniprogram/wxapp.js | 65 +++++++++++++
14 files changed, 763 insertions(+)
create mode 100644 application/admin/controller/auth/Company.php
create mode 100644 application/admin/controller/miniprogram/Wxapp.php
create mode 100644 application/admin/lang/zh-cn/auth/company.php
create mode 100644 application/admin/lang/zh-cn/miniprogram/wxapp.php
create mode 100644 application/admin/model/Company.php
create mode 100644 application/admin/model/Wxapp.php
create mode 100644 application/admin/validate/Company.php
create mode 100644 application/admin/validate/Wxapp.php
create mode 100644 application/admin/view/auth/company/add.html
create mode 100644 application/admin/view/auth/company/edit.html
create mode 100644 application/admin/view/miniprogram/wxapp/add.html
create mode 100644 application/admin/view/miniprogram/wxapp/edit.html
create mode 100644 public/assets/js/backend/auth/company.js
create mode 100644 public/assets/js/backend/miniprogram/wxapp.js
diff --git a/application/admin/controller/auth/Company.php b/application/admin/controller/auth/Company.php
new file mode 100644
index 000000000..f92886405
--- /dev/null
+++ b/application/admin/controller/auth/Company.php
@@ -0,0 +1,37 @@
+model = new \app\admin\model\Company;
+
+ }
+
+
+
+ /**
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+ */
+
+
+}
diff --git a/application/admin/controller/miniprogram/Wxapp.php b/application/admin/controller/miniprogram/Wxapp.php
new file mode 100644
index 000000000..06320879f
--- /dev/null
+++ b/application/admin/controller/miniprogram/Wxapp.php
@@ -0,0 +1,71 @@
+model = new \app\admin\model\Wxapp;
+
+ }
+
+
+
+ /**
+ * 默认生成的控制器所继承的父类中有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(['company'])
+ ->where($where)
+ ->order($sort, $order)
+ ->paginate($limit);
+
+ foreach ($list as $row) {
+
+ $row->getRelation('company')->visible(['shortname']);
+ }
+
+ $result = array("total" => $list->total(), "rows" => $list->items());
+
+ return json($result);
+ }
+ return $this->view->fetch();
+ }
+
+}
diff --git a/application/admin/lang/zh-cn/auth/company.php b/application/admin/lang/zh-cn/auth/company.php
new file mode 100644
index 000000000..ac8bcd22b
--- /dev/null
+++ b/application/admin/lang/zh-cn/auth/company.php
@@ -0,0 +1,16 @@
+ '企业Id',
+ 'Name' => '企业名称',
+ 'Shortname' => '企业简称',
+ 'Contact' => '企业联系电话',
+ 'Mail' => '企业联系邮箱',
+ 'Address' => '企业地址',
+ 'Clientid' => '企业客户端ID',
+ 'Clientsecret' => '企业客户端秘钥',
+ 'Logo_image' => '企业/产品Logo',
+ 'Createtime' => '创建时间',
+ 'Updatetime' => '更新时间',
+ 'Status' => '状态'
+];
diff --git a/application/admin/lang/zh-cn/miniprogram/wxapp.php b/application/admin/lang/zh-cn/miniprogram/wxapp.php
new file mode 100644
index 000000000..e5cdb598c
--- /dev/null
+++ b/application/admin/lang/zh-cn/miniprogram/wxapp.php
@@ -0,0 +1,20 @@
+ '小程序Id',
+ 'App_id' => '小程序AppID',
+ 'App_secret' => '小程序AppSecret',
+ 'App_id_mt' => '维护小程序AppID',
+ 'App_secret_mt' => '维护小程序AppSecret',
+ 'Mchid' => '微信商户号id',
+ 'Apikey' => '微信支付密钥',
+ 'Cert_pem' => '证书文件cert',
+ 'Key_pem' => '证书文件key',
+ 'Is_recycle' => '是否回收',
+ 'Is_delete' => '是否删除',
+ 'Company_id' => '所属企业Id',
+ 'Create_time' => '创建时间',
+ 'Update_time' => '更新时间',
+ 'Status' => '状态',
+ 'Company.shortname' => '企业简称'
+];
diff --git a/application/admin/model/Company.php b/application/admin/model/Company.php
new file mode 100644
index 000000000..8098005a3
--- /dev/null
+++ b/application/admin/model/Company.php
@@ -0,0 +1,40 @@
+belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
+ }
+}
diff --git a/application/admin/validate/Company.php b/application/admin/validate/Company.php
new file mode 100644
index 000000000..e7fac4d34
--- /dev/null
+++ b/application/admin/validate/Company.php
@@ -0,0 +1,27 @@
+ [],
+ 'edit' => [],
+ ];
+
+}
diff --git a/application/admin/validate/Wxapp.php b/application/admin/validate/Wxapp.php
new file mode 100644
index 000000000..a351a763a
--- /dev/null
+++ b/application/admin/validate/Wxapp.php
@@ -0,0 +1,27 @@
+ [],
+ 'edit' => [],
+ ];
+
+}
diff --git a/application/admin/view/auth/company/add.html b/application/admin/view/auth/company/add.html
new file mode 100644
index 000000000..c66d8b544
--- /dev/null
+++ b/application/admin/view/auth/company/add.html
@@ -0,0 +1,72 @@
+
diff --git a/application/admin/view/auth/company/edit.html b/application/admin/view/auth/company/edit.html
new file mode 100644
index 000000000..061d81a40
--- /dev/null
+++ b/application/admin/view/auth/company/edit.html
@@ -0,0 +1,72 @@
+
diff --git a/application/admin/view/miniprogram/wxapp/add.html b/application/admin/view/miniprogram/wxapp/add.html
new file mode 100644
index 000000000..0b8ed76d9
--- /dev/null
+++ b/application/admin/view/miniprogram/wxapp/add.html
@@ -0,0 +1,94 @@
+
diff --git a/application/admin/view/miniprogram/wxapp/edit.html b/application/admin/view/miniprogram/wxapp/edit.html
new file mode 100644
index 000000000..b94b83ccd
--- /dev/null
+++ b/application/admin/view/miniprogram/wxapp/edit.html
@@ -0,0 +1,94 @@
+
diff --git a/public/assets/js/backend/auth/company.js b/public/assets/js/backend/auth/company.js
new file mode 100644
index 000000000..0fef7b034
--- /dev/null
+++ b/public/assets/js/backend/auth/company.js
@@ -0,0 +1,63 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+ var Controller = {
+ index: function () {
+ // 初始化表格参数配置
+ Table.api.init({
+ extend: {
+ index_url: 'auth/company/index' + location.search,
+ add_url: 'auth/company/add',
+ edit_url: 'auth/company/edit',
+ del_url: 'auth/company/del',
+ multi_url: 'auth/company/multi',
+ import_url: 'auth/company/import',
+ table: 'company',
+ }
+ });
+
+ var table = $("#table");
+
+ // 初始化表格
+ table.bootstrapTable({
+ url: $.fn.bootstrapTable.defaults.extend.index_url,
+ pk: 'id',
+ sortName: 'id',
+ fixedColumns: true,
+ fixedRightNumber: 1,
+ columns: [
+ [
+ {checkbox: true},
+ {field: 'id', title: __('Id')},
+ {field: 'name', title: __('Name')},
+ {field: 'shortname', title: __('Shortname')},
+ {field: 'contact', title: __('Contact')},
+ {field: 'mail', title: __('Mail')},
+ {field: 'address', title: __('Address')},
+ {field: 'clientId', title: __('Clientid')},
+ {field: 'clientSecret', title: __('Clientsecret')},
+ {field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
+ {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'status', title: __('Status')},
+ {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+ ]
+ ]
+ });
+
+ // 为表格绑定事件
+ Table.api.bindevent(table);
+ },
+ add: function () {
+ Controller.api.bindevent();
+ },
+ edit: function () {
+ Controller.api.bindevent();
+ },
+ api: {
+ bindevent: function () {
+ Form.api.bindevent($("form[role=form]"));
+ }
+ }
+ };
+ return Controller;
+});
diff --git a/public/assets/js/backend/miniprogram/wxapp.js b/public/assets/js/backend/miniprogram/wxapp.js
new file mode 100644
index 000000000..cebdbb02b
--- /dev/null
+++ b/public/assets/js/backend/miniprogram/wxapp.js
@@ -0,0 +1,65 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+ var Controller = {
+ index: function () {
+ // 初始化表格参数配置
+ Table.api.init({
+ extend: {
+ index_url: 'miniprogram/wxapp/index' + location.search,
+ add_url: 'miniprogram/wxapp/add',
+ edit_url: 'miniprogram/wxapp/edit',
+ del_url: 'miniprogram/wxapp/del',
+ multi_url: 'miniprogram/wxapp/multi',
+ import_url: 'miniprogram/wxapp/import',
+ table: 'wxapp',
+ }
+ });
+
+ var table = $("#table");
+
+ // 初始化表格
+ table.bootstrapTable({
+ url: $.fn.bootstrapTable.defaults.extend.index_url,
+ pk: 'id',
+ sortName: 'id',
+ fixedColumns: true,
+ fixedRightNumber: 1,
+ columns: [
+ [
+ {checkbox: true},
+ {field: 'id', title: __('Id')},
+ {field: 'app_id', title: __('App_id'), operate: 'LIKE'},
+ {field: 'app_secret', title: __('App_secret'), operate: 'LIKE'},
+ {field: 'app_id_mt', title: __('App_id_mt'), operate: 'LIKE'},
+ {field: 'app_secret_mt', title: __('App_secret_mt'), operate: 'LIKE'},
+ {field: 'mchid', title: __('Mchid'), operate: 'LIKE'},
+ {field: 'apikey', title: __('Apikey'), operate: 'LIKE'},
+ {field: 'is_recycle', title: __('Is_recycle')},
+ {field: 'is_delete', title: __('Is_delete')},
+ {field: 'company_id', title: __('Company_id')},
+ {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+ {field: 'status', title: __('Status')},
+ {field: 'company.shortname', title: __('Company.shortname')},
+ {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+ ]
+ ]
+ });
+
+ // 为表格绑定事件
+ Table.api.bindevent(table);
+ },
+ add: function () {
+ Controller.api.bindevent();
+ },
+ edit: function () {
+ Controller.api.bindevent();
+ },
+ api: {
+ bindevent: function () {
+ Form.api.bindevent($("form[role=form]"));
+ }
+ }
+ };
+ return Controller;
+});
--
Gitee
From 322b700d544d1b452799972da7c5e52c0b58aad4 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 09:48:31 +0800
Subject: [PATCH 0029/1004] users login debug
---
application/common/model/Wxapp.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 76be623fe..d73be2ff9 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -59,6 +59,7 @@ class Wxapp extends BaseModel
if (count($where) > 1) {
throw new BaseException(['msg' => '小程序Id Mapping条件超限']);
}
+ var_dump($where);
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::get($where);
--
Gitee
From fa9612fd58874001c71101579afda838b0699f34 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 09:54:47 +0800
Subject: [PATCH 0030/1004] users login debug
---
application/api/controller/Users.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 30849e751..756e9c892 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -26,7 +26,7 @@ class Users extends Api
$model = new UserModel;
try {
return $this->renderSuccess([
- 'user_id' => $model->login($this->request->post()),
+ 'user_id' => $model->login($this->request->param()),
'token' => $model->getToken()
]);
} catch (Exception $e) {
--
Gitee
From 4420fd07f776be9caecfb35a7b693bc48c46cff8 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 10:02:50 +0800
Subject: [PATCH 0031/1004] users login debug
---
application/common/model/Wxapp.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index d73be2ff9..76be623fe 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -59,7 +59,6 @@ class Wxapp extends BaseModel
if (count($where) > 1) {
throw new BaseException(['msg' => '小程序Id Mapping条件超限']);
}
- var_dump($where);
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::get($where);
--
Gitee
From 49a0f813bbcd855bad6a3cbdcf9d7d1ae0377ed3 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 11:06:19 +0800
Subject: [PATCH 0032/1004] users login debug
---
application/api/controller/Users.php | 4 ++--
application/common/controller/Api.php | 13 +------------
2 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 756e9c892..b470e9dab 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -30,7 +30,7 @@ class Users extends Api
'token' => $model->getToken()
]);
} catch (Exception $e) {
- return $this->renderError($e->getMessage());
+ return $this->error($e->getMessage());
}
}
@@ -59,7 +59,7 @@ class Users extends Api
try {
$userInfo = $this->getUser();
} catch (BaseException $e) {
- return $this->renderError($e->getMessage());
+ return $this->error($e->getMessage());
}
return $this->renderSuccess(compact('userInfo'));
}
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index 2700a2055..a7d610005 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -385,17 +385,6 @@ class Api
*/
protected function renderSuccess($data = [], $msg = 'success')
{
- return $this->renderJson(self::JSON_SUCCESS_STATUS, $msg, $data);
- }
-
- /**
- * 返回操作失败json
- * @param string $msg
- * @param array $data
- * @return array
- */
- protected function renderError($msg = 'error', $data = [])
- {
- return $this->renderJson(self::JSON_ERROR_STATUS, $msg, $data);
+ return $this->success($msg, $data);
}
}
--
Gitee
From b31842c195596ed6acf63e604e70ec1b26ea4d0e Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 11:10:10 +0800
Subject: [PATCH 0033/1004] users login debug
---
application/common/model/Users.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/model/Users.php b/application/common/model/Users.php
index cc6b1fea2..2bb0fce26 100644
--- a/application/common/model/Users.php
+++ b/application/common/model/Users.php
@@ -11,7 +11,7 @@ use app\common\model\user\PointsLog as PointsLogModel;
*/
class Users extends BaseModel
{
- protected $name = 'user';
+ protected $name = 'users';
// 性别
private $gender = ['未知', '男', '女'];
--
Gitee
From 3abe2c342b0501f07414bbdba7a097d565e59109 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 11:22:31 +0800
Subject: [PATCH 0034/1004] users login debug
---
application/api/model/Users.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index 4a65d644e..d043578fc 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -102,6 +102,7 @@ class Users extends UserModel
$wxapp_arr = WxappModel::getWxappCache($wxapp_id);
// 保存/更新用户记录
unset($data['app_id']);
+ var_dump($data);
if (!$model->allowField(true)->save(array_merge($data, [
'company_id' => $wxapp_arr['company_id']
]))) {
--
Gitee
From 05f1aaf7b0962f5df964af4fab9aa80d51852221 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 11:40:28 +0800
Subject: [PATCH 0035/1004] users login debug
---
application/common/model/BaseModel.php | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 6f7c68299..6d1eaf716 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -16,6 +16,7 @@ class BaseModel extends Model
{
public static $redis;
public static $wxapp_id;
+ public static $company_id = 0;
public static $base_url;
protected $alias = '';
@@ -32,7 +33,9 @@ class BaseModel extends Model
// 获取当前域名
self::$base_url = base_url();
// 后期静态绑定wxapp_id
- self::bindWxappId();
+// self::bindWxappId();
+ // 后期静态绑定company_id
+ self::bindCompanyId();
}
/**
@@ -63,6 +66,21 @@ class BaseModel extends Model
}
}
+ /**
+ * 后期静态绑定类名称
+ * 用于定义全局查询范围的company_id条件
+ * 子类调用方式:
+ * 非静态方法: self::$company_id
+ * 静态方法中: $self = new static(); $self::$company_id
+ */
+ private static function bindCompanyId()
+ {
+ if ($module = self::getCalledModule()) {
+ $callfunc = 'set' . ucfirst($module) . 'WxappId';
+ method_exists(new self, $callfunc) && self::$callfunc();
+ }
+ }
+
/**
* 设置wxapp_id (store模块)
*/
@@ -79,6 +97,8 @@ class BaseModel extends Model
{
$request = Request::instance();
self::$wxapp_id = Wxapp::getMappingWxappId(['app_id' => $request->param('app_id')]);
+ $wxapp_arr = Wxapp::getWxappCache(self::$wxapp_id);
+ self::$company_id = $wxapp_arr['company_id'];
}
/**
@@ -87,8 +107,8 @@ class BaseModel extends Model
*/
protected function base($query)
{
- if (self::$wxapp_id > 0) {
- $query->where($query->getTable() . '.wxapp_id', self::$wxapp_id);
+ if (self::$company_id > 0) {
+ $query->where($query->getTable() . '.company_id', self::$company_id);
}
}
--
Gitee
From 8a5ab4bf44d16e7c4614970a1ed0f5bbe9b6036c Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 11:42:46 +0800
Subject: [PATCH 0036/1004] users login debug
---
application/api/model/Users.php | 1 -
application/common/model/BaseModel.php | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index d043578fc..4a65d644e 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -102,7 +102,6 @@ class Users extends UserModel
$wxapp_arr = WxappModel::getWxappCache($wxapp_id);
// 保存/更新用户记录
unset($data['app_id']);
- var_dump($data);
if (!$model->allowField(true)->save(array_merge($data, [
'company_id' => $wxapp_arr['company_id']
]))) {
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 6d1eaf716..d8e5ac143 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -98,6 +98,7 @@ class BaseModel extends Model
$request = Request::instance();
self::$wxapp_id = Wxapp::getMappingWxappId(['app_id' => $request->param('app_id')]);
$wxapp_arr = Wxapp::getWxappCache(self::$wxapp_id);
+ var_dump($wxapp_arr);
self::$company_id = $wxapp_arr['company_id'];
}
--
Gitee
From 7eed9b442b345b6a8206fe9559ba00b2ad04904a Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:15:38 +0800
Subject: [PATCH 0037/1004] users login debug
---
application/common/model/Wxapp.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 76be623fe..81a322d72 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -22,7 +22,7 @@ class Wxapp extends BaseModel
*/
public static function detail($id = null)
{
- return self::detail($id);
+ return static::get($id);
}
/**
@@ -61,7 +61,7 @@ class Wxapp extends BaseModel
}
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
- $data = self::get($where);
+ $data = static::get($where);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
--
Gitee
From d2e91108ba98e6b9f989c205110d81d10695eed0 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:18:06 +0800
Subject: [PATCH 0038/1004] users login debug
---
application/common/model/Users.php | 2 +-
application/common/model/Wxapp.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/common/model/Users.php b/application/common/model/Users.php
index 2bb0fce26..5212f86f5 100644
--- a/application/common/model/Users.php
+++ b/application/common/model/Users.php
@@ -69,7 +69,7 @@ class Users extends BaseModel
} else {
$filter['id'] = (int)$where;
}
- return static::get($filter, $with);
+ return get_object_vars(static::get($filter, $with));
}
/**
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 81a322d72..a6363acf2 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -22,7 +22,7 @@ class Wxapp extends BaseModel
*/
public static function detail($id = null)
{
- return static::get($id);
+ return get_object_vars(static::get($id));
}
/**
--
Gitee
From 1941d44a95f4777d7086985f265ab86e12e7a867 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:26:48 +0800
Subject: [PATCH 0039/1004] users login debug
---
application/common/model/Wxapp.php | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index a6363acf2..5e9b2995a 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -20,9 +20,15 @@ class Wxapp extends BaseModel
* @return static|null
* @throws \think\exception\DbException
*/
- public static function detail($id = null)
+ public static function detail($where, $with = [])
{
- return get_object_vars(static::get($id));
+ $filter = ['status' => 1];
+ if (is_array($where)) {
+ $filter = array_merge($filter, $where);
+ } else {
+ $filter['id'] = (int)$where;
+ }
+ return get_object_vars(static::get($filter, $with));
}
/**
@@ -61,7 +67,7 @@ class Wxapp extends BaseModel
}
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
- $data = static::get($where);
+ $data = self::detail($where);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
--
Gitee
From 677b403b2ca785732014df61e89f557ac2e6c4e5 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:28:45 +0800
Subject: [PATCH 0040/1004] users login debug
---
application/common/model/BaseModel.php | 1 -
application/common/model/Wxapp.php | 4 +++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index d8e5ac143..6d1eaf716 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -98,7 +98,6 @@ class BaseModel extends Model
$request = Request::instance();
self::$wxapp_id = Wxapp::getMappingWxappId(['app_id' => $request->param('app_id')]);
$wxapp_arr = Wxapp::getWxappCache(self::$wxapp_id);
- var_dump($wxapp_arr);
self::$company_id = $wxapp_arr['company_id'];
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 5e9b2995a..217486440 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -28,7 +28,9 @@ class Wxapp extends BaseModel
} else {
$filter['id'] = (int)$where;
}
- return get_object_vars(static::get($filter, $with));
+ $detail = static::get($filter, $with);
+ var_dump($detail);
+ return $detail;
}
/**
--
Gitee
From 30665d5bfabfc780a04a0bb79dccc9a85b8baf37 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:30:39 +0800
Subject: [PATCH 0041/1004] users login debug
---
application/common/model/Wxapp.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 217486440..c5d24ee5a 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -22,7 +22,7 @@ class Wxapp extends BaseModel
*/
public static function detail($where, $with = [])
{
- $filter = ['status' => 1];
+ $filter = ['is_delete' => 0];
if (is_array($where)) {
$filter = array_merge($filter, $where);
} else {
--
Gitee
From 795bb78480f7045c825803b5ec33a3b789ada25d Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:50:58 +0800
Subject: [PATCH 0042/1004] users login debug
---
application/common/model/Users.php | 2 +-
application/common/model/Wxapp.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/common/model/Users.php b/application/common/model/Users.php
index 5212f86f5..2bb0fce26 100644
--- a/application/common/model/Users.php
+++ b/application/common/model/Users.php
@@ -69,7 +69,7 @@ class Users extends BaseModel
} else {
$filter['id'] = (int)$where;
}
- return get_object_vars(static::get($filter, $with));
+ return static::get($filter, $with);
}
/**
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index c5d24ee5a..f04237f8b 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -29,7 +29,6 @@ class Wxapp extends BaseModel
$filter['id'] = (int)$where;
}
$detail = static::get($filter, $with);
- var_dump($detail);
return $detail;
}
@@ -48,6 +47,7 @@ class Wxapp extends BaseModel
if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
+ var_dump($data->getData());
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
}
return $data;
--
Gitee
From dd3115f82911ce2664c4d360b3b8ed743f869d26 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:53:46 +0800
Subject: [PATCH 0043/1004] users login debug
---
application/common/model/Wxapp.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index f04237f8b..ededd0360 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -70,6 +70,7 @@ class Wxapp extends BaseModel
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::detail($where);
+ var_dump($data);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
--
Gitee
From d29ece49e6bd5e20774bbaf8c9073dab63500a00 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:54:46 +0800
Subject: [PATCH 0044/1004] users login debug
---
application/common/model/Wxapp.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index ededd0360..75519285f 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -47,8 +47,7 @@ class Wxapp extends BaseModel
if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- var_dump($data->getData());
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data->getData());
}
return $data;
}
@@ -70,7 +69,7 @@ class Wxapp extends BaseModel
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::detail($where);
- var_dump($data);
+ var_dump($data->getData());
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
--
Gitee
From 9e0b99af9df920feb5383b649878ab627a5e51dc Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 13:58:31 +0800
Subject: [PATCH 0045/1004] users login debug
---
application/common/model/Wxapp.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 75519285f..a3941e514 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -69,10 +69,9 @@ class Wxapp extends BaseModel
$mapping_key = array_values($where)[0];
if (!$id = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key)) {
$data = self::detail($where);
- var_dump($data->getData());
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data->getData());
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
}
return $id;
--
Gitee
From cf4e6db0609c62e0da8a5ab861b4a50dd4932e64 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:06:35 +0800
Subject: [PATCH 0046/1004] users login debug
---
application/common/library/RedisKey.php | 5 +++++
application/common/model/Wxapp.php | 5 ++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/application/common/library/RedisKey.php b/application/common/library/RedisKey.php
index c16574f48..837190c9e 100644
--- a/application/common/library/RedisKey.php
+++ b/application/common/library/RedisKey.php
@@ -30,4 +30,9 @@ class RedisKey
const AIRPLUS_HASH_USERS_INFO = self::PROJECT_NAME_PREFIX . "hash_users_info";
+ public static function redisCacheDataParser($data)
+ {
+ return json_encode($data->getData(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_UNICODE);
+ }
+
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index a3941e514..44a2dcb89 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -47,7 +47,7 @@ class Wxapp extends BaseModel
if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data->getData());
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data->getData()));
}
return $data;
}
@@ -71,11 +71,10 @@ class Wxapp extends BaseModel
$data = self::detail($where);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $data->getData());
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data->getData()));
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
}
return $id;
}
-
}
--
Gitee
From 2b4b784c8dd20154a281e818b8ae64af8f085a32 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:07:15 +0800
Subject: [PATCH 0047/1004] users login debug
---
application/common/model/Wxapp.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index 44a2dcb89..d09fb4758 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -47,7 +47,7 @@ class Wxapp extends BaseModel
if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data->getData()));
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data));
}
return $data;
}
@@ -71,7 +71,7 @@ class Wxapp extends BaseModel
$data = self::detail($where);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data->getData()));
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data));
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
}
return $id;
--
Gitee
From 2715f23ca1a291fdf94bfb981747fa9e3235493c Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:10:27 +0800
Subject: [PATCH 0048/1004] users login debug
---
application/common/model/Wxapp.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index d09fb4758..b6f62a302 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -47,9 +47,10 @@ class Wxapp extends BaseModel
if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data));
+ $json = RedisKey::redisCacheDataParser($data);
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $json);
}
- return $data;
+ return json_decode($data, true);
}
/**
* 根据小程序表其他字段获取小程序表Id
--
Gitee
From 5e4da4730f32073b9b93af97379bd7893e421413 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:13:12 +0800
Subject: [PATCH 0049/1004] users login debug
---
application/api/model/Users.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index 4a65d644e..6abda63c9 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -2,6 +2,7 @@
namespace app\api\model;
+use think\Cache;
use app\common\exception\BaseException;
use app\common\library\RedisKey;
use app\common\model\Users as UserModel;
--
Gitee
From d5140e2ae5a2add305e847f6a9ebb827348bd8fc Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:26:19 +0800
Subject: [PATCH 0050/1004] users login debug
---
application/api/model/Users.php | 12 ++++++++----
application/common/library/RedisKey.php | 5 -----
application/common/model/Wxapp.php | 12 +++++++-----
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index 6abda63c9..79e7d32a1 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -103,11 +103,15 @@ class Users extends UserModel
$wxapp_arr = WxappModel::getWxappCache($wxapp_id);
// 保存/更新用户记录
unset($data['app_id']);
- if (!$model->allowField(true)->save(array_merge($data, [
+// if (!$model->allowField(true)->save(array_merge($data, [
+// 'company_id' => $wxapp_arr['company_id']
+// ]))) {
+// throw new BaseException(['msg' => '用户注册失败']);
+// }
+ var_dump($data);
+ $model->allowField(true)->save(array_merge($data, [
'company_id' => $wxapp_arr['company_id']
- ]))) {
- throw new BaseException(['msg' => '用户注册失败']);
- }
+ ]));
} catch (\Exception $e) {
throw new BaseException(['msg' => $e->getMessage()]);
}
diff --git a/application/common/library/RedisKey.php b/application/common/library/RedisKey.php
index 837190c9e..c16574f48 100644
--- a/application/common/library/RedisKey.php
+++ b/application/common/library/RedisKey.php
@@ -30,9 +30,4 @@ class RedisKey
const AIRPLUS_HASH_USERS_INFO = self::PROJECT_NAME_PREFIX . "hash_users_info";
- public static function redisCacheDataParser($data)
- {
- return json_encode($data->getData(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_UNICODE);
- }
-
}
diff --git a/application/common/model/Wxapp.php b/application/common/model/Wxapp.php
index b6f62a302..51e37b3f3 100644
--- a/application/common/model/Wxapp.php
+++ b/application/common/model/Wxapp.php
@@ -44,13 +44,15 @@ class Wxapp extends BaseModel
if (is_null($id)) {
throw new BaseException(['msg' => 'id不可为空']);
}
- if (!$data = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
+ if (!$cache = self::$redis->hGet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id)) {
$data = self::detail($id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
- $json = RedisKey::redisCacheDataParser($data);
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, $json);
+ $array = $data->getData();
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, json_encode($array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
+ } else {
+ $array = json_decode($cache, true);
}
- return json_decode($data, true);
+ return $array;
}
/**
* 根据小程序表其他字段获取小程序表Id
@@ -72,7 +74,7 @@ class Wxapp extends BaseModel
$data = self::detail($where);
if (empty($data)) throw new BaseException(['msg' => '未找到小程序信息']);
$id = $data['id'];
- self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, RedisKey::redisCacheDataParser($data));
+ self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_INFO, $id, json_encode($data->getData(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
self::$redis->hSet(RedisKey::AIRPLUS_HASH_WXAPP_FIELD_MAPPING_WXAPP_ID, $mapping_key, $id);
}
return $id;
--
Gitee
From 795e10fda808e0c043a32ad599a3afcc7c3d7a5e Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:38:09 +0800
Subject: [PATCH 0051/1004] user interface implement
---
application/api/model/Users.php | 4 ++--
application/common/controller/Api.php | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index 79e7d32a1..b877d9526 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -108,10 +108,10 @@ class Users extends UserModel
// ]))) {
// throw new BaseException(['msg' => '用户注册失败']);
// }
- var_dump($data);
- $model->allowField(true)->save(array_merge($data, [
+ $result = $model->allowField(true)->save(array_merge($data, [
'company_id' => $wxapp_arr['company_id']
]));
+ var_dump($result);
} catch (\Exception $e) {
throw new BaseException(['msg' => $e->getMessage()]);
}
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index a7d610005..c74463a16 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -2,7 +2,7 @@
namespace app\common\controller;
-use app\api\model\User as UserModel;
+use app\api\model\Users as UserModel;
use app\common\exception\BaseException;
use app\common\library\Auth;
use think\Config;
--
Gitee
From ae891ed8aa1f5534509f38143113f9365b088a70 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:48:24 +0800
Subject: [PATCH 0052/1004] user interface implement
---
application/api/model/Users.php | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index b877d9526..e120e039d 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -103,15 +103,12 @@ class Users extends UserModel
$wxapp_arr = WxappModel::getWxappCache($wxapp_id);
// 保存/更新用户记录
unset($data['app_id']);
-// if (!$model->allowField(true)->save(array_merge($data, [
-// 'company_id' => $wxapp_arr['company_id']
-// ]))) {
-// throw new BaseException(['msg' => '用户注册失败']);
-// }
$result = $model->allowField(true)->save(array_merge($data, [
'company_id' => $wxapp_arr['company_id']
]));
- var_dump($result);
+ if ($result === false) {
+ throw new BaseException(['msg' => '用户注册失败']);
+ }
} catch (\Exception $e) {
throw new BaseException(['msg' => $e->getMessage()]);
}
--
Gitee
From 7337da6a4671ca955a0899a02740bfdcecdc736b Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:52:37 +0800
Subject: [PATCH 0053/1004] user interface implement
---
application/common/controller/Api.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index c74463a16..1b42063d1 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -53,7 +53,7 @@ class Api
* 无需登录的方法,同时也就不需要鉴权了
* @var array
*/
- protected $noNeedLogin = [];
+ protected $noNeedLogin = ['*'];
/**
* 无需鉴权的方法,但需要登录
--
Gitee
From 0f7124e737d835a7c041e5ff61fcc24700ec587a Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:54:12 +0800
Subject: [PATCH 0054/1004] user interface implement
---
application/common/controller/Api.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php
index 1b42063d1..f87f7f590 100644
--- a/application/common/controller/Api.php
+++ b/application/common/controller/Api.php
@@ -53,7 +53,7 @@ class Api
* 无需登录的方法,同时也就不需要鉴权了
* @var array
*/
- protected $noNeedLogin = ['*'];
+ protected $noNeedLogin = '*';
/**
* 无需鉴权的方法,但需要登录
--
Gitee
From cba2cc43b13d85e9e57ad45495531ad6bba46db7 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 14:54:53 +0800
Subject: [PATCH 0055/1004] user interface implement
---
application/api/controller/Users.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index b470e9dab..3e2ba6e3f 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -13,7 +13,6 @@ use think\Exception;
*/
class Users extends Api
{
- protected $noNeedLogin = ['login'];
protected $noNeedRight = '*';
/**
--
Gitee
From e774483705d458efd0a3b096040bd32ef99c3a37 Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 15:10:08 +0800
Subject: [PATCH 0056/1004] user interface implement
---
application/common/model/BaseModel.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php
index 6d1eaf716..8928310ba 100644
--- a/application/common/model/BaseModel.php
+++ b/application/common/model/BaseModel.php
@@ -35,7 +35,7 @@ class BaseModel extends Model
// 后期静态绑定wxapp_id
// self::bindWxappId();
// 后期静态绑定company_id
- self::bindCompanyId();
+// self::bindCompanyId();
}
/**
--
Gitee
From 848804308074a1ddc88af84c27916744ed7bf9ef Mon Sep 17 00:00:00 2001
From: Leo
Date: Fri, 18 Feb 2022 15:43:52 +0800
Subject: [PATCH 0057/1004] user interface implement
---
application/api/controller/Users.php | 19 +++++++++++++++++++
application/api/model/Users.php | 25 ++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/application/api/controller/Users.php b/application/api/controller/Users.php
index 3e2ba6e3f..e9c7c14b7 100644
--- a/application/api/controller/Users.php
+++ b/application/api/controller/Users.php
@@ -46,6 +46,7 @@ class Users extends Api
'token' => $model->getToken()
]);
}
+
/**
* 当前用户详情
* @return array
@@ -63,4 +64,22 @@ class Users extends Api
return $this->renderSuccess(compact('userInfo'));
}
+ /**
+ * 更新用户信息
+ * @return array
+ * @throws \app\common\exception\BaseException
+ * @throws \think\exception\DbException
+ */
+ public function userinfo()
+ {
+ $model = new UserModel;
+ // 当前用户信息
+ try {
+ $userInfo = $model->userinfo($this->request->param());
+ } catch (BaseException $e) {
+ return $this->error($e->getMessage());
+ }
+ return $this->renderSuccess(compact('userInfo'));
+ }
+
}
diff --git a/application/api/model/Users.php b/application/api/model/Users.php
index e120e039d..81f83ec76 100644
--- a/application/api/model/Users.php
+++ b/application/api/model/Users.php
@@ -49,7 +49,6 @@ class Users extends UserModel
* @return string
* @throws BaseException
* @throws \think\Exception
- * @throws \think\exception\DbException
*/
public function login($post)
{
@@ -61,6 +60,30 @@ class Users extends UserModel
return $user_id;
}
+ /**
+ * 更新用户信息
+ * @param array $post
+ * @return int|true
+ * @throws \think\Exception
+ */
+ public function userinfo($data)
+ {
+ // 查询用户是否已存在
+ $user = self::getUser($data['token']);
+ $model = $user ?: $this;
+ try {
+ // 保存/更新用户记录
+ unset($data['token']);
+ $result = $model->allowField(true)->save($data);
+ if ($result === false) {
+ throw new BaseException(['msg' => '更新用户信息失败']);
+ }
+ } catch (\Exception $e) {
+ throw new BaseException(['msg' => $e->getMessage()]);
+ }
+ return $model;
+ }
+
/**
* 获取token
* @return mixed
--
Gitee
From 22163ce4fb12453b7909ec757ad9db3f658ed614 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A4=8F=E4=BA=AC18988752064?=
Date: Sat, 19 Feb 2022 18:09:49 +0800
Subject: [PATCH 0058/1004] rmv status field of users, company and wxapp
---
application/admin/view/auth/company/add.html | 6 ------
application/admin/view/auth/company/edit.html | 6 ------
application/admin/view/miniprogram/wxapp/add.html | 6 ------
application/admin/view/miniprogram/wxapp/edit.html | 6 ------
application/admin/view/user/users/add.html | 6 ------
application/admin/view/user/users/edit.html | 6 ------
public/assets/js/backend/auth/company.js | 1 -
public/assets/js/backend/miniprogram/wxapp.js | 1 -
public/assets/js/backend/user/users.js | 1 -
9 files changed, 39 deletions(-)
diff --git a/application/admin/view/auth/company/add.html b/application/admin/view/auth/company/add.html
index c66d8b544..c75c68429 100644
--- a/application/admin/view/auth/company/add.html
+++ b/application/admin/view/auth/company/add.html
@@ -56,12 +56,6 @@
-
-
-
-
-
-