فهرست منبع

wes 多宝福袋

wesmiler 3 سال پیش
والد
کامیت
f845bd7cf5
100فایلهای تغییر یافته به همراه8830 افزوده شده و 0 حذف شده
  1. 13 0
      .gitignore
  2. 21 0
      LICENSE
  3. 128 0
      README 2.md
  4. 36 0
      README.en.md
  5. 19 0
      README.md
  6. 1 0
      app/.htaccess
  7. 94 0
      app/BaseController.php
  8. 58 0
      app/ExceptionHandle.php
  9. 10 0
      app/Request.php
  10. 38 0
      app/admin/config/admin.php
  11. 10 0
      app/admin/config/app.php
  12. 30 0
      app/admin/config/cache.php
  13. 10 0
      app/admin/config/console.php
  14. 19 0
      app/admin/config/route.php
  15. 185 0
      app/admin/controller/Ajax.php
  16. 136 0
      app/admin/controller/Index.php
  17. 100 0
      app/admin/controller/Login.php
  18. 61 0
      app/admin/controller/box/AppointList.php
  19. 63 0
      app/admin/controller/box/Box.php
  20. 111 0
      app/admin/controller/box/HandleBoxAction.php
  21. 187 0
      app/admin/controller/box/OpenBoxAction.php
  22. 231 0
      app/admin/controller/coupon/Couponarea.php
  23. 202 0
      app/admin/controller/coupon/Couponplan.php
  24. 74 0
      app/admin/controller/coupon/Couponplanbuylog.php
  25. 46 0
      app/admin/controller/informational/CouponData.php
  26. 93 0
      app/admin/controller/informational/Xzlog.php
  27. 61 0
      app/admin/controller/informational/Yesterdaydata.php
  28. 31 0
      app/admin/controller/mall/Cate.php
  29. 27 0
      app/admin/controller/mall/Express.php
  30. 49 0
      app/admin/controller/mall/ExpressDelivery.php
  31. 256 0
      app/admin/controller/mall/Goods.php
  32. 55 0
      app/admin/controller/mall/GoodsBuyType.php
  33. 33 0
      app/admin/controller/mall/GoodsMenu.php
  34. 157 0
      app/admin/controller/mall/GoodsSpecType.php
  35. 27 0
      app/admin/controller/mall/ShopBuynote.php
  36. 26 0
      app/admin/controller/mall/ShopHotKeywords.php
  37. 198 0
      app/admin/controller/mall/ShopOrder.php
  38. 27 0
      app/admin/controller/mall/ShopSupplier.php
  39. 27 0
      app/admin/controller/mall/UserAddress.php
  40. 208 0
      app/admin/controller/system/Admin.php
  41. 108 0
      app/admin/controller/system/Article.php
  42. 91 0
      app/admin/controller/system/Auth.php
  43. 84 0
      app/admin/controller/system/Banner.php
  44. 75 0
      app/admin/controller/system/Config.php
  45. 143 0
      app/admin/controller/system/Faq.php
  46. 51 0
      app/admin/controller/system/Log.php
  47. 205 0
      app/admin/controller/system/Menu.php
  48. 121 0
      app/admin/controller/system/Node.php
  49. 144 0
      app/admin/controller/system/Payconfig.php
  50. 43 0
      app/admin/controller/system/Quick.php
  51. 38 0
      app/admin/controller/system/Uploadfile.php
  52. 52 0
      app/admin/controller/system/Xzfenhong.php
  53. 630 0
      app/admin/controller/user/Recharge.php
  54. 663 0
      app/admin/controller/user/User.php
  55. 162 0
      app/admin/controller/withdraw/Withdraw.php
  56. 189 0
      app/admin/controller/xzdata/Dianfei.php
  57. 188 0
      app/admin/controller/xzdata/Huafei.php
  58. 21 0
      app/admin/event.php
  59. 37 0
      app/admin/logic/BoxLogic.php
  60. 40 0
      app/admin/logic/BoxMidHandleLogic.php
  61. 39 0
      app/admin/logic/BoxRecordLogic.php
  62. 85 0
      app/admin/logic/MoneyLogLogic.php
  63. 35 0
      app/admin/logic/PayConfigLogic.php
  64. 44 0
      app/admin/logic/PaymentLogic.php
  65. 75 0
      app/admin/logic/ScoreLogLogic.php
  66. 35 0
      app/admin/logic/ShopCategoryLogic.php
  67. 94 0
      app/admin/logic/ShopGoodsLogic.php
  68. 25 0
      app/admin/logic/ShopGoodsSpecLogic.php
  69. 57 0
      app/admin/logic/ShopGoodsSpecTypeLogic.php
  70. 49 0
      app/admin/logic/ShopGoodsTypeLogic.php
  71. 35 0
      app/admin/logic/ShopHotKeywordsLogic.php
  72. 127 0
      app/admin/logic/ShopOrderLogic.php
  73. 33 0
      app/admin/logic/ShopSupplierLogic.php
  74. 34 0
      app/admin/logic/SystemAdminLogic.php
  75. 55 0
      app/admin/logic/SystemArticleLogic.php
  76. 19 0
      app/admin/logic/SystemAuthLogic.php
  77. 62 0
      app/admin/logic/SystemBannerLogic.php
  78. 19 0
      app/admin/logic/SystemConfigLogic.php
  79. 77 0
      app/admin/logic/SystemFaqLogic.php
  80. 43 0
      app/admin/logic/SystemLogLogic.php
  81. 54 0
      app/admin/logic/SystemMenuLogic.php
  82. 54 0
      app/admin/logic/SystemNodeLogic.php
  83. 554 0
      app/admin/logic/UserLogic.php
  84. 34 0
      app/admin/logic/UserteamLogLogic.php
  85. 241 0
      app/admin/logic/WithdrawLogLogic.php
  86. 42 0
      app/admin/logic/WithdrawLogic.php
  87. 21 0
      app/admin/middleware.php
  88. 67 0
      app/admin/middleware/CheckAdmin.php
  89. 53 0
      app/admin/middleware/CsrfMiddleware.php
  90. 77 0
      app/admin/middleware/SystemLog.php
  91. 58 0
      app/admin/middleware/ViewInit.php
  92. 23 0
      app/admin/model/MallCate.php
  93. 30 0
      app/admin/model/MallGoods.php
  94. 31 0
      app/admin/model/SystemAdmin.php
  95. 64 0
      app/admin/model/SystemAuth.php
  96. 21 0
      app/admin/model/SystemAuthNode.php
  97. 22 0
      app/admin/model/SystemConfig.php
  98. 29 0
      app/admin/model/SystemLog.php
  99. 70 0
      app/admin/model/SystemMenu.php
  100. 0 0
      app/admin/model/SystemNode.php

+ 13 - 0
.gitignore

@@ -0,0 +1,13 @@
+# ---> Laravel
+/bootstrap/compiled.php
+.env.*.php
+.env.php
+.env
+.idea
+runtime
+/composer.lock
+/vendor/*
+/public/upload
+/addons/dbapp_online/*
+*.zip
+.DS_Store

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 EasyAdmin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 128 - 0
README 2.md

@@ -0,0 +1,128 @@
+
+![EasyAdmin-logo](public/static/common/images/logo-2.png)
+
+
+[![Php Version](https://img.shields.io/badge/php-%3E=7.1.0-brightgreen.svg?maxAge=2592000&color=yellow)](https://github.com/php/php-src)
+[![Mysql Version](https://img.shields.io/badge/mysql-%3E=5.7-brightgreen.svg?maxAge=2592000&color=orange)](https://www.mysql.com/)
+[![Thinkphp Version](https://img.shields.io/badge/thinkphp-%3E=6.0.2-brightgreen.svg?maxAge=2592000)](https://github.com/top-think/framework)
+[![Layui Version](https://img.shields.io/badge/layui-=2.5.5-brightgreen.svg?maxAge=2592000&color=critical)](https://github.com/sentsin/layui)
+[![Layuimini Version](https://img.shields.io/badge/layuimini-%3E=2.0.4.2-brightgreen.svg?maxAge=2592000&color=ff69b4)](https://github.com/zhongshaofa/layuimini)
+[![EasyAdmin Doc](https://img.shields.io/badge/docs-passing-green.svg?maxAge=2592000)](http://easyadmin.99php.cn/docs)
+[![EasyAdmin License](https://img.shields.io/badge/license-MIT-green?maxAge=2592000&color=blue)](https://github.com/zhongshaofa/easyadmin/blob/v2/LICENSE)
+
+## 项目介绍
+
+基于ThinkPHP6.0和layui的快速开发的后台管理系统。
+
+技术交流QQ群:[763822524](https://jq.qq.com/?_wv=1027&k=5IHJawE) `加群请备注来源:如gitee、github、官网等`。
+
+## 安装教程
+>EasyAdmin 使用 Composer 来管理项目依赖。因此,在使用 EasyAdmin 之前,请确保你的机器已经安装了 Composer。
+
+#### 通过 Composer 创建项目`建议`
+`composer create-project --prefer-dist zhongshaofa/easyadmin blog`  
+
+#### 通过git下载安装包,composer安装依赖包
+
+```bash
+第一步,下载安装包
+
+git clone https://github.com/zhongshaofa/easyadmin
+或者
+git clone https://gitee.com/zhongshaofa/easyadmin
+
+
+第二步,安装依赖包
+composer install
+
+```
+
+
+
+## 站点地址
+
+* 官方网站:[http://easyadmin.99php.cn](http://easyadmin.99php.cn)
+
+* 文档地址:[http://easyadmin.99php.cn/docs](http://easyadmin.99php.cn/docs)
+
+* 演示地址:[http://easyadmin.99php.cn/admindemo](http://easyadmin.99php.cn/admindemo)(账号:admin,密码:123456。备注:只有查看信息的权限)
+ 
+## 代码仓库
+
+* GitHub地址:[https://github.com/zhongshaofa/easyadmin](https://github.com/zhongshaofa/easyadmin)
+
+* Gitee地址:[https://gitee.com/zhongshaofa/easyadmin](https://gitee.com/zhongshaofa/easyadmin)
+
+
+## 项目特性
+* 快速CURD命令行
+    * 一键生成控制器、模型、视图、JS文件
+    * 支持关联查询、字段设置等等
+* 基于`auth`的权限管理系统
+    * 通过`注解方式`来实现`auth`权限节点管理
+    * 具备一键更新`auth`权限节点,无需手动输入管理
+    * 完善的后端权限验证以及前面页面按钮显示、隐藏控制
+* 完善的菜单管理
+    * 分模块管理
+    * 无限极菜单
+    * 菜单编辑会提示`权限节点`
+* 完善的上传组件功能
+    * 本地存储
+    * 阿里云OSS`建议使用`
+    * 腾讯云COS
+    * 七牛云OSS
+* 完善的前端组件功能
+   * 对layui的form表单重新封装,无需手动拼接数据请求
+   * 简单好用的`图片、文件`上传组件
+   * 简单好用的富文本编辑器`ckeditor`
+   * 对弹出层进行再次封装,以极简的方式使用
+   * 对table表格再次封装,在使用上更加舒服
+   * 根据table的`cols`参数再次进行封装,提供接口实现`image`、`switch`、`list`等功能,再次基础上可以自己再次扩展
+   * 根据table参数一键生成`搜索表单`,无需自己编写
+* 完善的后台操作日志
+   * 记录用户的详细操作信息
+   * 按月份进行`分表记录`
+* 一键部署静态资源到OSS上
+   * 所有在`public\static`目录下的文件都可以一键部署
+   * 一个配置项切换静态资源(oss/本地)
+* 上传文件记录管理
+* 后台路径自定义,防止别人找到对应的后台地址
+
+## 特别感谢
+
+以下项目排名不分先后
+
+* ThinkPHP:[https://github.com/top-think/framework](https://github.com/top-think/framework)
+
+* Layuimini:[https://github.com/zhongshaofa/layuimini](https://github.com/zhongshaofa/layuimini)
+
+* Annotations:[https://github.com/doctrine/annotations](https://github.com/doctrine/annotations)
+
+* Layui:[https://github.com/sentsin/layui](https://github.com/sentsin/layui)
+
+* Jquery:[https://github.com/jquery/jquery](https://github.com/jquery/jquery)
+
+* RequireJs:[https://github.com/requirejs/requirejs](https://github.com/requirejs/requirejs)
+
+* CKEditor:[https://github.com/ckeditor/ckeditor4](https://github.com/ckeditor/ckeditor4)
+
+* Echarts:[https://github.com/apache/incubator-echarts](https://github.com/apache/incubator-echarts)
+ 
+ ## 免责声明
+
+>任何用户在使用`EasyAdmin`后台框架前,请您仔细阅读并透彻理解本声明。您可以选择不使用`EasyAdmin`后台框架,若您一旦使用`EasyAdmin`后台框架,您的使用行为即被视为对本声明全部内容的认可和接受。
+
+* `EasyAdmin`后台框架是一款开源免费的后台快速开发框架 ,主要用于更便捷地开发后台管理;其尊重并保护所有用户的个人隐私权,不窃取任何用户计算机中的信息。更不具备用户数据存储等网络传输功能。
+* 您承诺秉着合法、合理的原则使用`EasyAdmin`后台框架,不利用`EasyAdmin`后台框架进行任何违法、侵害他人合法利益等恶意的行为,亦不将`EasyAdmin`后台框架运用于任何违反我国法律法规的 Web 平台。
+* 任何单位或个人因下载使用`EasyAdmin`后台框架而产生的任何意外、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带或衍生的损失等),本开源项目不承担任何法律责任。
+* 用户明确并同意本声明条款列举的全部内容,对使用`EasyAdmin`后台框架可能存在的风险和相关后果将完全由用户自行承担,本开源项目不承担任何法律责任。
+* 任何单位或个人在阅读本免责声明后,应在《MIT 开源许可证》所允许的范围内进行合法的发布、传播和使用`EasyAdmin`后台框架等行为,若违反本免责声明条款或违反法律法规所造成的法律责任(包括但不限于民事赔偿和刑事责任),由违约者自行承担。
+* 如果本声明的任何部分被认为无效或不可执行,其余部分仍具有完全效力。不可执行的部分声明,并不构成我们放弃执行该声明的权利。
+* 本开源项目有权随时对本声明条款及附件内容进行单方面的变更,并以消息推送、网页公告等方式予以公布,公布后立即自动生效,无需另行单独通知;若您在本声明内容公告变更后继续使用的,表示您已充分阅读、理解并接受修改后的声明内容。
+  
+  
+ ## 捐赠支持
+ 
+开源项目不易,若此项目能得到你的青睐,可以捐赠支持作者持续开发与维护,感谢所有支持开源的朋友。
+
+ ![Image text](https://chung-common.oss-cn-beijing.aliyuncs.com/donate_qrcode.png)

+ 36 - 0
README.en.md

@@ -0,0 +1,36 @@
+# EasyAdmin
+
+#### Description
+{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
+
+#### Software Architecture
+Software architecture description
+
+#### Installation
+
+1.  xxxx
+2.  xxxx
+3.  xxxx
+
+#### Instructions
+
+1.  xxxx
+2.  xxxx
+3.  xxxx
+
+#### Contribution
+
+1.  Fork the repository
+2.  Create Feat_xxx branch
+3.  Commit your code
+4.  Create Pull Request
+
+
+#### Gitee Feature
+
+1.  You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
+2.  Gitee blog [blog.gitee.com](https://blog.gitee.com)
+3.  Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
+4.  The most valuable open source project [GVP](https://gitee.com/gvp)
+5.  The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
+6.  The most popular members  [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+### 数据表修改记录
+
+```mysql
+alter table db_money_log add withdraw_log_id int(11) null COMMENT 'type = 12 退回手续费记录ID' AFTER uid2;
+
+ALTER TABLE db_shop_goods_spec_relation add INDEX index_goods_id(goods_id);
+
+ALTER TABLE db_express_shipping_method add INDEX index_template_id(template_id);
+
+ALTER TABLE db_area add INDEX index_pid(pid);
+
+ALTER TABLE db_shop_category add INDEX index_parent_id(parent_id);
+
+ALTER TABLE db_shop_goods add INDEX index_supplier(supplier);
+
+ALTER TABLE db_shop_order_goods add INDEX goods_id(goods_id);
+ALTER TABLE db_shop_order_goods add INDEX goods_category(goods_category);
+ALTER TABLE db_shop_order_goods add INDEX goods_spec_id(goods_spec_id);
+```

+ 1 - 0
app/.htaccess

@@ -0,0 +1 @@
+deny from all

+ 94 - 0
app/BaseController.php

@@ -0,0 +1,94 @@
+<?php
+declare (strict_types = 1);
+
+namespace app;
+
+use think\App;
+use think\exception\ValidateException;
+use think\Validate;
+
+/**
+ * 控制器基础类
+ */
+abstract class BaseController
+{
+    /**
+     * Request实例
+     * @var \think\Request
+     */
+    protected $request;
+
+    /**
+     * 应用实例
+     * @var \think\App
+     */
+    protected $app;
+
+    /**
+     * 是否批量验证
+     * @var bool
+     */
+    protected $batchValidate = false;
+
+    /**
+     * 控制器中间件
+     * @var array
+     */
+    protected $middleware = [];
+
+    /**
+     * 构造方法
+     * @access public
+     * @param  App  $app  应用对象
+     */
+    public function __construct(App $app)
+    {
+        $this->app     = $app;
+        $this->request = $this->app->request;
+
+        // 控制器初始化
+        $this->initialize();
+    }
+
+    // 初始化
+    protected function initialize()
+    {}
+
+    /**
+     * 验证数据
+     * @access protected
+     * @param  array        $data     数据
+     * @param  string|array $validate 验证器名或者验证规则数组
+     * @param  array        $message  提示信息
+     * @param  bool         $batch    是否批量验证
+     * @return array|string|true
+     * @throws ValidateException
+     */
+    protected function validate(array $data, $validate, array $message = [], bool $batch = false)
+    {
+        if (is_array($validate)) {
+            $v = new Validate();
+            $v->rule($validate);
+        } else {
+            if (strpos($validate, '.')) {
+                // 支持场景
+                list($validate, $scene) = explode('.', $validate);
+            }
+            $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
+            $v     = new $class();
+            if (!empty($scene)) {
+                $v->scene($scene);
+            }
+        }
+
+        $v->message($message);
+
+        // 是否批量验证
+        if ($batch || $this->batchValidate) {
+            $v->batch(true);
+        }
+
+        return $v->failException(true)->check($data);
+    }
+
+}

+ 58 - 0
app/ExceptionHandle.php

@@ -0,0 +1,58 @@
+<?php
+namespace app;
+
+use think\db\exception\DataNotFoundException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\Handle;
+use think\exception\HttpException;
+use think\exception\HttpResponseException;
+use think\exception\ValidateException;
+use think\Response;
+use Throwable;
+
+/**
+ * 应用异常处理类
+ */
+class ExceptionHandle extends Handle
+{
+    /**
+     * 不需要记录信息(日志)的异常类列表
+     * @var array
+     */
+    protected $ignoreReport = [
+        HttpException::class,
+        HttpResponseException::class,
+        ModelNotFoundException::class,
+        DataNotFoundException::class,
+        ValidateException::class,
+    ];
+
+    /**
+     * 记录异常信息(包括日志或者其它方式记录)
+     *
+     * @access public
+     * @param  Throwable $exception
+     * @return void
+     */
+    public function report(Throwable $exception): void
+    {
+        // 使用内置的方式记录异常日志
+        parent::report($exception);
+    }
+
+    /**
+     * Render an exception into an HTTP response.
+     *
+     * @access public
+     * @param \think\Request   $request
+     * @param Throwable $e
+     * @return Response
+     */
+    public function render($request, Throwable $e): Response
+    {
+        // 添加自定义异常处理机制
+
+        // 其他错误交给系统处理
+        return parent::render($request, $e);
+    }
+}

+ 10 - 0
app/Request.php

@@ -0,0 +1,10 @@
+<?php
+namespace app;
+
+// 应用请求对象类
+class Request extends \think\Request
+{
+
+    protected $filter = ['htmlspecialchars'];
+
+}

+ 38 - 0
app/admin/config/admin.php

@@ -0,0 +1,38 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+return [
+
+    // 不需要验证登录的控制器
+    'no_login_controller' => [
+        'login',
+    ],
+
+    // 不需要验证登录的节点
+    'no_login_node'       => [
+        'login/index',
+        'login/out',
+    ],
+
+    // 不需要验证权限的控制器
+    'no_auth_controller'  => [
+        'ajax',
+        'login',
+        'index',
+    ],
+
+    // 不需要验证权限的节点
+    'no_auth_node'        => [
+        'login/index',
+        'login/out',
+    ],
+];

+ 10 - 0
app/admin/config/app.php

@@ -0,0 +1,10 @@
+<?php
+// +----------------------------------------------------------------------
+// | 应用设置
+// +----------------------------------------------------------------------
+
+use think\facade\Env;
+
+return [
+
+];

+ 30 - 0
app/admin/config/cache.php

@@ -0,0 +1,30 @@
+<?php
+use think\facade\Env;
+
+// +----------------------------------------------------------------------
+// | 缓存设置
+// +----------------------------------------------------------------------
+
+return [
+    // 默认缓存驱动
+    'default' => 'file',
+
+    // 缓存连接方式配置
+    'stores'  => [
+        'file' => [
+            // 驱动方式
+            'type'       => 'File',
+            // 缓存保存目录
+            'path'       => '',
+            // 缓存前缀
+            'prefix'     => '',
+            // 缓存有效期 0表示永久缓存
+            'expire'     => 30,
+            // 缓存标签前缀
+            'tag_prefix' => 'tag:',
+            // 序列化机制 例如 ['serialize', 'unserialize']
+            'serialize'  => [],
+        ],
+        // 更多的缓存连接
+    ],
+];

+ 10 - 0
app/admin/config/console.php

@@ -0,0 +1,10 @@
+<?php
+// +----------------------------------------------------------------------
+// | 控制台配置
+// +----------------------------------------------------------------------
+return [
+    // 指令定义
+    'commands' => [
+        'alioss'    => 'addons\alioss\command\Alioss',
+    ],
+];

+ 19 - 0
app/admin/config/route.php

@@ -0,0 +1,19 @@
+<?php
+// +----------------------------------------------------------------------
+// | 路由设置
+// +----------------------------------------------------------------------
+
+return [
+
+    // 路由中间件
+    'middleware' => [
+
+//        // 后台视图初始化
+//        \app\admin\middleware\ViewInit::class,
+
+        // 检测用户是否登录
+//        \app\admin\middleware\CheckAdmin::class,
+
+
+    ],
+];

+ 185 - 0
app/admin/controller/Ajax.php

@@ -0,0 +1,185 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller;
+
+use app\common\model\SystemUploadfile;
+use app\common\controller\AdminController;
+use app\common\service\MenuService;
+use EasyAdmin\upload\Uploadfile;
+use services\CacheServices;
+use think\db\Query;
+use think\facade\Cache;
+use utils\RedisCache;
+
+class Ajax extends AdminController
+{
+
+    /**
+     * 初始化后台接口地址
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function initAdmin()
+    {
+        $cacheData = Cache::get('initAdmin_' . session('admin.id'));
+        if (!empty($cacheData)) {
+            return json($cacheData);
+        }
+        $menuService = new MenuService(session('admin.id'));
+        $data        = [
+            'logoInfo' => [
+                'title' => sysconfig('site', 'logo_title'),
+                'image' => sysconfig('site', 'logo_image'),
+                'href'  => __url('index/index'),
+            ],
+            'homeInfo' => $menuService->getHomeInfo(),
+            'menuInfo' => $menuService->getMenuTree(),
+        ];
+        Cache::tag('initAdmin')->set('initAdmin_' . session('admin.id'), $data);
+        return json($data);
+    }
+
+    /**
+     * 清理缓存接口
+     */
+    public function clearCache()
+    {
+        CacheServices::clear();
+        RedisCache::keyDel("caches:config*");
+        RedisCache::keyDel("caches:sysconfig*");
+        RedisCache::keyDel("caches:articles*");
+        RedisCache::keyDel("caches:banners*");
+        RedisCache::keyDel("caches:goods*");
+
+        // 其他临时缓存
+        RedisCache::keyDel("caches:temp*");
+        Cache::clear();
+        $this->success('清理缓存成功');
+    }
+
+    /**
+     * 上传文件
+     */
+    public function upload()
+    {
+        $this->checkPostRequest();
+        $data = [
+            'upload_type' => $this->request->post('upload_type'),
+            'file'        => $this->request->file('file'),
+        ];
+
+        $uploadConfig = sysconfig('upload');
+        empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
+        $rule = [
+            'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
+            'file|文件'              => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
+        ];
+
+        $this->validate($data, $rule);
+        try {
+            $upload = Uploadfile::instance()
+                ->setUploadType($data['upload_type'])
+                ->setUploadConfig($uploadConfig)
+                ->setFile($data['file'])
+                ->save();
+        } catch (\Exception $e) {
+            $this->error($e->getMessage() . $e->getLine(). $e->getFile());
+        }
+
+        if ($upload['save'] == true) {
+            $this->success($upload['msg'], ['url' => $upload['url']]);
+        } else {
+            $this->error($upload['msg']);
+        }
+    }
+
+    /**
+     * 上传图片至编辑器
+     * @return \think\response\Json
+     */
+    public function uploadEditor()
+    {
+        $this->checkPostRequest();
+        $data         = [
+            'upload_type' => $this->request->post('upload_type'),
+            'file'        => $this->request->file('upload'),
+        ];
+        $uploadConfig = sysconfig('upload');
+        empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
+        $rule = [
+            'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
+            'file|文件'              => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
+        ];
+        $this->validate($data, $rule);
+        try {
+            $upload = Uploadfile::instance()
+                ->setUploadType($data['upload_type'])
+                ->setUploadConfig($uploadConfig)
+                ->setFile($data['file'])
+                ->save();
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+        if ($upload['save'] == true) {
+            return json([
+                'error'    => [
+                    'message' => '上传成功',
+                    'number'  => 201,
+                ],
+                'fileName' => '',
+                'uploaded' => 1,
+                'url'      => $upload['url'],
+            ]);
+        } else {
+            $this->error($upload['msg']);
+        }
+    }
+
+    /**
+     * 获取上传文件列表
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getUploadFiles()
+    {
+        $get         = $this->request->get();
+        $page        = isset($get['page']) && !empty($get['page']) ? $get['page'] : 1;
+        $limit       = isset($get['limit']) && !empty($get['limit']) ? $get['limit'] : 10;
+        $title       = isset($get['title']) && !empty($get['title']) ? $get['title'] : null;
+        $this->model = new SystemUploadfile();
+        $count       = $this->model
+            ->where(function (Query $query) use ($title) {
+                !empty($title) && $query->where('original_name', 'like', "%{$title}%");
+            })
+            ->count();
+        $list        = $this->model
+            ->where(function (Query $query) use ($title) {
+                !empty($title) && $query->where('original_name', 'like', "%{$title}%");
+            })
+            ->page($page, $limit)
+            ->order($this->sort)
+            ->select();
+        $data        = [
+            'code'  => 0,
+            'msg'   => '',
+            'count' => $count,
+            'data'  => $list,
+        ];
+        return json($data);
+    }
+
+}

+ 136 - 0
app/admin/controller/Index.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace app\admin\controller;
+
+
+use app\admin\logic\PaymentLogic;
+use app\admin\logic\ShopGoodsLogic;
+use app\admin\logic\UserLogic;
+use app\admin\logic\WithdrawLogic;
+use app\common\model\SystemAdmin;
+use app\common\model\SystemQuick;
+use app\common\controller\AdminController;
+use think\App;
+use think\facade\Env;
+
+class Index extends AdminController
+{
+
+    /**
+     * 后台主页
+     * @return string
+     * @throws \Exception
+     */
+    public function index()
+    {
+        return $this->fetch('', [
+            'admin' => session('admin'),
+        ]);
+    }
+
+    /**
+     * 后台欢迎页
+     * @return string
+     * @throws \Exception
+     */
+    public function welcome()
+    {
+        $rechargeTotal = PaymentLogic::getTotal([4,5]);
+        $rechargeTotal = $rechargeTotal>100000? round($rechargeTotal/10000, 2).'万' : $rechargeTotal;
+        $withdrawTotal = WithdrawLogic::getTotal(0);
+        $withdrawTotal = $withdrawTotal>100000? round($withdrawTotal/10000, 2).'万' : $withdrawTotal;
+
+        $counts = [
+            'user_count'=> UserLogic::getCountByTime(0),
+            'goods_count'=> ShopGoodsLogic::getCount(),
+            'recharge_total'=> $rechargeTotal,
+            'withdraw_total'=> $withdrawTotal,
+        ];
+        $quicks = SystemQuick::field('id,title,icon,href')
+            ->where(['status' => 1])
+            ->order('sort')
+            ->limit(8)
+            ->select();
+        $this->assign('quicks', $quicks);
+        $this->assign('counts', $counts);
+        return $this->fetch();
+    }
+
+    /**
+     * 修改管理员信息
+     * @return string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function editAdmin()
+    {
+        $id = session('admin.id');
+        $row = (new SystemAdmin())
+            ->withoutField('password')
+            ->find($id);
+        empty($row) && $this->error('用户信息不存在');
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $this->isDemo && $this->error('演示环境下不允许修改');
+            $rule = [];
+            $this->validate($post, $rule);
+            try {
+                $save = $row
+                    ->allowField(['head_img', 'phone', 'remark', 'update_time'])
+                    ->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * 修改密码
+     * @return string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function editPassword()
+    {
+        $id = session('admin.id');
+        $row = (new SystemAdmin())
+            ->withoutField('password')
+            ->find($id);
+        if (!$row) {
+            $this->error('用户信息不存在');
+        }
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $this->isDemo && $this->error('演示环境下不允许修改');
+            $rule = [
+                'password|登录密码'       => 'require',
+                'password_again|确认密码' => 'require',
+            ];
+            $this->validate($post, $rule);
+            if ($post['password'] != $post['password_again']) {
+                $this->error('两次密码输入不一致');
+            }
+
+            try {
+                $save = $row->save([
+                    'password' => password($post['password']),
+                ]);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            if ($save) {
+                $this->success('保存成功');
+            } else {
+                $this->error('保存失败');
+            }
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+}

+ 100 - 0
app/admin/controller/Login.php

@@ -0,0 +1,100 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller;
+
+
+use app\common\model\SystemAdmin;
+use app\common\controller\AdminController;
+use think\captcha\facade\Captcha;
+use think\facade\Env;
+
+/**
+ * Class Login
+ * @package app\admin\controller
+ */
+class Login extends AdminController
+{
+
+    /**
+     * 初始化方法
+     */
+    public function initialize()
+    {
+        parent::initialize();
+        $action = $this->request->action();
+        if (!empty(session('admin')) && !in_array($action, ['out'])) {
+            $adminModuleName = config('app.admin_alias_name');
+            $this->success('已登录,无需再次登录', [], __url("@{$adminModuleName}"));
+        }
+    }
+
+    /**
+     * 用户登录
+     * @return string
+     * @throws \Exception
+     */
+    public function index()
+    {
+        $captcha = Env::get('easyadmin.captcha', 1);
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $rule = [
+                'username|用户名'      => 'require',
+                'password|密码'       => 'require',
+                'keep_login|是否保持登录' => 'require',
+            ];
+            $captcha == 1 && $rule['captcha|验证码'] = 'require|captcha';
+            $this->validate($post, $rule);
+            $admin = SystemAdmin::where(['username' => $post['username']])->find();
+            if (empty($admin)) {
+                $this->error('用户不存在');
+            }
+
+            if (password($post['password']) != $admin->password) {
+                $this->error('密码输入有误');
+            }
+            if ($admin->status == 0) {
+                $this->error('账号已被禁用');
+            }
+            $admin->login_num += 1;
+            $admin->save();
+            $admin = $admin->toArray();
+            unset($admin['password']);
+            $admin['expire_time'] = $post['keep_login'] == 1 ? true : time() + 7200;
+            session('admin', $admin);
+            $this->success('登录成功');
+        }
+        $this->assign('captcha', $captcha);
+        $this->assign('demo', $this->isDemo);
+        return $this->fetch();
+    }
+
+    /**
+     * 用户退出
+     * @return mixed
+     */
+    public function out()
+    {
+        session('admin', null);
+        $this->success('退出登录成功');
+    }
+
+    /**
+     * 验证码
+     * @return \think\Response
+     */
+    public function captcha()
+    {
+        return Captcha::create();
+    }
+}

+ 61 - 0
app/admin/controller/box/AppointList.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\admin\controller\box;
+
+
+use app\admin\logic\BoxRecordLogic;
+use app\common\model\BoxRecordModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="魔盒")
+ */
+class AppointList extends AdminController
+{
+
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new BoxRecordModel();
+    }
+
+    use Curd;
+
+    /**
+     * @NodeAnotation(title="预约记录")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = BoxRecordLogic::getList($page, $limit, $where, $this->sort);
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+}
+
+
+

+ 63 - 0
app/admin/controller/box/Box.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace app\admin\controller\box;
+
+
+use app\admin\logic\BoxLogic;
+use app\common\model\BoxModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="魔盒")
+ */
+class Box extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new BoxModel();
+    }
+
+    /**
+     * @NodeAnotation(title="福袋列表")
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = BoxLogic::getList($page, $limit, $where, $this->sort);
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+
+
+
+
+
+
+
+
+}

+ 111 - 0
app/admin/controller/box/HandleBoxAction.php

@@ -0,0 +1,111 @@
+<?php
+
+namespace app\admin\controller\box;
+
+use app\common\model\BoxMidHandleModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\ShopGoodsModel;
+use app\common\model\ThirddataLogModel;
+use app\common\model\ThirddataModel;
+use think\App;
+use think\facade\Db;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="盲盒开奖")
+ */
+class HandleBoxAction extends AdminController
+{
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new BoxMidHandleModel();
+    }
+
+    /**
+     * @NodeAnotation(title="系统自动前置开奖结果")
+     */
+    public function index(){
+
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            $count =    $this->model
+                ->alias('r')
+                ->leftJoin('user u', 'u.id = r.uid')
+                ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
+                ->order('r.box_type desc')
+                ->page($page, $limit)
+                ->count();
+
+            $list = $this->model
+                ->alias('r')
+                ->leftJoin('user u', 'u.id = r.uid')
+                ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income,u.total_appoint_count,u.box10,u.box20,u.box30,u.box40')
+                ->order('r.box_type desc')
+                ->page($page, $limit)
+                ->select()->toArray();
+
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+
+        }
+
+        return $this->fetch();
+    }
+
+    public function updateUserBox(){
+
+        $list = Db::name('box_record')->where('status', 1)->select()->toArray();
+
+        $model = new ShopGoodsModel();
+        foreach ($list as $key=>$val){
+
+            for ($i = 0; $i < $val['num']; $i++){
+                $box_type = rand(0, 4);
+                if ($box_type > 0){
+                    $goods = $model
+                        ->where('box_type', $box_type*10)
+//                    ->field('goods_id,box_type,goods_img,price,goods_name')
+
+                        ->paginate(1)
+                        ->toArray();
+
+                    Db::name('box_mid_handle')->insert([
+                        'status'=>1,
+                        'h_sn'=>createdHandleOrderSn(),
+                        'uid'=>$val['uid'],
+                        'rid'=>$val['id'],
+                        'goods_id'=>$goods['data'][0]['goods_id'],
+                        'create_time'=>sr_getcurtime(time()),
+                        'box_type'=>$box_type*10,
+                        'goods_price'=>$goods['data'][0]['price']
+                    ]);
+
+                }
+
+                // 把记录表改变状态
+                Db::name('box_record')->where('id', '>', 0)->save([
+                   'status'=>2
+                ]);
+
+            }
+
+        }
+    }
+}
+
+
+

+ 187 - 0
app/admin/controller/box/OpenBoxAction.php

@@ -0,0 +1,187 @@
+<?php
+
+namespace app\admin\controller\box;
+
+
+use app\common\model\BoxMidHandleModel;
+use app\common\model\BoxRecordModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\service\BoxRecordService;
+use think\App;
+use think\facade\Db;
+use utils\RedisCache;
+
+/**
+ * 开福袋 by wes
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="盲盒开奖")
+ */
+class OpenBoxAction extends AdminController
+{
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new BoxRecordModel();
+    }
+
+    use Curd;
+
+    /**
+     * @NodeAnotation(title="福袋预约记录")
+     */
+    public function index()
+    {
+
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+
+            list($page, $limit, $where) = $this->buildTableParames();
+            $isMatch = $this->request->get('match', 0);
+            if ($isMatch) {
+                $where['is_set_match'] = 1;
+                $where['box10'] = 1;
+            }
+
+            $list = BoxRecordService::make()->getCatchList($where, $limit);
+            $data = [
+                'code' => 0,
+                'msg' => '获取成功',
+                'count' => isset($list['total']) ? $list['total'] : 0,
+                'data' => isset($list['data']) ? $list['data'] : [],
+            ];
+            return json($data);
+        }
+
+        $totalNum = BoxRecordModel::where('id', '>', 0)->sum('num');
+        $totalCurnum = BoxRecordModel::where('id', '>', 0)
+            ->where('status', 1)
+            ->where('create_time', '>=', date('Y-m-d'))
+            ->sum('num');
+
+        $this->assign('cur_info', [
+            'total_num' => $totalNum,
+            'total_money' => $totalNum * env('boxsetting.ONE_BOX_PRICE'),
+            'total_curnum' => $totalCurnum,
+            'total_curmoney' => $totalCurnum * env('boxsetting.ONE_BOX_PRICE'),
+        ]);
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="手动干预福袋开奖")
+     */
+    public function beforeopen($id)
+    {
+        if ($this->request->isPost()) {
+            $data = $this->request->post();
+            $result = BoxRecordService::make()->setBoxMatch($id, $data);
+            if ($result === true) {
+                $this->success('设置成功');
+            } else {
+                $this->error($result ? $result : '设置失败');
+            }
+        }
+
+        $info = $this->model->where('id', $id)->find();
+        $this->assign('data', $info);
+        return $this->fetch();
+
+    }
+
+    /**
+     * @NodeAnotation(title="系统自动前置开奖结果")
+     */
+    public function beforehandle()
+    {
+
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            $model = new BoxMidHandleModel();
+            $count = $list = $model
+                ->alias('m')
+                ->leftJoin('user u', 'u.id = r.uid')
+                ->field('r.*,u.mobile')
+                ->order('r.num desc')
+                ->page($page, $limit)
+                ->count();
+
+            $list = $this->model
+                ->alias('r')
+                ->leftJoin('user u', 'u.id = r.uid')
+                ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
+                ->order('r.num desc')
+                ->page($page, $limit)
+                ->select()->toArray();
+
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * 设置匹配
+     * @param $id
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function setting($id)
+    {
+        if ($this->request->isAjax()) {
+            $data = $this->request->post();
+            $result = BoxRecordService::make()->setBoxMatch($id, $data);
+            if ($result === true) {
+                $this->success('设置成功');
+            } else {
+                $this->error($result ? $result : '设置失败');
+            }
+        }
+
+        $this->assign('id', $id);
+        return $this->fetch();
+    }
+
+    /**
+     * 手动开奖
+     * @param $id
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function openBox()
+    {
+        $data = $this->request->post();
+        $ids = isset($data['id']) ? $data['id'] : [];
+        $result = BoxRecordService::make()->openBox($ids, $data);
+        if (is_array($result)) {
+            $this->success($result['msg'], $result['data'], '', 10);
+        } else {
+            $this->error($result ? $result : '开奖失败');
+        }
+
+    }
+
+}
+
+
+

+ 231 - 0
app/admin/controller/coupon/Couponarea.php

@@ -0,0 +1,231 @@
+<?php
+
+namespace app\admin\controller\coupon;
+
+
+use app\admin\model\SystemAdmin;
+use app\common\model\CouponAreaModel;
+use app\common\model\CouponPlanModel;
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\ThirddataLogModel;
+use app\common\model\ThirddataModel;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * (业务已取消)
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="消费券分类管理")
+ */
+class Couponarea extends AdminController
+{
+
+
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new CouponAreaModel();
+    }
+
+    use Curd;
+
+    protected $allowModifyFields = [
+        'can_buy',
+        'status'
+    ];
+
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $count = $this->model
+                ->where($where)
+                ->count();
+//            return 11;
+
+//            return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
+            $list = $this->model
+                ->withoutField('password')
+                ->withAttr('buy_time', function ($val, $data){
+                    if (!$val){return '还未配置时间';}
+                    $curdata = json_decode($val);
+                    $cu_data['day'] = sr_getcurtime($curdata->day, 'Y-m-d');
+
+                    $arr_time = $curdata->time;
+                    for ($i = 0; $i < count($arr_time); $i++){
+                        $val1 = $curdata->time[$i];
+                        $key = 'time'.($i+1);
+                        $cu_data[$key] = (sr_getcurtime($val1->start_time, 'H:i:s') . ' - ' . sr_getcurtime($val1->end_time, 'H:i:s'));
+                    }
+
+                    return ($cu_data['day']. '日'. ($cu_data['time1']?('【'.$cu_data['time1'].'】'):'' ). '|'. (isset($cu_data['time2'])?('【'.$cu_data['time2'].'】'):''). '|' .(isset($cu_data['time3'])?('【'.$cu_data['time3'].'】'):''));
+                })
+                ->where($where)
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()){
+            $row = request()->post();
+            $row['create_time'] = sr_getcurtime(time());
+            unset($row['file']);
+            $modelplan = new CouponPlanModel();
+            Db::startTrans();
+            try {
+                $a_id = $this->model->insertGetId($row);
+                $modelplan->insert([
+                   'area_id'=>$a_id,
+                    'target_num'=>$row['begin_num'],
+                    'create_time'=>sr_getcurtime(time()),
+                    'less_num'=>$row['begin_num'],
+                    'buy_least'=>10,
+                    'buy_most'=>1000
+                ]);
+                Db::commit();
+            }catch (\Exception $e){
+                Db::rollback();
+                $this->error('添加失败'. $e->getMessage());
+
+            }
+            $this->success('添加成功');
+        }
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="修改")
+     */
+    public function edit ($id)
+    {
+        $row = $this->model->find($id);
+
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [];
+            $this->validate($post, $rule);
+            try {
+                if (!empty($post['content'])) {
+                    $post['content'] = htmlspecialchars_decode($post['content']);
+                }
+                $save = $row->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="配置时间")
+     */
+    public function addtime($id){
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $day = strtotime($post['day']);
+            $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
+            $endToday=mktime(24,0,0,date('m'),date('d'),date('Y'));
+            $is_today = false;
+            if ($beginToday<=$day && $endToday>$day){
+                $is_today = true;
+            }
+
+            $timearr = [];
+
+            if ($post['time1']){
+                $arrtime1 = explode(' - ', $post['time1']);
+//                sr_log('aaa'.$post['day'].' '. $arrtime1[0]);
+                $arrtime1 = [strtotime($post['day'].' '. $arrtime1[0]), strtotime($post['day'].' '. $arrtime1[1])];
+                array_push($timearr, ['start_time' => $arrtime1[0], 'end_time' => $arrtime1[1]]);
+            }
+
+            if ($post['time2']){
+                $arrtime2 = explode(' - ', $post['time2']);
+                $arrtime2 = [strtotime($post['day'].' '.$arrtime2[0]), strtotime($post['day'].' '.$arrtime2[1])];
+                array_push($timearr, ['start_time' => $arrtime2[0], 'end_time' => $arrtime2[1]]);
+            }
+
+            if ($post['time3']){
+                $arrtime3 = explode(' - ', $post['time3']);
+                $arrtime3 = [strtotime($post['day'].' '.$arrtime3[0]), strtotime($post['day'].' '.$arrtime3[1])];
+                array_push($timearr, ['start_time' => $arrtime3[0], 'end_time' => $arrtime3[1]]);
+            }
+            if (count($timearr) == 0){
+                $this->error('请选择时间段');
+            }
+
+            foreach ($timearr as $key=>$value){
+                if ($timearr[$key]['start_time'] > $timearr[$key]['end_time']){
+                    $this->error('时间段开始时间比如小于结束时间');
+                }
+            }
+
+            if (!compareDate($timearr)){
+                $this->error('时间段交叉,保存失败');
+            }
+
+            try {
+
+                $save = $row->save([
+                    'buy_time' => json_encode(['day'=>$day, 'time'=>$timearr]),
+                    'is_today'=>($is_today?1:0)
+                ]);
+
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+
+        }
+
+        $curdata = json_decode($row['buy_time']);
+
+        if ($curdata){
+            $cu_data['day'] = sr_getcurtime($curdata->day, 'Y-m-d');
+
+            $arr_time = $curdata->time;
+//        dd($arr_time);
+            for ($i = 0; $i < count($arr_time); $i++){
+                $val = $curdata->time[$i];
+                $key = 'time'.($i+1);
+                $cu_data[$key] = (sr_getcurtime($val->start_time, 'H:i:s') . ' - ' . sr_getcurtime($val->end_time, 'H:i:s'));
+            }
+            $this->assign('row', $cu_data);
+        }
+
+        return $this->fetch();
+    }
+
+
+}

+ 202 - 0
app/admin/controller/coupon/Couponplan.php

@@ -0,0 +1,202 @@
+<?php
+
+
+namespace app\admin\controller\coupon;
+
+
+use app\admin\model\SystemAdmin;
+use app\common\model\CouponAreaModel;
+use app\common\model\CouponPlanModel;
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\ThirddataLogModel;
+use app\common\model\ThirddataModel;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**(业务已取消)
+ * (业务已取消)
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="消费券计划管理")
+ */
+class Couponplan extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new CouponPlanModel();
+    }
+
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $count = $this->model
+                ->withJoin('area', 'LEFT')
+                ->where($where)
+                ->count();
+
+//            return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
+            $list = $this->model
+//                ->withoutField('password')
+//                ->withAttr('buy_time', function ($val, $data){
+//                    $dataval = json_decode($val);
+//                    if (!$dataval){
+//                        return '全天时间段';
+//                    }else{
+//                        $time = '';
+//                        foreach ($data as $k=>$v){
+//                            $time .= '每天'.$v['start'].'到'.$v['end'];
+//                        }
+//                        return $time;
+//                    }
+//
+//                })
+                ->withJoin('area', 'LEFT')
+                ->where($where)
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+//    /**
+//     * @NodeAnotation(title="添加")
+//     */
+//    public function add()
+//    {
+//        if ($this->request->isAjax()){
+//            $row = request()->post();
+//            $row['create_time'] = sr_getcurtime(time());
+//            unset($row['file']);
+//            $modelplan = new CouponPlanModel();
+//            Db::startTrans();
+//            try {
+//                $a_id = $this->model->insertGetId($row);
+//                $modelplan->insert([
+//                    'area_id'=>$a_id,
+//                    'target_num'=>$row['begin_num'],
+//                    'create_time'=>sr_getcurtime(time()),
+//                    'buy_least'=>1,
+//                    'buy_most'=>1000
+//                ]);
+//                Db::commit();
+//            }catch (\Exception $e){
+//                $this->error('添加失败'. $e->getMessage());
+//                Db::rollback();
+//            }
+//            $this->success('添加成功');
+//        }
+//
+//        return $this->fetch();
+//    }
+
+    /**
+     * @NodeAnotation(title="爆仓")
+     */
+    public function baocang($id){
+        if ($this->request->isAjax()){
+
+            Db::startTrans();
+            try {
+                $this->model->baocang($id);
+                Db::commit();
+            }catch (\Exception $e){
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+        }
+        $this->success('成功');
+    }
+
+    /**
+     * @NodeAnotation(title="发放")
+     */
+    public function fafang($id){
+        if ($this->request->isAjax()){
+
+            // 1 代表小数点后面几位   .代表小数点跟正数分割的字符    ,这个是千位的 分割
+//            return number_format(444567.24, 1, '.', ',');
+            Db::startTrans();
+            try {
+                $this->model->fafang($id);
+                Db::commit();
+            }catch (\Exception $e){
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+        }
+        $this->success('发放成功');
+    }
+
+    /**
+     * @NodeAnotation(title="修改目标值")
+     */
+    public function edittarget($id){
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $plan_info = $this->model->where('id', $post['id'])->findOrEmpty();
+
+            $target = $post['target'];
+
+            if (intval($target) < 10){
+                $this->error('输入目标金额错误');
+            }
+
+            if (intval($target)%10 != 0){
+                $this->error('输入必须是10的整数倍');
+            }
+
+            empty($plan_info) && $this->error('信息不存在');
+            if ($plan_info['status'] != 0){
+                $this->error('状态错误,请刷新数据');
+            }
+
+            $this->model->startTrans();
+            try {
+                $this->model->where('id', $post['id'])->save(['target_num'=>$target]);
+                $this->model->where('id', $post['id'])->save(['less_num'=>$target-$plan_info['cur_num']]);
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+
+        $info = Db::name('coupon_plan')->where('id', $id)->find();
+        $this->assign('info', $info);
+        $area_info = Db::name('coupon_area')->where('id', $info['area_id'])->find();
+        $this->assign('info', $info);
+        $this->assign('areainfo', $area_info);
+        return $this->fetch();
+    }
+
+
+
+
+
+
+}

+ 74 - 0
app/admin/controller/coupon/Couponplanbuylog.php

@@ -0,0 +1,74 @@
+<?php
+
+
+namespace app\admin\controller\coupon;
+
+
+use app\admin\model\SystemAdmin;
+use app\common\model\CouponAreaModel;
+use app\common\model\CouponPlanLogModel;
+use app\common\model\CouponPlanModel;
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\ThirddataLogModel;
+use app\common\model\ThirddataModel;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * (业务已取消)
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="消费券购买列表")
+ */
+class Couponplanbuylog extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new CouponPlanLogModel();
+    }
+
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $count = $this->model
+                ->withJoin(['area', 'plan', 'user'], 'LEFT')
+                ->where($where)
+                ->count();
+
+
+            $list = $this->model
+                ->withJoin(['area', 'plan', 'user'], 'LEFT')
+                ->where($where)
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+
+
+
+}

+ 46 - 0
app/admin/controller/informational/CouponData.php

@@ -0,0 +1,46 @@
+<?php
+
+
+namespace app\admin\controller\informational;
+
+
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * (业务已取消)
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="商品分类管理")
+ */
+class CouponData extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ShopCategory();
+    }
+
+    public function index(){
+
+        $score = Db::name('user')->where('id', 'not in', [7493267, 7493266])->where('user_type', 'not in', [4])->sum('score');
+        $this->assign('score', $score);
+
+        $chizi = Db::name('coupon_plan_log')->where('state', 1)->where('uid', 'not in', [7493267,7493266])->sum('buy_num');
+        $this->assign('chizi', $chizi);
+
+        return $this->fetch();
+    }
+
+
+
+}

+ 93 - 0
app/admin/controller/informational/Xzlog.php

@@ -0,0 +1,93 @@
+<?php
+
+
+namespace app\admin\controller\informational;
+
+
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\WithDrawLogModel;
+use app\common\model\XzLogModel;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * (业务已取消)
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="星钻转赠记录")
+ */
+class Xzlog extends AdminController
+{
+
+
+    use Curd;
+
+    public function __construct (App $app, XzLogModel $model)
+    {
+        parent::__construct($app);
+        $this->model = $model;
+    }
+
+
+    /**
+     * 提现列表
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            foreach ($where as $key=>$val){
+                if ($val[0] == 'status'){
+                    $where[$key][0] = 'o.status';
+                }
+                if ($val[0] == 'create_at'){
+                    $where[$key][0] = 'create_at';
+                    $where[$key][2] = sr_getcurtime($where[$key][2]);
+                }
+
+            }
+
+            $count = $this->model
+                ->where('type', 'in',[6])
+                ->withJoin('user', 'INNER')
+                ->where($this->user_map)
+                ->where($where)
+                ->count();
+            $list = $this->model
+                ->where('type', 'in',[6])
+                ->withJoin('user', 'INNER')
+                ->where($this->user_map)
+                ->where($where)
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            foreach ($list as $key=>$val){
+                $list[$key]['mobile2'] = Db::name('user')->where('id', $val['uid2'])->value('mobile');
+            }
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+
+}

+ 61 - 0
app/admin/controller/informational/Yesterdaydata.php

@@ -0,0 +1,61 @@
+<?php
+
+
+namespace app\admin\controller\informational;
+
+
+use app\admin\logic\PaymentLogic;
+use app\admin\logic\UserLogic;
+use app\admin\logic\WithdrawLogic;
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="昨日数据管理")
+ */
+class Yesterdaydata extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+    }
+
+    /**
+     * @NodeAnotation(title="后台数据列表")
+     */
+    public function index(){
+        $yesterdayDate = sr_getcurtime(time()-86400, 'Y-m-d');
+        $day = sr_getcurtime(time(), 'Y-m-d');
+        $res = [
+            // 昨日数据
+            'yesterday'=>sr_getcurtime(time()-86400, 'Y年-m月-d日'),
+            'yesterday_register'=> UserLogic::getCountByTime($yesterdayDate),
+            'yesterday_recharge'=> PaymentLogic::getTotal([4,5], $yesterdayDate),
+            'yesterday_withdraw'=> WithdrawLogic::getTotal($yesterdayDate),
+
+            // 今日数据
+            'today'=>sr_getcurtime(time(), 'Y年-m月-d日'),
+            'today_register'=> UserLogic::getCountByTime($day),
+            'today_recharge'=> PaymentLogic::getTotal([4,5], $day),
+            'today_withdraw'=> WithdrawLogic::getTotal($day),
+
+        ];
+
+        $this->assign('res', $res);
+        return $this->fetch();
+    }
+
+
+
+}

+ 31 - 0
app/admin/controller/mall/Cate.php

@@ -0,0 +1,31 @@
+<?php
+
+
+namespace app\admin\controller\mall;
+
+
+use app\common\model\ShopCategory;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\Model;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="商品分类管理")
+ */
+class Cate extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ShopCategory();
+    }
+
+}

+ 27 - 0
app/admin/controller/mall/Express.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="express")
+ */
+class Express extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\Express();
+        
+    }
+
+    
+}

+ 49 - 0
app/admin/controller/mall/ExpressDelivery.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\common\command\Tree;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+
+/**
+ * @ControllerAnnotation(title="express_delivery")
+ */
+class ExpressDelivery extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ExpressDelivery();
+
+    }
+
+    public function add ()
+    {
+        if ($this->request->isAjax()) {
+            $data = $this->request->post();
+            return $this->model->saveExpress($data);
+        }
+        return $this->fetch();
+    }
+
+    public function edit ($id)
+    {
+        $data = $this->model->where(['id' => $id])->findOrEmpty()->toArray();
+        $items = Db::name('express_shipping_method')->where(['template_id' => $data['id']])->select()->toArray();
+        $this->assign('data', $data);
+        $this->assign('items', $items);
+        if ($this->request->isAjax()) {
+            $data = $this->request->post();
+            return $this->model->saveExpress($data);
+        }
+        return $this->fetch();
+    }
+}

+ 256 - 0
app/admin/controller/mall/Goods.php

@@ -0,0 +1,256 @@
+<?php
+
+
+namespace app\admin\controller\mall;
+
+use app\admin\logic\ShopGoodsLogic;
+use app\admin\logic\ShopGoodsSpecLogic;
+use app\admin\logic\ShopGoodsSpecTypeLogic;
+use app\admin\logic\ShopGoodsTypeLogic;
+use app\admin\logic\ShopHotKeywordsLogic;
+use app\admin\logic\ShopSupplierLogic;
+use app\admin\model\dao\ShopGoodsSpecRelation;
+use app\admin\model\dao\ShopGoodsSpecType;
+use app\common\model\ShopGoods as ShopGoods;
+use app\common\model\ShopGoodsSpec;
+use app\admin\traits\Curd;
+use app\common\command\Tree;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use app\common\model\ShopGoodsSpecType as Spec;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * Class Goods
+ * @package app\admin\controller\mall
+ * @ControllerAnnotation(title="商城商品管理")
+ */
+class Goods extends AdminController
+{
+
+    use Curd;
+
+    protected $relationSearch = true;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ShopGoods();
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+
+            list($count, $list) = ShopGoodsLogic::getList($page, $limit, $where);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    public function goodsBase($id)
+    {
+        list($data, $hot_keywords, $shop_goods_type, $shop_supplier, $specAttrId) = ShopGoodsLogic::getGoodsBase($id);
+
+        $this->assign('shop_goods_type', $shop_goods_type);
+        $this->assign('box_type', system_box_typesetting());
+        $this->assign('hot_keywords', $hot_keywords);
+        $this->assign('shop_supplier', $shop_supplier);
+        $this->assign('specAttrId', $specAttrId);
+        $this->assign('data', $data);
+    }
+
+
+    /**
+     * @param $goodsId
+     * @param $attriId
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * 获取商品规格,商品sku
+     */
+    public function getGoodsSpecData($goodsId, $attriId)
+    {
+        if ($this->request->isAjax()) {
+            $specRelation = ShopGoodsSpecRelation::getArrListByGoodsId($goodsId);
+            $specAttrId   = ShopGoodsSpecType::getPidById($specRelation[0]['spec_id']);
+            $specType     = ShopGoodsSpecTypeLogic::getCacheList();
+
+            $specType    = app()->make(Tree::class)->DeepTree($specType, 'child');
+            $specTypeArr = [];
+            foreach ($specType as $k => $v) {
+                if ($v['id'] == $specAttrId) {
+                    if (isset($v['child']))
+                        $specTypeArr = $v['child'];
+                }
+            }
+
+            $specRelationArr = array_reduce($specRelation, function ($result, $value) {
+                return array_merge($result,
+                    array_values(json_decode($value['spec_value'], true)));
+            }, array());
+
+            $specRelationArr = array_column($specRelationArr, 'id');
+            foreach ($specTypeArr as $k => &$v) {
+                if (isset($v['child'])) {
+                    foreach ($v['child'] as $ck => &$cv) {
+                        if (in_array($cv['id'], $specRelationArr)) {
+                            $cv['checked'] = true;
+                        } else {
+                            $cv['checked'] = false;
+                        }
+                    }
+                }
+            }
+
+            $goodsSkuArr = [];
+            $goodsSku    = ShopGoodsSpecLogic::getGoodsSpecByGoodId($goodsId);
+            foreach ($goodsSku as $sk => $sv) {
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][picture]']      = $sv['picture'];
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][price]']        = $sv['price'];
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][cost_price]']   = $sv['cost_price'];
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][weight]']       = $sv['weight'];
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][stock]']        = $sv['stock'];
+                $goodsSkuArr['skus[' . $sv['spec_ids'] . '][rebate_score]'] = $sv['rebate_score'];
+            }
+
+            $data = [
+                'code' => 0,
+                'msg'  => '',
+                'spec' => $specTypeArr,
+                'sku'  => $goodsSkuArr
+            ];
+            return json($data);
+        }
+    }
+
+    /**
+     * @NodeAnotation(title="商品添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()) {
+            $goods = $this->request->post();
+            Db::startTrans();
+            try {
+                if (!isset($goods['is_exist_many_spec'])) {
+                    ShopGoods::singleSpecGoods($goods);
+                } else {
+                    ShopGoods::manySpecGoods($goods);
+                }
+                Db::commit();
+
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            $this->success('成功');
+        }
+        $hot_keywords  = ShopHotKeywordsLogic::getCacheList();
+        $shop_supplier = ShopSupplierLogic::getCacheList();
+        $this->assign('hot_keywords', $hot_keywords);
+        $this->assign('shop_supplier', $shop_supplier);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="商品编辑")
+     */
+    public function edit($id)
+    {
+        if ($this->request->isAjax()) {
+            $goods = $this->request->post();
+            Db::startTrans();
+            try {
+                if (!isset($goods['is_exist_many_spec'])) {
+                    ShopGoods::singleSpecGoods($goods);
+                } else {
+                    ShopGoods::manySpecGoods($goods);
+                }
+                Db::commit();
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            $this->success('保存成功');
+        }
+        $this->goodsBase($id);
+        return $this->fetch();
+    }
+
+
+    public function copy($id)
+    {
+        if ($this->request->isAjax()) {
+            $goods = $this->request->post();
+            Db::startTrans();
+            try {
+                if (!isset($goods['is_exist_many_spec'])) {
+                    ShopGoods::singleSpecGoods($goods);
+                } else {
+                    ShopGoods::manySpecGoods($goods);
+                }
+                Db::commit();
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            $this->success('保存成功');
+        }
+        $this->goodsBase($id);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="入库")
+     */
+    public function stock($id)
+    {
+        $sku = ShopGoodsSpecLogic::getGoodsSpecByGoodId($id);
+        $this->assign('sku', $sku);
+
+        if ($this->request->isAjax()) {
+            $data = $this->request->post();
+            if (empty($data['goods_id'])) {
+                return json(['code' => 0, 'msg' => '参数错误']);
+            }
+            unset($data['goods_id']);
+            $stock = [];
+            foreach ($data as $k => $v) {
+                $stock[] = [
+                    'goods_spec_id' => explode('_', $k)[1],
+                    'stock'         => $v
+                ];
+            }
+            $ShopGoodsSpec = new ShopGoodsSpec();
+            $flag          = $ShopGoodsSpec->saveAll($stock);
+
+            return $flag ? json(['code' => 1, 'msg' => '保存成功']) :
+                json(['code' => 0, 'msg' => '保存失败']);
+        }
+        return $this->fetch();
+    }
+
+}

+ 55 - 0
app/admin/controller/mall/GoodsBuyType.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace app\admin\controller\mall;
+
+
+use app\common\model\ShopCategory;
+use app\common\model\ShopGoodsTypeModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\GoodsBuyType
+ * @ControllerAnnotation(title="商品类型管理")
+ */
+class GoodsBuyType extends AdminController
+{
+
+//    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ShopGoodsTypeModel();
+    }
+
+    /**
+     * @NodeAnotation(title="商品类型")
+     */
+    public function index()
+    {
+
+        $list = $this->model
+            ->where('status', 1)
+            ->field('id,name')
+            ->select()
+            ->toArray();
+        $this->success('成功', $list);
+    }
+
+    /**
+     * @NodeAnotation(title="福袋类型")
+     */
+    public function boxouttype(){
+        $this->success('成功', system_box_typesetting());
+    }
+
+
+}

+ 33 - 0
app/admin/controller/mall/GoodsMenu.php

@@ -0,0 +1,33 @@
+<?php
+
+
+namespace app\admin\controller\mall;
+
+
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\ShopGoodsMenu;
+use app\common\model\ShopGoodsMenuModel;
+use app\common\model\ShopGoodsModel;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\Model;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\mall
+ * @ControllerAnnotation(title="商品分类管理")
+ */
+class GoodsMenu extends AdminController
+{
+
+    use Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ShopGoodsMenuModel();
+    }
+
+}

+ 157 - 0
app/admin/controller/mall/GoodsSpecType.php

@@ -0,0 +1,157 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\admin\logic\ShopGoodsSpecTypeLogic;
+use app\common\command\Tree;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\mall
+ * @ControllerAnnotation(title="商品规格管理")
+ */
+class GoodsSpecType extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ShopGoodsSpecType();
+
+    }
+    /**
+     * @NodeAnotation(title="规格列表")
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where['pid'] = 0;
+
+            list($count, $list) = ShopGoodsSpecTypeLogic::getList($page, $limit, $where, $this->sort);
+
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="规格获取")
+     */
+    public function getSpec ()
+    {
+        if ($this->request->isAjax()) {
+            $data = ShopGoodsSpecTypeLogic::getTopList();
+
+            $data = [
+                'code' => 1,
+                'msg' => '',
+                'data' => $data,
+            ];
+            return json($data);
+        }
+    }
+
+    public function getSpecItems ()
+    {
+        if ($this->request->isAjax()) {
+            $id = $this->request->post('id');
+            $data = $this->model->select()->toArray();
+            $data = app()->make(Tree::class)->DeepTree($data, 'child');
+            $spec = [];
+            foreach ($data as $k => $v) {
+                if ($v['id'] == $id) {
+                    $spec = isset($v['child']) ? $v['child'] : [];
+                }
+            }
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'data' => $spec,
+            ];
+            return json($data);
+        }
+    }
+
+    public function Spec ($id)
+    {
+        if ($id == 1) {
+            exit('<h1 style="color:red">默认单规格属性无法编辑规格</h1>');
+        }
+        $data = $this->model->select()->toArray();
+        $data = app()->make(Tree::class)->DeepTree($data);
+        $spec = [];
+        foreach ($data as $k => $v) {
+            if ($v['id'] == $id) {
+                if (isset($v['children']))
+                    $spec = $v['children'];
+            }
+        }
+        $this->assign('spec', $spec);
+        return $this->fetch();
+    }
+
+    public function addSpec ()
+    {
+        if ($this->request->isAjax()) {
+            $pid = $this->request->post('pid');
+            $spec = $this->request->post('spec');
+            $row = ['pid' => $pid, 'title' => $spec, 'created_time' => date('y-m-d H:i:s', time())];
+            $flag = $this->model->save($row);
+            $flag ? $this->success('添加成功', ['id' => $this->model->id]) : $this->success('添加失败');
+        }
+    }
+
+    public function delSpec ($id)
+    {
+        if ($this->request->isAjax()) {
+            $id = $this->request->post('id');
+            $flag = $this->model->where(['pid' => $id])->whereOr(['id' => $id])->delete();
+            $flag ? $this->success('删除成功') : $this->success('删除失败');
+        }
+    }
+
+    public function addSpecItems ()
+    {
+        if ($this->request->isAjax()) {
+            $pid = $this->request->post('pid');
+            $data = $this->request->post('value');
+            $arr = [];
+            foreach ($data as $k => &$v) {
+                $arr[$k]['created_time'] = date('Y-m-d H:i:s', time());
+                $arr[$k]['pid'] = $pid;
+                $arr[$k]['title'] = $v;
+            }
+            $flag = $this->model->saveAll($arr);
+            $flag ? $this->success('添加成功') : $this->success('添加失败');
+        }
+    }
+
+    public function delSpecItems ($id)
+    {
+        if ($this->request->isAjax()) {
+            $id = $this->request->post('id');
+            $flag = $this->model->where(['id' => $id])->delete();
+            $flag ? $this->success('删除成功') : $this->success('删除失败');
+        }
+    }
+
+}

+ 27 - 0
app/admin/controller/mall/ShopBuynote.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="shop_buynote")
+ */
+class ShopBuynote extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ShopBuynote();
+        
+    }
+
+    
+}

+ 26 - 0
app/admin/controller/mall/ShopHotKeywords.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\admin\logic\ShopHotKeywordsLogic;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="shop_hot_keywords")
+ */
+class ShopHotKeywords extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ShopHotKeywords();
+    }
+
+}

+ 198 - 0
app/admin/controller/mall/ShopOrder.php

@@ -0,0 +1,198 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\admin\logic\ShopOrderLogic;
+use app\common\controller\AdminController;
+use app\validate\admin\mall\shopOrder\EditStatus;
+use app\validate\admin\user\user\PhoneSet;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+use think\exception\ValidateException;
+use think\facade\Db;
+use app\admin\model\dao\ShopOrder as ShopOrderDao;
+
+/**
+ * @ControllerAnnotation(title="shop_order")
+ */
+class ShopOrder extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ShopOrder();
+
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = ShopOrderLogic::getList($page, $limit, $where);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="修改备注")
+     */
+    public function editdesc($id)
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $row  = $this->model->where('order_id', $id)->find();
+            empty($row) && $this->error('取消失败');
+
+            $row->order_remark = $post['error_text'];
+
+
+            Db::startTrans();
+            try {
+
+                $row->save();
+                Db::commit();
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->error('设置失败' . $e->getMessage());
+            }
+            $this->success('设置成功');
+        }
+
+        $row = ShopOrderDao::getOrderById($id);
+        $this->assign('info', $row);
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="修改订单状态")
+     */
+    public function editstatus($id)
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+
+            try {
+                validate(EditStatus::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $result = ShopOrderLogic::editStatus($post['id'], $post['status']);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('修改订单状态成功');
+        }
+
+        $row               = $this->model->where('order_id', $id)->find();
+        $row['status_map'] = ShopOrderLogic::getStatusMap();
+        $this->assign('info', $row);
+
+        return $this->fetch('editstatus');
+    }
+
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function details($orderId)
+    {
+        $order = $this->model->where(['order_id' => $orderId])->with(['user', 'goods', 'shipping'])->find()->toArray();
+
+        if ($order['status'] == 5 || $order['status'] == 6) {
+            // 新的地址
+            $ygOrderInfo                       = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
+            $newAddress_info                   = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
+            $order['shipping']['sp_id']        = 99999;
+            $order['shipping']['sp_mobile']    = $newAddress_info['mobile'];
+            $order['shipping']['sp_name']      = $newAddress_info['name'];
+            $order['shipping']['sp_mergename'] = $newAddress_info['mergename'];
+        }
+        $this->assign('data', $order);
+        return $this->fetch();
+    }
+
+    /**
+     * 订单配送列表(疑似无效)
+     * @NodeAnotation(title="列表")
+     */
+    public function delivery($orderId)
+    {
+        $express  = Db::name('express')->field('id,name,code')->select()->toArray();
+        $shipping = Db::name('shop_order_shipping')->where(['order_id' => $orderId])->findOrEmpty();
+        $order    = Db::name('shop_order')->where('order_id', $shipping['order_id'])->find();
+        $this->assign('express', $express);
+        if ($order['status'] == 5 || $order['status'] == 6) {
+            // 新的地址
+            $ygOrderInfo              = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
+            $newAddress_info          = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
+            $shipping['sp_id']        = 99999;
+            $shipping['sp_mobile']    = $newAddress_info['mobile'];
+            $shipping['sp_name']      = $newAddress_info['name'];
+            $shipping['sp_mergename'] = $newAddress_info['mergename'];
+        }
+        $this->assign('shipping', $shipping);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 订单配送设置物流信息(疑似无效)
+     * @NodeAnotation(title="列表")
+     */
+    public function deliverySave()
+    {
+        if ($this->request->isPost()) {
+            $data = $this->request->post();
+            if (empty($data['order_id'])) {
+                return json(['code' => 0, 'msg' => '参数错误']);
+            }
+            if (empty($data['ship_number']) || empty($data['ship_name'])) {
+                return json(['code' => 0, 'msg' => '物流信息不能为空']);
+            }
+            $ex = explode('_', $data['ship_name']);
+            // 发货
+            if ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [5])->find()) {
+
+                $res          = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
+                $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
+                Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 3)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 4]);
+
+                // 重新发货
+            } elseif ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [6])->find()) {
+                $res          = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
+                $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
+                Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 4)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number']]);
+
+            } else {
+                $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 2]);
+            }
+
+
+            if (!$res) {
+                return json(['code' => 0, 'msg' => '操作失败']);
+            }
+            return json(['code' => 1, 'msg' => '操作成功']);
+        }
+    }
+}

+ 27 - 0
app/admin/controller/mall/ShopSupplier.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="shop_supplier")
+ */
+class ShopSupplier extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\ShopSupplier();
+        
+    }
+
+    
+}

+ 27 - 0
app/admin/controller/mall/UserAddress.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\controller\mall;
+
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="user_address")
+ */
+class UserAddress extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new \app\common\model\UserAddress();
+        
+    }
+
+    
+}

+ 208 - 0
app/admin/controller/system/Admin.php

@@ -0,0 +1,208 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\admin\logic\SystemAdminLogic;
+use app\common\model\SystemAdmin;
+use app\admin\service\TriggerService;
+use app\common\constants\AdminConstant;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="管理员管理")
+ */
+class Admin extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    protected $sort = [
+        'sort' => 'desc',
+        'id'   => 'desc',
+    ];
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemAdmin();
+        $this->assign('auth_list', $this->model->getAuthList());
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = SystemAdminLogic::getList($page, $limit, $where, $this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $post             = $this->request->post();
+            $authIds          = $this->request->post('auth_ids', []);
+            $post['auth_ids'] = implode(',', array_keys($authIds));
+            $rule             = [];
+            $this->validate($post, $rule);
+            try {
+                $save = $this->model->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="编辑")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isPost()) {
+            $post             = $this->request->post();
+            $authIds          = $this->request->post('auth_ids', []);
+            $post['auth_ids'] = implode(',', array_keys($authIds));
+            $rule             = [];
+            $this->validate($post, $rule);
+            if (isset($row['password'])) {
+                unset($row['password']);
+            }
+            try {
+                $save = $row->save($post);
+                TriggerService::updateMenu($id);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $row->auth_ids = explode(',', $row->auth_ids);
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="编辑")
+     */
+    public function password($id)
+    {
+        $this->checkPostRequest();
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [
+                'password|登录密码'       => 'require',
+                'password_again|确认密码' => 'require',
+            ];
+            $this->validate($post, $rule);
+            if ($post['password'] != $post['password_again']) {
+                $this->error('两次密码输入不一致');
+            }
+            try {
+                $save = $row->save([
+                    'password' => password($post['password']),
+                ]);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $row->auth_ids = explode(',', $row->auth_ids);
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="删除")
+     */
+    public function delete($id)
+    {
+        $this->checkPostRequest();
+        $row = $this->model->whereIn('id', $id)->select();
+        $row->isEmpty() && $this->error('数据不存在');
+        $id == AdminConstant::SUPER_ADMIN_ID && $this->error('超级管理员不允许修改');
+        if (is_array($id)) {
+            if (in_array(AdminConstant::SUPER_ADMIN_ID, $id)) {
+                $this->error('超级管理员不允许修改');
+            }
+        }
+        try {
+            $save = $row->delete();
+        } catch (\Exception $e) {
+            $this->error('删除失败');
+        }
+        $save ? $this->success('删除成功') : $this->error('删除失败');
+    }
+
+    /**
+     * @NodeAnotation(title="属性修改")
+     */
+    public function modify()
+    {
+        $this->checkPostRequest();
+        $post = $this->request->post();
+        $rule = [
+            'id|ID'    => 'require',
+            'field|字段' => 'require',
+            'value|值'  => 'require',
+        ];
+        $this->validate($post, $rule);
+        if (!in_array($post['field'], $this->allowModifyFields)) {
+            $this->error('该字段不允许修改:' . $post['field']);
+        }
+        if ($post['id'] == AdminConstant::SUPER_ADMIN_ID && $post['field'] == 'status') {
+            $this->error('超级管理员状态不允许修改');
+        }
+        $row = $this->model->find($post['id']);
+        empty($row) && $this->error('数据不存在');
+        try {
+            $row->save([
+                $post['field'] => $post['value'],
+            ]);
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+        $this->success('保存成功');
+    }
+
+
+}

+ 108 - 0
app/admin/controller/system/Article.php

@@ -0,0 +1,108 @@
+<?php
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\SystemAdminLogic;
+use app\admin\logic\SystemArticleLogic;
+use app\admin\model\dao\SystemArticle;
+use app\admin\model\dao\SystemArticleType;
+use app\common\controller\AdminController;
+use app\common\model\ArticleTypeModel;
+use app\common\model\CouponPlanModel;
+use app\common\model\SystemArticleModel;
+use app\common\model\SystemBannerModel;
+use app\common\model\UserModel;
+use think\App;
+use think\facade\Db;
+use think\Request;
+
+/**
+ * @ControllerAnnotation(title="系统公告/文章配置")
+ */
+class Article extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new SystemArticleModel();
+
+    }
+
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = SystemArticleLogic::getList($page, $limit, $where, $this->sort);
+
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="修改")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [];
+            $this->validate($post, $rule);
+
+            try {
+                $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
+//                $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
+                $save = $row->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()) {
+            $row = request()->post();
+            list($save, $msg) = SystemArticleLogic::add($row);
+            $save ? $this->success($msg) : $this->error($msg);
+        }
+
+        return $this->fetch();
+    }
+
+
+    public function articleType()
+    {
+        $list  = SystemArticle::getIdNameMapByStatus(1);
+        $this->success('成功', $list);
+
+    }
+
+
+}

+ 91 - 0
app/admin/controller/system/Auth.php

@@ -0,0 +1,91 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\common\model\SystemAuth;
+use app\common\model\SystemAuthNode;
+use app\admin\service\TriggerService;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="角色权限管理")
+ * Class Auth
+ * @package app\admin\controller\system
+ */
+class Auth extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    protected $sort = [
+        'sort' => 'desc',
+        'id'   => 'desc',
+    ];
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemAuth();
+    }
+
+    /**
+     * @NodeAnotation(title="授权")
+     */
+    public function authorize($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $list = $this->model->getAuthorizeNodeListByAdminId($id);
+            $this->success('获取成功', $list);
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="授权保存")
+     */
+    public function saveAuthorize()
+    {
+        $this->checkPostRequest();
+        $id = $this->request->post('id');
+        $node = $this->request->post('node', "[]");
+        $node = json_decode($node, true);
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        try {
+            $authNode = new SystemAuthNode();
+            $authNode->where('auth_id', $id)->delete();
+            if (!empty($node)) {
+                $saveAll = [];
+                foreach ($node as $vo) {
+                    $saveAll[] = [
+                        'auth_id' => $id,
+                        'node_id' => $vo,
+                    ];
+                }
+                $authNode->saveAll($saveAll);
+            }
+            TriggerService::updateMenu();
+        } catch (\Exception $e) {
+            $this->error('保存失败');
+        }
+        $this->success('保存成功');
+    }
+
+}

+ 84 - 0
app/admin/controller/system/Banner.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\SystemBannerLogic;
+use app\common\controller\AdminController;
+use app\common\model\SystemBannerModel;
+use think\App;
+use utils\RedisCache;
+
+/**
+ * @ControllerAnnotation(title="系统banner配置")
+ */
+class Banner extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new SystemBannerModel();
+
+    }
+
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = SystemBannerLogic::getList($page, $limit, $where, $this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="修改")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [];
+            $this->validate($post, $rule);
+            $save = SystemBannerLogic::edit($post);
+            $save === true ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()) {
+            $row  = request()->post();
+            $save = SystemBannerLogic::add($row);
+            $save === true ? $this->success('添加成功') : $this->error('添加失败');
+        }
+
+        return $this->fetch();
+    }
+
+
+}

+ 75 - 0
app/admin/controller/system/Config.php

@@ -0,0 +1,75 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\common\model\SystemConfig;
+use app\admin\service\TriggerService;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use services\CacheServices;
+use think\App;
+use think\facade\Db;
+
+/**
+ * Class Config
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="系统配置管理")
+ */
+class Config extends AdminController
+{
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemConfig();
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+
+        $this->assign('total_renwu', 11);
+        $this->assign('total_shouxu', 22);
+
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="保存")
+     */
+    public function save()
+    {
+        $this->checkPostRequest();
+        $post = $this->request->post();
+        sr_log(json_encode($post));
+        try {
+            foreach ($post as $key => $val) {
+                $this->model
+                    ->where('name', $key)
+                    ->update([
+                        'value' => $val,
+                    ]);
+            }
+            TriggerService::updateMenu();
+            TriggerService::updateSysconfig();
+        } catch (\Exception $e) {
+            $this->error('保存失败');
+        }
+        $this->success('保存成功');
+    }
+
+}

+ 143 - 0
app/admin/controller/system/Faq.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\SystemFaqLogic;
+use app\common\controller\AdminController;
+use app\common\model\SystemFaq;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="system_faq")
+ */
+class Faq extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new SystemFaq();
+
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = SystemFaqLogic::getList($page, $limit, $where, $this->sort);
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="修改")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [];
+            $this->validate($post, $rule);
+            try {
+                if (empty($post['url'])) {
+                    unset($post['url']);
+                }
+                if (!empty($post['content'])) {
+                    $post['content'] = htmlspecialchars_decode($post['content']);
+                }
+                $save = $row->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            try {
+                if ($post['parent_id'] == 1) {
+                    $db = \think\facade\Db::name('system_faq')
+                        ->where(['parent_id' => 1])
+                        ->count();
+                    if ($db >= 5) {
+                        $this->error('保存失败');
+                    }
+                }
+                if (!empty($post['content'])) {
+                    $post['content'] = htmlspecialchars_decode($post['content']);
+                }
+                $save = $this->model->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="删除")
+     */
+    public function delete($id)
+    {
+        $row = $this->model->find($id);
+        if ($row->id == 1) {
+            $this->error('父类常见问题不能删除');
+        }
+        empty($row) && $this->error('数据不存在');
+        try {
+            $save = $row->delete();
+        } catch (\Exception $e) {
+            $this->error('删除失败');
+        }
+        if ($save) {
+            $this->success('删除成功');
+        } else {
+            $this->error('删除失败');
+        }
+    }
+
+
+    /**
+     * @NodeAnotation(title="选择上级")
+     */
+    public function type()
+    {
+        $list = SystemFaqLogic::getTopList();
+        $data = [
+            'code'  => 1,
+            'msg'   => '',
+            'count' => count($list),
+            'data'  => $list,
+        ];
+        return json($data);
+    }
+}

+ 51 - 0
app/admin/controller/system/Log.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\admin\controller\system;
+
+
+use app\admin\logic\SystemLogLogic;
+use app\common\model\SystemLog;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="操作日志管理")
+ * Class Auth
+ * @package app\admin\controller\system
+ */
+class Log extends AdminController
+{
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemLog();
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            [$page, $limit, $where, $excludeFields] = $this->buildTableParames(['month']);
+
+            list($count, $list) = SystemLogLogic::getList($page, $limit, $where, $excludeFields, $this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+}

+ 205 - 0
app/admin/controller/system/Menu.php

@@ -0,0 +1,205 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\SystemMenuLogic;
+use app\common\model\SystemMenu;
+use app\common\model\SystemNode;
+use app\admin\service\TriggerService;
+use app\common\constants\MenuConstant;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use app\common\controller\AdminController;
+use think\App;
+
+/**
+ * Class Menu
+ * @package app\admin\controller\system
+ * @ControllerAnnotation(title="菜单管理",auth=true)
+ */
+class Menu extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    protected $sort = [
+        'sort' => 'desc',
+        'id'   => 'asc',
+    ];
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemMenu();
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($count, $list) = SystemMenuLogic::getList($this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add($id = null)
+    {
+        $homeId = $this->model
+            ->where([
+                'pid' => MenuConstant::HOME_PID,
+            ])
+            ->value('id');
+        if ($id == $homeId) {
+            $this->error('首页不能添加子菜单');
+        }
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $rule = [
+                'pid|上级菜单'   => 'require',
+                'title|菜单名称' => 'require',
+                'icon|菜单图标'  => 'require',
+            ];
+            $this->validate($post, $rule);
+
+            $result = SystemMenuLogic::add($post);
+            $result === true ? $this->success('保存成功') : $this->error('保存失败');
+
+        }
+        $pidMenuList = $this->model->getPidMenuList();
+        $this->assign('id', $id);
+        $this->assign('pidMenuList', $pidMenuList);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="编辑")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $rule = [
+                'pid|上级菜单'   => 'require',
+                'title|菜单名称' => 'require',
+                'icon|菜单图标'  => 'require',
+            ];
+            $this->validate($post, $rule);
+
+            $result = SystemMenuLogic::edit($id, $post);
+            $result === true ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $pidMenuList = $this->model->getPidMenuList();
+        $this->assign([
+            'id'          => $id,
+            'pidMenuList' => $pidMenuList,
+            'row'         => $row,
+        ]);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="删除")
+     */
+    public function delete($id)
+    {
+        $this->checkPostRequest();
+        $row = $this->model->whereIn('id', $id)->select();
+        empty($row) && $this->error('数据不存在');
+        try {
+            $save = $row->delete();
+        } catch (\Exception $e) {
+            $this->error('删除失败');
+        }
+        if ($save) {
+            TriggerService::updateMenu();
+            $this->success('删除成功');
+        } else {
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * @NodeAnotation(title="属性修改")
+     */
+    public function modify()
+    {
+        $this->checkPostRequest();
+        $post = $this->request->post();
+        $rule = [
+            'id|ID'    => 'require',
+            'field|字段' => 'require',
+            'value|值'  => 'require',
+        ];
+        $this->validate($post, $rule);
+        $row = $this->model->find($post['id']);
+        if (!$row) {
+            $this->error('数据不存在');
+        }
+        if (!in_array($post['field'], $this->allowModifyFields)) {
+            $this->error('该字段不允许修改:' . $post['field']);
+        }
+        $homeId = $this->model
+            ->where([
+                'pid' => MenuConstant::HOME_PID,
+            ])
+            ->value('id');
+        if ($post['id'] == $homeId && $post['field'] == 'status') {
+            $this->error('首页状态不允许关闭');
+        }
+        try {
+            $row->save([
+                $post['field'] => $post['value'],
+            ]);
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+        TriggerService::updateMenu();
+        $this->success('保存成功');
+    }
+
+    /**
+     * @NodeAnotation(title="添加菜单提示")
+     */
+    public function getMenuTips()
+    {
+        $node = input('get.keywords');
+        $list = SystemNode::whereLike('node', "%{$node}%")
+            ->field('node,title')
+            ->limit(10)
+            ->select();
+        return json([
+            'code'    => 0,
+            'content' => $list,
+            'type'    => 'success',
+        ]);
+    }
+
+}

+ 121 - 0
app/admin/controller/system/Node.php

@@ -0,0 +1,121 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\admin\logic\SystemNodeLogic;
+use app\common\model\SystemNode;
+use app\admin\service\TriggerService;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use app\admin\service\NodeService;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="系统节点管理")
+ * Class Node
+ * @package app\admin\controller\system
+ */
+class Node extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemNode();
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+
+            list($count,$list) = SystemNodeLogic::getList();
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="系统节点更新")
+     */
+    public function refreshNode($force = 0)
+    {
+        $this->checkPostRequest();
+        $nodeList = (new NodeService())->getNodelist();
+        empty($nodeList) && $this->error('暂无需要更新的系统节点');
+        $model = new SystemNode();
+        try {
+            if ($force == 1) {
+                $updateNodeList = $model->whereIn('node', array_column($nodeList, 'node'))->select();
+                $formatNodeList = array_format_key($nodeList, 'node');
+                foreach ($updateNodeList as $vo) {
+                    isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->update([
+                        'title'   => $formatNodeList[$vo['node']]['title'],
+                        'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
+                    ]);
+                }
+            }
+            $existNodeList = $model->field('node,title,type,is_auth')->select();
+            foreach ($nodeList as $key => $vo) {
+                foreach ($existNodeList as $v) {
+                    if ($vo['node'] == $v->node) {
+                        unset($nodeList[$key]);
+                        break;
+                    }
+                }
+            }
+            $model->saveAll($nodeList);
+            TriggerService::updateNode();
+        } catch (\Exception $e) {
+            $this->error('节点更新失败');
+        }
+        $this->success('节点更新成功');
+    }
+
+    /**
+     * @NodeAnotation(title="清除失效节点")
+     */
+    public function clearNode()
+    {
+        $this->checkPostRequest();
+        $nodeList = (new NodeService())->getNodelist();
+        $model = new SystemNode();
+        try {
+            $existNodeList = $model->field('id,node,title,type,is_auth')->select()->toArray();
+            $formatNodeList = array_format_key($nodeList, 'node');
+            foreach ($existNodeList as $vo) {
+                !isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->delete();
+            }
+            TriggerService::updateNode();
+        } catch (\Exception $e) {
+            $this->error('节点更新失败');
+        }
+        $this->success('节点更新成功');
+    }
+}

+ 144 - 0
app/admin/controller/system/Payconfig.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\PayConfigLogic;
+use app\admin\logic\SystemFaqLogic;
+use app\common\controller\AdminController;
+use app\common\model\PayConfigModel;
+use app\common\model\SystemFaq;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="支付配置")
+ */
+class Payconfig extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+
+        $this->model = new PayConfigModel();
+
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            list($count, $list) = PayConfigLogic::getList($page, $limit, $where, $this->sort);
+
+            $data  = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="修改")
+     */
+    public function edit($id)
+    {
+        $row = $this->model->find($id);
+        empty($row) && $this->error('数据不存在');
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $rule = [];
+            $this->validate($post, $rule);
+            try {
+                if (empty($post['url'])) {
+                    unset($post['url']);
+                }
+                if (!empty($post['content'])) {
+                    $post['content'] = htmlspecialchars_decode($post['content']);
+                }
+                $save = $row->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        $this->assign('row', $row);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="添加")
+     */
+    public function add()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            try {
+                if ($post['parent_id'] == 1) {
+                    $db = \think\facade\Db::name('system_faq')
+                        ->where(['parent_id' => 1])
+                        ->count();
+                    if ($db >= 5) {
+                        $this->error('保存失败');
+                    }
+                }
+                if (!empty($post['content'])) {
+                    $post['content'] = htmlspecialchars_decode($post['content']);
+                }
+                $save = $this->model->save($post);
+            } catch (\Exception $e) {
+                $this->error('保存失败');
+            }
+            $save ? $this->success('保存成功') : $this->error('保存失败');
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="删除")
+     */
+    public function delete($id)
+    {
+        $row = $this->model->find($id);
+        if ($row->id == 1) {
+            $this->error('父类常见问题不能删除');
+        }
+        empty($row) && $this->error('数据不存在');
+        try {
+            $save = $row->delete();
+        } catch (\Exception $e) {
+            $this->error('删除失败');
+        }
+        if ($save) {
+            $this->success('删除成功');
+        } else {
+            $this->error('删除失败');
+        }
+    }
+
+
+    /**
+     * @NodeAnotation(title="选择上级")
+     */
+    public function type()
+    {
+        $list = SystemFaqLogic::getTopList();
+
+        $data = [
+            'code'  => 1,
+            'msg'   => '',
+            'count' => count($list),
+            'data'  => $list,
+        ];
+        return json($data);
+    }
+}

+ 43 - 0
app/admin/controller/system/Quick.php

@@ -0,0 +1,43 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\common\model\SystemQuick;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="快捷入口管理")
+ * Class Quick
+ * @package app\admin\controller\system
+ */
+class Quick extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    protected $sort = [
+        'sort' => 'desc',
+        'id'   => 'desc',
+    ];
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemQuick();
+    }
+
+}

+ 38 - 0
app/admin/controller/system/Uploadfile.php

@@ -0,0 +1,38 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller\system;
+
+
+use app\common\model\SystemUploadfile;
+use app\common\controller\AdminController;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="上传文件管理")
+ * Class Uploadfile
+ * @package app\admin\controller\system
+ */
+class Uploadfile extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new SystemUploadfile();
+    }
+
+}

+ 52 - 0
app/admin/controller/system/Xzfenhong.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace app\admin\controller\system;
+
+use app\admin\logic\UserteamLogLogic;
+use app\common\controller\AdminController;
+use app\common\model\PayConfigModel;
+use app\common\model\SystemFaq;
+use app\common\model\UserteamLogModel;
+use think\App;
+
+/**
+ * @ControllerAnnotation(title="星钻等级分红")
+ */
+class Xzfenhong extends AdminController
+{
+
+    use \app\admin\traits\Curd;
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+
+
+        $this->model = new UserteamLogModel();
+
+    }
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+//            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            list($count, $list) = UserteamLogLogic::getList($page, $limit, $where, $this->sort);
+
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+
+}

+ 630 - 0
app/admin/controller/user/Recharge.php

@@ -0,0 +1,630 @@
+<?php
+namespace app\admin\controller\user;
+
+use app\common\model\MoneyLog;
+use app\common\model\PaymentModel;
+use app\common\model\RechargeOrderModel;
+use app\common\model\ScoreLog;
+//use app\admin\model\UpgradeLog;
+use app\common\model\ScoreLogModel;
+use app\common\model\User as UserModel;
+use app\common\model\UserData;
+use app\admin\traits\Curd;
+use app\common\constants\AdminConstant;
+use app\common\controller\AdminController;
+use app\common\model\UserMoneyModel;
+use app\common\model\UserteamLogModel;
+use app\Request;
+use EasyAdmin\tool\CommonTool;
+use jianyan\excel\Excel;
+use think\App;
+use think\facade\Db;
+
+
+class Recharge extends AdminController
+{
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+        $this->model = new RechargeOrderModel();
+    }
+
+    protected $sort = [
+        'order_id' => 'desc',
+    ];
+
+    use Curd;
+
+    /**
+     * 充值列表
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+//            if (($pid = $this->request->param('pid')) !== false && $pid)
+//                $where[] = ['pid', '=', $this->request->param('pid', '')];
+
+
+            sr_log(json_encode($where));
+
+            $count = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+//                ->where($this->user_map)
+                ->count();
+            $list = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+//                ->where($this->user_map)
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+
+            $data = [
+                'code' => 0,
+                'msg' => Db::getLastSql(),
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+    public function agree($id){
+        $info = $this->model->where('order_id', $id)->where('status', 3)->find();
+        if (empty($info))
+            $this->error('记录不存在');
+        $user = Db::name('user')->findOrEmpty(['id' => $info['user_id']]);
+        if (empty($user) || $user['status'] != 1)
+            $this->error('用户不存在或已被禁用');
+
+        $paymodel = new PaymentModel();
+//        $pay_info = $paymodel->where('remarks', $info['recharge_sn']);
+
+        $nowTime = date('Y-m-d H:i:s', time());
+
+        $info->save(['status'=>2, 'pay_type'=>19,'updated_time' => $nowTime]);
+
+        edit_user_money(12, $info['user_id'], $info['payment']);
+        $this->success('处理成功');
+
+    }
+
+    public function disagree($id){
+        if ($this->request->isPost()){
+            $post = $this->request->post();
+            $row = $this->model->where('order_id', $id)->where('status', 'in', '3')->find();
+            empty($row) && $this->error('取消失败');
+
+            $row->status = 4;
+            $row->error_text = $post['error_text'];
+
+
+            Db::startTrans();
+            try {
+
+
+
+                $row->save();
+                Db::commit();
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->error('取消失败'.$e->getMessage());
+            }
+            $this->success('取消成功');
+        }
+
+
+        return $this->fetch();
+    }
+
+    /**
+     * 禁用用户
+     * @param $id
+     */
+    public function forbid ($id)
+    {
+        $user = $this->model->findOrEmpty($id);
+        empty($user) && $this->error('数据不存在');
+        $user['status'] == 0 && $this->error('该用户已被禁用');
+        if ($this->model->where('id', $id)->save(['status' => 0]))
+            $this->success('禁用成功');
+        else
+            $this->error('禁用失败');
+    }
+
+    /**
+     * 启用用户
+     * @param $id
+     */
+    public function enable ($id)
+    {
+        $user = $this->model->findOrEmpty($id);
+        empty($user) && $this->error('数据不存在');
+        $user['status'] == 1 && $this->error('该用户已启用');
+        if ($this->model->where('id', $id)->save(['status' => 1]))
+            $this->success('启用成功');
+        else
+            $this->error('启用失败');
+    }
+
+    /**
+     * 会员详情
+     * @param Request $request
+     * @param UpgradeLog $upgradeLog
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function details (Request $request)
+    {
+        $id = $request->param('id');
+        $info = $this->model
+            ->withJoin('userData', 'INNER')
+            ->where('id', $id)
+            ->find()
+            ->toArray();
+//        $upgrade_log = $upgradeLog->where('uid', $id)->order('create_at', 'desc')->select();
+//        $this->assign('upgrade_log', $upgrade_log);
+        $this->assign('info', $info);
+        return $this->fetch();
+    }
+
+
+
+
+
+    /**
+     * 添加用户
+     * @return mixed
+     */
+    public function add ()
+    {
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $mobile = $this->model->where('mobile', $post['mobile'])->value('id');
+            $mobile && $this->error('该手机号码已被注册');
+            $invite = $this->model->where('code|px_code', $post['code'])->value('id');
+            !$invite && $this->error('邀请人不存在');
+            $this->model->startTrans();
+            try {
+                $insert['mobile'] = $post['mobile'];
+                $insert['reg_ip'] = $this->request->ip();
+                $insert['avatar'] = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg';
+                $insert['code'] = create_invite_code();
+                $insert['px_code'] = create_invite_code();
+                $insert['user_type'] = 2;
+                $rz_money = 1.5 + rand(0, 30) / 100;
+                $this->model->save($insert);
+                $uid = $this->model->id;
+                $user_data = new UserData();
+                $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息
+                $this->bindRelation($post['code'], $uid); // 绑定关系
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('添加用户失败');
+            }
+            $this->success('添加成功');
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 邀请页面
+     * @return mixed
+     */
+    public function invite ()
+    {
+        $admin = session('admin');
+        !$admin['user_id'] && $this->error('没有该权限');
+        $user = $this->model->findOrEmpty(['id' => $admin['user_id']]);
+        empty($user) && $this->error('用户信息不存在');
+        $this->assign('user_id', encode($admin['user_id']));
+        return $this->fetch();
+    }
+
+    /**
+     * 兜底
+     * @return mixed
+     */
+    public function doudi ()
+    {
+        return 22;
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            empty($user) && $this->error('用户不存在');
+            $post['active'] <= 0 && $this->error('参数错误');
+            $path = trim_string($user['path'] . ',' . $user['id']);
+            $path_explode = explode(',', $path);
+            $insert = [];
+            foreach ($path_explode as $value) {
+                $insert[] = [
+                    'active' => $post['active'],
+                    'uid' => $value,
+                    'ip' => $this->request->ip(),
+                    'user_admin' => session('?admin.username') ? session('admin.username') : '',
+                    'from_uid' => $post['uid'],
+                    'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30),
+                ];
+            }
+            $this->model->startTrans();
+            try {
+                $this->model->whereIn('id', $path)->save(['active_set' => ['inc', $post['active']], 'total_number' => ['inc', $post['active']], 'total_number_real' => ['inc', $post['active']], 'total_active' => ['inc', $post['active']]]);
+                ActiveSet::insertAll($insert);
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败');
+            }
+            $this->success('成功');
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 增加余额
+     * @return mixed
+     */
+    public function editmoney ()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            $money = $post['money'];
+            $type = $post['type'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                if ($type == 'more'){
+                    edit_user_money(7, $post['uid'], $money);
+                }else {
+                    edit_user_money(8, $post['uid'], $money);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+    /**
+     * 末尾奖励
+     * @return mixed
+     */
+    public function moweiscore ()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+
+            $money = $post['money'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                edit_user_score(8, $post['uid'], $money);
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+
+
+    /**
+     * 余额明细
+     * @param MoneyLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function moneyLog (UserMoneyModel $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            $count = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.money');
+            $list = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('money', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+    /**
+     * 查看上级
+     * @param Request $request
+     * @param UpgradeLog $upgradeLog
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function lookpidlevel (Request $request)
+    {
+        if ($this->request->isAjax()) {
+
+//            if (($pid = $this->request->param('pid')) !== false && $pid)
+//                $where[] = ['pid', '=', $this->request->param('pid', '')];
+            $id = $this->request->param('id');
+            $path = Db::name('user')->where('id', $id)->value('path');
+            $arr = explode(',', $path);
+
+            $ids = $arr;
+            $ids = implode(',',$ids);
+            $order= 'field(id,'.$ids.')';
+//            return User::whereIn('id',$ids)->order(Db::raw($order))->select();
+
+            $where = array();
+
+            $where[] = ['uid', 'in', $arr];
+            sr_log($where);
+            $count = $this->model
+                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->count();
+            $list = $this->model
+                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->order(Db::raw($order))
+                ->select();
+
+            $data = [
+                'code' => 0,
+                'msg' => '成功',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 元宝明细
+     * @param CoinLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function coinLog (CoinLog $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            $count = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.coin');
+            $list = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('coin', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 积分明细
+     * @param ScoreLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function scoreLog (ScoreLogModel $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            $count = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.score');
+            $list = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('score', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 积分明细
+     * @param ActiveLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function activeLog (ActiveLog $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            $count = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.active');
+            $list = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('active', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data = [
+                'code' => 0,
+                'msg' => '',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="导出")
+     */
+    public function export ()
+    {
+        list($page, $limit, $where) = $this->buildTableParames();
+        $tableName = $this->model->getName();
+        $tableName = CommonTool::humpToLine(lcfirst($tableName));
+        $prefix = config('database.connections.mysql.prefix');
+        $dbList = Db::query("show full columns from {$prefix}{$tableName}");
+        $header = [];
+        foreach ($dbList as $vo) {
+            $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
+            if (!in_array($vo['Field'], $this->noExportFields)) {
+                $header[] = [$comment, $vo['Field']];
+            }
+        }
+        $list = $this->model
+            ->where($where)
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->limit(100000)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+        $fileName = time();
+        return Excel::exportData($list, $header, $fileName, 'xlsx');
+    }
+
+
+    public function teamincome (Request $request)
+    {
+        if ($this->request->isAjax()) {
+
+//            if (($pid = $this->request->param('pid')) !== false && $pid)
+//                $where[] = ['pid', '=', $this->request->param('pid', '')];
+            $id = $this->request->param('id');
+//            $path = Db::name('user')->where('id', $id)->value('path');
+            $where = array();
+            $where[] = ['uid', '=', $id];
+            $where[] = ['type', '=', 3];
+            $count = Db::name('userteam_log')
+//                ->withJoin('user', 'INNER')
+                ->where($where)
+                ->count();
+            $list = Db::name('userteam_log')
+//                ->withJoin('user', 'INNER')
+                ->where($where)
+                ->order($this->sort)
+                ->select();
+
+
+            $data = [
+                'code' => 0,
+                'msg' => '成功',
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+}

+ 663 - 0
app/admin/controller/user/User.php

@@ -0,0 +1,663 @@
+<?php
+
+namespace app\admin\controller\user;
+
+use app\admin\logic\MoneyLogLogic;
+use app\admin\logic\ScoreLogLogic;
+use app\admin\logic\UserLogic;
+use app\common\model\User as UserModel;
+use app\admin\traits\Curd;
+use app\common\controller\AdminController;
+use app\common\model\UserMoneyModel;
+use app\Request;
+use app\validate\admin\user\user\ModifyMoney;
+use app\validate\admin\user\user\ModifyScore;
+use app\validate\admin\user\user\ModifyPid;
+use app\validate\admin\user\user\PhoneSet;
+use jianyan\excel\Excel;
+use think\App;
+use think\exception\ValidateException;
+use think\facade\Cache;
+use app\admin\model\dao\User as UserDao;
+
+
+class User extends AdminController
+{
+
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new UserModel();
+    }
+
+    use Curd;
+
+    /**
+     * 会员列表
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            Cache::set("USER_EXPORT", ['page' => $page, 'limit' => $limit, 'where' => $where]);
+
+            if (($pid = $this->request->param('pid')) !== false && $pid)
+                $where[] = ['pid', '=', $this->request->param('pid', '')];
+
+            $userLogic = new UserLogic();
+            $data      = $userLogic->getList($page, $limit, $where, $this->sort, $this->user_map);
+            return $data;
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 禁用用户
+     * @param $id
+     */
+    public function forbid($id)
+    {
+        list($result, $msg) = UserLogic::forbid($id);
+        if ($result !== true) {
+            $this->error($msg);
+        }
+        $this->success($msg);
+    }
+
+    /**
+     * 启用用户
+     * @param $id
+     */
+    public function enable($id)
+    {
+        list($result, $msg) = UserLogic::enable($id);
+        if ($result !== true) {
+            $this->error($msg);
+        }
+        $this->success($msg);
+
+    }
+
+    /**
+     * 会员详情
+     * @param Request $request
+     * @return mixed
+     */
+    public function details(Request $request)
+    {
+        $id   = $request->param('id');
+        $info = UserLogic::getUserDetail($id);
+        $this->assign('info', $info);
+        return $this->fetch();
+    }
+
+
+    /**
+     * 添加用户(功能不存在)
+     * @return mixed
+     */
+    /*public function add()
+    {
+        if ($this->request->isAjax()) {
+            $post   = $this->request->post();
+            $mobile = $this->model->where('mobile', $post['mobile'])->value('id');
+            $mobile && $this->error('该手机号码已被注册');
+            $invite = $this->model->where('code|px_code', $post['code'])->value('id');
+            !$invite && $this->error('邀请人不存在');
+            $this->model->startTrans();
+            try {
+                $insert['mobile']    = $post['mobile'];
+                $insert['reg_ip']    = $this->request->ip();
+                $insert['avatar']    = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg';
+                $insert['code']      = create_invite_code();
+                $insert['px_code']   = create_invite_code();
+                $insert['user_type'] = 2;
+                $rz_money            = 1.5 + rand(0, 30) / 100;
+                $this->model->save($insert);
+                $uid       = $this->model->id;
+                $user_data = new UserData();
+                $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息
+                $this->bindRelation($post['code'], $uid); // 绑定关系
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('添加用户失败');
+            }
+            $this->success('添加成功');
+        }
+        return $this->fetch();
+    }*/
+
+    /**
+     * 邀请页面
+     * @return mixed
+     */
+    public function invite()
+    {
+        $admin = session('admin');
+        !$admin['user_id'] && $this->error('没有该权限');
+        $user = UserDao::getUserOrEmptyById($admin['user_id']);
+
+        empty($user) && $this->error('用户信息不存在');
+        $this->assign('user_id', encode($admin['user_id']));
+        return $this->fetch();
+    }
+
+    /**
+     * 兜底
+     * @return mixed
+     */
+    public function doudi()
+    {
+        return 22;
+        if ($this->request->isAjax()) {
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            empty($user) && $this->error('用户不存在');
+            $post['active'] <= 0 && $this->error('参数错误');
+            $path         = trim_string($user['path'] . ',' . $user['id']);
+            $path_explode = explode(',', $path);
+            $insert       = [];
+            foreach ($path_explode as $value) {
+                $insert[] = [
+                    'active'     => $post['active'],
+                    'uid'        => $value,
+                    'ip'         => $this->request->ip(),
+                    'user_admin' => session('?admin.username') ? session('admin.username') : '',
+                    'from_uid'   => $post['uid'],
+                    'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30),
+                ];
+            }
+            $this->model->startTrans();
+            try {
+                $this->model->whereIn('id', $path)->save(['active_set' => ['inc', $post['active']], 'total_number' => ['inc', $post['active']], 'total_number_real' => ['inc', $post['active']], 'total_active' => ['inc', $post['active']]]);
+                ActiveSet::insertAll($insert);
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败');
+            }
+            $this->success('成功');
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 增加余额(功能已屏蔽)
+     * @return mixed
+     */
+    /*public function editmoney()
+    {
+        if ($this->request->isPost()) {
+
+            $post  = $this->request->post();
+            $user  = $this->model->findOrEmpty(['id' => $post['uid']]);
+            $money = $post['money'];
+            $type  = $post['type'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                if ($type == 'more') {
+                    edit_user_money(7, $post['uid'], $money);
+                } else {
+                    edit_user_money(8, $post['uid'], $money);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败' . $e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }*/
+
+    /**
+     * 修改手机号码
+     * @return mixed
+     */
+    public function phoneset()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+
+            try {
+                validate(PhoneSet::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $userLogic = new UserLogic();
+            $result    = $userLogic->modifyPhone($post['id'], $post['phone']);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('成功');
+        }
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
+        $this->assign('info', $user);
+        return $this->fetch('phoneset');
+    }
+
+    /*
+    * 修改所属上级
+    * @return mixed
+    */
+    public function modifypid()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+            try {
+                validate(ModifyPid::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $userLogic = new UserLogic();
+            $result    = $userLogic->modifypid($post['id'], $post['pid']);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('成功');
+        }
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
+        $this->assign('info', $user);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 等级设置
+     * @return mixed
+     */
+    public function levelset()
+    {
+
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+
+            $result = UserLogic::levelset($post);
+            if ($result !== true) {
+                $this->error($result);
+            }
+            $this->success('成功');
+        }
+
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
+        $this->assign('info', $user);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 回收卡设置
+     * @return mixed
+     */
+    public function recyclecountset()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+
+            $result = UserLogic::recycleCountSet($post);
+            if ($result !== true) {
+                $this->error($result);
+            }
+            $this->success('成功');
+        }
+
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
+        $this->assign('info', $user);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 末尾奖励(功能已注释)
+     * @return mixed
+     */
+    /*public function moweiscore()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+
+            $money = $post['money'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                edit_user_score(8, $post['uid'], $money);
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败' . $e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }*/
+
+
+    /**
+     * 余额明细
+     * @param UserMoneyModel $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function moneyLog()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            list($count, $list) = MoneyLogLogic::getMoneyLog($page, $limit, $where, $this->sort);
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+
+    /**
+     * 查看上级
+     * @return mixed|\think\response\Json
+     */
+    public function lookpidlevel()
+    {
+        if ($this->request->isAjax()) {
+
+            $id = $this->request->param('id');
+
+            list($count, $list) = UserLogic::lookpidlevel($id);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '成功',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 元宝明细(功能已失效)
+     * @param CoinLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    /*public function coinLog(CoinLog $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.coin');
+            $list      = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('coin', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }*/
+
+    /**
+     * 积分明细
+     * @return mixed|\think\response\Json
+     */
+    public function scoreLog()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+
+            list($count, $list) = ScoreLogLogic::scoreLog($page, $limit, $where, $this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 活跃明细(功能已失效)
+     * @param ActiveLog $model
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    /*public function activeLog(ActiveLogModel $model)
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
+                ->where($where)
+                ->count();
+            $type_conf = config('type.active');
+            $list      = $model
+                ->where($where)
+                ->withAttr('type', function ($value, $data) use ($type_conf) {
+                    return $type_conf[$value];
+                })
+                ->withAttr('active', function ($value, $data) {
+                    if ($data['state'] == 2)
+                        $value = '-' . $value;
+                    return $value;
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }*/
+
+    /**
+     * @NodeAnotation(title="导出")
+     */
+    public function export()
+    {
+        list($page, $limit, $where) = $this->buildTableParames();
+
+        if (empty($where)) {
+            $search = Cache::get("USER_EXPORT");
+            $page   = $search['page'];
+            $limit  = $search['limit'];
+            $where  = $search['where'];
+        }
+
+        $header = getExportHeader($this->model->getName(), $this->noExportFields);
+
+        $list     = UserLogic::getExportList($where, $page, $limit);
+        $fileName = time();
+        return Excel::exportData($list, $header, $fileName, 'xlsx');
+    }
+
+
+    /**
+     * 团队充值(已失效)
+     * @return mixed
+     */
+    /*public function teamincome(Request $request)
+    {
+        if ($this->request->isAjax()) {
+
+//            if (($pid = $this->request->param('pid')) !== false && $pid)
+//                $where[] = ['pid', '=', $this->request->param('pid', '')];
+            $id = $this->request->param('id');
+//            $path = Db::name('user')->where('id', $id)->value('path');
+            $where   = array();
+            $where[] = ['team_id', '=', $id];
+            $where[] = ['type', '=', 5];
+            $count   = Db::name('userteam_log')
+//                ->withJoin('user', 'INNER')
+                ->where($where)
+                ->count();
+            $list    = Db::name('userteam_log')
+//                ->withJoin('user', 'INNER')
+                ->where($where)
+                ->order($this->sort)
+                ->select();
+
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '成功',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }*/
+
+    /*
+    * 修改积分
+    * @return mixed
+    */
+    public function modifyscore()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+
+            try {
+                validate(ModifyScore::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $userLogic = new UserLogic();
+            $result    = $userLogic->ModifyScore($post);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('成功');
+        }
+        $user              = UserDao::getUserOrEmptyById($this->request['id']);
+        $user['type_map']  = ScoreLogLogic::getTypeMap();
+        $user['state_map'] = ScoreLogLogic::getStateMap();
+        $this->assign('info', $user);
+
+        return $this->fetch();
+    }
+
+    /*
+    * 修改余额
+    * @return mixed
+    */
+    public function modifymoney()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+
+            try {
+
+                validate(ModifyMoney::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $userLogic = new UserLogic();
+            $result    = $userLogic->ModifyMoney($post);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('成功');
+        }
+        $user              = UserDao::getUserOrEmptyById($this->request['id']);
+        $user['type_map']  = MoneyLogLogic::getTypeMap();
+        $user['state_map'] = MoneyLogLogic::getStateMap();
+        $this->assign('info', $user);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 注销用户
+     * @param $id
+     */
+    public function deluser($id)
+    {
+        if ($this->request->isAjax()) {
+            $userLogic = new UserLogic();
+            $flag      = $userLogic->delUser($id);
+
+            $flag === true ? $this->success('删除成功') : $this->success('删除失败');
+        }
+    }
+
+
+}

+ 162 - 0
app/admin/controller/withdraw/Withdraw.php

@@ -0,0 +1,162 @@
+<?php
+/**
+ * 提现
+ */
+
+namespace app\admin\controller\withdraw;
+
+use alipay\AopCertClient;
+use alipay\request\AlipayFundTransUniTransferRequest;
+use app\admin\logic\UserLogic;
+use app\admin\logic\WithdrawLogLogic;
+use app\admin\model\dao\WithdrawLog;
+use app\admin\traits\Curd;
+use app\api\services\AliPayServices;
+use app\api\services\ThirdPayServices;
+use app\validate\admin\withdraw\withdraw\ReturnServiceMoney;
+use EasyAdmin\annotation\ControllerAnnotation;
+use EasyAdmin\annotation\NodeAnotation;
+use app\common\controller\AdminController;
+use app\common\model\WithDrawLogModel;
+use jianyan\excel\Excel;
+use think\App;
+use think\Exception;
+use think\exception\ValidateException;
+use think\facade\Cache;
+use think\facade\Db;
+
+/**
+ * Class Admin
+ * @package app\admin\controller\withdraw
+ * @ControllerAnnotation(title="提现管理处理")
+ */
+class Withdraw extends AdminController
+{
+    public function __construct(App $app, WithDrawLogModel $model)
+    {
+        parent::__construct($app);
+        $this->model = $model;
+    }
+
+    use Curd;
+
+    /**
+     * @NodeAnotation(title="列表")
+     */
+    public function index()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            Cache::set("WITHDRAW_EXPORT", ['page' => $page, 'limit' => $limit, 'where' => $where]);
+
+            list($count, $list) = WithdrawLogLogic::getList($page, $limit, $where, $this->user_map, $this->sort);
+
+            $data = [
+                'code'  => 0,
+                'msg'   => '',
+                'count' => $count,
+                'data'  => $list,
+            ];
+            return json($data);
+        }
+
+        $this->assign('limits',[10, 15, 20, 25, 50, 100]);
+        return $this->fetch();
+    }
+
+    /**
+     * @NodeAnotation(title="提现失败")
+     */
+    public function withdrawerror($id)
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+
+            list($return, $msg) = WithdrawLogLogic::withdrawError($id, $post);
+
+            $return === true ? $this->success($msg) : $this->error($msg);
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * @NodeAnotation(title="执行提现")
+     */
+    public function tx($id)
+    {
+        list($return, $msg) = WithdrawLogLogic::tx($id);
+        $return === true ? $this->success($msg) : $this->error($msg);
+    }
+
+    /**
+     * @NodeAnotation(title="导出")
+     */
+    public function export()
+    {
+        list($page, $limit, $where) = $this->buildTableParames();
+
+        if (empty($where)) {
+            $search = Cache::get("WITHDRAW_EXPORT");
+            $page   = $search['page'];
+            $limit  = $search['limit'];
+            $where  = $search['where'];
+        }
+
+        $header = getExportHeader($this->model->getName(), $this->noExportFields);
+
+        $list     = WithdrawLogLogic::getExportList($where, $page, $limit);
+        $fileName = time();
+        return Excel::exportData($list, $header, $fileName, 'xlsx');
+    }
+
+    /**
+     * @NodeAnotation(title="提现数据")
+     */
+    public function withdrawdata()
+    {
+        $tx_success = WithdrawLog::SumPracticalMoneyByStatus(1);
+        $this->assign('tx_success', $tx_success);
+
+        $tx = WithdrawLog::SumPracticalMoneyByStatus(0);
+        $this->assign('tx', $tx);
+
+        return $this->fetch();
+    }
+
+    /**
+     * 退还手续费
+     * @return mixed
+     */
+    public function returnservicemoney()
+    {
+        $id = $this->request['id'];
+
+        $withdrawLog = new WithdrawLogLogic();
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+
+            try {
+                validate(ReturnServiceMoney::class)->check($post);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+
+            $result = $withdrawLog->returnServiceMoney($post);
+            if ($result !== true) {
+                $this->error($result);
+            }
+
+            $this->success('成功');
+        }
+        $withdrawLog->getWithdrawLog($id);
+        $this->assign('info', $withdrawLog);
+
+        return $this->fetch();
+    }
+}

+ 189 - 0
app/admin/controller/xzdata/Dianfei.php

@@ -0,0 +1,189 @@
+<?php
+namespace app\admin\controller\xzdata;
+
+use alipay\AopCertClient;
+use alipay\request\AlipayFundTransUniTransferRequest;
+use app\common\model\MoneyLog;
+use app\common\model\ScoreLog;
+//use app\admin\model\UpgradeLog;
+use app\common\model\ScoreLogModel;
+use app\common\model\ThirdxzDforderModel;
+use app\common\model\ThirdxzHforderModel;
+use app\common\model\User as UserModel;
+use app\common\model\UserData;
+use app\admin\traits\Curd;
+use app\common\constants\AdminConstant;
+use app\common\controller\AdminController;
+use app\common\model\UserMoneyModel;
+use app\Request;
+use EasyAdmin\tool\CommonTool;
+use jianyan\excel\Excel;
+use think\App;
+use think\facade\Db;
+
+
+class Dianfei extends AdminController
+{
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ThirdxzDforderModel();
+    }
+
+    use Curd;
+
+    /**
+     * 充值列表
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            if (($pid = $this->request->param('pid')) !== false && $pid)
+                $where[] = ['pid', '=', $this->request->param('pid', '')];
+
+//            if (($create_time = $this->request->param('create_time')) !== false && $create_time)
+//                $where[] = ['create_time','in', explode(' - ', $create_time)];
+            foreach ($where as $key=>&$val){
+                if ($val[0] == 'create_time'){
+                    $val[2] = sr_getcurtime($val[2]);
+                }
+            }
+
+//            sr_log(json_encode($where));
+            $count = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->where($this->user_map)
+                ->count();
+            $list = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->where($this->user_map)
+                ->withAttr('type', function ($val, $data){
+                    return ($val==1?'移动':($val==2?'联通':'电信'));
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+
+            $data = [
+                'code' => 0,
+                'msg' => Db::getLastSql(),
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 执行提现
+     * @param $id
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function czsuccess ($id)
+    {
+
+        $info = $this->model->where('id', $id)->where('status', 1)->find();
+        if (empty($info))
+            $this->error('充值记录状态或已充值');
+        $user = Db::name('user')->findOrEmpty(['id' => $info['uid']]);
+        if (empty($user) || $user['status'] != 1)
+            $this->error('用户不存在或已被禁用');
+        if ($user['is_auth'] != 1)
+            $this->error('该用户还未实名认证');
+
+        $this->model->where('id', $id)->save(['status'=>2]);
+        $this->success('充值成功');
+    }
+
+    /**
+     * 充值失败
+     * @return mixed
+     */
+    public function czerror ()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $order_info = $this->model->where('id', $post['id'])->findOrEmpty();
+
+            $is_backsx = $post['is_backsx'];
+            $error_text = $post['error_text'];
+
+            empty($order_info) && $this->error('信息不存在');
+            if ($order_info['status'] != 1){
+                $this->error('状态错误,请刷新数据');
+            }
+
+            $this->model->startTrans();
+            try {
+                $this->model->where('id', $post['id'])->save(['status'=>3,'error_text'=>$error_text, 'is_backsx'=>$is_backsx]);
+                if ($is_backsx == 1){
+                    edit_user_xz(18, $order_info['uid'], $order_info['xz_num']+$order_info['shouxu'], $order_info['hf_ordersn'], $order_info['shouxu']);
+                    edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10);
+                }else{
+                    edit_user_xz(18, $order_info['uid'], $order_info['xz_num'], $order_info['hf_ordersn'], 0);
+                    edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * 增加余额
+     * @return mixed
+     */
+    public function editmoney ()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            $money = $post['money'];
+            $type = $post['type'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                if ($type == 'more'){
+                    edit_user_money(7, $post['uid'], $money);
+                }else {
+                    edit_user_money(8, $post['uid'], $money);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+
+
+}

+ 188 - 0
app/admin/controller/xzdata/Huafei.php

@@ -0,0 +1,188 @@
+<?php
+namespace app\admin\controller\xzdata;
+
+use alipay\AopCertClient;
+use alipay\request\AlipayFundTransUniTransferRequest;
+use app\common\model\MoneyLog;
+use app\common\model\ScoreLog;
+//use app\admin\model\UpgradeLog;
+use app\common\model\ScoreLogModel;
+use app\common\model\ThirdxzHforderModel;
+use app\common\model\User as UserModel;
+use app\common\model\UserData;
+use app\admin\traits\Curd;
+use app\common\constants\AdminConstant;
+use app\common\controller\AdminController;
+use app\common\model\UserMoneyModel;
+use app\Request;
+use EasyAdmin\tool\CommonTool;
+use jianyan\excel\Excel;
+use think\App;
+use think\facade\Db;
+
+
+class Huafei extends AdminController
+{
+
+    public function __construct (App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ThirdxzHforderModel();
+    }
+
+    use Curd;
+
+    /**
+     * 充值列表
+     * @return mixed|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index ()
+    {
+        if ($this->request->isAjax()) {
+            if (input('selectFields')) {
+                return $this->selectList();
+            }
+            list($page, $limit, $where) = $this->buildTableParames();
+
+            if (($pid = $this->request->param('pid')) !== false && $pid)
+                $where[] = ['pid', '=', $this->request->param('pid', '')];
+
+//            if (($create_time = $this->request->param('create_time')) !== false && $create_time)
+//                $where[] = ['create_time','in', explode(' - ', $create_time)];
+            foreach ($where as $key=>&$val){
+                if ($val[0] == 'create_time'){
+                    $val[2] = sr_getcurtime($val[2]);
+                }
+            }
+
+//            sr_log(json_encode($where));
+            $count = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->where($this->user_map)
+                ->count();
+            $list = $this->model
+//                ->withJoin('userData', 'INNER')
+                ->where($where)
+                ->where($this->user_map)
+                ->withAttr('type', function ($val, $data){
+                    return ($val==1?'移动':($val==2?'联通':'电信'));
+                })
+                ->page($page, $limit)
+                ->order($this->sort)
+                ->select();
+
+            $data = [
+                'code' => 0,
+                'msg' => Db::getLastSql(),
+                'count' => $count,
+                'data' => $list,
+            ];
+            return json($data);
+        }
+        return $this->fetch();
+    }
+
+    /**
+     * 执行提现
+     * @param $id
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function czsuccess ($id)
+    {
+
+        $info = $this->model->where('id', $id)->where('status', 1)->find();
+        if (empty($info))
+            $this->error('充值记录状态或已充值');
+        $user = Db::name('user')->findOrEmpty(['id' => $info['uid']]);
+        if (empty($user) || $user['status'] != 1)
+            $this->error('用户不存在或已被禁用');
+        if ($user['is_auth'] != 1)
+            $this->error('该用户还未实名认证');
+
+        $this->model->where('id', $id)->save(['status'=>2]);
+        $this->success('充值成功');
+    }
+
+    /**
+     * 充值失败
+     * @return mixed
+     */
+    public function czerror ()
+    {
+        if ($this->request->isPost()) {
+            $post = $this->request->post();
+            $order_info = $this->model->where('id', $post['id'])->findOrEmpty();
+
+            $is_backsx = $post['is_backsx'];
+            $error_text = $post['error_text'];
+
+            empty($order_info) && $this->error('信息不存在');
+            if ($order_info['status'] != 1){
+                $this->error('状态错误,请刷新数据');
+            }
+
+            $this->model->startTrans();
+            try {
+                $this->model->where('id', $post['id'])->save(['status'=>3,'error_text'=>$error_text, 'is_backsx'=>$is_backsx]);
+                if ($is_backsx == 1){
+                    edit_user_xz(15, $order_info['uid'], $order_info['xz_num']+$order_info['shouxu'], $order_info['hf_ordersn'], $order_info['shouxu']);
+                    edit_user_couponnum(5, $order_info['uid'], $order_info['price']/10);
+                }else{
+                    edit_user_xz(15, $order_info['uid'], $order_info['xz_num'], $order_info['hf_ordersn'], 0);
+                    edit_user_couponnum(5, $order_info['uid'], $order_info['price']/10);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+
+    /**
+     * 增加余额
+     * @return mixed
+     */
+    public function editmoney ()
+    {
+        if ($this->request->isPost()) {
+
+            $post = $this->request->post();
+            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            $money = $post['money'];
+            $type = $post['type'];
+            empty($user) && $this->error('用户不存在');
+
+            $this->model->startTrans();
+            try {
+                if ($type == 'more'){
+                    edit_user_money(7, $post['uid'], $money);
+                }else {
+                    edit_user_money(8, $post['uid'], $money);
+                }
+
+                $this->model->commit();
+            } catch (\Exception $e) {
+                $this->model->rollback();
+                $this->error('失败'.$e->getMessage());
+            }
+            $this->success('成功');
+        }
+
+        return $this->fetch();
+    }
+
+
+
+}

+ 21 - 0
app/admin/event.php

@@ -0,0 +1,21 @@
+<?php
+// 事件定义文件
+return [
+    'bind' => [
+    ],
+
+    'listen' => [
+        'AppInit'  => [
+            \app\admin\listener\ViewInitListener::class,
+        ],
+        'HttpRun'  => [
+            \app\admin\listener\ViewInitListener::class,
+        ],
+        'HttpEnd'  => [],
+        'LogLevel' => [],
+        'LogWrite' => [],
+    ],
+
+    'subscribe' => [
+    ],
+];

+ 37 - 0
app/admin/logic/BoxLogic.php

@@ -0,0 +1,37 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class BoxLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+
+        $count = (new BoxModel())
+            ->where($where)
+            ->count();
+
+        $list = (new BoxModel())
+            ->withoutField('password')
+            ->withAttr('box_img', function ($val, $data) {
+                return getWebUrl() . '/' . $val;
+            })
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 40 - 0
app/admin/logic/BoxMidHandleLogic.php

@@ -0,0 +1,40 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxMidHandleModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class BoxMidHandleLogic
+{
+
+    public static function getList($page, $limit)
+    {
+
+        $count = (new BoxMidHandleModel())
+            ->alias('r')
+            ->leftJoin('user u', 'u.id = r.uid')
+            ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
+            ->order('r.box_type desc')
+            ->page($page, $limit)
+            ->count();
+
+        $list = (new BoxMidHandleModel())
+            ->alias('r')
+            ->leftJoin('user u', 'u.id = r.uid')
+            ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income,u.total_appoint_count,u.box10,u.box20,u.box30,u.box40')
+            ->order('r.box_type desc')
+            ->page($page, $limit)
+            ->select()->toArray();
+
+        return [$count, $list];
+    }
+}

+ 39 - 0
app/admin/logic/BoxRecordLogic.php

@@ -0,0 +1,39 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxRecordModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class BoxRecordLogic
+{
+
+    public static function getList( $page,  $limit,  $where, array $sort)
+    {
+
+        $count = (new BoxRecordModel())
+            ->where($where)
+            ->count();
+
+        $list = (new BoxRecordModel())
+            ->withJoin('user', 'LEFT')
+            ->withAttr('box_img', function ($val, $data) {
+                return getWebUrl() . '/' . $val;
+            })
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+
+    }
+}

+ 85 - 0
app/admin/logic/MoneyLogLogic.php

@@ -0,0 +1,85 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class MoneyLogLogic
+{
+
+    // 1.预约福袋  2.回收商品 3.预约福袋空盒退回  4.奖金流失  5.直推收益到奖金  6-奖金领取  7-团队收益到奖金  8-利润结算兑换  9-余额提现  10-提现失败退还  11-提现多次返回  12-提现手续费退回,13-提现失败退回 14-奖金领取退回  15-系统退回  16-平台充值  17-平台扣除
+    private static $typeMap = [
+        ['id' => 0, 'name' => '其他'],
+        ['id' => 1, 'name' => '预约福袋'],
+        ['id' => 2, 'name' => '回收商品'],
+        ['id' => 3, 'name' => '预约福袋空盒退回'],
+        ['id' => 4, 'name' => '奖金流失'],
+        ['id' => 5, 'name' => '直推收益到奖金'],
+        ['id' => 6, 'name' => '奖金领取'],
+        ['id' => 7, 'name' => '团队收益到奖金'],
+        ['id' => 8, 'name' => '利润结算兑换'],
+        ['id' => 9, 'name' => '余额提现'],
+        ['id' => 10, 'name' => '提现失败退还'],
+        ['id' => 11, 'name' => '提现多次返回'],
+        ['id' => 12, 'name' => '提现手续费退回'],
+        ['id' => 13, 'name' => '提现失败退回'],
+        ['id' => 14, 'name' => '奖金领取退回'],
+        ['id' => 15, 'name' => '系统退回'],
+        ['id' => 16, 'name' => '平台充值'],
+        ['id' => 17, 'name' => '平台扣除'],
+    ];
+
+    private static $stateMap = [
+        ['id' => 1, 'name' => '增加'],
+        ['id' => 2, 'name' => '减少']
+    ];
+
+    /**
+     * @return array[]
+     */
+    public static function getStateMap(): array
+    {
+        return self::$stateMap;
+    }
+
+    /**
+     * @return array[]
+     */
+    public static function getTypeMap(): array
+    {
+        return self::$typeMap;
+    }
+
+    public static function getMoneyLog($page, $limit, $where, $sort)
+    {
+        $model = new UserMoneyModel();
+        $count = $model
+            ->where($where)
+            ->count();
+
+        $type_conf = config('type.money');
+
+        $list = $model
+            ->where($where)
+            ->withAttr('type', function ($value, $data) use ($type_conf) {
+                return $type_conf[$value];
+            })
+            ->withAttr('money', function ($value, $data) {
+                if ($data['state'] == 2)
+                    $value = '-' . $value;
+                return $value;
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 35 - 0
app/admin/logic/PayConfigLogic.php

@@ -0,0 +1,35 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\PayConfigModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class PayConfigLogic
+{
+
+    public static function getList( $page,  $limit,  $where,  $sort)
+    {
+        $count = (new PayConfigModel())
+            ->where($where)
+            ->count();
+        $list  = (new PayConfigModel())
+            ->where($where)
+            ->withAttr('channel', function ($val, $data) {
+                return $val == 1 ? '支付宝' : '微信';
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 44 - 0
app/admin/logic/PaymentLogic.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\common\model\PaymentModel;
+use app\common\model\ShopGoods;
+use think\facade\Cache;
+
+/**
+ * 充值购买记录
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class PaymentLogic
+{
+    /**
+     * 支付统计
+     * @param array $orderType 支付类型如:[4,5]
+     * @param string $time 时间节点如:2023-03-01
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public static function getTotal(array $orderType, $time='0')
+    {
+        $cacheKey = "caches:payment:total_{$time}";
+        if(!Cache::has($cacheKey)){
+            $data = PaymentModel::whereIn('order_type', $orderType)
+                ->where('state', 6)
+                ->where(function($query) use($time){
+                    if($time){
+                        $query->where('creat_at','>=', $time);
+                    }
+                })->sum('total_fee');
+            if($data){
+                Cache::set($cacheKey, $data, rand(3,5));
+            }
+
+            return $data;
+        }
+
+        return Cache::get($cacheKey);
+    }
+
+}

+ 75 - 0
app/admin/logic/ScoreLogLogic.php

@@ -0,0 +1,75 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\ScoreLogModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class ScoreLogLogic
+{
+
+    // 预约福袋  2.预约福袋空盒退回  3.买商品送积分   4.提现多次返回  6.兑换商品,  12-平台充补,13-平台扣除
+    private static $typeMap = [
+        ['id' => 0, 'name' => '其他'],
+        ['id' => 1, 'name' => '预约福袋'],
+        ['id' => 2, 'name' => '预约福袋空盒退回'],
+        ['id' => 3, 'name' => '买商品送积分'],
+        ['id' => 4, 'name' => '提现多次返回'],
+        ['id' => 6, 'name' => '兑换商品'],
+        ['id' => 12, 'name' => '平台充补'],
+        ['id' => 13, 'name' => '平台扣除']
+    ];
+
+    private static $stateMap = [
+        ['id' => 1, 'name' => '增加'],
+        ['id' => 2, 'name' => '减少']
+    ];
+
+    /**
+     * @return array[]
+     */
+    public static function getStateMap(): array
+    {
+        return self::$stateMap;
+    }
+
+    /**
+     * @return array[]
+     */
+    public static function getTypeMap(): array
+    {
+        return self::$typeMap;
+    }
+
+    public static function scoreLog(mixed $page, mixed $limit, mixed $where, array $sort)
+    {
+        $model     = new ScoreLogModel();
+        $count     = $model
+            ->where($where)
+            ->count();
+        $type_conf = config('type.score');
+        $list      = $model
+            ->where($where)
+            ->withAttr('type', function ($value, $data) use ($type_conf) {
+                return $type_conf[$value];
+            })
+            ->withAttr('score', function ($value, $data) {
+                if ($data['state'] == 2)
+                    $value = '-' . $value;
+                return $value;
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+    }
+
+}

+ 35 - 0
app/admin/logic/ShopCategoryLogic.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopCategory;
+use app\admin\model\dao\ShopGoodsSpec;
+use app\admin\model\dao\ShopGoodsSpecRelation;
+use app\admin\model\dao\ShopGoodsSpecType;
+use app\admin\model\dao\ShopGoodsType;
+use app\common\model\ShopGoods;
+use think\facade\Cache;
+use think\facade\Db;
+
+class ShopCategoryLogic
+{
+
+    private static $CACHE_ID_KEY = "cache:shop_category:id:";
+
+    public static function getCateById($id)
+    {
+        $key = self::$CACHE_ID_KEY . $id;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopCategory::getById($id);
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delIdCache($id)
+    {
+        $key = self::$CACHE_ID_KEY.$id;
+        Cache::delete($key);
+    }
+}

+ 94 - 0
app/admin/logic/ShopGoodsLogic.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopGoodsSpec;
+use app\admin\model\dao\ShopGoodsSpecRelation;
+use app\admin\model\dao\ShopGoodsSpecType;
+use app\admin\model\dao\ShopGoodsType;
+use app\common\model\ShopGoods;
+use think\db\Query;
+use think\facade\Cache;
+use think\facade\Db;
+
+/**
+ * 商城商品
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class ShopGoodsLogic
+{
+    /**
+     * 数量统计
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public static function getCount()
+    {
+        $cacheKey = "caches:goods:counts";
+        if (!Cache::has($cacheKey)) {
+            $data = ShopGoods::where(['on_sale' => 1])->count('goods_id');
+            if ($data) {
+                Cache::set($cacheKey, $data, rand(3, 5));
+            }
+
+            return $data;
+        }
+
+        return Cache::get($cacheKey);
+    }
+
+    public static function getList($page, $limit, $where)
+    {
+        $model = new ShopGoods();
+        $count = $model
+            ->withJoin(['supplier', 'cate' => function (Query $query) {
+                $query->where('cate.id', '>', 0);
+            }], 'LEFT')
+            ->where($where)
+            ->count();
+
+        $list = $model
+            ->withJoin(['supplier', 'cate' => function (Query $query) {
+                $query->where('cate.id', '>', 0);
+            }], 'LEFT')
+            ->where($where)
+            ->page($page, $limit)
+            ->order('goods_id desc')
+            ->select()->toArray();
+
+        foreach ($list as $k => &$v) {
+//            $v['cate'] = ShopCategoryLogic::getCateById($v['category']);
+            $v['id'] = $v['goods_id'];
+//                $v['supplier'] = Db::name('shop_supplier')->where(['id'=>$v['supplier']])->value('name');
+            $v['goods_type'] = ShopGoodsTypeLogic::getNameByCache($v['goods_type']);
+        }
+        return [$count, $list];
+    }
+
+    public static function getGoodsOrEmpty($id)
+    {
+    }
+
+    public static function getGoodsBase($id)
+    {
+        $model = new ShopGoods();
+        $data  = $model->where(['goods_id' => $id])->findOrEmpty()->toArray();
+
+        if ($data['goods_img_banner']) {
+            $data['goods_img_banner'] = implode('|', json_decode($data['goods_img_banner'], true));
+        }
+        $data['goods_remark'] = htmlspecialchars_decode($data['goods_remark']);
+        $specRelation         = ShopGoodsSpecRelation::getArrListByGoodsId($id);
+        $specAttrId           = ShopGoodsSpecType::getPidById($specRelation[0]['spec_id']);
+        if ($data['is_exist_many_spec'] == 0) {
+            $data['defaultSku'] = ShopGoodsSpec::getGoodsSpecByGoodId($id);
+        }
+
+        $hot_keywords    = ShopHotKeywordsLogic::getCacheList();
+        $shop_supplier   = ShopSupplierLogic::getCacheList();
+        $shop_goods_type = ShopGoodsTypeLogic::getCacheList();
+        return [$data, $hot_keywords, $shop_goods_type, $shop_supplier, $specAttrId];
+    }
+
+}

+ 25 - 0
app/admin/logic/ShopGoodsSpecLogic.php

@@ -0,0 +1,25 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopGoods;
+use app\admin\model\dao\ShopGoodsSpec;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class ShopGoodsSpecLogic
+{
+
+    public static function getGoodsSpecByGoodId($goodsId)
+    {
+        return ShopGoodsSpec::getGoodsSpecByGoodId($goodsId);
+    }
+}

+ 57 - 0
app/admin/logic/ShopGoodsSpecTypeLogic.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopGoodsSpecType;
+
+;
+
+use think\facade\Cache;
+use app\common\model\ShopGoodsSpecType as ShopGoodsSpecTypeModel;
+
+/**
+ *
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class ShopGoodsSpecTypeLogic
+{
+    private static $CACHE_LIST_KEY = "cache:shop_goods_spec_type:list";
+
+    public static function getCacheList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopGoodsSpecType::getArrList();
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new ShopGoodsSpecTypeModel())
+            ->where($where)
+            ->count();
+        $list  = (new ShopGoodsSpecTypeModel())
+            ->withoutField('password')
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+    }
+
+    public static function getTopList()
+    {
+        return ShopGoodsSpecType::getTopList();
+    }
+}

+ 49 - 0
app/admin/logic/ShopGoodsTypeLogic.php

@@ -0,0 +1,49 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\ShopGoodsType;
+use think\facade\Cache;
+use think\facade\Db;
+
+class ShopGoodsTypeLogic
+{
+    private static $CACHE_NAME_KEY = "SHOPGOODSTYPENAME";
+
+    private static $CACHE_LIST_KEY = "cache:shop_goods_type:list";
+
+    public function __construct()
+    {
+    }
+
+
+    public static function getNameByCache($goodsType)
+    {
+        $key = self::$CACHE_NAME_KEY . $goodsType;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopGoodsType::getValueById($goodsType);
+        Cache::set($key, $name, 5 * 60);
+        return $name;
+    }
+
+    public static function getCacheList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopGoodsType::getList();
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+}

+ 35 - 0
app/admin/logic/ShopHotKeywordsLogic.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopGoodsType;
+use app\admin\model\dao\ShopHotKeywords;
+use app\common\model\ShopGoods;
+use think\facade\Cache;
+
+/**
+ * 商城商品
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class ShopHotKeywordsLogic
+{
+    private static $CACHE_LIST_KEY = "cache:shop_host_keywords:list";
+
+    public static function getCacheList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopHotKeywords::getList();
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+}

+ 127 - 0
app/admin/logic/ShopOrderLogic.php

@@ -0,0 +1,127 @@
+<?php
+
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopGoods;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\UserAddress;
+use think\facade\Db;
+
+class ShopOrderLogic
+{
+
+    // 0待付款 1待发货 2已发货 3取消订单  4.已完成
+    private static $statusMap = [
+        ['id' => 0, 'name' => '待付款'],
+        ['id' => 1, 'name' => '待发货'],
+//        ['id' => 2, 'name' => '已发货'],
+        ['id' => 3, 'name' => '取消订单'],
+//        ['id' => 4, 'name' => '已完成']
+    ];
+
+    /**
+     * @return array[]
+     */
+    public static function getStatusMap(): array
+    {
+        return self::$statusMap;
+    }
+
+    public static function editStatus($orderId, $status)
+    {
+        $shopOrder = ShopOrder::getOrderById($orderId);
+        if (empty($shopOrder)) {
+            return "订单不存在";
+        }
+
+        if ($shopOrder['status'] != $status) {
+            Db::startTrans();
+            try {
+                $result = ShopOrder::editStatus($orderId, $status);
+                if (!$result) {
+                    Db::rollback();
+                    return "订单更新状态失败";
+                }
+                Db::commit();
+            } catch (\Exception $exception) {
+                Db::rollback();
+                return "失败:" . $exception->getMessage();
+            }
+        }
+
+
+        return true;
+    }
+
+    public static function getList($page, $limit, $where)
+    {
+
+        $model = new \app\common\model\ShopOrder();
+        foreach ($where as $key => $val) {
+            if ($val[0] == 'status') {
+                $where[$key][0] = 'o.status';
+            }
+            if ($val[0] == 'created_time') {
+                $where[$key][0] = 'o.created_time';
+                $where[$key][2] = sr_getcurtime($where[$key][2]);
+            }
+
+            if ($val[0] == 'order_type') {
+                $where[$key][0] = 'o.order_type';
+            }
+
+        }
+
+        $count = $model
+            ->alias('o')
+            ->with(['goods'])
+            ->where($where)
+//                ->where('o.status', '<>', 3)
+            ->leftJoin('user u', 'u.id = o.user_id')
+            ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
+            ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
+            ->count();
+
+        $list = $model
+            ->alias('o')
+            ->with(['goods'])
+            ->where($where)
+//                ->where('o.status', '<>', 3)
+            ->leftJoin('user u', 'u.id = o.user_id')
+            ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
+            ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
+            ->order('o.order_id desc')
+            ->withAttr('order_sn', function ($val, $data) {
+                return '编号:' . $val;
+            })
+            ->page($page, $limit)
+            ->select()->toArray();
+
+        foreach ($list as $k => $v) {
+            $goods_id   = $v['goods'][0]['goods_id'];
+            $goods_info = ShopGoods::getGoodsById($goods_id);
+            if ($goods_info) {
+                $list[$k]['cost_price'] = $goods_info['cost_price'];
+            } else {
+                $list[$k]['cost_price'] = 0;
+            }
+
+            if ($v['status'] == 5 || $v['status'] == 6) {
+                // 新的地址
+                $ygOrderInfo              = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find();
+                $newAddress_info          = UserAddress::getUserAddress($ygOrderInfo['address_id']);
+                $list[$k]['sp_id']        = 99999;
+                $list[$k]['sp_mobile']    = $newAddress_info['mobile'];
+                $list[$k]['sp_name']      = $newAddress_info['name'];
+                $list[$k]['sp_mergename'] = $newAddress_info['mergename'];
+
+            }
+
+
+        }
+        return [$count, $list];
+    }
+
+
+}

+ 33 - 0
app/admin/logic/ShopSupplierLogic.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\admin\model\dao\ShopSupplier;
+use think\facade\Cache;
+
+/**
+ * 商城商品
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class ShopSupplierLogic
+{
+    private static $CACHE_LIST_KEY = "cache:shop_supplier:list";
+
+    public static function getCacheList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = ShopSupplier::getList();
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+}

+ 34 - 0
app/admin/logic/SystemAdminLogic.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\admin\model\SystemAdmin;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemAdminLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemAdmin())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemAdmin())
+            ->withoutField('password')
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 55 - 0
app/admin/logic/SystemArticleLogic.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\SystemArticle;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\SystemArticleModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemArticleLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemArticleModel())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemArticleModel())
+            ->where($where)
+            ->withAttr('type', function ($val, $data) {
+                return config('type.article')[$val] ? config('type.article')[$val] : '未知类型';
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function add($row)
+    {
+        $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
+        $row['create_time'] = sr_getcurtime(time());
+        unset($row['file']);
+
+        $type_info = SystemArticle::getById($row['type']);
+        if ($type_info) {
+            $count = SystemArticle::count($row['type']);
+
+            if ($count >= $type_info['max_count']) {
+                return [false, '这种类型只能存在' . $type_info['max_count'] . '种'];
+            }
+        }
+
+        return (new SystemArticleModel())->insert($row);
+    }
+}

+ 19 - 0
app/admin/logic/SystemAuthLogic.php

@@ -0,0 +1,19 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemAuthLogic
+{
+
+}

+ 62 - 0
app/admin/logic/SystemBannerLogic.php

@@ -0,0 +1,62 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\SystemBannerModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+use utils\RedisCache;
+
+class SystemBannerLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemBannerModel())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemBannerModel())
+            ->where($where)
+            ->withAttr('img_pic', function ($val, $data) {
+                return __HTTPGETIMGADMIN($val);
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function edit($post)
+    {
+        $row = new SystemBannerModel();
+        try {
+            $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
+            $post['img_pic']     = __HTTPSAVEIMGADMIN($post['img_pic']);
+            $save                = $row->save($post);
+            RedisCache::clear('getAppBanner' . $row['type']);
+            return $save;
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+    }
+
+    public static function add($data)
+    {
+        $data['img_pic']     = __HTTPSAVEIMGADMIN($data['img_pic']);
+        $data['banner_desc'] = htmlspecialchars_decode($data['banner_desc']);
+        $data['create_time'] = sr_getcurtime(time());
+        unset($data['file']);
+        $save = (new SystemBannerModel())->insert($data);
+        RedisCache::clear('getAppBanner' . $data['type']);
+        return $save;
+    }
+}

+ 19 - 0
app/admin/logic/SystemConfigLogic.php

@@ -0,0 +1,19 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemConfigLogic
+{
+
+}

+ 77 - 0
app/admin/logic/SystemFaqLogic.php

@@ -0,0 +1,77 @@
+<?php
+
+
+namespace app\admin\logic;
+
+use app\common\model\SystemFaq;
+use app\admin\model\dao\SystemFaq as SystemFaqDao;
+use think\facade\Cache;
+
+class SystemFaqLogic
+{
+
+    private static $CACHE_ID_KEY = "cache:system_faq:id:";
+
+    private static $CACHE_LIST_KEY = "cache:system_faq:list";
+
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemFaq())
+            ->where($where)
+            ->count();
+        $list  = (new SystemFaq())
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        foreach ($list as &$v) {
+            if ($v->parent_id == 0) {
+                $v->parent_id = '最上级';
+            } else {
+                $self         = SystemFaqLogic::getTitleById($v->parent_id);
+                $v->parent_id = $self;
+            }
+        }
+        return [$count, $list];
+    }
+
+    private static function getTitleById($parent_id)
+    {
+        $key = self::$CACHE_ID_KEY . $parent_id;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = SystemFaqDao::getTitleById($parent_id);
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delTitleCache($parent_id)
+    {
+        $key = self::$CACHE_ID_KEY . $parent_id;
+        Cache::delete($key);
+    }
+
+    public static function getTopList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $list = SystemFaqDao::getTopArrList();
+        array_push($list, ['id' => 0, 'title' => '最上级']);
+
+        Cache::set($key, $list, 10 * 60);
+        return $list;
+    }
+
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+
+
+}

+ 43 - 0
app/admin/logic/SystemLogLogic.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\admin\model\SystemLog;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemLogLogic
+{
+
+    public static function getList($page, $limit, $where, $excludeFields, $sort)
+    {
+        $month = (isset($excludeFields['month']) && !empty($excludeFields['month']))
+            ? date('Ym', strtotime($excludeFields['month']))
+            : date('Ym');
+
+        // todo TP6框架有一个BUG,非模型名与表名不对应时(name属性自定义),withJoin生成的sql有问题
+
+        $count = (new SystemLog())
+            ->setMonth($month)
+            ->with('admin')
+            ->where($where)
+            ->select();
+        $list  = (new SystemLog())
+            ->setMonth($month)
+            ->with('admin')
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+    }
+}

+ 54 - 0
app/admin/logic/SystemMenuLogic.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\admin\model\SystemMenu;
+use app\admin\service\TriggerService;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemMenuLogic
+{
+
+    public static function getList($sort)
+    {
+        $list = (new SystemMenu())->order($sort)->select();
+        return [$list->count(), $list];
+    }
+
+    public static function add($post)
+    {
+        try {
+            $save = (new SystemMenu())->save($post);
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+        if (!$save) return '保存失败';
+
+        TriggerService::updateMenu();
+
+        return true;
+    }
+
+    public static function edit($id, $post)
+    {
+        try {
+            $save = SystemMenu::where(['id' => $id])->save($post);
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+        if (!$save) return '保存失败';
+
+        TriggerService::updateMenu();
+
+        return true;
+    }
+}

+ 54 - 0
app/admin/logic/SystemNodeLogic.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\SystemNode;
+use app\admin\service\NodeService;
+use app\admin\service\TriggerService;
+use app\admin\model\dao\SystemNode as SystemNodeDao;
+
+class SystemNodeLogic
+{
+
+    public static function getList()
+    {
+        $list = (new SystemNode())
+            ->getNodeTreeList();
+
+        return [count($list), $list];
+    }
+
+    public static function refreshNode($force)
+    {
+        $nodeList = (new NodeService())->getNodelist();
+        if (empty($nodeList)) return '暂无需要更新的系统节点';
+        $model = new SystemNode();
+        try {
+            if ($force == 1) {
+                $updateNodeList = SystemNodeDao::getNodeByNodeList($nodeList);
+                $formatNodeList = array_format_key($nodeList, 'node');
+                foreach ($updateNodeList as $vo) {
+                    if (isset($formatNodeList[$vo['node']])) {
+                        SystemNodeDao::update($vo['id'], $formatNodeList[$vo['node']]['title'], $formatNodeList[$vo['node']]['is_auth']);
+                    }
+                }
+            }
+            $existNodeList = SystemNodeDao::getNodeAndTitleAndIsAuth();
+            foreach ($nodeList as $key => $vo) {
+                foreach ($existNodeList as $v) {
+                    if ($vo['node'] == $v->node) {
+                        unset($nodeList[$key]);
+                        break;
+                    }
+                }
+            }
+            $model->saveAll($nodeList);
+            TriggerService::updateNode();
+        } catch (\Exception $e) {
+            return '节点更新失败' . $e->getMessage();
+        }
+        return true;
+    }
+}

+ 554 - 0
app/admin/logic/UserLogic.php

@@ -0,0 +1,554 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\User;
+use app\common\model\UserModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class UserLogic
+{
+    public static function forbid($id)
+    {
+        $user = User::getUserOrEmptyById($id);
+        if (empty($user)) return [false, '数据不存在'];
+
+        if ($user['status'] == 0) return [false, '该用户已被禁用'];
+
+        $result = User::updateStatus($id, 0);
+
+        return $result ? [true, '禁用成功'] : [false, '禁用失败'];
+    }
+
+    public static function enable($id)
+    {
+        $user = User::getUserOrEmptyById($id);
+        if (empty($user)) return [false, '数据不存在'];
+
+        if ($user['status'] == 1) return [false, '该用户已启用'];
+
+        $result = User::updateStatus($id, 1);
+
+        return $result ? [true, '禁用成功'] : [false, '禁用失败'];
+    }
+
+    public static function getUserDetail($id)
+    {
+        $user = new User();
+        return $user->getUserDetail($id);
+    }
+
+    public static function levelset($post)
+    {
+        $level = $post['level'];
+        if ($level > 4) {
+            return '最高等级4级';
+        }
+
+        $user = User::getUserOrEmptyById($post['id']);
+        if (empty($user)) return '用户不存在';
+
+        $level_type = 1;
+        if ($level > $user['level']) {
+            $level_type = 2;
+        }
+        Db::startTrans();
+        try {
+            $userData = ['level' => $level, 'level_type' => $level_type];
+            User::update($post['id'], $userData);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return '失败' . $e->getMessage();
+        }
+        return true;
+    }
+
+    public static function lookpidlevel($id)
+    {
+        $path = Db::name('user')->where('id', $id)->value('path');
+        $arr  = explode(',', $path);
+
+        $ids   = $arr;
+        $ids   = implode(',', $ids);
+        $order = 'field(id,' . $ids . ')';
+
+        $where = array();
+
+        $where[] = ['uid', 'in', $arr];
+        sr_log($where);
+
+        $user  = new UserModel();
+        $count = $user
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->count();
+
+        $list = $user
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->order(Db::raw($order))
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function getExportList($where, $page, $limit)
+    {
+        return (new UserModel())
+            ->where($where)
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->page($page, $limit)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+    }
+
+    public static function recycleCountSet($post)
+    {
+        $user = User::getUserById($post['id']);
+        if (empty($user)) return '用户不存在';
+
+        if (empty($post['recycle_count']) || $post['recycle_count'] < 0 || $post['recycle_count'] > 500) {
+            return '回收卡数量格式有误';
+        }
+
+        try {
+            $updateData = ['recycle_count' => $post['recycle_count']];
+            $result     = User::update($user['id'], $updateData);
+            if (!$result) return "更新临时卡数量失败";
+
+        } catch (\Exception $e) {
+            return '失败' . $e->getMessage();
+        }
+
+        return true;
+    }
+
+    public function getList($page, $limit, $where, $sort, $userMap)
+    {
+        $where[] = ['status', '<>', 3];
+        $userDao = new User();
+        $count   = $userDao->getCount($where, $userMap);
+        $list    = $userDao->getPageList($page, $limit, $where, $sort, $userMap);
+
+        foreach ($list as &$item) {
+            //团队会员(包括1、2级和自身)的积分账户合计、余额账户合计
+            // 计算团队成员(包括1、2级和自身)ID
+
+            $teamIds = $this->getTeamMoneyAndScore($item['id']);
+
+            // 积分账户合计
+            $item['score_total'] = $teamIds['score'];
+            // 余额账户合计
+            $item['money_total'] = $teamIds['money'];
+        }
+
+        $data = [
+            'code'  => 0,
+            'msg'   => Db::getLastSql(),
+            'count' => $count,
+            'data'  => $list,
+        ];
+        return json($data);
+    }
+
+    /**
+     * 获取团队自身,一级、二级自己的余额/积分
+     * @param $uid
+     */
+    private function getTeamMoneyAndScore($uid)
+    {
+        $cacheKey = 'userLogicTeamIds_' . $uid;
+
+        if (!Cache::has($cacheKey)) {
+
+            // 自身
+            $user = Db::table(User::$table)
+                ->where('id', $uid)
+                ->field(['id', 'score', 'money'])
+                ->find();
+
+            $totalScore = $user['score'];
+            $totalMoney = $user['money'];
+
+
+            // 一级子用户
+            Db::table(User::$table)
+                ->where('pid', $uid)
+                ->field(['id', 'score', 'money'])
+                ->chunk(100, function ($users) use (&$totalScore, &$totalMoney) {
+                    foreach ($users as $user) {
+                        $uids[]     = $user['id'];
+                        $totalScore += $user['score'];
+                        $totalMoney += $user['money'];
+                    }
+
+                    // 二级子用户
+                    Db::table(User::$table)
+                        ->whereIn('pid', $uids)
+                        ->field(['id', 'score', 'money'])
+                        ->chunk(100, function ($users) use (&$totalScore, &$totalMoney) {
+                            foreach ($users as $user) {
+                                $totalScore += $user['score'];
+                                $totalMoney += $user['money'];
+                            }
+                        });
+
+                }, ['score', 'money']);
+
+            Cache::set($cacheKey, ['score' => $totalScore, 'money' => sprintf("%.2f", $totalMoney)], 5 * 60);
+        }
+
+        return Cache::get($cacheKey);
+
+    }
+
+    /**
+     * 修改用户手机号码
+     * @param  $uid
+     * @param  $phone
+     */
+    public function modifyPhone($uid, $phone)
+    {
+        // 判断手机号码是否使用过
+        $user = User::getUserById($uid);
+        if (empty($user)) return '用户不存在';
+
+        if ($user['mobile'] == $phone) return "请输入新的手机号码";
+
+        if (User::getUserByMobile($phone)) return "该手机号码已注册";
+
+        // 修改用户信息
+        try {
+            $updateData = [
+                'mobile' => $phone,
+            ];
+
+            // 按照账号原规则,手机号码作为用户名,同时修改新的用户名
+            if ($user['mobile'] == $user['user_name']) {
+                $updateData['user_name'] = $phone;
+            }
+
+            $result = User::update($uid, $updateData);
+            if (!$result) return "更新手机号码失败,请稍后重试";
+
+        } catch (\Exception $e) {
+            return '失败' . $e->getMessage();
+        }
+
+        return true;
+
+    }
+
+    /**
+     * 修改用户所属上级
+     * @param  $uid
+     * @param  $pid
+     */
+    public function modifypid($uid, $pid)
+    {
+        $user = User::getUserById($uid);
+        if (empty($user)) return '用户不存在';
+
+        // 查询pid是否存在用户path中
+        if ($uid == $pid) {
+            return "不能修改自己为上级";
+        }
+
+        if ($user['pid'] == $pid) {
+            return "该用户已所属待变更的上级,不能修改";
+        }
+
+
+        $parentUser = User::getUserById($pid);
+        if (empty($parentUser)) {
+            return '所属上级不存在';
+        }
+        // 判断降级或升级
+
+        // 判断升级,降级、插入
+        list($operateType, $prefixPath) = $this->getOperateType($user['id'], $user['path'], $pid, $parentUser['path']);
+
+        Db::startTrans();
+        try {
+
+            if ($operateType) {
+                // 死循环,分支
+                $result = $this->modifypidByResetTopLevel($user['id'], $user['path'], $pid, $parentUser['path'], $prefixPath);
+            } else {
+                // 正常,迭代修改下级
+                $result = $this->modifypidByUpdateNextLevel($user['id'], $user['path'], $pid, $parentUser['path']);
+            }
+
+            if (!$result) {
+                Db::rollback();
+                return "修改用户所属上级失败,请确认用户的层级关系";
+            }
+            Db::commit();
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return "失败:" . $exception->getMessage();
+        }
+
+        return true;
+
+        // 升级,abcdef,e升级到b后 分为两种情况 1.abef 2.abcd
+
+        // 降级 abcdef,c降级到e后 分为两种情况 1. ecf 2.abcd
+
+        // 插入 abcdef,插入j到b后 分为两种情况 1.abj 2.abcdef
+
+
+    }
+
+    /**
+     * 修改余额
+     * @param  $post
+     */
+    public function ModifyMoney($post)
+    {
+        $user = User::getUserById($post['uid']);
+        if (empty($user)) {
+            return "用户不存在";
+        }
+
+        Db::startTrans();
+        try {
+            if ($post['state'] == 1) {
+                $afterMoney = $user['money'] + $post['money'];
+            } else {
+                $afterMoney = $user['money'] - $post['money'];
+                if ($afterMoney < 0) {
+                    return "账号余额不足";
+                }
+            }
+            $afterMoney = round($afterMoney, 2);
+
+            $moneyLog = [
+                'uid'          => $post['uid'],
+                'type'         => $post['type'] ?? 0,
+                'money'        => $post['money'],
+                'create_at'    => date('Y-m-d H:i:s'),
+                'state'        => $post['state'] ?? '0',
+                'from_id'      => $post['from_id'] ?? '0',
+                'before_money' => $user['money'],
+                'after_money'  => $afterMoney,
+                'uid2'         => $post['uid2'] ?? 0,
+                'free_type'    => $post['free_type'] ?? '',
+                'remark'       => $post['remark'],
+            ];
+            // 子级path变更
+            MoneyLog::AddMoneyLog($moneyLog);
+
+            User::UpdateUserMoney($user['id'], $afterMoney);
+
+            Db::commit();
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return "失败:" . $exception->getMessage();
+        }
+
+        return true;
+    }
+
+    /**
+     * 修改积分
+     * @param  $post
+     */
+    public function ModifyScore($post)
+    {
+
+        $user = User::getUserById($post['uid']);
+        if (empty($user)) {
+            return "用户不存在";
+        }
+        Db::startTrans();
+        try {
+
+
+            if ($post['state'] == 1) {
+                $afterScore = $user['score'] + $post['score'];
+            } else {
+                $afterScore = $user['score'] - $post['score'];
+                if ($afterScore < 0) {
+                    return "账号积分不足";
+                }
+            }
+
+            $moneyLog = [
+                'uid'          => $post['uid'],
+                'type'         => $post['type'] ?? 0,
+                'score'        => $post['score'],
+                'create_at'    => date('Y-m-d H:i:s'),
+                'scene'        => $post['scene'] ?? 0,
+                'from_id'      => $post['from_id'] ?? '0',
+                'state'        => $post['state'] ?? '0',
+                'before_score' => $user['score'],
+                'after_score'  => $afterScore,
+                'uid2'         => $post['uid2'] ?? 0,
+            ];
+            // 子级path变更
+            ScoreLog::AddScoreLog($moneyLog);
+
+            User::UpdateUserScore($user['id'], $afterScore);
+
+            Db::commit();
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return "失败:" . $exception->getMessage();
+        }
+
+        return true;
+    }
+
+    /**
+     * 删除用户
+     * @param $id
+     */
+    public function delUser($id)
+    {
+        $user = User::getUserById($id);
+        if (empty($user)) {
+            return "用户不存在";
+        }
+        if (User::updateStatus($id, 3) !== 1) {
+            return false;
+        }
+        return true;
+    }
+
+    /* 注册用户数量统计
+     * @param string $time 时间节点如:2023-03-01
+     * @return 
+     * @throws \think\db\exception\DbException
+     */
+    public static function getCountByTime($time = '0')
+    {
+        $cacheKey = "caches:user:counts_{$time}";
+        if (!Cache::has($cacheKey)) {
+            $data = UserModel::where(['status' => 1])
+                ->where(function ($query) use ($time) {
+                    if ($time) {
+                        $query->where('reg_time', '>=', $time);
+                    }
+                })->count('id');
+            if ($data) {
+                Cache::set($cacheKey, $data, rand(3, 5));
+            }
+
+            return $data;
+        }
+
+        return Cache::get($cacheKey);
+    }
+
+    /**
+     * 判断操作类型,true-死循环 false-正常
+     * @param $pid
+     * @param $path
+     * @return int
+     */
+    private function getOperateType($uid, $path, $pid, $pUserPath)
+    {
+//        $pUserPathArr = explode(',', $pUserPath);
+        list($isFallLevel, $prefixPath) = $this->isFallLevel($uid, $pid);
+
+        if ($isFallLevel) {
+            return [true, $prefixPath];
+        }
+
+        return [false, null];
+    }
+
+    private function modifypidByUpdateNextLevel($id, $path, $pid, $parentUserPath)
+    {
+        $parentUserPathArr = explode(',', $parentUserPath);
+        $newUserPathArr    = $parentUserPathArr;
+        $newUserPathArr[]  = $pid;
+
+        $result = $this->iteraMidifyPathByPid($newUserPathArr, $id);
+        if (!$result) return false;
+        // 更新用户Pid,Path
+        return User::modifyUserPidAndPath($id, $pid, implode(',', $newUserPathArr));
+    }
+
+    private function iteraMidifyPathByPid($newUserPathArr, $pid)
+    {
+        $newUserPathArr[] = $pid;
+        $result           = Db::table(User::$table)
+            ->where([
+                'pid' => $pid
+            ])
+            ->field(['id', 'path'])
+            ->chunk(100, function ($users) use ($pid, $newUserPathArr) {
+                foreach ($users as $user) {
+                    User::modifyUserPath($user['id'], implode(',', $newUserPathArr));
+                    $this->iteraMidifyPathByPid($newUserPathArr, $user['id']);
+                }
+            });
+        return $result;
+    }
+
+    private function modifypidByResetTopLevel($id, $path, $pid, $parentUserPath, $prefixPath)
+    {
+        $newUserPathArr[] = $pid;
+
+        $this->updatePidAndPathByPath($id, $prefixPath);
+
+        $parentUser       = User::getUserById($pid);
+        $newUserPathArr   = explode(',', $parentUser['path']);
+        $newUserPathArr[] = $pid;
+
+        User::modifyUserPidAndPath($id, $pid, implode(',', $newUserPathArr));
+
+        $this->iteraMidifyPathByPid($newUserPathArr, $id);
+
+        return true;
+//        $result = User::modifyUserPidAndPath($pid, 0, '');
+//        if (!$result) return false;
+//        return User::modifyUserPidAndPath($id, $pid, implode(',', $newUserPathArr));
+    }
+
+    private function isFallLevel($uid, $pid)
+    {
+        $user = Db::query(sprintf("SELECT id,path,pid FROM db_user WHERE FIND_IN_SET('%s',path) and FIND_IN_SET('%s',path) LIMIT 1;", $uid, $pid));
+        if (empty($user)) {
+            return [false, null];
+        }
+        $userPath = explode(',', $user[0]['path']);
+        $uidIndex = array_search($uid, $userPath);
+        if ($uidIndex < array_search($pid, $userPath)) {
+            $returnPath = [];
+            if (isset($userPath[$uidIndex - 1])) {
+                $returnPath[] = $userPath[$uidIndex - 1];
+            }
+            $returnPath[] = $userPath[$uidIndex];
+            $returnPath[] = $userPath[$uidIndex + 1];
+
+            return [true, $returnPath];
+        }
+        return [false, null];
+    }
+
+    private function updatePidAndPathByPath($uid, $prefixPath)
+    {
+        $newTopUid = $prefixPath[count($prefixPath) - 1];
+
+        // 从阶段处更新,分支出来作为第一层
+        User::modifyUserPidAndPath($newTopUid, 0, '');
+
+        User::modifyUserPidAndPathByPid($uid, 0, '');
+
+        $newUserPathArr = [];
+        return $this->iteraMidifyPathByPid($newUserPathArr, $newTopUid);
+
+    }
+
+}

+ 34 - 0
app/admin/logic/UserteamLogLogic.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\UserFansModel;
+use app\common\model\UserMoneyModel;
+use app\common\model\UserteamLogModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class UserteamLogLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new UserteamLogModel())
+            ->where($where)
+            ->count();
+        $list  = (new UserteamLogModel())
+            ->where($where)
+            ->where('type', 2)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 241 - 0
app/admin/logic/WithdrawLogLogic.php

@@ -0,0 +1,241 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\User;
+use app\admin\model\dao\WithdrawLog;
+use app\common\model\WithDrawLogModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class WithdrawLogLogic
+{
+
+    public static function getList($page, $limit, $where, $userMap, $sort)
+    {
+        foreach ($where as $key => &$val) {
+            if ($val[0] == 'status') {
+                $where[$key][0] = 'w.status';
+            }
+        }
+        $model = new WithDrawLogModel();
+
+        $count = $model
+//                ->withJoin('user', 'INNER')
+            ->where($userMap)
+            ->where($where)
+            ->count();
+        $list  = $model
+            ->alias('w')
+            ->leftJoin('user u', 'u.id = w.uid')
+//                ->withJoin('user', 'INNER')
+            ->where($userMap)
+            ->where($where)
+            ->field('w.*,u.path,u.user_type,u.luzi_money')
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+
+        $withdrawLog = new WithdrawLogLogic();
+
+        foreach ($list as $key => &$val) {
+
+//                老刘下级  13824334135  uid    5344367
+//                郑跃兵   17888779318     uid 5344369,13866400965 uid 5344368
+//                大飞    19805553599 uid 5344633 ,18682271568    uid 5344640
+//
+//                if ($val['user_type'] == 10){
+//                    $val['tips_text'] = '潘总号';
+//                }else{
+//                    $val['tips_text'] = '其他线';
+//                }
+//                    $val['tips_text'] = '其他线';
+
+//
+//                if (strpos($val['path'], '5344367') !== false || $val['uid'] == 5344367){
+//                    $val['tips_text'] = '老刘下级';
+//                }
+
+
+//
+//                if ((strpos($val['path'], '5344633') !== false || $val['uid'] == 5344633) || (strpos($val['path'], '5344640') !== false || $val['uid'] == 5344640)){
+//                    $val['tips_text'] = '大飞下级';
+//                }elseif ((strpos($val['path'], '5344369') !== false || $val['uid'] == 5344369) || (strpos($val['path'], '5344368') !== false || $val['uid'] == 5344368)){
+//                    $val['tips_text'] = '郑跃兵下级';
+//                }
+
+
+//                if (strpos($val['path'], '7493433') !== false){
+//                    $val['tips_text'] = '心态下级';
+//                }
+//
+            if (strpos($val['path'], '7493466') !== false) {
+                $val['tips_text'] = '郑下级';
+            }
+
+            if ($val['luzi_money'] > 0) {
+                $val['tips_text'] = '撸子标记,不要提现';
+            } else {
+                $val['tips_text'] = '';
+            }
+
+            $val['is_show'] = $withdrawLog->isShowReturnServiceMoney($val['id']);
+
+
+        }
+
+        return [$count, $list];
+    }
+
+    public static function withdrawError($id, $post)
+    {
+        $model = new WithDrawLogModel();
+        $row   = $model->where('id', $id)->where('status', 'in', '0')->find();
+        if (empty($row)) return [false, '取消失败'];
+
+        $row->status    = 3;
+        $row->fail_log  = $post['error_text'];
+        $is_backsx      = $post['is_backsx'];
+        $row->is_backsx = $is_backsx;
+
+        Db::startTrans();
+        try {
+            if ($is_backsx == 1) {
+                edit_user_money(10, $row['uid'], $row['apply_money']);
+            } else {
+                edit_user_money(10, $row['uid'], $row['practical_money']);
+            }
+
+            Db::name('user')->where('id', $row['uid'])->dec('total_withdraw', $row['apply_money'])->update();
+            $row->save();
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return [false, '取消失败' . $e->getMessage()];
+        }
+
+        return [true, '取消成功'];
+    }
+
+    public static function tx($id)
+    {
+        $model = new WithDrawLogModel();
+        $info  = $model->where('id', $id)->where('status', 0)->find();
+        if (empty($info)) return [false, '提现记录不存在'];
+
+        $user = User::getUserOrEmptyById($info['uid']);
+        if (empty($user) || $user['status'] != 1) return [false, '用户不存在或已被禁用'];
+
+        if ($user['luzi_money'] > 0) return [false, '撸子账号 联系技术处理'];
+
+        User::updateTotalTeamWithdraw($user['path'], $info['apply_money']);
+        User::updateTotalTeamWithdraw($user['id'], $info['apply_money']);
+
+        // 支付宝提现
+        if ($info['channel'] == 1) {
+            $updateData = ['status' => 1, 'out_biz_no' => '1111', 'final_transfer_type' => 1];
+            WithdrawLog::update($id, $updateData);
+
+            return [true, '提现成功'];
+        } else {
+
+            $info->status              = 1;
+            $info->update_at           = date('Y-m-d H:i:s', time());
+            $info->final_transfer_type = 3;
+
+            $info->save();
+        }
+        return [true, '提现成功'];
+    }
+
+    public static function getExportList($where, $page, $limit)
+    {
+        return (new WithDrawLogModel())
+            ->where($where)
+            ->withJoin('user', 'INNER')
+            ->where($where)
+            ->page($page, $limit)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+    }
+
+    public function returnServiceMoney($post)
+    {
+        $withdrawLog = WithdrawLog::getWithdrawLogById($post['id']);
+        if (empty($withdrawLog)) {
+            return "记录不存在";
+        }
+
+        if ($withdrawLog['status'] != 3) {
+            return "该提现记录不可以退还服务费";
+        }
+
+        if ($withdrawLog['service_money'] < $post['service_money']) {
+            return "提现金额不可以大于服务费";
+        }
+
+        $moneyLog = MoneyLog::getMoneyLogByFromId($post['id']);
+        if ($moneyLog) {
+            return "当前提现记录已退还服务费";
+        }
+
+        Db::startTrans();
+        try {
+            $afterMoney   = $withdrawLog['service_money'] + $post['service_money'];
+            $moneyLog     = [
+                'uid'             => $withdrawLog['uid'],
+                'type'            => 12,
+                'money'           => $post['service_money'],
+                'create_at'       => date('Y-m-d H:i:s'),
+                'state'           => 1,
+                'from_id'         => '0',
+                'before_money'    => $withdrawLog['service_money'],
+                'after_money'     => $afterMoney,
+                'uid2'            => 0,
+                'free_type'       => '',
+                'remark'          => $post['remark'],
+                'withdraw_log_id' => $withdrawLog['id'],
+            ];
+            $serviceMoney = $withdrawLog['service_money'] - $post['service_money'];
+            WithdrawLog::updateServiceMoney($withdrawLog['id'], $serviceMoney);
+            MoneyLog::AddMoneyLog($moneyLog);
+            User::UpdateUserMoney($withdrawLog['uid'], $afterMoney);
+            Db::commit();
+        } catch (\Exception $exception) {
+            Db::rollback();
+            return "失败:" . $exception->getMessage();
+        }
+
+        return true;
+    }
+
+    public function getWithdrawLog($id)
+    {
+        $withdrawLog = WithdrawLog::getWithdrawLogById($id);
+
+
+        return $withdrawLog;
+    }
+
+    private function isShowReturnServiceMoney($id)
+    {
+        $key = 'WITHDRAWLOGRETURNSERVICEMONEY_' . $id;
+        if (Cache::has($key) && 1 == 2) {
+            return Cache::get($key);
+        }
+
+        $moneyLog = MoneyLog::getMoneyLogByFromId($id);
+
+        $isShow = $moneyLog ? 1 : 0;
+        Cache::set($key, $isShow, 5 * 60);
+        return $isShow;
+
+    }
+}

+ 42 - 0
app/admin/logic/WithdrawLogic.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\common\model\PaymentModel;
+use app\common\model\ShopGoods;
+use app\common\model\WithDrawLogModel;
+use think\facade\Cache;
+
+/**
+ * 提现记录
+ * Class ShopGoodsLogic
+ * @package app\admin\logic
+ */
+class WithdrawLogic
+{
+    /**
+     * 提现统计
+     * @param string $time 时间节点如:2023-03-01
+     * @return mixed
+     */
+    public static function getTotal($time = '0')
+    {
+        $cacheKey = "caches:withdraw:total_{$time}";
+        if(!Cache::has($cacheKey)){
+            $data = WithDrawLogModel::where('status', 1)
+                ->where(function($query) use($time){
+                    if($time){
+                        $query->where('create_at','>=', $time);
+                    }
+                })->sum('practical_money');
+            if($data){
+                Cache::set($cacheKey, $data, rand(3,5));
+            }
+
+            return $data;
+        }
+
+        return Cache::get($cacheKey);
+    }
+
+}

+ 21 - 0
app/admin/middleware.php

@@ -0,0 +1,21 @@
+<?php
+// 全局中间件定义文件
+return [
+
+    // Session初始化
+    \think\middleware\SessionInit::class,
+
+    // 系统操作日志
+    \app\admin\middleware\SystemLog::class,
+
+    // Csrf安全校验
+    \app\admin\middleware\CsrfMiddleware::class,
+
+    // 后台视图初始化
+//    \app\admin\middleware\ViewInit::class,
+
+    // 检测用户是否登录
+//    \app\admin\middleware\CheckAdmin::class,
+
+
+];

+ 67 - 0
app/admin/middleware/CheckAdmin.php

@@ -0,0 +1,67 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\middleware;
+
+use app\common\service\AuthService;
+use think\Request;
+
+/**
+ * @deprecated  废弃,新版TP不支持在中间件获取控制器相关信息
+ * 检测用户登录和节点权限
+ * Class CheckAdmin
+ * @package app\admin\middleware
+ */
+class CheckAdmin
+{
+
+    use \app\common\traits\JumpTrait;
+
+    public function handle(Request $request, \Closure $next)
+    {
+        $adminConfig = config('admin');
+        $adminId = session('admin.id');
+        $expireTime = session('admin.expire_time');
+        /** @var AuthService $authService */
+        $authService = app(AuthService::class, ['adminId' => $adminId]);
+        $currentNode = $authService->getCurrentNode();
+        $currentController = parse_name($request->controller());
+
+        // 验证登录
+        if (!in_array($currentController, $adminConfig['no_login_controller']) &&
+            !in_array($currentNode, $adminConfig['no_login_node'])) {
+            empty($adminId) && $this->error('请先登录后台', [], __url(Env::get('easyadmin.admin', '').'/login/index'));
+
+            // 判断是否登录过期
+            if ($expireTime !== true && time() > $expireTime) {
+                session('admin', null);
+                $this->error('登录已过期,请重新登录', [], __url(Env::get('easyadmin.admin', '').'/login/index'));
+            }
+        }
+
+        // 验证权限
+        if (!in_array($currentController, $adminConfig['no_auth_controller']) &&
+            !in_array($currentNode, $adminConfig['no_auth_node'])) {
+            $check = $authService->checkNode($currentNode);
+            !$check && $this->error('无权限访问');
+
+            // 判断是否为演示环境
+            if(env('easyadmin.is_demo', false) && $request->isPost()){
+                $this->error('演示环境下不允许修改');
+            }
+
+        }
+
+        return $next($request);
+    }
+
+}

+ 53 - 0
app/admin/middleware/CsrfMiddleware.php

@@ -0,0 +1,53 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\middleware;
+
+
+use app\Request;
+use CsrfVerify\drive\ThinkphpCache;
+use CsrfVerify\entity\CsrfVerifyEntity;
+use CsrfVerify\interfaces\CsrfVerifyInterface;
+use think\facade\Session;
+
+class CsrfMiddleware
+{
+    use \app\common\traits\JumpTrait;
+
+    public function handle(Request $request, \Closure $next)
+    {
+        if (env('EASYADMIN.IS_CSRF', true)) {
+            if (!in_array($request->method(), ['GET', 'HEAD', 'OPTIONS'])) {
+
+                // 跨域校验
+                $refererUrl = $request->header('REFERER', null);
+//                $refererInfo = parse_url($refererUrl);
+//                $host = $request->host(true);
+//                if (!isset($refererInfo['host']) || $refererInfo['host'] != $host) {
+//                    $this->error('当前请求不合法!1');
+//                }
+//
+//                // CSRF校验
+//                // @todo 兼容CK编辑器上传功能
+//                $ckCsrfToken = $request->post('ckCsrfToken', null);
+//                $data = !empty($ckCsrfToken) ? ['__token__' => $ckCsrfToken] : [];
+//
+//                $check = $request->checkToken('__token__', $data);
+//                if (!$check) {
+//                    $this->error('请求验证失败,请重新刷新页面!');
+//                }
+
+            }
+        }
+        return $next($request);
+    }
+}

+ 77 - 0
app/admin/middleware/SystemLog.php

@@ -0,0 +1,77 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\middleware;
+
+use app\admin\service\SystemLogService;
+use app\Request;
+use EasyAdmin\tool\CommonTool;
+use think\facade\Log;
+
+/**
+ * 系统操作日志中间件
+ * Class SystemLog
+ * @package app\admin\middleware
+ */
+class SystemLog
+{
+
+    /**
+     * 敏感信息字段,日志记录时需要加密
+     * @var array
+     */
+    protected $sensitiveParams = [
+        'password',
+        'password_again',
+        'phone',
+        'mobile'
+    ];
+
+    public function handle(Request $request, \Closure $next)
+    {
+        $params = $request->param();
+        if (isset($params['s'])) {
+            unset($params['s']);
+        }
+        foreach ($params as $key => $val) {
+            in_array($key, $this->sensitiveParams) && $params[$key] = "***********";
+        }
+        $method = strtolower($request->method());
+        $url = $request->url();
+
+        trace([
+            'url'    => $url,
+            'method' => $method,
+            'params' => $params,
+        ],
+            'requestDebugInfo'
+        );
+
+        if ($request->isAjax()) {
+            if (in_array($method, ['post', 'put', 'delete'])) {
+                $ip = CommonTool::getRealIp();
+                $data = [
+                    'admin_id'    => session('admin.id'),
+                    'url'         => $url,
+                    'method'      => $method,
+                    'ip'          => $ip,
+                    'content'     => json_encode($params, JSON_UNESCAPED_UNICODE),
+                    'useragent'   => $_SERVER['HTTP_USER_AGENT'],
+                    'create_time' => time(),
+                ];
+                SystemLogService::instance()->save($data);
+            }
+        }
+        return $next($request);
+    }
+
+}

+ 58 - 0
app/admin/middleware/ViewInit.php

@@ -0,0 +1,58 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\middleware;
+
+
+use app\admin\service\ConfigService;
+use app\common\constants\AdminConstant;
+use think\App;
+use think\facade\Request;
+use think\facade\View;
+
+/**
+ * @deprecated  废弃,新版TP不支持在中间件获取控制器相关信息
+ * Class ViewInit
+ * @package app\admin\middleware
+ */
+class ViewInit
+{
+
+    public function handle(\app\Request $request, \Closure $next)
+    {
+        list($thisModule, $thisController, $thisAction) = [app('http')->getName(), Request::controller(), $request->action()];
+        list($thisControllerArr, $jsPath) = [explode('.', $thisController), null];
+        foreach ($thisControllerArr as $vo) {
+            empty($jsPath) ? $jsPath = parse_name($vo) : $jsPath .= '/' . parse_name($vo);
+        }
+        $autoloadJs = file_exists(root_path('public')."static/{$thisModule}/js/{$jsPath}.js") ? true : false;
+        $thisControllerJsPath = "{$thisModule}/js/{$jsPath}.js";
+        $adminModuleName = config('app.admin_alias_name');
+        $isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
+        $data = [
+            'adminModuleName'      => $adminModuleName,
+            'thisController'       => parse_name($thisController),
+            'thisAction'           => $thisAction,
+            'thisRequest'          => parse_name("{$thisModule}/{$thisController}/{$thisAction}"),
+            'thisControllerJsPath' => "{$thisControllerJsPath}",
+            'autoloadJs'           => $autoloadJs,
+            'isSuperAdmin'         => $isSuperAdmin,
+            'version'              => env('app_debug') ? time() : ConfigService::getVersion(),
+        ];
+
+        View::assign($data);
+        $request->adminModuleName = $adminModuleName;
+        return $next($request);
+    }
+
+
+}

+ 23 - 0
app/admin/model/MallCate.php

@@ -0,0 +1,23 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class MallCate extends TimeModel
+{
+
+    protected $deleteTime = 'delete_time';
+
+}

+ 30 - 0
app/admin/model/MallGoods.php

@@ -0,0 +1,30 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class MallGoods extends TimeModel
+{
+
+    protected $table = "";
+
+    protected $deleteTime = 'delete_time';
+
+    public function cate()
+    {
+        return $this->belongsTo('app\common\model\MallCate', 'cate_id', 'id');
+    }
+
+}

+ 31 - 0
app/admin/model/SystemAdmin.php

@@ -0,0 +1,31 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class SystemAdmin extends TimeModel
+{
+
+    protected $deleteTime = 'delete_time';
+
+    public function getAuthList()
+    {
+        $list = (new SystemAuth())
+            ->where('status', 1)
+            ->column('title', 'id');
+        return $list;
+    }
+
+}

+ 64 - 0
app/admin/model/SystemAuth.php

@@ -0,0 +1,64 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class SystemAuth extends TimeModel
+{
+
+    protected $deleteTime = 'delete_time';
+
+    /**
+     * 根据角色ID获取授权节点
+     * @param $authId
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getAuthorizeNodeListByAdminId($authId)
+    {
+        $checkNodeList = (new SystemAuthNode())
+            ->where('auth_id', $authId)
+            ->column('node_id');
+        $systemNode = new SystemNode();
+        $nodelList = $systemNode
+            ->where('is_auth', 1)
+            ->field('id,node,title,type,is_auth')
+            ->select()
+            ->toArray();
+        $newNodeList = [];
+        foreach ($nodelList as $vo) {
+            if ($vo['type'] == 1) {
+                $vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
+                $vo['checked'] = false;
+                $vo['title'] = "{$vo['title']}【{$vo['node']}】";
+                $children = [];
+                foreach ($nodelList as $v) {
+                    if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
+                        $v = array_merge($v, ['field' => 'node', 'spread' => true]);
+                        $v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
+                        $v['title'] = "{$v['title']}【{$v['node']}】";
+                        $children[] = $v;
+                    }
+                }
+                !empty($children) && $vo['children'] = $children;
+                $newNodeList[] = $vo;
+            }
+        }
+        return $newNodeList;
+    }
+
+}

+ 21 - 0
app/admin/model/SystemAuthNode.php

@@ -0,0 +1,21 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class SystemAuthNode extends TimeModel
+{
+
+}

+ 22 - 0
app/admin/model/SystemConfig.php

@@ -0,0 +1,22 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class SystemConfig extends TimeModel
+{
+
+}

+ 29 - 0
app/admin/model/SystemLog.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\admin\model;
+
+
+use app\common\model\TimeModel;
+
+class SystemLog extends TimeModel
+{
+
+    public function __construct(array $data = [])
+    {
+        parent::__construct($data);
+        $this->name = 'system_log_' . date('Ym');
+    }
+
+    public function setMonth($month)
+    {
+        $this->name = 'system_log_' . $month;
+        return $this;
+    }
+
+    public function admin()
+    {
+        return $this->belongsTo('app\common\model\SystemAdmin', 'admin_id', 'id');
+    }
+
+
+}

+ 70 - 0
app/admin/model/SystemMenu.php

@@ -0,0 +1,70 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | EasyAdmin
+// +----------------------------------------------------------------------
+// | PHP交流群: 763822524
+// +----------------------------------------------------------------------
+// | 开源协议  https://mit-license.org 
+// +----------------------------------------------------------------------
+// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\model;
+
+
+
+use app\common\constants\MenuConstant;
+use app\common\model\TimeModel;
+
+class SystemMenu extends TimeModel
+{
+
+    protected $deleteTime = 'delete_time';
+
+    public function getPidMenuList()
+    {
+        $list        = $this->field('id,pid,title')
+            ->where([
+                ['pid', '<>', MenuConstant::HOME_PID],
+                ['status', '=', 1],
+            ])
+            ->select()
+            ->toArray();
+        $pidMenuList = $this->buildPidMenu(0, $list);
+        $pidMenuList = array_merge([[
+            'id'    => 0,
+            'pid'   => 0,
+            'title' => '顶级菜单',
+        ]], $pidMenuList);
+        return $pidMenuList;
+    }
+
+    protected function buildPidMenu($pid, $list, $level = 0)
+    {
+        $newList = [];
+        foreach ($list as $vo) {
+            if ($vo['pid'] == $pid) {
+                $level++;
+                foreach ($newList as $v) {
+                    if ($vo['pid'] == $v['pid'] && isset($v['level'])) {
+                        $level = $v['level'];
+                        break;
+                    }
+                }
+                $vo['level'] = $level;
+                if ($level > 1) {
+                    $repeatString = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+                    $markString   = str_repeat("{$repeatString}├{$repeatString}", $level - 1);
+                    $vo['title']  = $markString . $vo['title'];
+                }
+                $newList[] = $vo;
+                $childList = $this->buildPidMenu($vo['id'], $list, $level);
+                !empty($childList) && $newList = array_merge($newList, $childList);
+            }
+
+        }
+        return $newList;
+    }
+
+}

+ 0 - 0
app/admin/model/SystemNode.php


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است