Browse Source

第一次提交

yingzi 1 year ago
commit
d94a487d6a
100 changed files with 10675 additions and 0 deletions
  1. 1 0
      .env
  2. 2 0
      .gitignore
  3. 32 0
      LICENSE.txt
  4. 56 0
      README.md
  5. 1 0
      app/.htaccess
  6. 24 0
      app/AppService.php
  7. 138 0
      app/BaseController.php
  8. 58 0
      app/BaseViewController.php
  9. 58 0
      app/ExceptionHandle.php
  10. 1 0
      app/ExecptionHandle.php
  11. 8 0
      app/Request.php
  12. 18 0
      app/api/config/app.php
  13. 37 0
      app/api/controller/AuthController.php
  14. 122 0
      app/api/controller/Login.php
  15. 137 0
      app/api/controller/Pub.php
  16. 70 0
      app/api/controller/v1/Pay.php
  17. 2189 0
      app/api/controller/v1/User.php
  18. 66 0
      app/api/exception/ExecptionHandle.php
  19. 36 0
      app/api/middleware/AllowOriginMiddleware.php
  20. 72 0
      app/api/middleware/SeretKeyMiddleware.php
  21. 57 0
      app/api/middleware/UserMiddleware.php
  22. 7 0
      app/api/provider.php
  23. 22 0
      app/api/route/login.php
  24. 36 0
      app/api/route/pay.php
  25. 24 0
      app/api/route/pub.php
  26. 31 0
      app/api/route/route.php
  27. 133 0
      app/api/route/user.php
  28. 28 0
      app/build.php
  29. 443 0
      app/command/Org/RedisCli.php
  30. 57 0
      app/command/Org/RedisPool.php
  31. 437 0
      app/common.php
  32. 20 0
      app/controller/Index.php
  33. 17 0
      app/event.php
  34. 16 0
      app/home/controller/Index.php
  35. 142 0
      app/lib/OrderLib.php
  36. 10 0
      app/middleware.php
  37. 14 0
      app/model/api/Activity.php
  38. 14 0
      app/model/api/ActivityOrder.php
  39. 14 0
      app/model/api/Admin.php
  40. 97 0
      app/model/api/AdverPage.php
  41. 64 0
      app/model/api/Advert.php
  42. 14 0
      app/model/api/AppBug.php
  43. 14 0
      app/model/api/Bank.php
  44. 14 0
      app/model/api/Coupon.php
  45. 14 0
      app/model/api/Goods.php
  46. 14 0
      app/model/api/GoodsCate.php
  47. 14 0
      app/model/api/GoodsLove.php
  48. 14 0
      app/model/api/Label.php
  49. 14 0
      app/model/api/News.php
  50. 14 0
      app/model/api/Order.php
  51. 14 0
      app/model/api/OrderInfo.php
  52. 14 0
      app/model/api/OrderMono.php
  53. 67 0
      app/model/api/PayTrade.php
  54. 14 0
      app/model/api/ShowTemplate.php
  55. 25 0
      app/model/api/Sys.php
  56. 14 0
      app/model/api/Tx.php
  57. 251 0
      app/model/api/User.php
  58. 14 0
      app/model/api/UserAddress.php
  59. 14 0
      app/model/api/UserCircle.php
  60. 14 0
      app/model/api/UserCircleLove.php
  61. 14 0
      app/model/api/UserCoupon.php
  62. 197 0
      app/model/api/UserDetail.php
  63. 14 0
      app/model/api/UserLogin.php
  64. 15 0
      app/model/api/UserLove.php
  65. 195 0
      app/model/api/UserScoreDetail.php
  66. 14 0
      app/model/api/UserShop.php
  67. 119 0
      app/model/system/Admin.php
  68. 19 0
      app/model/system/AdminLog.php
  69. 161 0
      app/model/system/AdminMenu.php
  70. 70 0
      app/model/system/AdminRole.php
  71. 166 0
      app/model/system/RolePath.php
  72. 27 0
      app/model/system/Sys.php
  73. 9 0
      app/provider.php
  74. 9 0
      app/service.php
  75. 0 0
      app/system/.htaccess
  76. 32 0
      app/system/common.php
  77. 18 0
      app/system/config/app.php
  78. 23 0
      app/system/config/log.php
  79. 21 0
      app/system/config/route.php
  80. 55 0
      app/system/controller/AuthController.php
  81. 99 0
      app/system/controller/Login.php
  82. 103 0
      app/system/controller/ShowTemplate.php
  83. 189 0
      app/system/controller/v1/Activity.php
  84. 201 0
      app/system/controller/v1/Admin.php
  85. 157 0
      app/system/controller/v1/Adver.php
  86. 138 0
      app/system/controller/v1/Circle.php
  87. 371 0
      app/system/controller/v1/Goods.php
  88. 48 0
      app/system/controller/v1/Index.php
  89. 99 0
      app/system/controller/v1/Label.php
  90. 224 0
      app/system/controller/v1/Log.php
  91. 761 0
      app/system/controller/v1/Member.php
  92. 73 0
      app/system/controller/v1/News.php
  93. 710 0
      app/system/controller/v1/Order.php
  94. 53 0
      app/system/controller/v1/Pub.php
  95. 121 0
      app/system/controller/v1/Role.php
  96. 104 0
      app/system/controller/v1/RolePath.php
  97. 103 0
      app/system/controller/v1/ShowTemplate.php
  98. 149 0
      app/system/controller/v1/Sys.php
  99. 107 0
      app/system/controller/v1/SysMenu.php
  100. 311 0
      app/system/controller/v1/Tx.php

+ 1 - 0
.env

@@ -0,0 +1 @@
+APP_DEBUG =  false
APP_TRACE =  false
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai

[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = root
USERNAME = infant_service
PASSWORD = "irLSTT3Y3E8tt6HW"
#USERNAME = root
#PASSWORD = "admin1234"
PREFIX = table_
HOSTPORT = 3306
CHARSET = utf8mb4
DEBUG = true

[LANG]
default_lang = zh-cn


[APPINFO]
APP_API_DOMAIN = 'https://api.myjie.cn'
APP_ADMIN_DOMAIN = 'https://system.myjie.cn'


+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/public/resource/
+/nbproject/

+ 32 - 0
LICENSE.txt

@@ -0,0 +1,32 @@
+
+ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
+版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
+All rights reserved。
+ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
+
+Apache Licence是著名的非盈利开源组织Apache采用的协议。
+该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
+允许代码修改,再作为开源或商业软件发布。需要满足
+的条件: 
+1. 需要给代码的用户一份Apache Licence ;
+2. 如果你修改了代码,需要在被修改的文件中说明;
+3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
+带有原来代码中的协议,商标,专利声明和其他原来作者规
+定需要包含的说明;
+4. 如果再发布的产品中包含一个Notice文件,则在Notice文
+件中需要带有本协议内容。你可以在Notice中增加自己的
+许可,但不可以表现为对Apache Licence构成更改。 
+具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

+ 56 - 0
README.md

@@ -0,0 +1,56 @@
+ThinkPHP 6.0
+===============
+
+> 运行环境要求PHP7.1+,兼容PHP8.0。
+
+[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api)
+
+ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。
+
+## 主要新特性
+
+* 采用`PHP7`强类型(严格模式)
+* 支持更多的`PSR`规范
+* 原生多应用支持
+* 更强大和易用的查询
+* 全新的事件系统
+* 模型事件和数据库事件统一纳入事件系统
+* 模板引擎分离出核心
+* 内部功能中间件化
+* SESSION/Cookie机制改进
+* 对Swoole以及协程支持改进
+* 对IDE更加友好
+* 统一和精简大量用法
+
+## 安装
+
+~~~
+composer create-project topthink/think tp 6.0.*
+~~~
+
+如果需要更新框架使用
+~~~
+composer update topthink/framework
+~~~
+
+## 文档
+
+[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
+
+## 参与开发
+
+请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。
+
+## 版权信息
+
+ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
+
+本项目包含的第三方源码和二进制文件之版权信息另行标注。
+
+版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn)
+
+All rights reserved。
+
+ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
+
+更多细节参阅 [LICENSE.txt](LICENSE.txt)

+ 1 - 0
app/.htaccess

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

+ 24 - 0
app/AppService.php

@@ -0,0 +1,24 @@
+<?php
+declare (strict_types = 1);
+
+namespace app;
+
+use library\utils\Json;
+use think\Service;
+
+/**
+ * 应用服务类
+ */
+class AppService extends Service
+{
+    public function register()
+    {
+        // 服务注册
+        $this->app->bind('json', Json::class);
+    }
+
+    public function boot()
+    {
+        // 服务启动
+    }
+}

+ 138 - 0
app/BaseController.php

@@ -0,0 +1,138 @@
+<?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;
+
+    protected $view;
+
+    /**
+     * 是否批量验证
+     * @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, '.')) {
+                // 支持场景
+                [$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);
+    }
+
+
+
+    /**
+     * 模板参数
+     * @param type $name 参数名称
+     * @param type $value 输出模板
+     */
+    protected function assign($name, $value) {
+        $this->viewInit();
+        $this->view->assign($name, $value);
+    }
+
+    /**
+     * 输出格式
+     */
+    protected function display($template = '') {
+        $this->viewInit();
+        $request = request();
+        if (empty($template))
+            $template = $request->action();
+        return $this->view->fetch($template);
+    }
+
+
+
+    private function viewInit(){
+        if($this->view == null) {
+            $app         = config('app');
+            $req         = [
+                '__IMAGES__' => $app['__IMAGES__'], // image变量
+                '__JS__'     => $app['__JS__'], // js变量
+                '__CSS__'    => $app['__CSS__'], // css变量
+                '__ASSETS__' => $app['__ASSETS__'] //assets 变量
+            ];
+            $this->view = app('view');
+        }
+    }
+
+
+
+
+
+}

+ 58 - 0
app/BaseViewController.php

@@ -0,0 +1,58 @@
+<?php
+declare (strict_types = 1);
+
+namespace app;
+
+use think\App;
+use think\exception\ValidateException;
+use think\Validate;
+use think\View;
+
+/**
+ * 控制器基础类
+ */
+ class BaseViewController extends BaseController
+{
+
+    private $_view;
+
+     public function __construct(App $app) {
+         global $_A;
+         $req = [
+             '__IMAGES__' => config("app")['__IMAGES__'], // image变量
+             '__JS__' => config("app")['__JS__'], // js变量
+             '__CSS__' => config("app")['__CSS__'], // css变量
+             '__ASSETS__' => config("app")['__ASSETS__'] //assets 变量
+         ];
+         //$this->_view = new View;
+         $this->_view = \app('view');
+         $this->_view->filter(function($content) use($req) {
+             $content = strtr($content, $req);
+             return $content;
+         });
+         parent::__construct($app);
+     }
+
+
+     /**
+      * 模板参数
+      * @param type $name 参数名称
+      * @param type $value 输出模板
+      */
+     protected function assign($name, $value) {
+         $this->_view->assign($name, $value);
+     }
+
+     /**
+      * 输出模板
+      * @global array $_A
+      * @param array $template 模板名称
+      * @return type
+      */
+     protected function display($template = '') {
+         global $_A;
+         $this->_view->assign("_A", $_A);
+         return $this->_view->fetch($template);
+     }
+
+}

+ 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);
+    }
+}

+ 1 - 0
app/ExecptionHandle.php

@@ -0,0 +1 @@
+<?php

+ 8 - 0
app/Request.php

@@ -0,0 +1,8 @@
+<?php
+namespace app;
+
+// 应用请求对象类
+class Request extends \think\Request
+{
+
+}

+ 18 - 0
app/api/config/app.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-11-10 12:58
+// +----------------------------------------------------------------------
+return [
+
+//    '__JS__'          => '/public/system/js',
+//    '__ASSETS__'      => '/public/system/assets',
+//    '__CSS__'         => '/public/system/css',
+//    '__IMAGES__'      => '/public/system/img',
+
+];

+ 37 - 0
app/api/controller/AuthController.php

@@ -0,0 +1,37 @@
+<?php
+declare (strict_types = 1);
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+namespace app\api\controller;
+
+/**
+ * 基类 所有控制器继承的类
+ * Class AuthController
+ * @package app\adminapi\controller
+ */
+class AuthController extends \app\BaseController
+{
+    /**
+     * 当前登陆管理员信息[记录日志]
+     * @var
+     */
+    protected $user;
+
+    /**
+     * 初始化
+     */
+    protected function initialize()
+    {
+        parent::initialize();
+        $this->user = $this->request->user;
+        event('UserVisit', [$this->user, 'api']);
+    }
+
+}

+ 122 - 0
app/api/controller/Login.php

@@ -0,0 +1,122 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\controller;
+
+use app\BaseController;
+use app\model\api\User as UserModel;
+use app\model\api\UserLogin;
+use app\Request;
+use library\lib\weixina;
+use library\services\JsonNull;
+use library\services\UtilService;
+
+use think\Cache;
+use think\Image;
+
+class Login extends BaseController
+{
+
+
+    /**
+     * 微信登录
+     * @param Request $request
+     */
+    public function weixinLogin(Request $request){
+        [$code,$nickname,$avatar,$device_id,$model,$platform,$system,$gender] = UtilService::getMore([
+            ['code', '', 'empty', 'code参数错误'],
+            ['nickname','微信用户',],
+            ['avatar','',],
+            ['device_id',''],
+            ['model',''],
+            ['platform',''],
+            ['system',''],
+            ['gender','0'],
+        ], $request, true);
+        //用户登录
+        if(empty($avatar)){
+            //默认通向
+            $avatar = "";
+        }
+        if(!in_array((string)$gender, array("0","1","2"))){
+            $gender = 0;
+        }
+        $regip = get_client_ip();
+        if(empty($regip)){
+            $regip = $request->ip();
+        }
+        $weixinA = new weixina();
+        $data=$weixinA->auth_code2Session($code);//新版
+        if(empty($data) || empty($data['openid'])) {
+            return app('json')->fail("微信授权登录失败,关闭页面重新授权".$weixinA->error);
+        }
+        $member = (new UserModel)->where("openid",$data["openid"])->find();
+        if(empty($member)){
+            //用户注册
+            $uid = (new UserModel)->insertGetId(array(
+                "openid"=>$data["openid"],
+                "unionid"=>empty($data["unionid"])?"":$data["unionid"],
+                "nickname"=>$nickname,
+                "avatar"=>$avatar,
+                "sex"=>(int)$gender,
+                "regtime"=>time(),
+                "regip"=>$regip,
+            ));
+            if(empty($uid)){
+                return app('json')->fail("网络繁忙,请稍后尝试");
+            }
+            //生成MD5
+            $token = base64_encode(md5($uid ."openid" .$data["openid"] . time()));
+            (new UserModel)->where('uid', $uid)->save(['lasttime'=>time(),'token'=>$token]);
+            //生成登录日志
+            (new UserLogin)->insert([
+                'uid'         => $uid, 
+                'ip'          => $regip, 
+                'time'        => time(),
+                'device_id'   => $device_id,
+                'from_plat'   => $platform,
+                'device_type' => $system,
+                'version'     => $model,
+            ]);
+            $result             = [];
+            $result['nickname'] = $nickname;
+            $result['avatar']   = $avatar;
+            $result['token']    = $token;
+            return app('json')->success($result);
+        }
+        if ($member['status'] == -1) {
+            return app('json')->fail("账号已被禁用");
+        }
+        //生成MD5
+        $token = base64_encode(md5($member['uid'] ."openid" . $member['openid'] . time()));
+        (new UserModel)->where('uid', $member['uid'])->save([
+            'lasttime' => time(),
+            'token'    => $token,
+        ]);
+        //生成登录日志
+        (new UserLogin)->insert([
+            'uid'         => $member['uid'], 
+            'ip'          => $regip, 
+            'time'        => time(),
+            'device_id'   => $device_id,
+            'from_plat'   => $platform,
+            'device_type' => $system,
+            'version'     => $model,
+        ]);
+        $result             = [];
+        $result['nickname'] = $member['nickname'];
+        $result['avatar']   = $member['avatar'];
+        $result['token']    = $token;
+        return app('json')->success($result);
+    }
+
+}

+ 137 - 0
app/api/controller/Pub.php

@@ -0,0 +1,137 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\controller;
+use think\facade\View;
+use app\BaseController;
+use app\Request;
+use library\services\UtilService;
+use library\utils\UtilsTool;
+use think\facade\Db;
+use think\Image;
+
+use app\model\api\AppBug;
+use app\model\api\ShowTemplate;
+
+class Pub extends BaseController
+{
+    private $user = null;
+    public function checkUser($token=null){
+        if(empty($token)){
+            return false;
+        }
+        $memData = (new UserModel)
+            ->where('token',$token)
+            ->where('status',1)
+            ->find();
+        if(empty($memData)){
+            return false;
+        }
+        $this->user = $memData->toArray();
+        return true;
+    }
+    
+    /**
+     * 获取皮肤模板列表
+     * @param Request $request
+     */
+    public function getShowTemplateList(Request $request){
+        $post = UtilService::getMore([
+            ['is_hot', '0'],
+            ['is_recommend', '0'],
+            ['page', 1],
+            ['pageSize', 50],
+        ], $request);
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
+        $where=[];
+        $where[]=["status","=",1];
+        if((int)$post["is_hot"]==1){
+            $where[]=["is_hot","=",1];
+        }
+        if((int)$post["is_recommend"]==1){
+            $where[]=["is_recommend","=",1];
+        }
+        
+        $totalCount = (new ShowTemplate)->where($where)->count();
+        $data=null;
+        if($totalCount>0){
+            $data = (new ShowTemplate)
+                ->field("id,title,price,old_price,status,img,is_hot,is_recommend")
+                ->where($where)
+                ->order("id", "desc")
+                ->page((int)$page, $post["pageSize"])
+                ->select();
+            foreach($data as $k=>$v){
+                $data[$k]["is_use"] = 0;//是否已经购买或者可以使用
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+    }
+    
+    
+    
+    
+    
+    
+    /**
+     * 获取系统信息
+     * @param Request $request
+     */
+    public function getSysData(Request $request){
+        $data = (new Sys)->where("id",1)->find()->toArray();
+        $data=[];
+        return app("json")->success($data);
+    }
+    /**
+     * 首页轮播
+     * @param Request $request
+     */
+    public function getHomeBanner(Request $request){
+        $data = (new AdvertModel)
+                ->field("id,img,title,url")
+                ->where("page_id",70)
+                ->where("is_show",1)
+                ->order("sort","desc")
+                ->select()
+                ->toArray();
+        $data = empty($data)?[]:$data;
+        return app("json")->success($data);
+    }
+
+   
+
+    
+    /**
+     * bug提交
+     * @param Request $request
+     */
+    public function appBugSub(Request $request){
+        [$error] = UtilService::getMore([
+            ['error', '','empty',"错误信息为空"],
+        ], $request,true);
+        $deviceId   = $request->header("deviceId", "");
+        $deviceType = $request->header("deviceType", "");
+        $fromPlat   = $request->header("fromPlat", "");
+        $version    = $request->header("version", "");
+        (new AppBug)->insert([
+            "device_id"   => $deviceId,
+            "device_type" => $deviceType,
+            "from_plat"   => $fromPlat,
+            "version"     => $version,
+            "error"       => $error,
+            "time"        => time()
+        ]);
+        return app("json")->success("提交成功");
+    }
+}

+ 70 - 0
app/api/controller/v1/Pay.php

@@ -0,0 +1,70 @@
+<?php
+declare (strict_types=1);
+namespace app\api\controller\v1;
+
+use app\Request;
+use app\BaseController;
+use app\model\api\PayTrade;
+use library\services\UtilService;
+use library\utils\weixinPay as wxpayApi;
+use app\lib\OrderLib;
+use think\Exception;
+
+class Pay extends BaseController{
+    /**
+     * 微信支付异步反馈
+     * @param Request $request
+     * @return boolean
+     */
+    public function wxpayNotify(Request $request){
+        $post = UtilService::getMore([
+            ['id', ''],
+            ['create_time', ''],
+            ['event_type',''],
+            ['resource_type', ''],
+            ['resource',[]],
+            ['summary', ''],
+        ], $request);
+        if(empty($post["event_type"]) || $post["event_type"] != "TRANSACTION.SUCCESS"){
+            return false;
+        }
+        if(empty($post["resource_type"]) || $post["resource_type"]!="encrypt-resource"){
+            return false;
+        }
+        if(empty($post["resource"])){
+            return false;
+        }
+        $wxpay = new wxpayApi();
+        $result = $wxpay->aesGcmDecrypt([
+            "associated_data"=>$post["resource"]["associated_data"],
+            "nonce"=>$post["resource"]["nonce"],
+            "ciphertext"=>$post["resource"]["ciphertext"],
+        ]);
+        
+        if(!$result){
+            return false;
+        }
+        //商家内部订单号
+        $out_trade_no   = $result["out_trade_no"];
+        $res = $wxpay->searchOrder($out_trade_no);
+        if(!$res){
+            return false;
+        }
+        $data = json_decode($res,true);
+        //支付成功
+        if($data["trade_state"]=="SUCCESS"){
+            $payDataInfo = [
+                    'totalMoney' =>(empty($data["amount"]) || empty($data["amount"]["total"]))      ?"未返回":$data["amount"]["total"]/100,
+                    'payMoney'   =>(empty($data["amount"]) || empty($data["amount"]["payer_total"]))?"未返回":$data["amount"]["payer_total"]/100,
+                    'payTradeNo' =>empty($data["transaction_id"]) ? "未返回" : $data["transaction_id"],
+                    'outTradeNo' =>empty($data["out_trade_no"])   ? "未返回" : $data["out_trade_no"],
+                    "tradeStatus"=>empty($data["trade_state"])    ? "未返回" : $data["trade_state"],
+                    "payTime"    =>empty($data["success_time"])   ? "未返回" : $data["success_time"],
+            ];
+            $pay_json = json_encode($payDataInfo);
+            (new OrderLib)->orderPay($out_trade_no, $pay_json);
+        }
+    }
+
+}
+

+ 2189 - 0
app/api/controller/v1/User.php

@@ -0,0 +1,2189 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\controller\v1;
+
+use app\BaseController;
+use app\model\api\Sys as SysModel;
+use app\model\api\User as UserModel;
+use app\model\api\Bank as BankModel;
+use app\model\api\UserLove as UserLoveModel;
+use app\model\api\UserCircle;
+use app\model\api\UserCircleLove;
+use app\model\api\Goods;
+use app\model\api\GoodsLove;
+use app\model\api\Order;
+use app\model\api\OrderInfo;
+use app\model\api\OrderMono;
+use app\model\api\Activity;
+use app\model\api\ActivityOrder;
+use app\model\api\Tx as TxModel;
+use app\lib\OrderLib;
+use app\model\api\PayTrade as PayTradeModel;
+use app\model\api\UserDetail as  UserDetailModel;
+use app\model\api\UserScoreDetail as  UserScoreDetailModel;
+use app\model\api\UserAddress;
+use app\model\api\UserShop;
+use app\model\api\Coupon as CouponModel;
+use app\model\api\UserCoupon as UserCouponModel;
+use app\Request;
+use library\services\UtilService;
+use library\utils\QRcodeComm;
+use library\utils\weixinPay as wxpayApi;
+use think\db\exception\DbException;
+use library\lib\weixina;
+use think\facade\Db;
+use think\Image;
+use think\Route;
+
+class User extends BaseController
+{
+    /**
+     * 获取用户基本数据
+     * @param Request $request
+     */
+    public function init(Request $request)
+    {
+        $result             = [];
+        $result['nickname']       = $request->user['nickname'];
+        $result['avatar']         = $request->user['avatar'];
+        $result['uip']            = $request->user['uip'];//用户UUID
+        $result['is_bind_parent'] = $request->user['parent_uid']>0?1:0;//是否绑定父级
+        $result['is_mobile']      = empty($request->user['mobile'])?0:1;//是否绑定手机号
+        return app('json')->success($result);
+    }
+
+    /**
+     * 会员中心信息
+     * @param Request $request
+     */
+    public function info(Request $request)
+    {
+        $result                = [];
+        //基础信息
+        $result['nickname']       = $request->user['nickname'];
+        $result['avatar']         = $request->user['avatar'];
+        $result['uip']            = $request->user['uip'];//用户UIP
+        $result['score']          = $request->user['score'];
+        $result['money']          = $request->user['money'];
+        $result['is_bind_parent'] = $request->user['parent_uid']>0?1:0;//是否绑定父级
+        $result['is_mobile']      = empty($request->user['mobile'])?0:1;//是否绑定手机号
+        
+        //动态发布信息
+        $result['loveCount']  = (new UserLoveModel)->where("uid",$request->user["uid"])->count();//关注数
+        $result['diaryCount'] = (new UserCircle)->where("uid",$request->user["uid"])->where("status",">",0)->count();//动态数
+        $result['fansCount']  = (new UserLoveModel)->where("love_uid",$request->user["uid"])->count();//粉丝数
+        $result['lookCount']  = $request->user['look_count'];;//观看量
+        $result['hotCount']   = $result['diaryCount']+$result['fansCount']+$result['lookCount'];//热度=发布量+粉丝数+观看量
+        //订单信息
+        $result['waitPayCount']     = (new Order)->where("uid",$request->user["uid"])->where("status",0)->count(); //待付款
+        $result['waitSendCount']    = (new Order)->where("uid",$request->user["uid"])->where("status",1)->count();//待发货
+        $result['waitAcceptCount']  = (new Order)->where("uid",$request->user["uid"])->where("status",2)->count();//待收货
+        $result['waitCommentCount'] = (new Order)->where("uid",$request->user["uid"])->where("status",3)->count();//待评价
+        //其他信息
+        $result['couponCount']      = (new UserCouponModel)->where("uid",$request->user["uid"])->where("status",0)->where("end_time",">",time())->count();//消费券数
+//        $result['logistics']=array(
+//            "img"=>"/static/image/test/test1.png",
+//            "title"=>"最新物流进展",
+//            "content"=>"您的订单已到达杭州转运中心,已入库",
+//        );
+        $orderList = (new Order)
+                ->field("id,order_id,name,tel,address,time,pay_time,fa_time,ok_time,status")
+                ->where("uid",$request->user["uid"])
+                ->where("status",1)
+                ->order("id","desc")
+                ->limit(2)
+                ->select()
+                ->toArray();
+        $orderList = empty($orderList) ? [] : $orderList;
+        $orderInfoModel=new OrderInfo();
+        foreach($orderList as $k=>$v){
+            $orderList[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $orderList[$k]["pay_time"] = empty($v["pay_time"]) ? "" : date("Y-m-d H:i:s",$v["pay_time"]);
+            $orderList[$k]["fa_time"]  = empty($v["fa_time"])  ? "" : date("Y-m-d H:i:s",$v["fa_time"]);
+            $orderList[$k]["ok_time"]  = empty($v["ok_time"])  ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
+            $orderList[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
+        }
+        $result['orderList'] = $orderList;
+        $result['shop_id'] = 0;
+        $result['shop_name'] = "";
+        $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
+        if(!empty($shopData)){
+           $result['shop_id'] = $shopData["id"];
+           $result['shop_name'] = $shopData["name"];
+        }
+        //收益记录数
+        $result['incomeCount'] = (new UserDetailModel)->where("uid",$request->user["uid"])->where("type",1)->count();
+        //下级分成记录数
+        $result['treeIncomeCount'] = (new UserDetailModel)->where("uid",$request->user["uid"])->where("type",1)->where("code","tree_per_income")->count();
+        return app('json')->success($result);
+    }
+    /**
+     * 保存个人资料
+     * @param Request $request
+     */
+    public function saveInfo(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['nickname', '', 'empty', '昵称不存在'],
+            ['avatar', '', 'empty', '头像不存在'],
+        ], $request);
+        $save['nickname'] = $post['nickname'];
+        $save['avatar']   = $post['avatar'];
+        (new UserModel)->where('uid', $request->user['uid'])->save($save);
+        return app('json')->success('保存成功');
+    }
+    
+    /**
+     * 绑定手机号
+     * @param Request $request
+     */
+    public function bindMobile(Request $request){
+        [$code] = UtilService::getMore([
+            ['code', '', 'empty', 'code参数错误'],
+        ], $request, true);
+        if(!empty($request->user['mobile'])){
+            return app('json')->fail("当前账户已绑定过手机号码");
+        }
+        $weixinA = new weixina();
+        $data=$weixinA->getPhoneNumber($code);//新版
+        if(empty($data) || empty($data['purePhoneNumber'])) {
+            return app('json')->fail("绑定失败,请重新绑定01".$weixinA->error);
+        }
+        $save=[
+            "countryCode"=>empty($data['countryCode'])?"":$data['countryCode'],
+            "mobile"=>$data['purePhoneNumber'],
+        ];
+        $r = (new UserModel)->where('uid', $request->user['uid'])->update($save);
+        if(!$r){
+            return app('json')->fail("绑定失败,请重新绑定02");
+        }
+        $result                    = [];
+        $result['nickname']        = $request->user['nickname'];
+        $result['avatar']          = $request->user['avatar'];
+        $result['token']           = $request->user['token'];
+        $result['uip']             = $request->user['uip'];
+        $result['is_mobile']       = 1;
+        return app('json')->success($result);
+        
+    }
+    /**
+     * 收藏商品
+     * @param Request $request
+     */
+    public function loveGoods(Request $request){
+        $post = UtilService::getMore([
+            ['id', '', 'empty', '参数错误'],
+        ], $request);
+        $data = (new Goods)->where("id",$post["id"])->where("status",1)->find();
+        if(empty($data)){
+            return app('json')->fail("当前商品已下架");
+        }
+        $count = (new GoodsLove)
+                ->where("uid",$request->user['uid'])
+                ->where("goods_id",$data["id"])
+                ->count();
+        $r=0;
+        $msg=$count > 0 ? "取消喜欢" : "喜欢";
+        if($count>0){
+            //取消喜欢
+            $r=(new GoodsLove)->where("uid",$request->user['uid'])->where("goods_id",$data["id"])->delete();
+        }else{
+            //点赞
+            $r=(new GoodsLove)->insert(array("uid"=>$request->user['uid'],"goods_id"=>$data["id"]));
+        }
+        if(empty($r)){
+            return app('json')->fail("{$msg}失败");
+        }
+        return app('json')->success("{$msg}成功");
+    }
+    /**
+     * 点赞圈子
+     * @param Request $request
+     */
+    public function loveCircle(Request $request){
+        $post = UtilService::getMore([
+            ['id', '', 'empty', '参数错误'],
+        ], $request);
+        $data = (new UserCircle)->where("id",$post["id"])->where("status",1)->find();
+        if(empty($data) || $data["uid"] == $request->user['uid']){
+            return app('json')->fail("当前动态不能点赞");
+        }
+        $count = (new UserCircleLove)
+                ->where("uid",$request->user['uid'])
+                ->where("circle_id",$data["id"])
+                ->count();
+        $r=0;
+        $msg=$count > 0 ? "取消点赞" : "点赞";
+        if($count>0){
+            //取消点赞
+            $r=(new UserCircleLove)->where("uid",$request->user['uid'])->where("circle_id",$data["id"])->delete();
+        }else{
+            //点赞
+            $r=(new UserCircleLove)->insert(array("uid"=>$request->user['uid'],"circle_id"=>$data["id"]));
+        }
+        if(empty($r)){
+            return app('json')->fail("{$msg}失败");
+        }
+        $love_count = (new UserCircleLove)->where("circle_id",$data["id"])->count();
+        (new UserCircle)->where('id', $data["id"])->update(["love_count"=>$love_count]);
+        return app('json')->success("{$msg}成功");
+    }
+    /**
+     * 添加关注
+     * @param Request $request
+     */
+    public function loveUser(Request $request){
+        $post = UtilService::getMore([
+            ['uip', '', 'empty', '用户不存在'],
+        ], $request);
+        $data = (new UserModel())->where("uip",$post["uip"])->find();
+        if(empty($data) || $data["uip"] == $request->user['uip']){
+            return app('json')->fail("用户不存在");
+        }
+        $count = (new UserLoveModel())
+                ->where("uid",$request->user['uid'])
+                ->where("love_uid",$data["uid"])
+                ->count();
+        $r=0;
+        $msg=$count > 0 ? "取消关注" : "关注";
+        if($count>0){
+            //取消关注
+            $r=(new UserLoveModel())->where("uid",$request->user['uid'])->where("love_uid",$data["uid"])->delete();
+        }else{
+            //关注
+            $r=(new UserLoveModel())->insert(array("uid"=>$request->user['uid'],"love_uid"=>$data["uid"],"time"=>time()));
+        }
+        if(empty($r)){
+            return app('json')->fail("{$msg}失败");
+        }
+        return app('json')->success("{$msg}成功");
+    }
+    /**
+     * 获取用户绑定
+     * @param Request $request
+     */
+    public function bankInfo(Request $request){
+        $data = [
+            "bank_type"=>$request->user["bank_type"],
+            "bank_num"=>$request->user["bank_num"],
+            "bank_name"=>$request->user["bank_name"],
+            "bank_ad"=>$request->user["bank_ad"],
+        ];
+        return app('json')->success($data);
+    }
+    /**
+     * 获取提现信息
+     * @param Request $request
+     */
+    public function tixianInfo(Request $request){
+        $sysData = (new SysModel)->where("id",1)->find();
+        $data = [
+            "bank_type"=>$request->user["bank_type"],
+            "bank_num"=>$request->user["bank_num"],
+            "bank_name"=>$request->user["bank_name"],
+            "bank_ad"=>$request->user["bank_ad"],
+            "money"=>$request->user["money"],
+            "tx_limit_money"=>$sysData["tx_limit_money"]
+        ];
+        return app('json')->success($data);
+    }
+    /**
+     * 获取提现类型
+     * @param Request $request
+     * @return type
+     */
+    public function getBankType(Request $request){
+        $data=(new BankModel)
+                ->where("status",1)
+                ->order("seq","desc")
+                ->order("id","desc")
+                ->select()
+                ->toArray();
+        $data = empty($data)?[]:$data;
+        return app('json')->success($data);
+    }
+    
+    /**
+     * 编辑绑定
+     * @param Request $request
+     * @return type
+     */
+    public function editBank(Request $request){
+        [$bank_type,$bank_name, $bank_num,$bank_ad] = UtilService::getMore([
+            ['bank_type', '', 'empty', '请选择提现方式'],
+            ['bank_name', '', 'empty', '请输入真实姓名'],
+            ['bank_num', '', 'empty', '请输入账号'],
+            ['bank_ad', ''],
+        ], $request, true);
+        if($bank_type!="alipay" && empty($bank_ad)){
+            return app('json')->fail("请输入开户行");
+        }
+        if($bank_type=="alipay"){
+            $bank_ad = "支付宝";
+        }
+        $typeCount=(new BankModel)->where("code",$bank_type)->count();
+        if($typeCount<=0){
+            return app('json')->fail("请选择正确的提现方式");
+        }
+        $save=[
+            "bank_type"=>$bank_type,
+            "bank_name"=>$bank_name,
+            "bank_num"=>$bank_num,
+            "bank_ad"=>$bank_ad,
+        ];
+        (new UserModel)->where("uid",$request->user['uid'])->update($save);
+        return app('json')->success("绑定成功");
+    }
+    /**
+     * 提现申请
+     * @param Request $request
+     */
+    public function tixianApply(Request $request){
+        [$money] = UtilService::getMore([
+            ['money', 0, 'is_numeric', '请输入正确的提现金额'],
+        ], $request, true);
+        //缓存
+        $redis = \think\facade\Cache::store('redis');
+        $key   = 'user_tixian_' . $request->user['uid'];
+        $bool  = $redis->handler()->exists($key);
+        if ($bool) {
+            return app('json')->fail('您的操作过于频繁,请稍等再重试!');
+        }
+        $redis->set($key,1,10);//30秒缓存
+        $user = $request->user;
+        if(empty($user["openid"])){
+            return app('json')->fail('您还未绑定微信');
+        }
+        if(floatval($money)<=0){
+            return app('json')->fail('请输入正确的提现金额');
+        }
+        if(floatval($money)>$user["money"]){
+            return app('json')->fail('您的余额不足,无法提现');
+        }
+        if(empty($user["bank_type"]) || empty($user["bank_num"]) || empty($user["bank_name"])){
+            return app('json')->fail('您还未绑定提现账户');
+        }
+        if($user["bank_type"]!="alipay" && empty($user["bank_ad"])){
+            return app('json')->fail('您还未绑定提现开户行');
+        }
+        $sysData = (new SysModel)->where("id",1)->find();
+        if(floatval($user["money"])<floatval($sysData["tx_limit_money"]) || floatval($money)<floatval($sysData["tx_limit_money"])){
+            return app('json')->fail("满{$sysData['tx_limit_money']}元,才可提现");
+        }
+        //提现手续费
+        $hand_money = $sysData["tx_process_per"] > 0 ? floatval($money) * $sysData["tx_process_per"] / 100 : 0;
+        $hand_money = num_min_format($hand_money);
+        $save=[];
+        $save["uid"]        = $user["uid"];
+        $save["bank_type"]  = $user["bank_type"];
+        $save["bank_num"]   = $user["bank_num"];
+        $save["bank_name"]  = $user["bank_name"];
+        $save["bank_ad"]    = $user["bank_ad"];
+        $save["money"]      = floatval($money);
+        $save["hand_money"] = ($sysData["tx_process_max"] > 0 && $hand_money > $sysData["tx_process_max"]) ? $sysData["tx_process_max"] : $hand_money;
+        $save["tx_money"]   = $save["money"] - $save["hand_money"];
+        $save["status"]     = 0;
+        $save["time"]       = time();
+        try{
+            Db::startTrans();
+            //插入提现申请
+            $tx_id = (new TxModel)->insertGetId($save);
+            if(empty($tx_id)){
+                return app('json')->fail('提交失败');
+            }
+            //更新提现账户余额并添加明细
+            $r= (new UserDetailModel)->txApplyMoney($user["uid"],floatval($money),$tx_id);
+            if(!$r){
+                (new TxModel)->where("id",$tx_id)->delete();
+                return app('json')->fail('提交失败');
+            }
+            Db::commit();
+            $redis->delete($key);
+            return app('json')->success('提交成功,等待客服处理');
+        } catch (DbException $db){
+            Db::rollback();
+            return app('json')->fail("订单生成失败");
+        }
+    }
+    
+    
+    
+    
+    
+    
+    /**
+     * 关注列表
+     * @param Request $request
+     */
+    public function loveList(Request $request)
+    {
+        $pageSize = 20;
+        [$page] = UtilService::getMore([
+            ['page', 1],
+        ], $request, true);
+        $data = (new UserLoveModel)
+            ->field("u.id,u2.uip,u2.nickname,u2.avatar")
+            ->alias("u")
+            ->join("user u2", "u2.uid = u.love_uid")
+            ->where("u.uid", $request->user['uid'])
+            ->order("id", "desc")
+            ->page((int)$page, $pageSize)
+            ->select();
+        $loveCount = (new UserLoveModel)->alias("u")->where("u.uid", $request->user['uid'])->count();
+        $tAr  = UtilService::getParam([
+            'id','uip', 'nickname', 'avatar'
+        ], $data);
+        return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize,'loveCount'=>$loveCount]);
+    }
+    /**
+     * 我的粉丝
+     * @param Request $request
+     */
+    public function fansList(Request $request)
+    {
+        $pageSize = 20;
+        [$page] = UtilService::getMore([
+            ['page', 1],
+        ], $request, true);
+        $data = (new UserLoveModel)
+            ->field("u.id,u2.uip,u2.nickname,u2.avatar")
+            ->alias("u")
+            ->join("user u2", "u2.uid = u.uid")
+            ->where("u.love_uid", $request->user['uid'])
+            ->order("id", "desc")
+            ->page((int)$page, $pageSize)
+            ->select();
+        $fansCount = (new UserLoveModel)->alias("u")->where("u.love_uid", $request->user['uid'])->count();
+        $tAr  = UtilService::getParam([
+           'id', 'uip', 'nickname', 'avatar'
+        ], $data);
+        return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize,'fansCount'=>$fansCount]);
+    }
+    /**
+     * 获取门店信息
+     * @param Request $request
+     * @return type
+     */
+    public function userShopInfo(Request $request){
+        $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
+        if(empty($shopData)){
+            return app('json')->fail("您还没有绑定店铺");
+        }
+        return app('json')->success($shopData->toArray());
+    }
+    /**
+     * 获取门店列表
+     * @param Request $request
+     */
+    public function getShopList(Request $request){
+        [$longitude,$latitude] = UtilService::getMore([
+            ['longitude', ""],
+            ['latitude', ""],
+        ], $request, true);
+        //经纬度排序
+        $lbsOrder="id desc";
+        if(!empty($longitude) && !empty($latitude)){
+            $lng = $longitude;
+            $lat = $latitude;
+            $lbsOrder = 'ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(('.$lng.' * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380';
+        }
+        $data = (new UserShop)
+                ->field("id,area, address,name,tel,lx_name,longitude,latitude")
+                ->where("is_show",1)
+                ->orderRaw($lbsOrder)
+                ->select();
+        $data = empty($data)?[]:$data->toArray();
+        return app('json')->success(['list' =>$data, 'pageSize' => 100]);
+    }
+    
+    /**
+     * 我的地址列表
+     * @param Request $request
+     */
+    public function addressList(Request $request){
+        $pageSize = 20;
+        [$page] = UtilService::getMore([
+            ['page', 1],
+        ], $request, true);
+        $data = (new UserAddress)
+            ->where("uid", $request->user['uid'])
+            ->order("time", "desc")
+            ->page((int)$page, $pageSize)
+            ->select();
+        $tAr  = UtilService::getParam([
+           'id','area', 'address', 'name', 'tel', 'defalut'
+        ], $data);
+        return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize]);
+    }
+    /**
+     * 删除地址
+     * @param Request $request
+     */
+    public function addressDel(Request $request){
+        $post = UtilService::getMore([
+            ['id','','empty','参数错误'],
+        ],$request);
+        $r = (new UserAddress)->where("id",$post["id"])->where("uid",$request->user["uid"])->delete();
+        if($r){
+            return app('json')->success("删除成功");
+        }else{ 
+            return app('json')->fail("删除失败");
+        }
+    }
+    
+    /**
+     * 获取用户券列表
+     * @param Request $request
+     */
+    public function couponList(Request $request){
+        $pageSize = 20;
+        [$page,$type] = UtilService::getMore([
+            ['page', 1],
+            ['type',''],
+        ], $request, true);
+        //清除失效的券
+        (new UserCouponModel)->where("uid", $request->user['uid'])->where("status",0)->where("end_time","<",time())->update(["status"=>-1]);
+        //条件
+        $where=[];
+        $where[] = ["uid","=",$request->user['uid']];
+        //未使用
+        if($type=="using"){
+            $where[] = ["status","=",0];
+        }
+        //已经使用
+        if($type=="used"){
+            $where[] = ["status","=",1];
+        }
+        //已过期
+        if($type=="nouser"){
+            $where[] = ["status","=",-1];
+        }
+        $data = (new UserCouponModel)
+            ->where($where)
+            ->order("time", "desc")
+            ->page((int)$page, $pageSize)
+            ->select()
+            ->toArray();
+        foreach($data as $k=>$v){
+            $data[$k]["start_time"] = date("Y.m.d",$v["start_time"]);
+            $data[$k]["end_time"] = date("Y.m.d",$v["end_time"]);
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
+    }
+    
+    /**
+     * 用户领券
+     * @param Request $request
+     */
+    public function gainCoupon(Request $request){
+        $post = UtilService::getMore([
+            ['coupon_id','','empty','参数错误'],
+        ],$request);
+        $data = (new CouponModel)->where("id",$post["coupon_id"])->where("status",1)->find();
+        if(empty($data)){
+            return app('json')->fail("当前优惠券不支持领取");
+        }
+        $userCouponData = (new UserCouponModel)->where("coupon_id",$post["coupon_id"])->where("uid",$request->user["uid"])->find();
+        if(!empty($userCouponData)){
+            return app('json')->fail("您已经领取过该优惠券了");
+        }
+        $ntime = time();
+        $save=[
+            "uid"=>$request->user["uid"],
+            "coupon_id"=>$data["id"],
+            "title"=>$data["title"],
+            "price"=>$data["price"],
+            "limit_price"=>$data["limit_price"],
+            "day"=>$data["day"],
+            "status"=>0,
+            "time"=>$ntime,
+            "start_time"=>strtotime(date("Y-m-d",$ntime)),
+            "end_time"=>$ntime+$data["day"]*24*60*60,
+        ];
+        $r = (new UserCouponModel)->insert($save);
+        if($r){
+            return app('json')->success("领取成功");
+        }else{ 
+            return app('json')->fail("领取失败");
+        }
+    }
+    
+    /**
+     * 添加编辑地址
+     * @param Request $request
+     */
+    public function addressAdd(Request $request){
+        $post = UtilService::getMore([
+            ['id',''],
+            ['area','','empty','请选择省市区'],
+            ['address','','empty','请填写详细地址'],
+            ['name','','empty','请填写姓名'],
+            ['tel','','empty','请填写电话'],
+        ],$request);
+        $post["time"] = time();
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $post["uid"]=$request->user["uid"];
+            $r = (new UserAddress)->insert($post);
+        }else{
+            $r = (new UserAddress)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+    
+    
+    
+    
+    /**
+     * 获取用户二维码
+     * @param Request $request
+     */
+    public function getUipErcode(Request $request){
+        $sysData = (new SysModel)->where("id",1)->find();
+        //二维码生成器
+        $QRcodeComm = new QRcodeComm();
+        $url=$sysData['system_url']."/pushurl/".$request->user['uip'];
+        $urlPath = $QRcodeComm->getPngErcode($url);
+        $savePath = $sysData['system_url'] . $urlPath;
+        if(!empty($request->user["ercode"])){
+            $rootPath = app()->getRootPath()."/public/resource".explode("resource",$request->user["ercode"])[1];
+            if(file_exists($rootPath)){
+                unlink($rootPath);
+            }
+        }
+        (new UserModel)->where("uid",$request->user["uid"])->update(array("ercode"=>$savePath));
+        return app('json')->success(['url' => $savePath]);
+    }
+    
+    
+    
+    /**
+     * 获取下单初始信息
+     * @param Request $request
+     */
+    public function getProBuyInfo(Request $request){
+        [$p_id,$is_ip_buy,$longitude,$latitude] = UtilService::getMore([
+            ['p_id','','empty','商品参数错误'],
+            ['is_ip_buy','0'],
+            ['longitude',''],
+            ['latitude',''],
+        ],$request,true);
+        
+        
+        $is_ip_buy = (int)$is_ip_buy==0?0:1;
+        $proData = (new Goods)->where("id",(int)$p_id)->where("status",1)->find();
+        if(empty($proData)){
+            return app('json')->fail("当前商品已下架");
+        }
+        $proData=$proData->toArray();
+        if($proData["limit"]<=0){
+            return app('json')->fail("当前商品限购不可购买");
+        }
+        if($is_ip_buy==1 && ($proData["is_ip"]==0 || !empty($proData["uid"]))){
+            return app('json')->fail("当前商品不可买断");
+        }
+        $price = floatval($proData["price"]);
+        if($is_ip_buy==1){
+            $price = floatval($proData["ip_price"]);
+        }
+        $img = explode(",", $proData["imgs"])[0];
+        $data=[
+            "score"=> $is_ip_buy == 1 ? 0 : $request->user["score"],
+            "use_score"=>0,
+            "is_score"=>1,
+            "proMoney"=>0,
+            "allMoney"=>0,
+            "couponMoney"=>0,
+            "coupon"=>[
+                "id"=>"",
+                "limit"=>0,//满多少可用
+                "price"=>0,//金额
+            ],
+            "mono"=>"",
+            "address"=>[
+                "id"=>"",
+                "address"=>"",
+                "name"=>"",
+                "tel"=>"",
+            ],
+            "shop"=>[
+                "id"=>"",
+                "address"=>"",
+                "name"=>"",
+                "tel"=>"",
+            ],
+            "pro"=>[],
+        ];
+        //商品信息
+        $data["pro"][]=[
+            "id"=>$proData["id"],
+            "img"=>$img,
+            "count"=>1,
+            "status"=>$proData["status"],
+            "title"=>$proData["title"],
+            "price"=>$price,
+            "ip_income_per"=>$proData["ip_income_per"],
+            "is_ip_buy"=>$is_ip_buy,
+            "limit"=>$is_ip_buy==1 ? 1 : $proData["limit"],
+            "data"=>empty($proData["data"])?[]:unserialize($proData["data"])
+        ];
+        //默认地址信息
+        $addressData = (new UserAddress)->where("uid", $request->user['uid'])->order("time", "desc")->find();
+        if(!empty($addressData)){
+            $data["address"]["id"]      = $addressData["id"];
+            $data["address"]["address"] = $addressData["area"].$addressData["address"];
+            $data["address"]["name"]    = $addressData["name"];
+            $data["address"]["tel"]     = $addressData["tel"];
+            $data["address"]["lx_name"] = "";
+        }
+        //默认店铺地址经纬度排序
+        $lbsOrder="id desc";
+        if(!empty($longitude) && !empty($latitude)){
+            $lng = $longitude;
+            $lat = $latitude;
+            $lbsOrder = 'ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(('.$lng.' * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380';
+        }
+        $shopData = (new UserShop)->where("is_show",1)->orderRaw($lbsOrder)->find();
+        if(!empty($shopData)){
+            $data["shop"]["id"]      = $shopData["id"];
+            $data["shop"]["address"] = $shopData["address"];
+            $data["shop"]["name"]    = $shopData["name"];
+            $data["shop"]["tel"]     = $shopData["tel"];
+            $data["shop"]["lx_name"] = $shopData["lx_name"];
+        }
+        $data["buyTypeData"]=[["id"=>0,"title"=>"商家配送","is_show"=>0,"is_default"=>0],["id"=>1,"title"=>"门店自提","is_show"=>1,"is_default"=>1]];
+        return app('json')->success($data);
+    }
+    
+    /**
+     * 获取报名表单信息
+     * @param Request $request
+     */
+    public function activityFromInfo(Request $request){
+        $post = UtilService::getMore([
+            ['id', '','empty','参数错误'],
+        ], $request);
+        $data = (new Activity)->where('is_show', 1)->where('id', $post["id"])->find();
+        if(empty($data)){
+            return app('json')->fail("数据获取失败");
+        }
+        $data = $data->toArray();
+        $acData=[];
+        $acData["id"]              = $data["id"];
+        $acData["img"]             = empty($data["imgs"])  ? "" : explode(",",$data["imgs"])[0];
+        $acData["title"]           = $data["title"];
+        $acData["status"]          = $data["time"] > time() ? 1 : 0;
+        $acData["time"]            = date("Y.m.d",$data["time"]);
+        $acData["deposits_price"]  = floatval($data["deposits_price"]);
+        $acData["data"]            = empty($data["data"]) ? [] : unserialize($data["data"]);
+        $acData["mono"]            = "";
+        foreach($acData["data"] as $k=>$v){
+            $acData["data"][$k]["value"]="";
+            if(!empty($v["parms"])){
+                $acData["data"][$k]["index"]=0;
+                $acData["data"][$k]["parms"] = array_merge(["选择{$v['title']}"],$v["parms"]);
+            }
+        }
+        return app('json')->success($acData);
+    }
+    /**
+     * 活动报名订单提交[第一步]
+     * @param Request $request
+     */
+    public function subActivityOrder(Request $request){
+        [$id,$data] = UtilService::getMore([
+            ['id','','empty','请选择要报名的活动'],
+            ['data','','empty','请填写报名信息'],
+        ],$request,true);
+        //缓存
+        $redis = \think\facade\Cache::store('redis');
+        $key   = 'order_sub_' . $request->user['uid'];
+        $bool  = $redis->handler()->exists($key);
+        if ($bool) {
+            return app('json')->fail('请务重复操作,请稍等在重试!');
+        }
+        $redis->set($key,1,5);//5秒缓存
+        if(empty($id) || empty($data)){
+            return app('json')->fail('提交参数有误01');
+        }
+        $data = json_decode($data,true);
+        if(!is_array($data)){
+            return app('json')->fail('提交参数有误02');
+        }
+        
+        $activityData = (new Activity)->where("id",(int)$id)->where("is_show",1)->find();
+        if(empty($activityData)){
+            return app('json')->fail("当前活动已下架");
+        }
+        $activityData=$activityData->toArray();
+        if($activityData["time"]<=time()){
+            return app('json')->fail("当前活动已经结束");
+        }
+        $price = floatval($activityData["deposits_price"]);
+//        if($price<=0){
+//            return app('json')->fail("活动报名费用错误");
+//        }
+        $img = explode(",", $activityData["imgs"])[0];
+        $allMoney = $price;//订单商品费用
+        $total_money = $allMoney;//订单总费用
+        $payMoney = $total_money;//订单需支付费用
+        $payMoney = $payMoney <= 0 ? 0 : $payMoney;
+        $nowTime = time();
+        //验证报名参数提交
+        $parmData = empty($activityData["data"]) ? [] : unserialize($activityData["data"]);
+        if(empty($parmData)){
+            return app('json')->fail("系统参数错误");
+        }
+        $newData = [];
+        foreach($parmData as $k=>$v){
+            $itemData=[
+                "title"=>trim($v["title"]),
+                "value"=>"",
+            ];
+            $check = false;
+            foreach($data as $dk=>$dv){
+                if($dv["title"]==$v["title"]){
+                    //验证必填项
+                    if((int)$v["required"]==1 && empty($dv["value"])){
+                        return app('json')->fail("{$v['title']}为必填项");
+                    }
+                    //下拉框验证
+                    if(!empty($dv["value"]) && $v["type"]=="select" && !in_array($dv["value"],$v["parms"])){
+                        return app('json')->fail("{$v['title']}选项不存在");
+                    }
+                    $itemData["value"]=trim($dv["value"]);
+                    $check = true;
+                    break;
+                }
+            }
+            if(!$check){
+                return app('json')->fail("请填写{$v['title']}");
+            }
+            $newData[]=$itemData;
+        }
+        if(empty($newData)){
+            return app('json')->fail("参数整合错误");
+        }
+        //主订单数据
+        $save=[];
+        $save['uid']          = $request->user['uid'];
+        $save['order_id']     =  makeOrderId($request->user['uid'],"A");
+        $save['pay_type']     = 'wxpay';//目前只支持微信支付
+        $save['total_money']  = $total_money;//订单总金额
+        $save['all_money']    = $allMoney;//商品中金额
+        $save['pay_money']    = $payMoney;//实际支付金额
+        $save['balance']      = 0;//余额支付了多少(目前没有余额支付)
+        $save['status']       = $payMoney <= 0 ? 1 : 0;
+        $save['pay_time']     = $payMoney <= 0 ? time() : 0;
+        $save['time']         = $nowTime;
+        $save['activity_id']  = $activityData["id"];
+        $save['data']         = serialize($newData);
+        $save['activity_data']= serialize([
+            "id"=>$activityData["id"],
+            "img"=>$img,
+            "title"=>$activityData["title"],
+            "address"=>$activityData["address"],
+            "deposits_price"=>$activityData["deposits_price"],
+            "time_str"=>$activityData["time_str"],
+            "time"=>date("Y-m-d H:i:s",$activityData["time"]),
+        ]);
+        
+        try{
+            Db::startTrans();
+            $o_id = (new ActivityOrder)->insertGetId($save);
+            if(empty($o_id)){
+                return app('json')->fail("报名订单提交失败");
+            }
+            //不需要支付
+            if($save['status']==1){
+                Db::commit();
+                return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
+            }
+            if(empty($request->user['openid'])){
+                return app('json')->fail('用户还未绑定微信!');
+            }
+            //清理之前支付凭证 || 防止重复购买
+            $payTrade = (new PayTradeModel)
+                    ->where("uid",$request->user["uid"])
+                    ->where("o_id",$o_id)
+                    ->where("type","activity")
+                    ->where("status",0)
+                    ->where("time","<",time() - 7*24*60*60)
+                    ->select()
+                    ->toArray();
+            $wxpay = new wxpayApi();
+            foreach ($payTrade as $v) {
+//                if($v['pay_type'] == 'wxpay') {
+//                    $result = $wxpay->closeOrder($v['pay_no']);
+//                }
+                (new PayTradeModel)->where("id",$v['id'])->where("status",0)->delete();
+            }
+            $mtime = microtime(true)*10000;
+            $payOn = "A".date("Ymd").$mtime .rand(1000,9000) . $request->user['uid'];
+            $out_trade_no="";
+            $payType  = $save["pay_type"];
+            //添加交易记录
+            $trade = [
+                'uid'      => $request->user['uid'],
+                'o_id'     => $o_id,
+                'order_id' =>$save["order_id"],
+                'pay_no'   => $payOn,
+                'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
+                'pay_type' => $payType,
+                'money'    => $payMoney,
+                'type'     => 'activity',
+                'd_json'   => serialize(['orderId'=>$save["order_id"],"give_score"=>0]),
+                'time'     => time(),
+                'status'   => 0,
+            ];
+            $r=(new PayTradeModel)->insert($trade);
+            if(!$r){
+                return app('json')->fail('支付信息获取失败!');
+            }
+            $clictip = get_client_ip();
+            if(empty($clictip)){
+                $clictip = $request->ip();
+            }
+            $payData =  $wxpay->wxmpPay([
+                'description' =>"微信小程序活动报名",
+                'out_trade_no' => $payOn,
+                'total' => $payMoney,
+                'openid' => $request->user['openid'],
+                'payer_client_ip'=>$clictip,
+            ]);
+            if(empty($payData)){
+                return app('json')->fail($wxpay->errorMsg);
+            }
+            Db::commit();
+            $redis->delete($key);
+            return app('json')->success([
+                'jsApiParameters'=> $payData,
+                'pay_no'         => $payOn,
+                'order_id'       => $save["order_id"],
+                "status"         => $save['status'],
+                "money"          => $payMoney,
+            ]);
+        } catch (DbException $db){
+            Db::rollback();
+            return app('json')->fail("订单生成失败");
+        }
+    }
+    /**
+     * 获取支付报名订单详情
+     * @param Request $request
+     */
+    public function payActivityOrderInfo(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $data = (new ActivityOrder)
+                ->field("order_id,total_money,all_money,pay_money,status,time")
+                ->where("order_id",$order_id)
+                ->where("uid",$request->user["uid"])
+                ->find();
+        if(empty($data)){
+            return app('json')->fail('信息不存在!');
+        }
+        $data=$data->toArray();
+        if($data["status"]==0 && $data["time"]<time() - 30*60){
+            (new ActivityOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
+            $data["status"]==-1;
+        }
+        $data["time"] = date("Y-m-d H:i:s",$data["time"]);
+         return app('json')->success($data);
+    }
+    
+    
+    
+    /**
+     * 提交订单[第一步]
+     * @param Request $request
+     */
+    public function subOrder(Request $request){
+        [$p_id,$address_id,$shop_id,$count,$mono,$coupon_id,$is_ip_buy,$is_score,$type] = UtilService::getMore([
+            ['p_id','','empty','请选择要购买的商品'],
+            ['address_id',''],
+            ['shop_id',''],
+            ['count','','is_numeric','请选择购买数量'],
+            ['mono',''],
+            ['coupon_id',''],
+            ['is_ip_buy','0'],
+            ['is_score','0'],
+            ['type','send'],
+        ],$request,true);
+        if(!in_array($type,["shop","send"])){
+            return app('json')->fail('参数错误!');
+        }
+        if($type=="shop"){
+            $address_id = "";
+        }else{
+            $shop_id = "";
+        }
+        if((int)$is_ip_buy==1){
+            $address_id = "";
+            $shop_id = "";
+        }
+        if((int)$is_ip_buy==0 && $type=="send" && empty($address_id)){
+            return app('json')->fail('请选择收货地址');
+        }
+        if((int)$is_ip_buy==0 && $type=="shop" && empty($shop_id)){
+            return app('json')->fail('请选择自提门店!');
+        }
+        if($type=="shop" && $is_ip_buy==1){
+            return app('json')->fail('买断不可选择门店自提!');
+        }
+        //用户缓存
+        $redis = \think\facade\Cache::store('redis');
+        $key   = 'order_sub_' . $request->user['uid'];
+        $bool  = $redis->handler()->exists($key);
+        if ($bool) {
+            return app('json')->fail('请务重复操作,请稍等在重试!');
+        }
+        $redis->set($key,1,5);//5秒缓存
+        
+        $is_ip_buy = (int)$is_ip_buy == 1 ? 1 : 0;
+        $is_score = (int)$is_score == 1 && $is_ip_buy==0 ? 1 : 0;//普通购买才可以使用积分
+        $is_ip_buy = (int)$is_ip_buy == 0 ? 0 : 1;
+        $coupon_id = $is_ip_buy == 1 ? 0 : (int)$coupon_id;
+        $count     = $is_ip_buy == 1 ? 1 : (int)$count;
+        
+        $proData = (new Goods)->where("id",(int)$p_id)->where("status",1)->find();
+        if(empty($proData)){
+            return app('json')->fail("当前商品已下架");
+        }
+        $proData=$proData->toArray();
+        if($proData["limit"]<=0 || $count>$proData['limit']){
+            return app('json')->fail("当前商品单次限购".$proData['limit']."件");
+        }
+        if($is_ip_buy==1 && ($proData["is_ip"]==0 || !empty($proData["uid"]))){
+            return app('json')->fail("当前商品不可买断");
+        }
+        
+        //IP商品缓存
+        if($is_ip_buy==1){
+            $ipkey   = 'order_sub_ip_' . $p_id;
+            $ipbool  = $redis->handler()->exists($ipkey);
+            if($ipbool){
+                return app('json')->fail('当前购买人数太多,请稍等再尝试!');
+            }
+            $redis->set($ipkey,1,5);//5秒缓存
+        }
+        
+        $price = floatval($proData["price"]);
+        if($is_ip_buy==1){
+            $price = floatval($proData["ip_price"]);
+        }
+        if($price<=0){
+            if($is_ip_buy==1){
+                $redis->delete($ipkey);
+            }
+            return app('json')->fail("商品价格错误");
+        }
+        $img = explode(",", $proData["imgs"])[0];
+        //优惠券
+        $couponData=null;
+        $couponMoney=0;
+        if(!empty($coupon_id)){
+            $couponData = (new UserCouponModel)->where("id",$coupon_id)->where("uid",$request->user["uid"])->where("status",0)->where("end_time",">",time())->find();
+            if(empty($couponData)){
+                if($is_ip_buy==1){
+                    $redis->delete($ipkey);
+                }
+                return app('json')->fail("当前优惠券不可用");
+            }
+            $couponMoney = $couponData["price"];
+        }
+        //收货地址
+        $addressData=null;
+        if(!empty($address_id)){
+            $addressData = (new UserAddress)->where("id",$address_id)->where("uid",$request->user["uid"])->find();
+            if(empty($addressData)){
+                return app('json')->fail("请选择收货地址02");
+            }
+        }
+        //门店地址
+        $shopData=null;
+        if(!empty($shop_id)){
+            $shopData = (new UserShop)->where("id",$shop_id)->where("is_show",1)->find();
+            if(empty($shopData)){
+                return app('json')->fail("请选择自提门店");
+            }
+        }
+        
+        $nowTime = time();
+        //订单详情数据
+        $infoData=[];
+        $info=[];
+        $info["o_id"]      = "";
+        $info["uid"]       = $request->user['uid'];
+        $info["p_id"]      = $proData["id"];
+        $info["title"]     = $proData["title"];
+        $info["img"]       = $img;
+        $info["count"]     = $count;
+        $info["price"]     = $price;
+        $info["money"]     = $price*$count;
+        $info["give_score"]= $is_ip_buy == 1 ? 0 : (int)$proData["give_score"] * $count;
+        $info["is_ip_buy"] = $is_ip_buy;
+        $info["add_time"]  = $nowTime;
+        $infoData[]=$info;
+        $give_score = 0;
+        $allMoney = 0;
+        $postageMoney = 0;
+        foreach($infoData as $k=>$v){
+            $allMoney+=$v["money"];
+            $give_score+=$v["give_score"];
+        }
+        if(!empty($couponData) && $allMoney<$couponData["limit_price"]){
+            if($is_ip_buy==1){
+                $redis->delete($ipkey);
+            }
+            return app('json')->fail("当前优惠券满{$couponData['limit_price']}可用");
+        }
+        $total_money = $allMoney + $postageMoney;
+        $payMoney = $total_money - $couponMoney;
+        $payMoney = $payMoney <= 0 ? 0 : $payMoney;
+        
+        //使用积分1:1元
+        $score=0;
+        if($payMoney>0 && $request->user["score"]>0 && $is_score==1){
+            $score = $request->user["score"] > $payMoney ? (int)$payMoney : (int)$request->user["score"];
+        }
+        $payMoney = $payMoney - $score;
+        //目前先不能支付0元
+//        if($payMoney<=0){
+//            return app('json')->fail("订单金额错误");
+//        }
+        //主订单数据
+        $save=[];
+        $save['uid']          = $request->user['uid'];
+        $save['order_id']     =  makeOrderId($request->user['uid']);
+        $save['pay_type']     = 'wxpay';//目前只支持微信支付
+        $save['total_money']  = $total_money;//订单总金额
+        $save['all_money']    = $allMoney;//商品中金额
+        $save['pay_money']    = $payMoney;//实际支付金额
+        $save['balance']      = 0;//余额支付了多少(目前没有余额支付)
+        $save['postage']      = $postageMoney;//邮费(目前不需要)
+        
+        $save['name']         = empty($addressData) ? "" : $addressData["name"];
+        $save['tel']          = empty($addressData) ? "" : $addressData["tel"];
+        $save['address']      = empty($addressData) ? "" : $addressData["area"].$addressData["address"];
+        $save['shop_id']      = empty($shopData) ? 0 : $shopData["id"];
+        $save['type']         = $type;
+        
+        $save['coupon_id']    = $coupon_id;
+        $save['coupon_money'] = $couponMoney;
+        $save['is_ip_buy']    = $is_ip_buy;
+        $save['status']       = $payMoney <= 0 ? 1 : 0;
+        $save['pay_time']     = $payMoney <= 0 ? time() : 0;
+        $save['score']        = $score;//使用积分
+        $save["mono"]         = $mono;//订单备注
+        $save['time']         = $nowTime;
+        $save['give_score']   = $give_score;//赠送积分
+        
+        try{
+            Db::startTrans();
+            $o_id = (new Order)->insertGetId($save);
+            if(empty($o_id)){
+                if($is_ip_buy==1){
+                    $redis->delete($ipkey);
+                }
+                return app('json')->fail("订单生成失败");
+            }
+            foreach($infoData as $k=>$v){
+                $infoData[$k]["o_id"] = $o_id;
+            }
+            (new OrderInfo)->insertAll($infoData);
+            //消费券
+            if(!empty($couponData)) {
+                (new UserCouponModel)->where("id",$couponData["id"])->update(["status"=>1]);
+            }
+            //积分
+            if($score>0){
+                $mono = "商城购买使用积分抵扣";
+                (new UserScoreDetailModel)->payScore($request->user["uid"],$score,"outcome_score",$mono,["o_id"=>$o_id]);
+            }
+            //如果支付为0则直接送积分
+            if($save['status']==1 && $give_score>0){
+                (new UserScoreDetailModel)->incomeScore($request->user["uid"], $give_score, "","income_score",["o_id"=>$o_id]);
+            }
+            //系统信息
+            $sysData = (new SysModel)->where("id",1)->find();
+            //普通购买
+            if($save['status']==1 && $payMoney>0 && $save["is_ip_buy"]==0){
+                //上级用户
+                if($request->user["parent_uid"]>0){
+                    $parentData = (new UserModel)->where("uid",$request->user["parent_uid"])->where("status",1)->find();
+                    //一级用户
+                    if(!empty($parentData) && $sysData['tree_income_per']>0 && $sysData['tree_income_per']<=100){
+                        $treepermono = "推广用户购买商品获得分成";//分成内容
+                        $treePerMoney = $payMoney*((int)$sysData['tree_income_per']/100);//分成收益金额
+                        if($treePerMoney>0){
+                            // return true;//暂时关闭分成
+                            (new UserDetailModel)->goodsIncome($request->user["parent_uid"],$treePerMoney,"tree_per_income",$treepermono,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
+                        }
+                    }
+                    //二级用户
+                    if(!empty($parentData) && $parentData["parent_uid"] > 0 && $sysData['tree_income_per_two']>0 && $sysData['tree_income_per_two']<=100){
+                        $treepermonoTwo = "二级推广用户购买商品获得分成";//分成内容
+                        $treePerMoneyTwo = $payMoney*((int)$sysData['tree_income_per_two']/100);//分成收益金额
+                        if($treePerMoneyTwo>0){
+                            // return true;//暂时关闭分成
+                            (new UserDetailModel)->goodsIncome($parentData["parent_uid"],$treePerMoneyTwo,"tree_per_income",$treepermonoTwo,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
+                        }
+                    }
+                }
+            }
+            //如果不需要支付则直接算IP分成
+            if($save['status']==1 && $payMoney>0 && $save["is_ip_buy"]==0 && !empty($proData["uid"]) && $proData["is_ip"]==1){
+//                $sysPer=$sysData['ip_income_per'];//分成比例,后台设置
+                $sysPer=$proData['ip_income_per'];//如果是单个商品则用这条
+                if($sysPer>0 && $sysPer<=100){
+                    $permono = "用户购买IP商品获得分成";//分成内容
+                    $perMoney = $payMoney*((int)$sysPer/100);//分成收益金额
+                    //增加用户收益
+                    if($perMoney>0){
+                        // return true;//暂时关闭分成
+                        (new UserDetailModel)->goodsIncome($proData["uid"],$perMoney,"per_income",$permono,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
+                    }
+                }
+            }
+            Db::commit();
+            $redis->delete($key);
+            if($is_ip_buy==1){
+                $redis->delete($ipkey);
+            }
+            return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
+        } catch (DbException $db){
+            Db::rollback();
+            if($is_ip_buy==1){
+                $redis->delete($ipkey);
+            }
+            return app('json')->fail("订单生成失败");
+        }
+    }
+    /**
+     * 获取支付订单详情[第二步]
+     * @param Request $request
+     */
+    public function payOrderInfo(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $data = (new Order)
+                ->field("order_id,total_money,all_money,pay_money,status,time,is_ip_buy")
+                ->where("order_id",$order_id)
+                ->where("uid",$request->user["uid"])
+                ->find();
+        if(empty($data)){
+            return app('json')->fail('订单不存在!');
+        }
+        $data=$data->toArray();
+        if($data["status"]==0 && $data["time"]<time()-30*60){
+            (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
+            $data["status"]==-1;
+        }
+        $data["time"] = date("Y-m-d H:i:s",$data["time"]);
+         return app('json')->success($data);
+    }
+    /**
+     * 生成支付[第三步]
+     * @param Request $request
+     */
+    public function orderPay(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        //缓存
+        $redis = \think\facade\Cache::store('redis');
+        $key   = 'order_pay_' . $request->user['uid'];
+        $bool  = $redis->handler()->exists($key);
+        if ($bool) {
+            return app('json')->fail('请务重复操作,请稍等在重试!');
+        }
+        $redis->set($key,1,6);//6秒缓存
+        $orderData = (new Order)
+            ->where("order_id",$order_id)
+            ->where("uid",$request->user["uid"])
+            ->find();
+        if(empty($orderData)){
+            return app('json')->fail('订单不存在!');
+        }
+        if(empty($request->user['openid'])){
+            return app('json')->fail('用户还未登录001!');
+        }
+        $orderData=$orderData->toArray();
+        if($orderData["status"]>0 || $orderData["pay_money"]<=0){
+            return app('json')->fail('订单已经支付了!');
+        }
+        if($orderData["status"]<0){
+            return app('json')->fail('当前订单不可支付!');
+        }
+        $orderInfoData = (new OrderInfo)->where("o_id",$orderData['id'])->find()->toArray();
+        
+        $proData = (new Goods)->where("id",$orderInfoData["p_id"])->find();
+        if(empty($proData) || $proData["status"]!=1){
+            return app('json')->fail('订单中的商品已下架,请重新下单!');
+        }
+        //ip买断验证
+        if($orderData["is_ip_buy"]==1 && (!empty($proData["uip"]) || $proData["is_ip"]==0)){
+             return app('json')->fail('当前商品已经不可买断,请重新下单!');
+        }
+        //清理之前支付凭证 || 防止重复购买
+        $payTrade = (new PayTradeModel)
+                ->where("uid",$request->user["uid"])
+                ->where("o_id",$orderData["id"])
+                ->where("status",0)
+                ->select()
+                ->toArray();
+        $wxpay = new wxpayApi();
+        foreach ($payTrade as $v) {
+            if($v['pay_type'] == 'wxpay') {
+                $result = $wxpay->closeOrder($v['pay_no']);
+            }
+//            (new PayTradeModel)->where("pay_no",$v['pay_no'])->delete();
+        }
+        $mtime = microtime(true)*10000;
+        $payOn = "P".date("Ymd").$mtime .rand(1000,9000) . $request->user['uid'];
+        $out_trade_no="";
+        $payMoney = $orderData["pay_money"];
+        $payType=$orderData["pay_type"];
+        
+        $give_score=$orderData["give_score"];//赠送积分
+        //添加交易记录
+        $trade = [
+            'uid' => $request->user['uid'],
+            'o_id' =>$orderData["id"],
+            'order_id' =>$orderData["order_id"],
+            'pay_no' => $payOn,
+            'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
+            'pay_type' => $payType,
+            'money' => $payMoney,
+            'type' => $orderData["is_ip_buy"]==1 ? 'ip' : 'pro',
+            'd_json' => serialize(['orderId'=>$orderData["order_id"],"give_score"=>$give_score]),
+            'time'  => time(),
+            'status'   => 0,
+        ];
+        $r=(new PayTradeModel)->insert($trade);
+        if(!$r){
+            return app('json')->fail('获取支付信息失败!');
+        }
+        $clictip = get_client_ip();
+        if(empty($clictip)){
+            $clictip = $request->ip();
+        }
+        
+        $data =  $wxpay->wxmpPay([
+            'description' =>$orderData["is_ip_buy"]==1?"微信小程序商城IP商品买断":"微信小程序商城普通商品购买",
+            'out_trade_no' => $payOn,
+            'total' => $payMoney,
+            'openid' => $request->user['openid'],
+            'payer_client_ip'=>$clictip,
+        ]);
+        if(empty($data)){
+            return app('json')->fail($clictip.$wxpay->errorMsg);
+        }
+        return app('json')->success([
+            'jsApiParameters'=> $data,
+            'pay_no'         => $payOn,
+            'order_id'       => $orderData["order_id"],
+        ]);
+    }
+    
+    /**
+     * 删除订单
+     * @param Request $request
+     */
+    public function orderDel(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $data = (new Order)->where("order_id",$order_id)->where("uid",$request->user["uid"])->find();
+        if(empty($data)){
+            return app('json')->fail('订单不存在!');
+        }
+        if($data["status"]>0){
+            return app('json')->fail('当前订单不可删除!');
+        }
+        (new Order)->where("order_id",$order_id)->where("status","<",1)->where("uid",$request->user["uid"])->delete();
+         return app('json')->success("订单删除成功");
+    }
+    
+    /**
+     * 清点
+     * @param Request $request
+     */
+    public function shopOrderSend(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $shopData = (new UserShop)->field("id,area, address,name,lx_name,tel,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
+        if(empty($shopData)){
+            return app('json')->fail("门店信息错误");
+        }
+        $data = (new Order)->where("order_id",$order_id)->where("shop_id",$shopData["id"])->find();
+        if(empty($data)){
+            return app('json')->fail('订单不存在!');
+        }
+        if($data["status"]!=1){
+            return app('json')->fail('当前订单状态不可清点!');
+        }
+        (new Order)->where("order_id",$order_id)->where("status",1)->where("shop_id",$shopData["id"])->update(["status"=>2,"fa_time"=>time()]);
+        //插入记录
+        $saveData=[
+            "o_id"=>$data["id"],
+            "order_id"=>$data["order_id"],
+            "mono"=>"门店确定清点完毕",
+            "time"=>time(),
+            "admin_id"=>0,
+            "admin_name"=>"门店",
+            "type"=>1,
+            "code"=>"shop",
+        ];
+        (new OrderMono)->insert($saveData);
+        return app('json')->success("订单确认清点");
+        
+    }
+    /**
+     * 提货
+     * @param Request $request
+     */
+    public function shopOrderOk(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $shopData = (new UserShop)->field("id,area, address,name,lx_name,tel,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
+        if(empty($shopData)){
+            return app('json')->fail("门店信息错误");
+        }
+        $data = (new Order)->where("order_id",$order_id)->where("shop_id",$shopData["id"])->find();
+        if(empty($data)){
+            return app('json')->fail('订单不存在!');
+        }
+        if($data["status"]!=2){
+            return app('json')->fail('当前订单状态不可确认提货!');
+        }
+        (new Order)->where("order_id",$order_id)->where("status",2)->where("shop_id",$shopData["id"])->update(["status"=>3,"ok_time"=>time()]);
+        //插入记录
+        $saveData=[
+            "o_id"=>$data["id"],
+            "order_id"=>$data["order_id"],
+            "mono"=>"门店确定用户已经提走商品",
+            "time"=>time(),
+            "admin_id"=>0,
+            "admin_name"=>"门店",
+            "type"=>1,
+            "code"=>"shop",
+        ];
+        (new OrderMono)->insert($saveData);
+        return app('json')->success("订单确认提货完成");
+    }
+    
+    /**
+     * 确认收货
+     * @param Request $request
+     */
+    public function orderOk(Request $request){
+        [$order_id] = UtilService::getMore([
+            ['order_id','','empty','参数错误'],
+        ],$request,true);
+        $data = (new Order)->where("order_id",$order_id)->where("uid",$request->user["uid"])->find();
+        if(empty($data)){
+            return app('json')->fail('订单不存在!');
+        }
+        if($data["status"]!=2){
+            return app('json')->fail('当前订单不可确认收货!');
+        }
+        (new Order)->where("order_id",$order_id)->where("status",2)->where("uid",$request->user["uid"])->update(["status"=>3,"ok_time"=>time()]);
+         return app('json')->success("订单确认收货完成");
+    }
+    
+    public function bindPushUip(Request $request){
+        [$pushuip] = UtilService::getMore([
+            ['pushuip','','empty','参数错误'],
+        ],$request,true);
+        //缓存
+        $redis = \think\facade\Cache::store('redis');
+        $key   = 'user_parent_bind_' . $request->user['uid'];
+        $bool  = $redis->handler()->exists($key);
+        if ($bool) {
+            return app('json')->fail('请务重复操作,请稍等在重试!');
+        }
+        $redis->set($key,1,3);//3秒缓存
+        
+        if(!empty($request->user["parent_uid"])){
+            return app('json')->success("绑定成功02");
+        }
+        if($request->user["uip"]==$pushuip){
+            return app('json')->success("绑定成功03");
+        }
+        $parentUser = (new UserModel)->where("uip",$pushuip)->find();
+        if(empty($parentUser)){
+            return app('json')->success("绑定成功04");
+        }
+        if(!empty($parentUser["parent_uid"]) && $parentUser["parent_uid"]==$request->user["uid"]){
+            return app('json')->success("绑定成功05");
+        }
+        
+        $r = (new UserModel)->where("uid",$request->user["uid"])->update(["parent_uid"=>$parentUser["uid"],"parent_time"=>time()]);
+        if(!$r){
+            return app('json')->fail('绑定失败!');
+        }
+        return app('json')->success("绑定成功");
+    }
+    
+    
+    /**
+     * 我的下级列表
+     * @param Request $request
+     */
+    public function branchUserList(Request $request){
+        [$page,$pageSize] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',50],
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        //条件
+        $where=[];
+        $where[] = ["parent_uid","=",$request->user['uid']];
+        $where[] = ["status",">",0];
+        $totalCount = (new UserModel)->where($where)->count();
+        $data = (new UserModel)
+            ->field("uip,nickname,avatar,mobile,status,uid")
+            ->where($where)
+            ->order("uid", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        $userDetailDb = new UserDetailModel();
+        foreach($data as $k=>$v){
+            $data[$k]["is_mobile"] = empty($v["mobile"])?0:1;
+            $data[$k]["treeIncomeCount"] = $userDetailDb->where("uid",$request->user["uid"])->where("cash_uid",$v["uid"])->where("type",1)->where("code","tree_per_income")->count();
+            $data[$k]["uid"] = null;
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'totalCount'=>$totalCount]);
+    }
+    
+    
+    /**
+     * 我的活动
+     * @param Request $request
+     */
+    public function activityList(Request $request){
+        [$page,$pageSize] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',50],
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        //条件
+        $where=[];
+        $where[] = ["d.uid","=",$request->user['uid']];
+        $where[] = ["d.status",">",0];
+        $data = (new ActivityOrder)
+            ->alias("d")
+            ->field("d.id,d.order_id,d.status,d.pay_money,i.imgs,i.title,i.time,i.time_str,i.address")
+            ->join("activity i", "i.id = d.activity_id","left")
+            ->where($where)
+            ->order("d.id", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y.m.d",(int)$v["time"]);
+            $data[$k]["img"] = empty($v["imgs"]) ? "" : explode(",", $v["imgs"])[0];
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
+    }
+    /**
+     * 活动报名详情
+     * @param Request $request
+     */
+    public function activityOrderInfo(Request $request){
+        [$id,$order_id] = UtilService::getMore([
+            ['id',''],
+            ['order_id',''],
+        ],$request,true);
+        if(empty($id) && empty($order_id)){
+            return app('json')->fail("参数错误");
+        }
+        $where=[];
+        $where[]=["uid","=",$request->user["uid"]];
+        if(!empty($id)){
+            $where[]=["id","=",$id];
+        }else{
+            $where[]=["order_id","=",$order_id];
+        }
+        $orderData = (new ActivityOrder)
+                ->alias("d")
+                ->field("d.*,i.imgs,i.title,i.time as activity_time,i.time_str,i.address")
+                ->join("activity i", "i.id = d.activity_id","left")
+                ->where($where)
+                ->find();
+        if(empty($orderData)){
+            return app('json')->fail("报名信息不存在");
+        }
+        $data=$orderData->toArray();
+        if($data["status"]==0 && $data["time"]<time()-30*60){
+            (new ActivityOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
+            $data["status"]==-1;
+        }
+        $data['activity_time'] = empty($data['activity_time'])?"":date('Y-m-d H:i:s',$data['activity_time']);
+        $data['time'] = date('Y.m.d',$data['time']);
+        $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
+        $data['ok_time'] =  empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
+        $data['img'] = empty($data["imgs"])?"": explode(",",$data["imgs"])[0];
+        $data['data'] = empty($data['data'])?[]: unserialize($data['data']);
+        return app('json')->success($data);
+    }
+    /**
+     * 获取收益明细
+     * @param Request $request
+     */
+    public function moneyDetail(Request $request){
+        [$page,$pageSize] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',50],
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        //条件
+        $where=[];
+        $where[] = ["d.uid","=",$request->user['uid']];
+        $data = (new UserDetailModel)
+            ->alias("d")
+            ->field("d.*,i.img,i.title as pro_title")
+            ->join("order_info i", "i.o_id = d.o_id","left")
+            ->where($where)
+            ->order("d.id", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["into"] = number_format(floatval($v["into"]),2);
+            if(empty($v["pro_title"])){
+                $data[$k]["pro_title"] = $v["title"];
+            }
+        }
+        $data = empty($data)?[]:$data;
+        $money = number_format(floatval($request->user["money"]),2);
+        $money_in = number_format(floatval($request->user["money_in"]),2);
+//        $isCheck = false;//关闭提现按钮
+        $isCheck = true;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'money'=>$money,'money_in'=>$money_in,'is_check'=>$isCheck]);
+    }
+    /**
+     * 获取积分明细
+     * @param Request $request
+     */
+    public function scoreDetail(Request $request){
+        [$page,$pageSize] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',50],
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        //条件
+        $where=[];
+        $where[] = ["d.uid","=",$request->user['uid']];
+        $data = (new UserScoreDetailModel)
+             ->alias("d")
+            ->field("d.*,i.img,i.title as pro_title")
+            ->join("order_info i", "i.o_id = d.o_id","left")
+            ->where($where)
+            ->order("d.id", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+        }
+        $data = empty($data)?[]:$data;
+        $score = $request->user["score"];
+        $score_in = $request->user["score_in"];
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'score'=>$score,'score_in'=>$score_in]);
+    }
+    public function shopOrderList(Request $request){
+        [$page,$pageSize,$type] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',20],
+            ['type','all'],
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
+        if(empty($shopData)){
+            return app('json')->success(['list' => [], 'pageSize' => $pageSize]);
+        }
+        //条件
+        $where=[];
+        $where[] = ["shop_id","=",$shopData["id"]];
+        //待支付
+        if($type=="pay"){
+            $where[] = ["status","=",0];
+        }
+        //待发货
+        if($type=="send"){
+            $where[] = ["status","=",1];
+        }
+        //待收货
+        if($type=="accept"){
+            $where[] = ["status","=",2];
+        }
+        //已完成
+        if($type=="finish"){
+            $where[] = ["status","=",3];
+        }
+        $data = (new Order)
+            ->where($where)
+            ->order("time", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        $orderInfoModel=new OrderInfo();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["pay_time"] = empty($v["pay_time"]) ? "" :date("Y-m-d H:i:s",$v["pay_time"]);
+            $data[$k]["fa_time"]  = empty($v["fa_time"]) ? "" :date("Y-m-d H:i:s",$v["fa_time"]);
+            $data[$k]["ok_time"]  = empty($v["ok_time"]) ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
+            $data[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
+    }
+    /**
+     * 订单列表
+     * @param Request $request
+     */
+    public function orderList(Request $request){
+        [$page,$pageSize,$type,$is_ip_buy] = UtilService::getMore([
+            ['page',1],
+            ['pageSize',20],
+            ['type','all'],
+            ['is_ip_buy','']
+        ],$request,true);
+        if($pageSize>50){
+            $pageSize = 50;
+        }
+        //条件
+        $where=[];
+        $where[] = ["uid","=",$request->user['uid']];
+        if(in_array((string)$is_ip_buy,["0","1"])){
+            $where[] = ["is_ip_buy","=",(int)$is_ip_buy];
+        }
+        //待支付
+        if($type=="pay"){
+            $where[] = ["status","=",0];
+        }
+        //待发货
+        if($type=="send"){
+            $where[] = ["status","=",1];
+        }
+        //待收货
+        if($type=="accept"){
+            $where[] = ["status","=",2];
+        }
+        //已完成
+        if($type=="finish"){
+            $where[] = ["status","=",3];
+        }
+        //失效订单
+        if((new Order)->where("uid",$request->user["uid"])->where("status",0)->where("time","<",time()-30*60)->count()>0){
+            (new Order)->where("uid",$request->user["uid"])->where("status",0)->where("time","<",time()-30*60)->update(["status"=>-1]);
+        }
+        $data = (new Order)
+            ->where($where)
+            ->order("time", "desc")
+            ->page((int)$page, (int)$pageSize)
+            ->select()
+            ->toArray();
+        $orderInfoModel=new OrderInfo();
+        $userDetailDb = new UserDetailModel();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["pay_time"] = empty($v["pay_time"]) ? "" :date("Y-m-d H:i:s",$v["pay_time"]);
+            $data[$k]["fa_time"]  = empty($v["fa_time"]) ? "" :date("Y-m-d H:i:s",$v["fa_time"]);
+            $data[$k]["ok_time"]  = empty($v["ok_time"]) ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
+            $data[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
+            $data[$k]["ipcount"] = 0;
+            $data[$k]["ipmoney"] = 0;
+            if($v["is_ip_buy"]==1){
+                foreach($data[$k]["info"] as $m=>$n){
+                    $totalData = $userDetailDb->field("count(*) as count,sum(`into`) as money")->where("uid",$request->user["uid"])->where("p_id",$n["p_id"])->where("type",1)->find();
+                    if(!empty($totalData) && !empty($totalData["count"])){
+                        $data[$k]["ipcount"]+=(int)$totalData["count"];
+                        $data[$k]["ipmoney"]+=(int)$totalData["money"];
+                    }
+                }
+            }
+            
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
+    }
+    
+    /**
+     * 获取订单详情
+     * @param Request $request
+     */
+    public function orderInfo(Request $request){
+        [$id,$order_id] = UtilService::getMore([
+            ['id',''],
+            ['order_id',''],
+        ],$request,true);
+        if(empty($id) && empty($order_id)){
+            return app('json')->fail("参数错误");
+        }
+        $where=[];
+        $where[]=["uid","=",$request->user["uid"]];
+        if(!empty($id)){
+            $where[]=["id","=",$id];
+        }else{
+            $where[]=["order_id","=",$order_id];
+        }
+        $orderData = (new Order)->where($where)->find();
+        if(empty($orderData)){
+            return app('json')->fail("订单不存在");
+        }
+        $data=$orderData->toArray();
+        $data["shop"]=[
+            "id"=>"",
+            "address"=>"",
+            "name"=>"",
+            "tel"=>""
+        ];
+        if($data["type"]=="shop"){
+            $shopData = (new UserShop)->where("id",$data["shop_id"])->find();
+            if(!empty($shopData)){
+                $data["shop"]["id"]        = $shopData["id"];
+                $data["shop"]["address"]   = $shopData["area"].$shopData["address"];
+                $data["shop"]["name"]      = $shopData["name"];
+                $data["shop"]["tel"]       = $shopData["tel"];
+                $data["shop"]["lx_name"]   = $shopData["lx_name"];
+                $data["shop"]["longitude"] = $shopData["longitude"];
+                $data["shop"]["latitude"]  = $shopData["latitude"];
+            }
+        }
+        if($data["status"]==0 && $data["time"]<time()-30*60){
+            (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
+            $data["status"]==-1;
+        }
+        
+        
+        $data['time'] = date('Y-m-d H:i:s',$orderData['time']);
+        $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
+        $data['fa_time'] =  empty($data['fa_time']) ? '' : date('Y-m-d H:i:s',$data['fa_time']);
+        $data['ok_time'] =  empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
+        
+        $data['coupon_title']="";
+        if(!empty($data['coupon_id'])) {
+            $couponData = (new UserCouponModel)->where("id",$data['coupon_id'])->find();
+            if(!empty($couponData)) {
+                $data['coupon_title'] = $couponData['title'];
+            }
+        }
+//        $tAr['tuiMono'] = '';
+//        if(!empty($tAr['isTui'])) {
+//            $tAr['tuiMono'] = M('orderMono')->where(['order_id'=>$order['id'],"type"=>0])->order("id desc")->getfield("mono");
+//        }
+        $info = (new OrderInfo)->where("o_id",$data["id"])->select();
+        $infoAr = [];
+        foreach ($info as $v2) {
+            $d2['p_id']      = $v2['p_id'];
+            $d2['title']     = $v2['title'];
+            $d2['img']       = $v2['img'];
+            $d2['count']     = $v2['count'];
+            $d2['price']     = $v2['price'];
+            $d2['money']     = $v2['money'];
+            $d2['is_ip_buy'] = $v2['is_ip_buy'];
+            $infoAr[] = $d2;
+        }
+        $data['info'] = $infoAr;
+        return app('json')->success($data);
+    }
+    
+    
+    /**
+     * 获取门店订单详情
+     * @param Request $request
+     */
+    public function shopOrderInfo(Request $request){
+        [$id,$order_id] = UtilService::getMore([
+            ['id',''],
+            ['order_id',''],
+        ],$request,true);
+        if(empty($id) && empty($order_id)){
+            return app('json')->fail("参数错误");
+        }
+        $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("uid",$request->user["uid"])->find();
+        if(empty($shopData)){
+            return app('json')->fail("门店信息错误");
+        }
+        $where=[];
+        $where[]=["shop_id","=",$shopData["id"]];
+        if(!empty($id)){
+            $where[]=["id","=",$id];
+        }else{
+            $where[]=["order_id","=",$order_id];
+        }
+        $orderData = (new Order)->where($where)->find();
+        if(empty($orderData)){
+            return app('json')->fail("订单不存在");
+        }
+        $data=$orderData->toArray();
+        $data["shop"]=[
+            "id"=>"",
+            "address"=>"",
+            "name"=>"",
+            "tel"=>""
+        ];
+        if($data["type"]=="shop"){
+            $shopData = (new UserShop)->where("id",$data["shop_id"])->find();
+            if(!empty($shopData)){
+                $data["shop"]["id"]        = $shopData["id"];
+                $data["shop"]["address"]   = $shopData["area"].$shopData["address"];
+                $data["shop"]["name"]      = $shopData["name"];
+                $data["shop"]["tel"]       = $shopData["tel"];
+                $data["shop"]["lx_name"]   = $shopData["lx_name"];
+                $data["shop"]["longitude"] = $shopData["longitude"];
+                $data["shop"]["latitude"]  = $shopData["latitude"];
+            }
+        }
+        if($data["status"]==0 && $data["time"]<time()-30*60){
+            (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
+            $data["status"]==-1;
+        }
+        
+        
+        $data['time'] = date('Y-m-d H:i:s',$orderData['time']);
+        $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
+        $data['fa_time'] =  empty($data['fa_time']) ? '' : date('Y-m-d H:i:s',$data['fa_time']);
+        $data['ok_time'] =  empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
+        
+        $data['coupon_title']="";
+        if(!empty($data['coupon_id'])) {
+            $couponData = (new UserCouponModel)->where("id",$data['coupon_id'])->find();
+            if(!empty($couponData)) {
+                $data['coupon_title'] = $couponData['title'];
+            }
+        }
+//        $tAr['tuiMono'] = '';
+//        if(!empty($tAr['isTui'])) {
+//            $tAr['tuiMono'] = M('orderMono')->where(['order_id'=>$order['id'],"type"=>0])->order("id desc")->getfield("mono");
+//        }
+        $info = (new OrderInfo)->where("o_id",$data["id"])->select();
+        $infoAr = [];
+        foreach ($info as $v2) {
+            $d2['p_id']      = $v2['p_id'];
+            $d2['title']     = $v2['title'];
+            $d2['img']       = $v2['img'];
+            $d2['count']     = $v2['count'];
+            $d2['price']     = $v2['price'];
+            $d2['money']     = $v2['money'];
+            $d2['is_ip_buy'] = $v2['is_ip_buy'];
+            $infoAr[] = $d2;
+        }
+        $data['info'] = $infoAr;
+        return app('json')->success($data);
+    }
+    
+    
+    /**
+     * 发布圈子
+     * @param Request $request
+     */
+    public function upCircle(Request $request){
+        $post = UtilService::getMore([
+            ['id',''],
+            ['title',''],
+            ['content','','empty','请输入动态内容'],
+            ['imgs',[]],
+            ['video',''],
+            ['video_img',''],
+            ['video_time',0],
+            ['pro_id',''],
+        ],$request);
+        
+        $post["status"]=0;
+        
+        $post["imgs"] = empty($post["imgs"]) ? "" : $post["imgs"];
+        $post["update_time"] = time();
+        if(empty($post["imgs"]) && empty($post["video"])){
+            return app('json')->fail("请至少上传一张主图");
+        }
+        if(!empty($post["imgs"])){
+            $post["video"]="";
+            $post["video_img"]="";
+            $post["video_time"]=0;
+        }
+        if(!empty($post["video"])){
+            $post["imgs"]="";
+            if(empty($post["video_img"])){
+                return app('json')->fail("视频封面错误");
+            }
+            if(empty($post["video_time"]) || (int)$post["video_time"]<=0){
+                return app('json')->fail("视频时长错误");
+            }
+        }
+        if(!empty($post["pro_id"])){
+            $proData = (new Goods)->where("id",$post["pro_id"])->where("status",1)->find();
+            if(empty($proData)){
+                return app('json')->fail("当前商品不可选中");
+            }
+        }else{
+            $post["pro_id"]=0;
+        }
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $post["time"] = time();
+            $post["uid"] = $request->user["uid"];
+            $r = (new UserCircle)->insert($post);
+        }else{
+            $r = (new UserCircle)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("发布成功,等待客服审核。");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+    
+    
+    /**
+     * 图片上传
+     * @param Request $request
+     * @return type
+     */
+    public function upload(Request $request){
+        $sysData = (new SysModel())->where("id",1)->find();
+        $file = $request->file('file');
+        $code = $request->post("code","image");
+        if(empty($file)) {
+            return app('json')->fail("未上传文件");
+        }
+        if(!in_array($code, ["video","image","circle","advert","goods","activity"])){
+            return app('json')->fail("上传路径错误");
+        }
+        $ext = $file->extension();
+        if(!in_array($ext, array("png","jpeg","gif","jpg"))){
+            return app('json')->fail("图片类型错误");
+        }
+        $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
+        if(!$upPath){
+            return app('json')->fail("图片上传失败01");
+        }
+        $savePath = $sysData['system_url'].'/resource/' . $upPath;
+        $imgUrl = str_replace("\\", "/", $savePath);
+        return app('json')->success(['img'=>$imgUrl]);
+    }
+    
+    /**
+     * 视频上传
+     * @param Request $request
+     * @return type
+     */
+    public function uploadVideo(Request $request){
+        $sysData = (new SysModel())->where("id",1)->find();
+        $file = $request->file('file');
+        $code = $request->post("code","video");
+        if(empty($file)) {
+            return app('json')->fail("未上传文件");
+        }
+        if(!in_array($code, ["video"])){
+            return app('json')->fail("上传路径错误");
+        }
+        $ext = $file->extension();
+        if(!in_array($ext, array("mp4","megp4"))){
+            return app('json')->fail("视频类型错误");
+        }
+        $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
+        if(!$upPath){
+            return app('json')->fail("上传失败01");
+        }
+        $savePath = $sysData['system_url'].'/resource/' . $upPath;
+        $imgUrl = str_replace("\\", "/", $savePath);
+        return app('json')->success(['video'=>$imgUrl]);
+    }
+    
+    
+    
+    
+    
+    
+    
+
+    /**
+     * 钻币明细
+     * @param Request $request
+     */
+    public function scoreList(Request $request)
+    {
+        $pageSize = 10;
+        [$page, $type, $monthTime]
+            = UtilService::getMore([
+            ['page', 1],
+            ['type',0],
+            ['monthTime', ''],
+        ], $request, true);
+        $data = (new UserScoreDetail)
+            ->where("uid", $request->user['uid'])
+            ->when($type!=0, function ($query) use ($type) {
+                if($type==1){
+                    $query->where("type", 1);
+                }
+                if($type==-1){
+                    $query->where("type", -1);
+                }
+            })
+            ->when(!empty($monthTime), function ($query) use ($monthTime) {
+                $query->whereMonth("time", $monthTime);
+            })
+            ->order("id", "desc")
+            ->page((int)$page, $pageSize)
+            ->select();
+        $tAr  = UtilService::getParam([
+            'id',
+            'title',
+            'content',
+            'type',
+            ['into','v',function($item){
+                return floatval($item);
+            }],
+            ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+        ], $data);
+        return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize]);
+
+    }
+
+   
+    
+    
+    
+}

+ 66 - 0
app/api/exception/ExecptionHandle.php

@@ -0,0 +1,66 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ 后台登录认证异常抛出  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 16:10
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+namespace app\api\exception;
+
+use library\exceptions\AuthException;
+use library\exceptions\GeneralException;
+use think\db\exception\DbException;
+use think\exception\Handle;
+use think\Response;
+use Throwable;
+
+class ExecptionHandle extends Handle {
+
+    /**
+     * 记录异常信息(包括日志或者其它方式记录)
+     *
+     * @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
+    {
+        // 添加自定义异常处理机制
+        $massageData = env('app_debug', false) ? [
+            'file' => $e->getFile(),
+            'line' => $e->getLine(),
+            'trace' => $e->getTrace(),
+            'previous' => $e->getPrevious(),
+        ] : [];
+
+        if ($e instanceof DbException) {
+            //记录服务器日志
+            return app('json')->fail('抱歉,服务器数据异常!', ['line'=>$e->getMessage()]);
+        }elseif ($e instanceof AuthException){
+            return app('json')->make($e->getCode() ?: -1, $e->getMessage());
+        } elseif ($e instanceof  GeneralException) {
+            return app('json')->make(-1, $e->getMessage());
+        } else {
+            return app('json')->make(-1, $e->getMessage());
+        }
+    }
+
+}

+ 36 - 0
app/api/middleware/AllowOriginMiddleware.php

@@ -0,0 +1,36 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-30 14:59
+// +----------------------------------------------------------------------
+namespace app\api\middleware;
+
+
+
+use app\Request;
+use library\interfaces\MiddlewareInterface;
+use \think\facade\Config;
+use think\Response;
+
+class AllowOriginMiddleware implements MiddlewareInterface {
+
+    public function handle(Request $request, \Closure $next)
+    {
+        $header['Access-Control-Allow-Credentials'] = 'true';
+        $header['Access-Control-Allow-Origin'] = '*';
+        $header['Access-Control-Allow-Methods'] = 'POST,GET,JSON,OPTIONS,DELETE';
+        $header['Access-Control-Allow-Headers'] = 'x-requested-with,content-type,cache-control,deviceId,deviceType,fromApp,fromPlat,mobileType,version,token,sign';
+        if ($request->method(true) == 'OPTIONS') {
+            $response = Response::create('ok')->code(200)->header($header);
+        } else {
+            $response = $next($request)->header($header);
+        }
+        return $response;
+    }
+
+}

+ 72 - 0
app/api/middleware/SeretKeyMiddleware.php

@@ -0,0 +1,72 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-30 14:59
+// +----------------------------------------------------------------------
+namespace app\api\middleware;
+
+use app\Request;
+use library\exceptions\AuthException;
+use library\interfaces\MiddlewareInterface;
+use library\services\UtilService;
+
+class SeretKeyMiddleware implements MiddlewareInterface
+{
+    public function handle(Request $request, \Closure $next)
+    {
+//        $this->checkSign($request);//暂时不用
+        return $next($request);
+    }
+
+
+    /**
+     * 检查数据是否正常
+     * @param $secret_key
+     */
+    private function checkSign(Request $request) {
+        $checkHeader = ['deviceId','deviceType','fromApp','fromPlat','mobileType','version','timestamp'];
+        $sign = $request->header('sign','');
+        $config = [
+            'token' => $request->header('token',''),
+            'deviceId' => $request->header('deviceId',''),
+            'deviceType' => $request->header('deviceType',0),
+            'fromApp' => $request->header('fromApp',''),
+            'fromPlat' => $request->header('fromPlat',''),
+            'mobileType' => $request->header('mobileType',''),
+            'version' => $request->header('version',''),
+            'timestamp' => $request->header('timestamp',''),
+        ];
+        foreach ($checkHeader as $v) {
+            if(empty($config[$v])) {
+               // throw new AuthException('签名参数出错!', 1001);
+            }
+        }
+//        $calSign = $this->makeSign($config);
+        if(strtoupper($sign) != $calSign){
+           // throw new AuthException('签名错误!加密规则:' . $this->makeSignStr($config), 1002);
+        }
+    }
+
+
+    private function makeSignStr(array $config)
+    {
+        $string = 'token=' . $config['token'] . ',deviceId=' . $config['deviceId'] . ',deviceType=' . $config['deviceType'] . ',fromApp=' . $config['fromApp'] . ',fromPlat=' . $config['fromPlat'] . ',mobileType=' . $config['mobileType'] . ',version=' . $config['version'] . ',timestamp=' . $config['timestamp'];
+        $salt = config('app.appSalt');
+        return $salt . $string;
+    }
+
+    private function makeSign(array $config)
+    {
+        $string = 'token=' . $config['token'] . ',deviceId=' . $config['deviceId'] . ',deviceType=' . $config['deviceType'] . ',fromApp=' . $config['fromApp'] . ',fromPlat=' . $config['fromPlat'] . ',mobileType=' . $config['mobileType'] . ',version=' . $config['version'] . ',timestamp=' . $config['timestamp'];
+        $salt = config('app.appSalt');
+        $sign = strtoupper(md5($salt . $string));
+        return $sign;
+    }
+
+
+}

+ 57 - 0
app/api/middleware/UserMiddleware.php

@@ -0,0 +1,57 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-08-30 14:59
+// +----------------------------------------------------------------------
+namespace app\api\middleware;
+
+
+use app\Request;
+
+use app\model\api\User as UserModel;
+use Firebase\JWT\JWT;
+use library\exceptions\AuthException;
+use library\interfaces\MiddlewareInterface;
+use think\facade\Env;
+
+class UserMiddleware implements MiddlewareInterface
+{
+    public function handle(Request $request, \Closure $next)
+    {
+        $token =$request->request('token');
+        $userData = $this->checkUser($token);
+        $request->user = $userData;
+        return $next($request);
+    }
+    /**
+     * 检查数据是否正常
+     * @param $secret_key
+     */
+    private function checkUser($token) {
+        if(empty($token)) {
+            throw new AuthException('用户登录凭证错误', -1);
+        }
+        try{
+            $memData = (new UserModel)
+                ->where('token',$token)
+                ->find();
+            if(empty($memData)) {
+                throw new AuthException('用户不存在', -1);
+            }
+            if($memData['status']==0) {
+                throw new AuthException('用户审核中', -1);
+            }
+            if($memData['status']==-1) {
+                throw new AuthException('用户已被禁用', -1);
+            }
+            return $memData->toArray();
+        }catch (\Throwable $e) {
+            throw new AuthException('系统错误,请重新登录', -1);
+        }
+    }
+}

+ 7 - 0
app/api/provider.php

@@ -0,0 +1,7 @@
+<?php
+use app\Request;
+
+// 容器Provider定义文件
+return [
+    'think\exception\Handle' => \app\api\exception\ExecptionHandle::class,
+];

+ 22 - 0
app/api/route/login.php

@@ -0,0 +1,22 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-09-05 09:21
+// +----------------------------------------------------------------------
+
+use app\api\middleware\AllowOriginMiddleware;
+use app\api\middleware\SeretKeyMiddleware;
+use think\facade\Route;
+
+Route::group('login', function () {
+    //微信登录
+    Route::rule('weixinLogin','Login/weixinLogin');
+})->middleware([
+    AllowOriginMiddleware::class,
+    SeretKeyMiddleware::class
+]);

+ 36 - 0
app/api/route/pay.php

@@ -0,0 +1,36 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-09-05 09:21
+// +----------------------------------------------------------------------
+
+use app\api\middleware\AllowOriginMiddleware;
+use app\api\middleware\SeretKeyMiddleware;
+use app\api\middleware\UserMiddleware;
+use think\facade\Route;
+
+Route::group('pay', function () {
+    
+    //微信异步返回
+    Route::rule('wxpayNotify', 'v1.Pay/wxpayNotify');
+    
+    //支付宝异步返回
+    Route::rule('alipayNotify', 'v1.Pay/alipayNotify');
+    //支付宝异步返回
+    Route::rule('alipayReturn', 'v1.Pay/alipayReturn');
+	//支付宝异步返回
+    Route::rule('alipayQuit', 'v1.Pay/alipayQuit');
+    //支付宝H5支付
+    Route::rule('alipayH5', 'v1.Pay/alipayH5');
+    //微信H5支付
+    Route::rule('wxpayH5', 'v1.Pay/wxpayH5');
+})->middleware([
+    AllowOriginMiddleware::class,
+    SeretKeyMiddleware::class,
+//    UserMiddleware::class,
+]);

+ 24 - 0
app/api/route/pub.php

@@ -0,0 +1,24 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-09-05 09:21
+// +----------------------------------------------------------------------
+
+use app\api\middleware\AllowOriginMiddleware;
+use app\api\middleware\SeretKeyMiddleware;
+use think\facade\Route;
+
+Route::group('pub', function () {
+    //获取皮肤模板列表
+    Route::rule('getShowTemplateList','Pub/getShowTemplateList');
+    //bug提交
+    Route::rule('appBugSub', 'Pub/appBugSub');
+})->middleware([
+    AllowOriginMiddleware::class,
+    SeretKeyMiddleware::class
+]);

+ 31 - 0
app/api/route/route.php

@@ -0,0 +1,31 @@
+<?php
+namespace app\api\route;
+
+use app\api\middleware\AllowOriginMiddleware;
+use app\api\middleware\SeretKeyMiddleware;
+use think\facade\Config;
+use think\facade\Route;
+use think\Response;
+
+/**
+ * 无需授权的接口
+ */
+Route::group(function () {
+    Route::rule('index', 'Index/index');
+})->middleware([
+    AllowOriginMiddleware::class,
+    SeretKeyMiddleware::class
+]);
+
+
+/**
+ * miss 路由
+ */
+Route::miss(function () {
+    if (app()->request->isOptions()) {
+        $header = Config::get('cookie.header');
+        $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
+        return Response::create('ok')->code(200)->header($header);
+    } else
+        return Response::create()->code(404);
+});

+ 133 - 0
app/api/route/user.php

@@ -0,0 +1,133 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | Author: TABLE ME
+// +----------------------------------------------------------------------
+// | Date: 2020-09-05 09:21
+// +----------------------------------------------------------------------
+
+use app\api\middleware\AllowOriginMiddleware;
+use app\api\middleware\SeretKeyMiddleware;
+use app\api\middleware\UserMiddleware;
+use think\facade\Route;
+
+Route::group('user', function () {
+    //绑定手机号码
+    Route::rule('bindMobile', 'v1.User/bindMobile');
+    //我的下级
+    Route::rule('branchUserList', 'v1.User/branchUserList');
+    
+    //获取用户基本信息
+    Route::rule('init', 'v1.User/init');
+    //获取会员中心信息信息
+    Route::rule('info', 'v1.User/info');
+    //我关注的列表
+    Route::rule('loveList', 'v1.User/loveList');
+    //我的粉丝列表
+    Route::rule('fansList', 'v1.User/fansList');
+    //关注取消关注
+    Route::rule('loveUser', 'v1.User/loveUser');
+    //喜欢取消喜欢商品
+    Route::rule('loveGoods', 'v1.User/loveGoods');
+    //获取二维码
+    Route::rule('getUipErcode', 'v1.User/getUipErcode');
+    //点赞圈子
+    Route::rule('loveCircle', 'v1.User/loveCircle');
+    //发布动态
+    Route::rule('upCircle', 'v1.User/upCircle');
+    //图片上传
+    Route::rule('upload', 'v1.User/upload');
+    //视频上传
+    Route::rule('uploadVideo', 'v1.User/uploadVideo');
+    
+    //门店列表
+    Route::rule('getShopList', 'v1.User/getShopList');
+    //门店详情
+    Route::rule('userShopInfo', 'v1.User/userShopInfo');
+    //门店订单列表
+    Route::rule('shopOrderList', 'v1.User/shopOrderList');
+    //清点
+    Route::rule('shopOrderSend', 'v1.User/shopOrderSend');
+    //提货
+    Route::rule('shopOrderOk', 'v1.User/shopOrderOk');
+    //详情
+    Route::rule('shopOrderInfo', 'v1.User/shopOrderInfo');
+    
+    
+    
+    //我的地址列表
+    Route::rule('addressList', 'v1.User/addressList');
+    //添加地址
+    Route::rule('addressAdd', 'v1.User/addressAdd');
+    //删除地址
+    Route::rule('addressDel', 'v1.User/addressDel');
+    //用户领券
+    Route::rule('gainCoupon', 'v1.User/gainCoupon');
+    Route::rule('couponList', 'v1.User/couponList');
+    //绑定详情
+    Route::rule('bankInfo', 'v1.User/bankInfo');
+    //提现详情
+    Route::rule('tixianInfo', 'v1.User/tixianInfo');
+    //提现申请
+    Route::rule('tixianApply', 'v1.User/tixianApply');
+    //活动报名表单详情
+    Route::rule('activityFromInfo', 'v1.User/activityFromInfo');
+    //活动报名提交
+    Route::rule('subActivityOrder', 'v1.User/subActivityOrder');
+    //获取支付订单详情
+    Route::rule('payActivityOrderInfo', 'v1.User/payActivityOrderInfo');
+    //我的活动
+    Route::rule('activityList', 'v1.User/activityList');
+    //活动报名详情
+    Route::rule('activityOrderInfo', 'v1.User/activityOrderInfo');
+    
+    
+    //获取提现类型
+    Route::rule('getBankType', 'v1.User/getBankType');
+    //编辑绑定
+    Route::rule('editBank', 'v1.User/editBank');
+    
+    //获取下单初始信息
+    Route::rule('getProBuyInfo', 'v1.User/getProBuyInfo');
+    //用户上级uip绑定
+    Route::rule('bindPushUip', 'v1.User/bindPushUip');
+    
+    
+    //提交订单
+    Route::rule('subOrder', 'v1.User/subOrder');
+    //获取支付订单详情
+    Route::rule('payOrderInfo', 'v1.User/payOrderInfo');
+    //获取订单详情
+    Route::rule('orderInfo', 'v1.User/orderInfo');
+    //获取订单列表
+    Route::rule('orderList', 'v1.User/orderList');
+    //订单删除
+    Route::rule('orderDel', 'v1.User/orderDel');
+    //确认收货
+    Route::rule('orderOk', 'v1.User/orderOk');
+    //收益明细
+    Route::rule('moneyDetail', 'v1.User/moneyDetail');
+    //积分明细
+    Route::rule('scoreDetail', 'v1.User/scoreDetail');
+    
+    
+    
+    
+    //订单支付
+    Route::rule('orderPay', 'v1.User/orderPay');
+    
+    
+    
+    
+    
+    
+    
+    
+})->middleware([
+    AllowOriginMiddleware::class,
+    SeretKeyMiddleware::class,
+    UserMiddleware::class,
+]);

+ 28 - 0
app/build.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: xurongyao <763569752@qq.com>
+ * Date: 2019/11/7 6:52 PM
+ */
+/**
+ * 创建模块配置
+ * php think build model_name
+ */
+return [
+    // 需要自动创建的文件
+    '__file__'   => ['.htaccess','ExecptionHandle.php','provider.php'],
+    // 需要自动创建的目录
+    '__dir__'    => ['api/v1','api/config','api/validates','api/route'],
+    // 需要自动控制器类
+    'controller' => ['Index'],
+    // 需要自动创建的表单验证
+    'validates' => ['Index'],
+    // 需要自动创建的路由
+    'route' => ['route'],
+    // 需要自动创建配置文件
+    'config'      => ['route'],
+    // 需要自动创建的多语言配置文件
+    'lang'      => ['zh-CN','en-US'],
+    // 需要自动创建的模板
+//    'view'       => ['index/index'],
+];

+ 443 - 0
app/command/Org/RedisCli.php

@@ -0,0 +1,443 @@
+<?php
+
+/**
+ * Redis 操作,支持 Master/Slave 的负载集群
+ *
+ */
+namespace app\command\Org;
+
+class RedisCli {
+
+    // 是否使用 M/S 的读写集群方案
+    private $_isUseCluster = false;
+    // Slave 句柄标记
+    private $_sn = 0;
+    // 服务器连接句柄
+    private $_linkHandle = array(
+        'master' => null, // 只支持一台 Master
+        'slave' => array(), // 可以有多台 Slave
+    );
+    
+    private $rsConfig = array();
+    
+    private $isCLT = false;
+
+    /**
+     * 构造函数
+     *
+     * @param boolean $isUseCluster 是否采用 M/S 方案
+     */
+    public function __construct($isUseCluster = false,$isCLI = false) {
+        $this->_isUseCluster = $isUseCluster;
+        $this->isCLT = $isCLI;
+    }
+
+    /**
+     * 连接服务器,注意:这里使用长连接,提高效率,但不会自动关闭
+     *
+     * @param array $config Redis服务器配置
+     * @param boolean $isMaster 当前添加的服务器是否为 Master 服务器
+     * @return boolean
+     */
+    public function connect($config = array('host' => '127.0.0.1', 'port' => 6379), $auth = array(), $isMaster = true) {
+        // default port
+        if (!isset($config['port'])) {
+            $config['port'] = 6379;
+        }
+        $this->rsConfig = array('config'=>$config,'auth'=>$auth);
+        // 设置 Master 连接
+        if ($isMaster) {
+            $this->_linkHandle['master'] = new \Redis();
+            if($this->isCLT)
+                $ret = $this->_linkHandle['master']->connect($config['host'], $config['port'],5);
+            else 
+                $ret = $this->_linkHandle['master']->pconnect($config['host'], $config['port'],5);
+            if (count($auth) > 0 && !empty($auth[0])) {
+                if ($this->_linkHandle['master']->auth($auth[0] . ":" . $auth[1]) === false) {
+                    die('Redis PassWord Error');
+                }
+            }
+        } else {
+            // 多个 Slave 连接
+            $this->_linkHandle['slave'][$this->_sn] = new Redis();
+            if($this->isCLT)
+                $ret = $this->_linkHandle['slave'][$this->_sn]->connect($config['host'], $config['port']);
+            else 
+                $ret = $this->_linkHandle['slave'][$this->_sn]->pconnect($config['host'], $config['port']);
+            
+            
+            if (count($auth) > 0 && !empty($auth[0])) {
+                if ($this->_linkHandle['master']->auth($auth[0] . ":" . $auth[1]) === false) {
+                    die('Redis PassWord Error');
+                }
+            }
+            ++$this->_sn;
+        }
+        return $ret;
+    }
+    
+    /**
+     * 重新连接
+     */
+    private function reConnect() {
+        $this->_linkHandle['master'] = new \Redis();
+        $config = $this->rsConfig['config'];
+        $auth = $this->rsConfig['auth'];
+        if($this->isCLT)
+                $ret = $this->_linkHandle['master']->connect($config['host'], $config['port'],5);
+            else 
+                $ret = $this->_linkHandle['master']->pconnect($config['host'], $config['port']);
+            
+        if (count($auth) > 0 && !empty($auth[0])) {
+            if ($this->_linkHandle['master']->auth($auth[0] . ":" . $auth[1]) === false) {
+                die('Redis PassWord Error');
+            }
+        }
+    }
+    /**
+     * 判断是否连接成功
+     */
+    public function isConnet() {
+        try {
+            $res = $this->getRedis()->ping();
+            if ($res !== '+PONG') {
+                $this->reConnect();
+            }
+        } catch (\RedisException $ex) {
+            $this->reConnect();
+        }
+        
+    }
+
+    /**
+     * 关闭连接
+     *
+     * @param int $flag 关闭选择 0:关闭 Master 1:关闭 Slave 2:关闭所有
+     * @return boolean
+     */
+    public function close($flag = 2) {
+        switch ($flag) {
+            // 关闭 Master
+            case 0:
+                $this->getRedis()->close();
+                break;
+            // 关闭 Slave
+            case 1:
+                for ($i = 0; $i < $this->_sn; ++$i) {
+                    $this->_linkHandle['slave'][$i]->close();
+                }
+                break;
+            // 关闭所有
+            case 1:
+                $this->getRedis()->close();
+                for ($i = 0; $i < $this->_sn; ++$i) {
+                    $this->_linkHandle['slave'][$i]->close();
+                }
+                break;
+        }
+        return true;
+    }
+
+    /**
+     * 得到 Redis 原始对象可以有更多的操作
+     *
+     * @param boolean $isMaster 返回服务器的类型 true:返回Master false:返回Slave
+     * @param boolean $slaveOne 返回的Slave选择 true:负载均衡随机返回一个Slave选择 false:返回所有的Slave选择
+     * @return redis object
+     */
+    public function getRedis($isMaster = true, $slaveOne = true) {
+        // 只返回 Master
+        if ($isMaster) {
+            return $this->_linkHandle['master'];
+        } else {
+            return $slaveOne ? $this->_getSlaveRedis() : $this->_linkHandle['slave'];
+        }
+    }
+
+    /**
+     * 写缓存
+     *
+     * @param string $key 组存KEY
+     * @param string $value 缓存值
+     * @param int $expire 过期时间, 0:表示无过期时间
+     */
+    public function set($key, $value, $expire = 0) {
+        // 永不超时
+        if ($expire == 0) {
+            $ret = $this->getRedis()->set($key, $value);
+        } else {
+            $ret = $this->getRedis()->setex($key, $expire, $value);
+        }
+        return $ret;
+    }
+
+    /**
+     * 读缓存
+     *
+     * @param string $key 缓存KEY,支持一次取多个 $key = array('key1','key2')
+     * @return string || boolean  失败返回 false, 成功返回字符串
+     */
+    public function get($key) {
+        // 是否一次取多个值
+        $func = is_array($key) ? 'mGet' : 'get';
+        // 没有使用M/S
+        if (!$this->_isUseCluster) {
+            return $this->getRedis()->{$func}($key);
+        }
+        // 使用了 M/S
+        return $this->_getSlaveRedis()->{$func}($key);
+    }
+    
+    /**
+     * 读取key值 支持模糊读取
+     * @param type $key
+     */
+    public function keyS($key){
+        return $this->getRedis()->keys($key);
+    }
+    
+    public function exists($key){
+        return $this->getRedis()->exists($key);
+    }
+
+    /*
+      // magic function
+      public function __call($name,$arguments){
+      return call_user_func($name,$arguments);
+      }
+     */
+
+    /**
+     * 条件形式设置缓存,如果 key 不存时就设置,存在时设置失败
+     *
+     * @param string $key 缓存KEY
+     * @param string $value 缓存值
+     * @return boolean
+     */
+    public function setnx($key, $value) {
+        return $this->getRedis()->setnx($key, $value);
+    }
+    
+      /**
+    * 返回成功
+    * @param type $key
+    */
+   public function llen($key){
+       return $this->getRedis()->llen($key);
+   }
+
+
+   /**
+    * 过期时间
+    */
+   public function expire($key,$expire = 0){
+       if($expire == 0)            return;
+
+       $this->getRedis()->expire($key,$expire);
+   }
+
+
+    /**
+     * 删除缓存
+     *
+     * @param string || array $key 缓存KEY,支持单个健:"key1" 或多个健:array('key1','key2')
+     * @return int 删除的健的数量
+     */
+    public function remove($key) {
+        // $key => "key1" || array('key1','key2')
+        return $this->getRedis()->delete($key);
+    }
+
+    /**
+     * 值加加操作,类似 ++$i ,如果 key 不存在时自动设置为 0 后进行加加操作
+     *
+     * @param string $key 缓存KEY
+     * @param int $default 操作时的默认值
+     * @return int 操作后的值
+     */
+    public function incr($key, $default = 1) {
+        if ($default == 1) {
+            return $this->getRedis()->incr($key);
+        } else {
+            return $this->getRedis()->incrBy($key, $default);
+        }
+    }
+
+    /**
+     * 值减减操作,类似 --$i ,如果 key 不存在时自动设置为 0 后进行减减操作
+     *
+     * @param string $key 缓存KEY
+     * @param int $default 操作时的默认值
+     * @return int 操作后的值
+     */
+    public function decr($key, $default = 1) {
+        if ($default == 1) {
+            return $this->getRedis()->decr($key);
+        } else {
+            return $this->getRedis()->decrBy($key, $default);
+        }
+    }
+
+    /**
+     * 添空当前数据库
+     *
+     * @return boolean
+     */
+    public function clear() {
+        return $this->getRedis()->flushDB();
+    }
+
+    /* =================== 以下私有方法 =================== */
+
+    /**
+     * 随机 HASH 得到 Redis Slave 服务器句柄
+     *
+     * @return redis object
+     */
+    private function _getSlaveRedis() {
+        // 就一台 Slave 机直接返回
+        if ($this->_sn <= 1) {
+            return $this->_linkHandle['slave'][0];
+        }
+        // 随机 Hash 得到 Slave 的句柄
+        $hash = $this->_hashId(mt_rand(), $this->_sn);
+        return $this->_linkHandle['slave'][$hash];
+    }
+    
+    
+
+    /**
+     * 根据ID得到 hash 后 0~m-1 之间的值
+     *
+     * @param string $id
+     * @param int $m
+     * @return int
+     */
+    private function _hashId($id, $m = 10) {
+        //把字符串K转换为 0~m-1 之间的一个值作为对应记录的散列地址
+        $k = md5($id);
+        $l = strlen($k);
+        $b = bin2hex($k);
+        $h = 0;
+        for ($i = 0; $i < $l; $i++) {
+            //相加模式HASH
+            $h += substr($b, $i * 2, 2);
+        }
+        $hash = ($h * 1) % $m;
+        return $hash;
+    }
+
+    /**
+     *    lpush 
+     */
+    public function lpush($key, $value) {
+        return $this->getRedis()->lpush($key, $value);
+    }
+
+    /**
+     *    add lpop
+     */
+    public function lpop($key) {
+        return $this->getRedis()->lpop($key);
+    }
+
+    /**
+     * lrange 
+     */
+    public function lrange($key, $start, $end) {
+        return $this->getRedis()->lrange($key, $start, $end);
+    }
+
+    /**
+     *    set hash opeation
+     */
+    public function hset($name, $key, $value) {
+        if (is_array($value)) {
+            return $this->getRedis()->hset($name, $key, serialize($value));
+        }
+        return $this->getRedis()->hset($name, $key, $value);
+    }
+
+    /**
+     *    get hash opeation
+     */
+    public function hget($name, $key = null, $serialize = true) {
+        if ($key) {
+            $row = $this->getRedis()->hget($name, $key);
+            if ($row && $serialize) {
+                unserialize($row);
+            }
+            return $row;
+        }
+        return $this->getRedis()->hgetAll($name);
+    }
+
+    /**
+     *    delete hash opeation
+     */
+    public function hdel($name, $key = null) {
+        if ($key) {
+            return $this->getRedis()->hdel($name, $key);
+        }
+        return $this->getRedis()->hdel($name);
+    }
+
+    /**
+     * Transaction start
+     */
+    public function multi() {
+        return $this->getRedis()->multi();
+    }
+
+    /**
+     * Transaction send
+     */
+    public function exec() {
+        return $this->getRedis()->exec();
+    }
+
+    /**
+     *
+     */
+    public function info($key){
+       return $this->getRedis()->scan($key);
+    }
+    
+    
+    /**
+     * 有序字段插入
+     * @param type $key
+     * @param type $num
+     * @param type $value
+     */
+    public function zAdd($key,$num,$value){
+        return $this->getRedis()->zadd($key,$num,$value);    
+    }
+    
+    /**
+     * 获取有序字段的长度
+     * @param type $key
+     */
+    public function zSize($key){
+        return $this->getRedis()->zsize($key);
+    }
+    
+    /**
+     * 删除有序字段数据
+     * @param type $key
+     * @param type $value
+     */
+    public function zDelete($key,$value){
+        return $this->getRedis()->zdelete($key,$value);
+    }
+    
+    /**
+     * 查询数据
+     */
+    public function zRange($key,$num){
+        return $this->getRedis()->zrange($key,$num,-1,true);
+    }
+
+}
+
+       

+ 57 - 0
app/command/Org/RedisPool.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: huangjianfeng
+ * Date: 2019-01-10
+ * Time: 20:41
+ */
+namespace app\command\Org;
+
+class RedisPool
+{
+
+    private $host;
+
+    private $port;
+
+    protected $available = true;
+
+    public function  __construct($host = '127.0.0.1',$port = 6379)
+    {
+        $this->pool = new \SplQueue;
+        $this->host = $host;
+        $this->port = $port;
+    }
+
+    public function put($redis)
+    {
+        $this->pool->push($redis);
+    }
+
+    public function get()
+    {
+        //有空闲连接且连接池处于可用状态
+        if ($this->available && count($this->pool) > 0) {
+            return $this->pool->pop();
+        }
+
+        //无空闲连接,创建新连接
+        $redis = new \Swoole\Coroutine\Redis();
+     //   $redis->setOption(\Redis::OPT_SCAN,\Redis::SCAN_RETRY);
+        $res = $redis->connect($this->host, $this->port);
+        if ($res == false) {
+            return false;
+        } else {
+            return $redis;
+        }
+    }
+
+    public function destruct()
+    {
+        // 连接池销毁, 置不可用状态, 防止新的客户端进入常驻连接池, 导致服务器无法平滑退出
+        $this->available = false;
+        while (!$this->pool->isEmpty()) {
+            $this->pool->pop();
+        }
+    }
+}

+ 437 - 0
app/common.php

@@ -0,0 +1,437 @@
+<?php
+// 应用公共文件
+
+
+/**
+ * 验证手机号是否正确
+ * @param number $mobile
+ * @author honfei
+ */
+function isMobile($mobile)
+{
+    if (!is_numeric($mobile)) {
+        return false;
+    }
+    return preg_match('/^1[3456789]{1}\d{9}$/', $mobile) ? true : false;
+}
+
+/**
+ * 中间加密 用正则
+ */
+function encryptTel($tel)
+{
+    $new_tel = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel);
+    return $new_tel;
+}
+
+
+/**
+ * 清除html
+ * @param $str
+ * @return mixed|string
+ */
+function clearHtml($str)
+{
+    if (!empty($str)) {
+        $str = html_entity_decode($str);
+        $str = strip_tags($str);
+        $str = str_replace("&nbsp;", "", $str);
+    }
+    return $str;
+}
+
+
+/**
+ * 字符串截取,支持中文和其他编码
+ * @static
+ * @access public
+ * @param string $str 需要转换的字符串
+ * @param string $start 开始位置
+ * @param string $length 截取长度
+ * @param string $charset 编码格式
+ * @param string $suffix 截断显示字符
+ * @return string
+ */
+function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = true)
+{
+    $_count = hanzi_length($str);
+    if ($length > $_count && $start == 0) {
+        $r = $str;
+    } else {
+        if (function_exists("mb_substr"))
+            $slice = mb_substr($str, $start, $length, $charset);
+        elseif (function_exists('iconv_substr')) {
+            $slice = iconv_substr($str, $start, $length, $charset);
+        } else {
+            $re['utf-8']  = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
+            $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
+            $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
+            $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
+            preg_match_all($re[$charset], $str, $match);
+            $slice = join("", array_slice($match[0], $start, $length));
+        }
+        $r = $suffix ? $slice . '...' : $slice;
+    }
+    return $r;
+}
+
+
+/**
+ * 计算字符串长度
+ * @param type $str
+ * @return int
+ */
+function hanzi_length($str)
+{
+    $len = strlen($str);
+    $i   = 0;
+    $n   = 0;
+    while ($i < $len) {
+        if (preg_match("/^[" . chr(0xa1) . "-" . chr(0xff) . "]+$/", $str[$i])) {
+            $i += 4;
+        } else {
+            $i += 1;
+        }
+        $n += 1;
+    }
+    return $n;
+}
+
+
+/**
+ * 随机码
+ * @param type $length
+ * @return string
+ */
+function randString($length, $c = false)
+{
+    if ($c) {
+        $_codeSet = '123456789';//不要加0
+    } else {
+        $_codeSet = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY';
+    }
+
+    $code = '';
+    for ($i = 0; $i < $length; $i++) {
+        $code .= $_codeSet[mt_rand(0, strlen($_codeSet) - 1)];
+    }
+    return $code;
+}
+
+
+/**
+ * 验证用户信息返回用户信息
+ *
+ */
+function is_mobile($user)
+{
+    $r = false;
+    //验证是否手机号码
+    $is_mobel = '/^0?(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[[0-9])[0-9]{8}/is';
+    if (preg_match($is_mobel, $user)) {
+        $r = true;
+    }
+    return $r;
+}
+
+function encodePassword($password)
+{
+    return empty($password) ? '' : md5('$^95@Kdf' . md5('Pincll@yiyun' . $password));
+}
+/**
+ * 生成用户唯一ip
+ * @param type $uid
+ */
+function makeUuip($uid){
+    $codeSert = '123456789ABCDEFGHJKLMNPQRTUVWXY';
+    $code = '';
+    $length = 10-strlen($uid)-2;
+    for ($i = 0; $i < $length; $i++) {
+        $code .= $codeSert[mt_rand(0, strlen($codeSert) - 1)];
+    }
+    return $code."IP".$uid;
+}
+
+function makeOrderId($uid,$per="H"){
+    $codeSert = '123456789ABCDEFGHJKLMNPQRTUVWXY';
+    $code = '';
+    $length = 4;
+    for ($i = 0; $i < $length; $i++) {
+        $code .= $codeSert[mt_rand(0, strlen($codeSert) - 1)];
+    }
+    $time = microtime(true)*10000;
+    return $per . $time . $code  . "OU" .$uid;
+}
+/**
+ * 获取唯一token
+ * @param type $lower 小写
+ * @return string
+ */
+function getPartToken($lower=false,$sep=true){
+    $key = "";
+    if (function_exists ( 'com_create_guid' )) {
+        $key = com_create_guid();
+    } else {
+        //mt_srand((double) microtime() * 10000); //optional for php 4.2.0 and up.
+        $charid = strtoupper(md5(uniqid(rand(),true))); //根据当前时间(微秒计)生成唯一id.
+        $hyphen = chr(45); // "-"
+        $uuid = '' . //chr(123)// "{"
+        substr($charid,0,8 ).$hyphen.substr($charid,8,4).$hyphen.substr($charid,12,4).$hyphen.substr($charid,16,4).$hyphen.substr($charid,20,12);
+        //.chr(125);// "}"
+        $key = $uuid;
+    }
+    //小写
+    if($lower){
+        $key = strtolower($key);
+    }
+    //无分隔符
+    if(!$sep){
+        $key = str_replace(chr(45), "", $key);
+    }
+    return $key;
+}
+/**
+ * 生成UUID
+ * @param $uid
+ * @return string
+ */
+function Uuid($uid)
+{
+    $uuid = randString(8,true);
+    $uuid = substr($uuid,0, - (strlen($uid)+1)) ."0". $uid;
+    return $uuid;
+}
+/**
+ * 生成客服UUID
+ * @param $uid
+ * @return string
+ */
+function Kuuid($admin_id)
+{
+    $uuid = randString(8,true);
+    $uuid = "kf".substr($uuid,0, - (strlen($admin_id)+1)) ."0". $admin_id;
+    return $uuid;
+}
+/**
+ * 生成TUUID
+ * @param $tuid
+ * @return string
+ */
+function Tuuid($tuid)
+{
+    $tuuid = randString(8,true);
+    $tuuid = substr($tuuid,0, - (strlen($tuid)+1))."0".$tuid;
+    $str   = "ABCDEFGHIJKLMNOPQRSTUVWSYZ";
+    $wordStart  = substr($str,mt_rand(0,25),1);
+    return $wordStart.$tuuid;
+}
+
+/**
+ * 验证身份证
+ * @param $num
+ * @return bool
+ */
+function IdentityCard($num) {
+    return \library\utils\IdentityCard::isValid($num);
+}
+
+/**
+ * 获取客户端IP地址
+ * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
+ * @return mixed
+ */
+function get_client_ip($type = 0) {
+    $type       =  $type ? 1 : 0;
+    static $ip  =   NULL;
+    if ($ip !== NULL) return $ip[$type];
+    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+        $arr    =   explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
+        $pos    =   array_search('unknown',$arr);
+        if(false !== $pos) unset($arr[$pos]);
+        $ip     =   trim($arr[0]);
+    }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
+        $ip     =   $_SERVER['HTTP_CLIENT_IP'];
+    }elseif (isset($_SERVER['REMOTE_ADDR'])) {
+        $ip     =   $_SERVER['REMOTE_ADDR'];
+    }
+    // IP地址合法验证
+    $long = sprintf("%u",ip2long($ip));
+    $ip   = $long ? array($ip, $long) : array('0.0.0.0', 0);
+    return $ip[$type];
+}
+/**
+ * 获取客户端信息
+ */
+function getClientInfo(){
+    $agent = $_SERVER['HTTP_USER_AGENT'];
+    if(empty($agent)){
+        return false;
+    }
+    $platform="";//平台
+    $browser="";//内置浏览器版本
+    //ios系统
+    if(strpos($agent,'iPad') !== false || strpos($agent,'iPhone') !== false){
+        $platform = "ios";
+    }
+    //android系统
+    if(strpos($agent,'Android') !== false){
+        $platform = "android";
+    }
+    //微信内置浏览器
+    if (strpos($agent,'MicroMessenger') !== false ) {
+        $browser = "weixin";
+    }
+    //QQ内置浏览器
+    if (strpos($agent,'QQ') !== false && strpos($agent,'_SQ_') !== false) {
+        $browser = "qq";
+    }
+    return ["platform"=>$platform,"browser"=>$browser];
+}
+/**
+ * 获取随机键值
+ * @param type $count
+ * @return type
+ */
+function getRandKeyVal(){
+    $words = "abcdefghijklmnopqrstuvwxyz";
+    $key = substr($words,mt_rand(0,25),1).substr($words,mt_rand(0,25),1).mt_rand(0,9);
+    $val = mt_rand(100,999);
+    return ["key"=>$key,"val"=>$val];
+}
+
+/**
+ * 不四舍五入保留小数
+ * @param type $num
+ * @param type $digit
+ * @return type
+ */
+function num_min_format($num,$digit=2){
+    $num = strval(floatval($num));
+    if(strpos($num,'.')===false){
+       return floatval($num);
+    }else{
+       return floatval(explode(".",$num)[0].".".substr(explode(".",$num)[1],0,$digit));
+    }
+}
+
+/*********************************经纬度计算函数*******************************/
+
+/**
+ * 获取定位信息
+ * @param type $lats
+ * @param type $lngs
+ * @param type $gps
+ * @param type $google
+ * @return type
+ */
+function getgps($lats,$lngs, $gps=false, $google=false)
+{
+    $lat=$lats;
+    $lng=$lngs;
+    if($gps)
+        $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=$lng&y=$lat");
+    else if($google)
+        $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=$lng&y=$lat");
+    else
+    return array($lat,$lng);
+    $arr=(array)json_decode($c);
+    if(!$arr['error'])
+    {
+        $lat=base64_decode($arr['y']);
+        $lng=base64_decode($arr['x']);
+    }
+    return array($lat,$lng);
+}
+/**
+* @desc 根据两点间的经纬度计算距离
+* @param float $lat 纬度值
+* @param float $lng 经度值
+*/
+function getDistance($lat1, $lng1, $lat2, $lng2) {
+    $earthRadius = 6367000; //approximate radius of earth in meters
+
+    $lat1 = ($lat1 * pi() ) / 180;
+    $lng1 = ($lng1 * pi() ) / 180;
+
+    $lat2 = ($lat2 * pi() ) / 180;
+    $lng2 = ($lng2 * pi() ) / 180;
+
+    $calcLongitude = $lng2 - $lng1;
+    $calcLatitude = $lat2 - $lat1;
+    $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
+    $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
+    $calculatedDistance = $earthRadius * $stepTwo;
+
+    return round($calculatedDistance);
+}
+/**
+*获取距离
+**/
+function getDicAres($size){
+    $v = $size / 1000;
+    return number_format($v, 2, '.', '');
+}
+
+/**
+ * 百度转化qq
+ * @param type $lng
+ * @param type $lat 
+ */
+function bMapTransQQMap($lng, $lat){
+    $x_pi=3.14159265358979324 * 3000.0/180.0;
+    $x = $lng - 0.0065;
+    $y = $lat - 0.006;
+    $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
+    $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
+    $lngs = $z * cos($theta);
+    $lats = $z * sin($theta);
+    return array($lngs,$lats);
+}
+
+/**
+ * 获取图片信息
+ * @param type $url
+ * @return type
+ */
+function getImageUrlInfo($url){
+    //图片信息
+    $imgInfo = @getimagesize($url);
+    if(!$imgInfo){
+        return false;
+    }
+    $urlAr = explode("/",$url);
+    $fileName = $urlAr[count($urlAr)-1];
+    $info=[];
+    $info["size"] = remote_filesize($url);
+    $info["name"] = explode(".",$fileName)[0];
+//    $info["url"]  = str_replace("/{$fileName}", "", $url);
+    $info["url"]  = $url;
+    $info["w"]    = $imgInfo[0];
+    $info["h"]    = $imgInfo[1];
+    $info["ext"]  = explode("/",$imgInfo["mime"])[1]; 
+    $info["md5"]  = md5_file($url);
+    return $info;
+}
+// 获取远程文件大小函数
+function remote_filesize($url, $user = "", $pw = "")
+{
+    ob_start();
+    $ch = curl_init($url);
+    curl_setopt($ch, CURLOPT_HEADER, 1);
+    curl_setopt($ch, CURLOPT_NOBODY, 1);
+    if(!empty($user) && !empty($pw))
+    {
+        $headers = array('Authorization: Basic ' .  base64_encode("$user:$pw"));
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+    }
+    $ok = curl_exec($ch);
+    curl_close($ch);
+    $head = ob_get_contents();
+    ob_end_clean();
+    $regex = '/Content-Length:\s([0-9].+?)\s/';
+    $count = preg_match($regex, $head, $matches);
+    return isset($matches[1]) ? intval($matches[1]) : 0;
+}
+
+
+

+ 20 - 0
app/controller/Index.php

@@ -0,0 +1,20 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\controller;
+
+use think\facade\View;
+
+class Index
+{
+    public function index()
+    {
+        echo "网站首页";
+    }
+    public function treaty(){
+        return View::fetch('treaty');
+    }
+    public function h5(){
+        return View::fetch('mobile');
+    }
+}

+ 17 - 0
app/event.php

@@ -0,0 +1,17 @@
+<?php
+// 事件定义文件
+return [
+    'bind'      => [
+    ],
+
+    'listen'    => [
+        'AppInit'  => [],
+        'HttpRun'  => [],
+        'HttpEnd'  => [],
+        'LogLevel' => [],
+        'LogWrite' => [],
+    ],
+
+    'subscribe' => [
+    ],
+];

+ 16 - 0
app/home/controller/Index.php

@@ -0,0 +1,16 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\home\controller;
+
+use think\facade\View;
+use app\model\api\Sys as SysModel;
+use app\Request;
+
+class Index
+{
+    public function index(Request $request)
+    {
+        echo "网站首页001";
+    }
+}

+ 142 - 0
app/lib/OrderLib.php

@@ -0,0 +1,142 @@
+<?php
+declare (strict_types=1);
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 支付结算
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+
+
+namespace app\lib;
+
+use app\model\api\PayTrade;
+use app\model\api\Order;
+use app\model\api\ActivityOrder;
+use app\model\api\OrderInfo;
+use app\model\api\Goods;
+use app\model\api\User as UserModel;
+use app\model\api\UserDetail as UserDetailModel;
+use app\model\api\UserScoreDetail;
+use app\model\api\Sys as SysModel;
+
+use think\facade\Db;
+
+class OrderLib
+{
+
+    /**
+     * 支付反馈
+     * @param $orderId
+     * @return bool|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function orderPay($payOn,$payDataInfo="")
+    {
+        $payTradeData = (new PayTrade)->where('pay_no', $payOn)->find();
+        if (empty($payTradeData)) {
+            return false;
+        }
+        //已支付
+        if ($payTradeData['status'] == 1) {
+            return false;
+        }
+        //处理支付成功
+        PayTrade::beginTrans();
+        $userData = (new UserModel)->where('uid', $payTradeData['uid'])->find();
+        try {
+            (new PayTrade)->where('id', $payTradeData['id'])->update(['status' => 1, 'pay_time' => time(),'pay_json' => $payDataInfo]);
+            if($payTradeData['type']=="activity"){
+                //活动报名
+                (new ActivityOrder)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
+                PayTrade::commitTrans();
+                return true;
+            }else{
+                //商城下单
+                (new Order)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
+            }
+            //商城下单普通商品增加积分
+            if ($payTradeData['type'] == 'pro') {
+                $json = unserialize($payTradeData['d_json']);
+                //添加购买用户的积分
+                if($json['give_score']>0){
+                    (new UserScoreDetail)->incomeScore($payTradeData['uid'], $json['give_score'], $payOn,"income_score",["o_id"=>$payTradeData['o_id']]);
+                }
+            }
+            PayTrade::commitTrans();
+        } catch (DbException $dbException) {
+            PayTrade::rollbackTrans();
+            return false;
+        }
+        //后台管理人员支付直接返回
+        if($payTradeData["pay_type"]=="system"){
+            return true;
+        }
+        //判断普通商品购买如果商品已被买断则在此处计算收益
+        $memData = $userData;
+        $orderData = (new Order)->where("id",$payTradeData['o_id'])->find();
+        $orderInfoData=null;
+        $proData=null;
+        if(!empty($orderData)){
+            $orderInfoData = (new OrderInfo)->where("o_id",$orderData['id'])->find()->toArray();
+        }
+        if(!empty($orderInfoData)){
+            $proData = (new Goods)->where("id",$orderInfoData["p_id"])->find();
+        }
+        //ip买断
+        if(!empty($proData) && $orderData["is_ip_buy"]==1 && empty($proData["uid"]) && $proData["is_ip"]==1){
+            (new Goods)->where("id",$proData["id"])->update(["uid"=>$memData["uid"],"uip"=>$memData["uip"]]);
+        }
+        
+//        return true;//暂时关闭分成
+        
+        //系统信息
+        $sysData = (new SysModel)->where("id",1)->find();
+        if($orderData["is_ip_buy"]==0){
+            //上级用户
+            if($memData["parent_uid"]>0){
+                //一级用户
+                $parentData = (new UserModel)->where("uid",$memData["parent_uid"])->where("status",1)->find();
+                if(!empty($parentData) && $sysData['tree_income_per']>0 && $sysData['tree_income_per']<=100){
+                    $treepermono = "推广用户购买商品获得分成";//分成内容
+                    $treePerMoney = $payTradeData["money"]*((int)$sysData['tree_income_per']/100);//分成收益金额
+                    if($treePerMoney>0){
+                        // return true;//暂时关闭分成
+                        (new UserDetailModel)->goodsIncome($memData["parent_uid"],$treePerMoney,"tree_per_income",$treepermono,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
+                    }
+                }
+                //二级用户
+                if(!empty($parentData) && $parentData["parent_uid"] > 0 && $sysData['tree_income_per_two']>0 && $sysData['tree_income_per_two']<=100){
+                    $treepermonoTwo = "二级推广用户购买商品获得分成";//分成内容
+                    $treePerMoneyTwo = $payTradeData["money"]*((int)$sysData['tree_income_per_two']/100);//分成收益金额
+                    if($treePerMoneyTwo>0){
+                        // return true;//暂时关闭分成
+                        (new UserDetailModel)->goodsIncome($parentData["parent_uid"],$treePerMoneyTwo,"tree_per_income",$treepermonoTwo,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
+                    }
+                }
+            }
+        }
+        //普通商品购买计算分成
+        if(!empty($proData) && $orderData["is_ip_buy"]==0 && !empty($proData["uid"]) && $proData["is_ip"]==1){
+            
+//            $sysPer=$sysData['ip_income_per'];//分成比例,后台设置
+            $sysPer=$proData['ip_income_per'];//如果是单个商品则用这条
+            if($sysPer<=0 || $sysPer>100){
+                return true;
+            }
+            $money = $payTradeData["money"];//支付金额
+            $permono = "用户购买商品获得分成";//分成内容
+            $perMoney = $money*((int)$sysPer/100);//分成收益金额
+            //增加用户收益
+            if($perMoney>0){
+                (new UserDetailModel)->goodsIncome($proData["uid"],$perMoney,"per_income",$permono,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
+            }
+        }
+        return true;
+    }
+}

+ 10 - 0
app/middleware.php

@@ -0,0 +1,10 @@
+<?php
+// 全局中间件定义文件
+return [
+    // 全局请求缓存
+    // \think\middleware\CheckRequestCache::class,
+    // 多语言加载
+    // \think\middleware\LoadLangPack::class,
+    // Session初始化
+    // \think\middleware\SessionInit::class
+];

+ 14 - 0
app/model/api/Activity.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Activity extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/ActivityOrder.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ActivityOrder extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Admin.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Admin extends Model
+{
+    //
+}

+ 97 - 0
app/model/api/AdverPage.php

@@ -0,0 +1,97 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AdverPage extends Model
+{
+    /**
+     * 保存分类
+     * @param $post
+     * @return bool
+     */
+    public function savePage($post){
+        if(!empty($post['id'])) {
+            $this->where('id',$post['id'])->save($post);
+            return true;
+        } else {
+            unset($post['id']);
+            $post['add_time'] = time();
+            $bool = $this->insert($post);
+            return $bool;
+        }
+    }
+    public function delAdver($id){
+        $this->where('pid',$id)->delete();
+        $this->where('id',$id)->delete();
+        return true;
+    }
+    /**
+     * 获取分类数据
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getArMenu($cate_name = '',$pid = '',$show =  0){
+        $menus = $this
+            ->when(!empty($cate_name),function ($query) use($cate_name){
+                $query->whereLike('cate_name',"%{$cate_name}%");
+            })
+            ->when(!empty($pid),function ($query) use($pid){
+                $query->where('pid',$pid);
+            })
+            ->order("sort","desc")
+            ->select();
+        $data = [];
+        foreach ($menus as $item) {
+            $data[] = $item->getData();
+        }
+        $menuAr = self::getTree($data);
+        return $menuAr;
+    }
+
+    /**
+     * 获取树型菜单
+     * @param $data
+     * @param int $pid
+     * @param int $level
+     * @return array
+     */
+    public static function getTree($data, $pid = 0, $level = 0)
+    {
+        $childs = self::getChild($data, $pid, $level);
+        array_multisort(array_column($childs, 'sort'), SORT_DESC, $childs);
+        foreach ($childs as $key => $navItem) {
+            $resChild = self::getTree($data, $navItem['id']);
+            if (null != $resChild) {
+                $childs[$key]['children'] = $resChild;
+            }
+        }
+        return $childs;
+    }
+
+    /**
+     * 获取子菜单
+     * @param $arr
+     * @param $id
+     * @param $lev
+     * @return array
+     */
+    private static function getChild(&$arr, $id, $lev)
+    {
+        $child = [];
+        foreach ($arr as $k => $value) {
+            if ($value['pid'] == $id) {
+                $value['level'] = $lev;
+                $child[] = $value;
+            }
+        }
+        return $child;
+    }
+}

+ 64 - 0
app/model/api/Advert.php

@@ -0,0 +1,64 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use library\basic\BaseModel;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Advert extends BaseModel
+{
+    /**
+     * 获取列表数据
+     * @param $page
+     * @param $where
+     * @param $pageCount
+     * @param $desc
+     */
+    public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
+        $data =  $this
+            ->field("p.*,ap.cate_name,ap.json")
+            ->alias("p")
+            ->join("adver_page ap",'ap.id=p.page_id')
+            ->when(!empty($where),function ($query) use($where){
+                if(!empty($where['page_id'])) {
+                    $query->where('p.page_id',$where['page_id']);
+                }
+                if(!empty($where['title'])) {
+                    $query->wherelike('p.title','%' . $where['title'] . '%');
+                }
+
+                if(isset($where['sassid'])) {
+                    $query->where('p.sassid',$where['sassid']);
+                }
+            })
+            ->order($desc)
+            ->paginate(['list_rows'=>$pageCount,'page'=>$page])
+            ->toArray();
+        foreach ($data['data'] as $k=>$v) {
+            $data['data'][$k]['time'] = date('Y-m-d',$v['time']);
+            $data['data'][$k]['jsonAr'] =  json_decode($v['data'],true);
+        }
+        //echo $this->getLastSql();
+        return [$data['total'],$data['data']];
+    }
+    /**
+     * 保存分类
+     * @param $post
+     * @return bool
+     */
+    public function savePage($post){
+        if(!empty($post['id'])) {
+            $this->where('id',$post['id'])->save($post);
+            return true;
+        } else {
+            unset($post['id']);
+            $post['time'] = time();
+            $bool = $this->insert($post);
+            return $bool;
+        }
+    }
+}

+ 14 - 0
app/model/api/AppBug.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AppBug extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Bank.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Bank extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Coupon.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Coupon extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Goods.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Goods extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/GoodsCate.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodsCate extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/GoodsLove.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodsLove extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Label.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Label extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/News.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class News extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/Order.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Order extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/OrderInfo.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderInfo extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/OrderMono.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderMono extends Model
+{
+    //
+}

+ 67 - 0
app/model/api/PayTrade.php

@@ -0,0 +1,67 @@
+<?php
+declare (strict_types=1);
+
+namespace app\model\api;
+
+use library\basic\BaseModel;
+use app\model\api\User as UserModel;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class PayTrade extends BaseModel
+{
+
+
+    /**
+     * 生成支付凭证
+     * @param $payType 支付类型
+     * @param $uid 用户UID
+     * @param $code 支付code
+     * @param $money 支付金额
+     * @param $content 支付说明
+     * @param $out_trade_no 其他订单
+     * @param $djson 额外说明
+     */
+    public function credentials($payType, $uid, $code, $money, $content = '支付凭证', $out_trade_no = '', $djson = [],$admin_id=0)
+    {
+        $apple_pid = (empty($djson) || empty($djson["apple_pid"])) ? '':$djson["apple_pid"];
+        $payOn = $this->mkPayOn($uid);
+        $userData = (new UserModel)->where("uid",$uid)->find();
+        $i_tuid = 0;
+        $i_uid  = 0;
+        if(!empty($userData) && $userData["i_tuid"]>0){
+            $i_tuid = intval($userData["i_tuid"]);
+        }
+        if(!empty($userData) && $userData["i_uid"]>0){
+            $i_uid = intval($userData["i_uid"]);
+        }
+        $bool  = $this->insert([
+            'pay_no'       => $payOn,
+            'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
+            'uid'          => $uid,
+            'pay_type'     => $payType,
+            'code'         => $code,
+            'money'        => $money,
+            'content'      => $content,
+            'd_json'       => serialize($djson),
+            'time'         => time(),
+            'admin_id'     => $admin_id,
+            'apple_pid'    => $apple_pid,
+            'i_tuid'       => $i_tuid,
+            'i_uid'        => $i_uid
+        ]);
+        return $bool ? $payOn : null;
+
+    }
+
+
+    /**
+     * 生成平台支付流水
+     */
+    private function mkPayOn($uid)
+    {
+        return 'PN' . time() . rand(1000, 9000) . $uid;
+    }
+}

+ 14 - 0
app/model/api/ShowTemplate.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ShowTemplate extends Model
+{
+    //
+}

+ 25 - 0
app/model/api/Sys.php

@@ -0,0 +1,25 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use library\basic\BaseModel;
+use library\traits\JwtAuthModelTrait;
+use library\traits\ModelTrait;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Sys extends Model
+{
+    use ModelTrait;
+    use JwtAuthModelTrait;
+    /**
+     * 保存数据
+     * @param $save
+     */
+    public function saveSys($save) {
+        $this->where('id',1)->save($save);
+    }
+}

+ 14 - 0
app/model/api/Tx.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Tx extends Model
+{
+    //
+}

+ 251 - 0
app/model/api/User.php

@@ -0,0 +1,251 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use Closure;
+use library\basic\BaseModel;
+use think\db\exception\DbException;
+use think\Model;
+use think\facade\Db;
+
+/**
+ * @mixin \think\Model
+ */
+class User extends BaseModel
+{
+    //
+    protected $pk = 'uid';
+    /**
+     * 获取列表数据
+     * @param $page
+     * @param $where
+     * @param $pageCount
+     * @param $desc
+     */
+    public function getList($page, $where = [], $pageCount = 20, $filed = '*', $desc = '')
+    {
+        $today = strtotime(date("Y-m-d"));
+        $data = $this
+            ->alias("m")
+            ->field("m.*,u.nickname as i_nickname,u.uuid as i_uuid,t.name as i_tname,t.tuuid as i_tuuid,s.day_surplus_talk,s.day_surplus_video,s.time as surplus_time"
+                    . ",(select count(*) from table_user_friends   as p where p.uid = m.uid)   as friendsCount"//朋友数
+                    . ",(select count(*) from table_user_attention as a where a.uid = m.uid)   as attentionCount"//关注数
+                    . ",(select count(*) from table_user_attention as f where f.i_uid = m.uid) as fasCount"//粉丝数
+                    . ",(select count(*) from table_user_visitors  as v where v.uid = m.uid)   as visitorsCount"//访客数
+                    . "")
+            ->leftJoin("user u","u.uid = m.i_uid")
+            ->leftJoin("user_surplus s","s.uid = m.uid and s.time = {$today}")
+            ->leftJoin("tuser t","t.tuid = m.i_tuid")
+            ->when(!empty($where), function ($query) use ($where) {
+
+                if (!empty($where['mobile'])) {
+                    $query->where('m.mobile', $where['mobile']);
+                }
+                
+                if (!empty($where['nickname'])) {
+                    $query->whereLike('m.nickname', "%{$where['nickname']}%");
+                }
+                
+                if (is_numeric($where['levelid']) && in_array(strval($where['levelid']),['0','1','2'])) {
+                    $query->where('m.levelid', intval($where['levelid']));
+                }
+                
+                if (is_numeric($where['is_certification']) && in_array(strval($where['is_certification']),['0','1','2'])) {
+                    $query->where('m.is_certification', intval($where['is_certification']));
+                }
+                
+                if (is_numeric($where['is_goddess']) && in_array(strval($where['is_goddess']),['0','1','2'])) {
+                    $query->where('m.is_goddess', intval($where['is_goddess']));
+                }
+                
+                if (!empty($where['address'])) {
+                    $query->whereLike('m.address', "%{$where['address']}%");
+                }
+                
+                if (!empty($where['now_address'])) {
+                    $query->whereLike('m.now_address', "%{$where['now_address']}%");
+                }
+
+                if (!empty($where['i_uid'])) {
+                    $query->where('m.i_uid', $where['i_uid']);
+                }
+                if (!empty($where['i_tuid'])) {
+                    $query->where('m.i_tuid', $where['i_tuid']);
+                }
+                
+                if (is_numeric($where["sex"]) && in_array(strval($where["sex"]),["0","1","2"])) {
+                    $query->where('m.sex', $where["sex"]);
+                }
+                
+                if (is_numeric($where["is_im"]) && in_array(strval($where["is_im"]),["0","1"])) {
+                    $query->where('m.is_im', $where["is_im"]);
+                }
+                
+                if (is_numeric($where["is_online"]) && in_array(strval($where["is_online"]),["0","1"])) {
+                    $query->where('m.is_online', $where["is_online"]);
+                }
+                
+                if (is_numeric($where["status"]) && in_array(strval($where["status"]),["0","1","-1"])) {
+                    $query->where('m.status', $where["status"]);
+                }
+
+                if (!empty($where['uid'])) {
+                    $query->where('m.uid', $where['uid']);
+                }
+                
+                if (!empty($where['uuid'])) {
+                    $query->where('m.uuid', $where['uuid']);
+                }
+                //注册时间
+                $startTime = "";
+                $endTime = "";
+                if(!empty($where['time']) && !empty($where['time'][0]) && !empty($where['time'][1])) {
+                   $startTime =  strtotime($where['time'][0]);
+                   $endTime = strtotime($where['time'][1]);
+                }
+                if (!empty($startTime) && !empty($endTime)) {
+                    $query->whereBetween("m.regtime","{$startTime},{$endTime}");
+                }
+                
+            })
+            ->order($desc)
+            ->paginate(['list_rows' => $pageCount, 'page' => $page])
+            ->toArray();
+        return [$data['total'], $data['data']];
+    }
+
+    /**
+     * 保存数据
+     * @param $data
+     * @param $admin_id
+     * @return array
+     */
+    public function saveUpdate($data, $admin_id)
+    {
+        try {
+            self::beginTrans();
+            
+            if(!is_numeric($data["levelid"]) || !in_array(strval($data["levelid"]),["0","1","2"])){
+                unset($data["levelid"]);
+            }
+            if(empty($data["mobile"])){
+                unset($data["mobile"]);
+            }else{
+                if(!isMobile($data["mobile"])){
+                    return [0, '请输入正确的手机号码'];
+                }
+            }
+            if(empty($data["nickname"])){
+                unset($data["nickname"]);
+            }
+            if(empty($data["address"])){
+                unset($data["address"]);
+            }
+            if(empty($data["now_address"])){
+                unset($data["now_address"]);
+            }
+            if(!is_numeric($data["status"]) || !in_array(strval($data["status"]),["0","1","-1"])){
+                unset($data["status"]);
+            }
+            if(!is_numeric($data["is_shield"]) || !in_array(strval($data["is_shield"]),["0","1"])){
+                unset($data["is_shield"]);
+            }
+            
+            //密码
+            if (!empty($data['password'])) {
+                $data['password'] = md5($data['password']);
+            }else{
+                unset($data["password"]);
+            }
+            if(empty($data["avatar"])){
+                unset($data["avatar"]);
+            }
+            if(!is_numeric($data["sex"]) || !in_array(strval($data["sex"]),["0","1","2"])){
+                unset($data["sex"]);
+            }
+            //特殊设置
+            if(empty($data["msg_price"]) || !is_numeric($data["msg_price"])){
+                unset($data["msg_price"]);
+            }
+            if(empty($data["video_price"]) || !is_numeric($data["video_price"])){
+                unset($data["video_price"]);
+            }
+            if(empty($data["audio_price"]) || !is_numeric($data["audio_price"])){
+                unset($data["audio_price"]);
+            }
+            if(empty($data["phone_price"]) || !is_numeric($data["phone_price"])){
+                unset($data["phone_price"]);
+            }
+            if(empty($data["wx_price"]) || !is_numeric($data["wx_price"])){
+                unset($data["wx_price"]);
+            }
+            if(empty($data["qq_price"]) || !is_numeric($data["qq_price"])){
+                unset($data["qq_price"]);
+            }
+            //开关设置
+            if(!is_numeric($data["is_rank"]) || !in_array(strval($data["is_rank"]),["0","1"])){
+                unset($data["is_rank"]);
+            }
+            if(!is_numeric($data["is_gift"]) || !in_array(strval($data["is_gift"]),["0","1"])){
+                unset($data["is_gift"]);
+            }
+            if(!is_numeric($data["is_msg"]) || !in_array(strval($data["is_msg"]),["0","1"])){
+                unset($data["is_msg"]);
+            }
+            if(!is_numeric($data["is_video"]) || !in_array(strval($data["is_video"]),["0","1"])){
+                unset($data["is_video"]);
+            }
+            if(!is_numeric($data["is_audio"]) || !in_array(strval($data["is_audio"]),["0","1"])){
+                unset($data["is_audio"]);
+            }
+            //uid
+            if (!empty($data['uid'])) {
+                $uData = $this->where('uid', $data['uid'])->find()->toArray();
+                if (empty($uData)) {
+                    return [0, '会员不存在'];
+                }
+                if(!empty($data["mobile"])){
+                    //判断手机是否重复
+                    $count = $this
+                        ->where('mobile', $data['mobile'])
+                        ->where('uid', '<>', $data['uid'])
+                        ->count();
+                    if ($count > 0) {
+                        return [0, '手机号码已经存在'];
+                    }
+                }
+            } else {
+                $data['regtime'] = time();
+            }
+
+            $this->saveModel($data);
+            self::commitTrans();
+            return [1, ''];
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return [0, '操作失败1'];
+        } catch (\Exception $e) {
+            self::rollbackTrans();
+            return [0, '操作失败2'];
+        }
+        return [0, '操作失败'];
+    }
+
+    /**
+     * 获取列表数据
+     * @param $page
+     * @param $where
+     * @param $pageCount
+     * @param $desc
+     */
+    public function getItem($uid)
+    {
+        $data = $this
+            ->field("m.*,(select mobile from table_user where uid = m.i_uid) as i_name")
+            ->alias("m")
+            ->where('uid', $uid)
+            ->select();
+        return $data;
+    }
+}

+ 14 - 0
app/model/api/UserAddress.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserAddress extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/UserCircle.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserCircle extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/UserCircleLove.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserCircleLove extends Model
+{
+    //
+}

+ 14 - 0
app/model/api/UserCoupon.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserCoupon extends Model
+{
+    //
+}

+ 197 - 0
app/model/api/UserDetail.php

@@ -0,0 +1,197 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+use library\basic\BaseModel;
+use think\facade\Db;
+use app\model\api\User as UserModel;
+
+/**
+ * @mixin \think\Model
+ */
+class UserDetail extends BaseModel
+{
+    private $config = [
+        'admin_add'          => ["code" => "后台补加余额",     "content" => "后台补加余额:{money}。"],
+        'admin_cut'          => ["code" => "后台补扣余额",     "content" => "后台补扣余额:{money}。"],
+        'tx_apply'           => ['code' => "提现余额",         "content" => "您发起提现,扣除余额:{money}。"],
+        'tx_refund'          => ['code' => "提现失败",         "content" => "提现失败,返还余额:{money}。"],
+        'per_income'         => ['code' => "商城购买分成",     "content" => "{mono} ,商品购买分成获得:{money}。"],
+        'tree_per_income'    => ['code' => "推广用户购买分成", "content" => "{mono} ,推广用户购买分成获得:{money}。"],
+        
+    ];
+    /**
+     * 后台充值余额
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function adminAddMoney($uid, $money,$admin_id,$othen="")
+    {
+        try {
+            self::beginTrans();
+            $post['uid']      = $uid;
+            $post['into']     = floatval($money);
+            $post['code']     = 'admin_add';
+            $post['title']    = $this->config['admin_add']['code'];
+            $post['content']  = $this->TplParam($this->config['admin_add']['content'],compact('money'));
+            $post['type']     = 1;
+            $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money);
+            $post['time']     = time();
+            $post['admin_id'] = $admin_id;
+            $post['othen']    = $othen;
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->update();
+            self::commitTrans();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+    }
+    /**
+     * 后台扣除余额
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function adminCutMoney($uid, $money,$admin_id,$othen="")
+    {
+        try {
+            self::beginTrans();
+            $post['uid']      = $uid;
+            $post['into']     = floatval($money);
+            $post['code']     = 'admin_cut';
+            $post['title']    = $this->config['admin_cut']['code'];
+            $post['content']  = $this->TplParam($this->config['admin_cut']['content'],compact('money'));
+            $post['type']     = -1;
+            $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') - floatval($money);
+            $post['time']     = time();
+            $post['admin_id'] = $admin_id;
+            $post['othen']    = $othen;
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->dec('money', floatval($money))->update();
+            self::commitTrans();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+    }
+    /**
+     * 用户提现余额
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function txApplyMoney($uid, $money,$tx_id)
+    {
+        $post['uid']      = $uid;
+        $post['into']     = floatval($money);
+        $post['code']     = 'tx_apply';
+        $post['title']    = $this->config['tx_apply']['code'];
+        $post['content']  = $this->TplParam($this->config['tx_apply']['content'],compact('money'));
+        $post['type']     = -1;
+        $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') - floatval($money);
+        $post['time']     = time();
+        $post['tx_id']    = $tx_id;
+        $this->insert($post);
+        $bool = Db::name("user")->where('uid', $uid)->dec('money', floatval($money))->update();
+        if ($bool > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+    /**
+     * 用户提现余额驳回返还
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function txRefundMoney($uid, $money,$tx_id)
+    {
+        $post['uid']      = $uid;
+        $post['into']     = floatval($money);
+        $post['code']     = 'tx_refund';
+        $post['title']    = $this->config['tx_refund']['code'];
+        $post['content']  = $this->TplParam($this->config['tx_refund']['content'],compact('money'));
+        $post['type']     = 1;
+        $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money);
+        $post['time']     = time();
+        $post['tx_id']    = $tx_id;
+        $this->insert($post);
+        $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->update();
+        if ($bool > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 购买获得收益
+     * @param type $uid
+     * @param type $money
+     * @param type $mono
+     * @param type $parms
+     */
+    public function goodsIncome($uid,$money,$code,$mono="",$parms=[]){
+        $money = num_min_format($money,2);
+        $post['uid']      = $uid;
+        $post['into']     = floatval($money);
+        $post['code']     = $code;
+        $post['title']    = $this->config[$code]['code'];
+        $post['content']  = $this->TplParam($this->config[$code]['content'],compact('money','mono'));
+        $post['type']     = 1;//收入为1,支出为-1
+        $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money);//余额
+        $post['time']     = time();
+        $post['tx_id']    = 0;
+        $post['cash_uid'] = empty($parms["cash_uid"]) ? 0 : $parms["cash_uid"];
+        $post['p_id'] = empty($parms["p_id"]) ? 0 : $parms["p_id"];
+        $post['o_id'] = empty($parms["o_id"]) ? 0 : $parms["o_id"];
+        $this->insert($post);
+        //买断者收益
+        $perMoney = 0;
+        if(in_array($code,["per_income"])){
+            $perMoney = floatval($money);
+        }
+        $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->inc('money_in', $perMoney)->update();
+        if ($bool > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    
+    /**
+     * 转义的模板信息
+     */
+    private function TplParam($content)
+    {
+        $data = func_get_args();
+        foreach ($data[1] as $k => $v) {
+            $content = str_replace('{' . $k . '}', $v, $content);
+        }
+        return $content;
+    }
+}

+ 14 - 0
app/model/api/UserLogin.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserLogin extends Model
+{
+    //
+}

+ 15 - 0
app/model/api/UserLove.php

@@ -0,0 +1,15 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use library\basic\BaseModel;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserLove extends BaseModel
+{
+    //
+}

+ 195 - 0
app/model/api/UserScoreDetail.php

@@ -0,0 +1,195 @@
+<?php
+declare (strict_types=1);
+
+namespace app\model\api;
+
+use app\model\api\User as UserModel;
+use library\basic\BaseModel;
+use think\facade\Db;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserScoreDetail extends BaseModel
+{
+    private $config = [
+        'admin_score_add'      => ["code" => "后台补加积分", "content" => "后台补加积分:{money}。"],
+        'admin_score_jdd'      => ["code" => "后台补扣积分", "content" => "后台补扣积分:{money}。"],
+        'income_score'         => ["code" => "商城下单赠送积分", "content" => "用户收入{money}积分"],
+        'outcome_score'        => ["code" => "商城购买积分抵扣支出",  "content" => "{mono},支出{money}积分"],
+    ];
+    
+    /**
+     * 后台充值积分余额
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function adminAddMoney($uid, $money,$admin_id,$mono="")
+    {
+        try {
+            self::beginTrans();
+            $post['uid']      = $uid;
+            $post['v']     = floatval($money);
+            $post['code']     = 'admin_score_add';
+            $post['title']    = $this->config['admin_score_add']['code'];
+            $post['content']  = $this->TplParam($this->config['admin_score_add']['content'],compact('money'));
+            $post['type']     = 1;
+            $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('score') + floatval($money);
+            $post['time']     = time();
+            $post['admin_id'] = $admin_id;
+            $post['othen']    = $mono;
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->inc('score', floatval($money))->update();
+            self::commitTrans();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+    }
+    /**
+     * 后台扣除积分余额
+     * @param $uid
+     * @param $money
+     * @param $admin_id
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function adminCutMoney($uid, $money,$admin_id,$mono="")
+    {
+        try {
+            self::beginTrans();
+            $post['uid']      = $uid;
+            $post['v']     = floatval($money);
+            $post['code']     = 'admin_score_jdd';
+            $post['title']    = $this->config['admin_score_jdd']['code'];
+            $post['content']  = $this->TplParam($this->config['admin_score_jdd']['content'],compact('money'));
+            $post['type']     = -1;
+            $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('score') - floatval($money);
+            $post['time']     = time();
+            $post['admin_id'] = $admin_id;
+            $post['othen']    = $mono;
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->dec('score', floatval($money))->update();
+            self::commitTrans();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+    }
+
+
+    /**
+     * 增加用户积分
+     * @param $uid
+     * @param $money
+     * @param $orderSn
+     * @return bool
+     * @throws \think\db\exception\DbException
+     */
+    public function incomeScore($uid, $money, $orderSn="",$code="income_score",$parms=array())
+    {
+        try {
+            $content          = $this->TplParam($this->config[$code]['content'],compact('money'));
+            $post['uid']      = $uid;
+            $post['v']        = $money;
+            $post['code']     = $code;
+            $post['title']    = $this->config[$code]['code'];
+            $post['content']  = $content;
+            $post['type']     = 1;
+            $post['time']     = time();
+            $post['order_sn'] = $orderSn;
+            $post['money']    = (float)(new User)->where('uid', $uid)->value('score') + $money;
+            $post['o_id']    = empty($parms["o_id"])?0:$parms["o_id"];
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->inc('score', floatval($money))->inc('score_in', floatval($money))->update();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            return false;
+        }
+    }
+ 
+    /**
+     * 消耗积分
+     * @param type $uid
+     * @param type $money
+     * @param type $mono
+     */
+    public function payScore($uid,$money,$code,$mono,$parms=array()){
+        try {
+            $content         = $this->TplParam($this->config[$code]['content'],compact('money', 'mono'));
+            $post['uid']     = $uid;
+            $post['v']       = $money;
+            $post['code']    = $code;
+            $post['title']   = $this->config[$code]['code'];
+            $post['content'] = $content;
+            $post['type']    = -1;
+            $post['time']    = time();
+            $post['money']   = (float)(new User)->where('uid', $uid)->value('score') - $money;
+            $post['o_id']    = empty($parms["o_id"])?0:$parms["o_id"];
+            $this->insert($post);
+            $bool = Db::name("user")->where('uid', $uid)->dec('score', floatval($money))->update();
+            if ($bool > 0) {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (DbException $db) {
+            return false;
+        }
+    }
+    /**
+     * 消耗积分,从冻结账户扣除
+     * @param type $uid
+     * @param type $money
+     * @param type $mono
+     */
+    public function payFreezeScore($uid,$money,$code,$mono,$parms=[]){
+        $content         = $this->TplParam($this->config[$code]['content'],compact('money', 'mono'));
+        $post['uid']     = $uid;
+        $post['v']       = $money;
+        $post['code']    = $code;
+        $post['title']   = $this->config[$code]['code'];
+        $post['content'] = $content;
+        $post['type']    = -1;
+        $post['time']    = time();
+        $post['money']   = (float)(new User)->where('uid', $uid)->value('score');
+        $this->insert($post);
+        $bool = Db::name("user")->where('uid', $uid)->dec('score_freeze', floatval($money))->update();
+        if ($bool > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 转义的模板信息
+     */
+    private function TplParam($content)
+    {
+        $data = func_get_args();
+        foreach ($data[1] as $k => $v) {
+            $content = str_replace('{' . $k . '}', $v, $content);
+        }
+        return $content;
+    }
+
+}

+ 14 - 0
app/model/api/UserShop.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\api;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class UserShop extends Model
+{
+    //
+}

+ 119 - 0
app/model/system/Admin.php

@@ -0,0 +1,119 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\traits\JwtAuthModelTrait;
+use library\traits\ModelTrait;
+use think\facade\Cache;
+use think\Model;
+
+class Admin extends BaseModel
+{
+    use ModelTrait;
+    use JwtAuthModelTrait;
+
+
+    /**
+     * 后台管理人员登录
+     * @param $username
+     * @param $pwd
+     * @return array|bool|Model|null
+     */
+    public static function login($username, $pwd){
+        $adminInfo = self::get(compact('username'));
+        if(empty($adminInfo)) return self::setErrorInfo('登录的账号不存在');
+        if (!$adminInfo['status']) return self::setErrorInfo('账户以后被停用!');
+        
+        if (!password_verify($pwd, $adminInfo['password'])) return self::setErrorInfo('账号或密码错误,请重新输入');
+        //发生事件
+        event('SystemAdminLoginAfter', [$adminInfo]);
+        return $adminInfo;
+    }
+
+    /**
+     * 管理添加,修改
+     * @param $post
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function saveAdmin($post) {
+        $save = [
+            'name'     => $post['name'],
+            'role_id'  => $post['role_id'],
+            'avatar'   => $post['avatar'],
+            'status'   => $post['status'],
+            'nickname' => empty($post['nickname'])?'':$post['nickname'],
+        ];
+        //是否密码写入
+        if(!empty($post['password'])) {
+            $save['password'] = password_hash($post['password'],PASSWORD_BCRYPT);
+        }
+        if($post['id']) {
+            $info = self::where("username",$post['username'])->find();
+            if(!empty($info) && $info['id'] != $post['id'] ) {
+                return self::setErrorInfo('登录的账号已存在');
+            }
+            //判断密码
+            if(empty($save['password'])) {
+                unset($post['password']);
+            }
+            self::where('id',$post['id'])->save($save);
+        } else {
+            $save['time'] = time();
+            $save['last_time'] = time();
+            $save['username'] = $post['username'];
+            $count = self::where("username",$post['username'])->count();
+            if($count > 0) {
+                return self::setErrorInfo('登录的账号已存在');
+            }
+
+            if(empty($save['password'])) {
+                return self::setErrorInfo('请输入登录密码');
+            }
+            self::insert($save);
+        }
+
+        return true;
+    }
+
+
+    /**
+     * 验证密码
+     * @param $id 管理ID
+     * @param $pwd 旧密码
+     * @return bool
+     */
+    public static function checkPassowrd($id,$pwd) {
+        $adminInfo = self::get(compact('id'));
+        if(empty($adminInfo)) return self::setErrorInfo('登录的账号不存在');
+        if (!password_verify($pwd, $adminInfo['password'])){
+            return false;
+        }
+        return true;
+    }
+
+
+    /**
+     * 生成token存放令牌 | 存放redis
+     * @param Admin $adminInfo
+     * @param $type
+     * @return array|bool
+     * @throws \Psr\SimpleCache\InvalidArgumentException
+     */
+    public static function createToken(Admin $adminInfo,$type)
+    {
+        $tokenInfo = $adminInfo->getToken($type, []);
+        $exp = (int)bcadd((string)($tokenInfo['params']['exp'] - $tokenInfo['params']['iat']), "60", 0);
+        try {
+            $key = md5($tokenInfo['token']);
+            $res = Cache::store('redis')->set($key, ['token' => $tokenInfo['token'], 'exp' => $exp], (int)$exp);
+        } catch (\Throwable $e) {
+            return self::setErrorInfo('保存token失败');
+        }
+        return $tokenInfo;
+    }
+}

+ 19 - 0
app/model/system/AdminLog.php

@@ -0,0 +1,19 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\traits\JwtAuthModelTrait;
+use library\traits\ModelTrait;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AdminLog extends BaseModel
+{
+    use ModelTrait;
+    use JwtAuthModelTrait;
+    //
+}

+ 161 - 0
app/model/system/AdminMenu.php

@@ -0,0 +1,161 @@
+<?php
+declare (strict_types=1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\utils\Arr;
+use think\db\exception\DbException;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AdminMenu extends BaseModel
+{
+    private $_data;
+
+    private $rolePath;
+
+
+    /**
+     * 设置显示状态
+     * @param $id
+     * @param $status
+     */
+    public function setStatus($id, $status)
+    {
+        self::beginTrans();
+        try {
+            $this->where('id', $id)->save(['is_show' => $status]);
+            $this->where('pid', $id)->save(['is_show' => $status]);
+            self::commitTrans();
+            return true;
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+
+    }
+
+    /**
+     * 保存分类
+     * @param $post
+     * @return bool
+     */
+    public function saveMenu($post)
+    {
+        if (!empty($post['id'])) {
+            $this->where('id', $post['id'])->save($post);
+            return true;
+        } else {
+            unset($post['id']);
+            $bool = $this->insert($post);
+            return $bool;
+        }
+    }
+
+
+    /**
+     * 删除栏目
+     * @param $id
+     */
+    public function delMenu($id)
+    {
+        $this->where('pid', $id)->delete();
+        $this->where('id', $id)->delete();
+        return true;
+    }
+
+
+    /**
+     * 获取admin端用户菜单
+     * @param $roule_id
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getRoute($roule_id)
+    {
+        $rules  = (new AdminRole())->getRoleId($roule_id);
+        $menuAr = $this->getArMenu(1);
+        $paths = [];
+        //判断权限
+        if ($rules['is_system']) {
+            $resultAr = Arr::toIviewUi($menuAr);
+        } else {
+            //获取权限
+            $rolePathData = RolePath::getMoule($rules['module']);
+            //权限对比
+            $resultAr = $this->permissions($rolePathData, $menuAr);
+            foreach ($rolePathData as $v) {
+                if(strpos($v['role_path'],',') !== false) {
+                    $aAr = explode(',',$v['role_path']);
+                    $aAr = array_filter($aAr,function ($item){ return empty(trim($item)) ? false  :true; });
+                   foreach ($aAr as $v2) {
+                       $paths[] = trim($v2);
+                   }
+
+                } else {
+                    if(!empty($v['role_path'])) $paths[] = trim($v['role_path']);
+                }
+            }
+        }
+        $resultAr = array_merge([[
+            'header'    => '0',
+            'icon'      => 'md-home',
+            'is_header' => 0,
+            'path'      => '/system/index',
+            'title'     => '主页',
+        ]], $resultAr);
+        return [$resultAr, ['is_system' => $rules['is_system'], 'data' => $paths]];
+    }
+
+    /**
+     * 获取分类数据
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getArMenu($show = 0)
+    {
+        $menus = $this->when(!empty($show), function ($query) {
+            $query->where('is_show', 1);
+        })->order("seq", "desc")->select();
+        $data  = [];
+        foreach ($menus as $item) {
+            $data[] = $item->getData();
+        }
+        $menuAr = Arr::getTree($data);
+        return $menuAr;
+    }
+
+    /**
+     * 权限分析
+     * @param $rolePath 权利组
+     * @param $menuAr 后台菜单组
+     */
+    public function permissions($rolePath, $menuAr)
+    {
+        $mPath   = array_column($rolePath, 'path_menu_id');
+        $nMenuAr = [];
+        foreach ($menuAr as $v) {
+            $d = [];
+            if(!empty($v['children'])) {
+                foreach ($v['children'] as $v2) {
+                    if (in_array($v2['id'], $mPath)) {
+                        $d[] = $v2;
+                    }
+                }
+            }
+            if (!empty($d)) {
+                $v['children'] = $d;
+                $nMenuAr[]     = $v;
+            }
+        }
+        return $nMenuAr;
+    }
+
+}

+ 70 - 0
app/model/system/AdminRole.php

@@ -0,0 +1,70 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\traits\JwtAuthModelTrait;
+use library\traits\ModelTrait;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AdminRole extends BaseModel
+{
+    use ModelTrait;
+    use JwtAuthModelTrait;
+    private $roleData;
+    private $sassId = 0;
+
+    public function setSassId($sassid) {
+        $this->sassId = $sassid;
+    }
+
+
+    /**
+     * @param $post
+     */
+    public function saveRole($post) {
+        $save['name'] = $post['name'];
+        $save['status'] = $post['status'];
+        if($post['id']) {
+            $info = $this->where("name",$post['name'])->find();
+            if(!empty($info) && $info['id'] != $post['id'] ) {
+                return self::setErrorInfo('角色名重复了');
+            }
+            $this->where('id',$post['id'])->save($save);
+            return true;
+        } else {
+            $this->insert([
+                'name'   => $post['name'],
+                'status' => $post['status']
+            ]);
+        }
+        return true;
+    }
+
+
+    /**
+     * 获取角色数据
+     * @param $id
+     * @param string $field
+     * @return mixed
+     */
+    public function getRoleId($id,$field = '*') {
+        $this->getRoleData();
+        foreach ($this->roleData as $v) {
+            if($v['id'] == $id) {
+                return $field == '*' ? $v : $v[$field];
+            }
+        }
+    }
+
+
+    public function getRoleData(){
+        if(empty($this->roleData))
+            $this->roleData = $this->where('status',1)->select();
+        return $this->roleData;
+    }
+}

+ 166 - 0
app/model/system/RolePath.php

@@ -0,0 +1,166 @@
+<?php
+declare (strict_types=1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\utils\Arr;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class RolePath extends BaseModel
+{
+
+    private $_list = [];
+
+    /**
+     * 获取分类数据
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getArMenu($show = 0)
+    {
+        $menus = $this
+            ->field("rp.*,(select title from table_admin_menu where id = rp.menu_id) as menu_title")
+            ->alias("rp")
+            ->when(!empty($show), function ($query) {
+                $query->where('is_show', 1);
+            })
+            ->order("seq", "desc")
+            ->select();
+        $data  = [];
+        foreach ($menus as $item) {
+            $data[] = $item->getData();
+        }
+        $menuAr = Arr::getTree($data);
+        return $menuAr;
+    }
+
+    /**
+     * 删除栏目
+     * @param $id
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function delMenu($id)
+    {
+        $mAr = $this->where('pid', $id)->select()->toArray();
+        foreach ($mAr as $v) {
+            $this->delMenu($v['id']);
+        }
+        $this->where('id', $id)->delete();
+    }
+
+
+    /**
+     * 设置显示状态
+     * @param $id 设置状态
+     * @param $status
+     * @return bool
+     */
+    public function setStatus($id, $status)
+    {
+        self::beginTrans();
+        try {
+            $this->where('id', $id)->save(['is_show' => $status]);
+            $this->where('pid', $id)->save(['is_show' => $status]);
+            self::commitTrans();
+            return true;
+        } catch (DbException $db) {
+            self::rollbackTrans();
+            return false;
+        }
+
+    }
+
+    /**
+     * 获取全部数据【select】
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getAll()
+    {
+        $this->_list = $this->order("seq","desc")->select()->toArray();
+        return $this->_list;
+    }
+    /**
+     * 根据id 获取数据
+     * @param $id
+     */
+    public function findData($id){
+        foreach ($this->_list as $v) {
+            if($id == $v['id']) return $v;
+        }
+        return null;
+    }
+
+    /**
+     * 获取数据
+     */
+    public function getRoleData()
+    {
+        return $this->getChild(0);
+    }
+
+    /**
+     * 获取关联属性
+     * @param $pid
+     */
+    public function getMenus($id) : int
+    {
+        foreach ($this->_list as $v) {
+            if($v['id'] == $id) return $v['menu_id'];
+        }
+        return  0;
+    }
+
+    /**
+     * 下一集合
+     * @param $pid
+     */
+    public function getChild($pid)
+    {
+        $tAr = [];
+        foreach ($this->_list as $v) {
+            if ($v['pid'] == $pid) {
+                $d             = $v;
+                $d['children'] = $this->getChild($v['id']);
+                $tAr[]         = $d;
+            }
+        }
+
+        return $tAr;
+    }
+
+    /**
+     * 获取model数据
+     * @param $moule
+     */
+    public static function getMoule($str){
+        $module = !empty($str) ? json_decode($str,true) : [];
+        if(empty($module)) return [];
+        $idAr = [];
+        foreach ($module as $k => $v) {
+            $idAr[] = str_replace('check_','',$k);
+        }
+        $model = new static();
+        $model->getAll();
+        $data = [];
+        foreach ($idAr as $v) {
+            $d = $model->findData($v);
+            if(!empty($d)) $data[] = $d;
+        }
+        //获取关联栏目
+        foreach ($data as &$v) {
+            $v['path_menu_id'] = $model->getMenus($v['pid']);
+        }
+        return $data;
+    }
+
+}

+ 27 - 0
app/model/system/Sys.php

@@ -0,0 +1,27 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model\system;
+
+use library\basic\BaseModel;
+use library\traits\JwtAuthModelTrait;
+use library\traits\ModelTrait;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Sys extends BaseModel
+{
+    use ModelTrait;
+    use JwtAuthModelTrait;
+
+
+    /**
+     * 保存数据
+     * @param $save
+     */
+    public function saveSys($save) {
+        $this->where('id',1)->save($save);
+    }
+}

+ 9 - 0
app/provider.php

@@ -0,0 +1,9 @@
+<?php
+use app\ExceptionHandle;
+use app\Request;
+
+// 容器Provider定义文件
+return [
+    'think\Request'          => Request::class,
+    'think\exception\Handle' => ExceptionHandle::class,
+];

+ 9 - 0
app/service.php

@@ -0,0 +1,9 @@
+<?php
+
+use app\AppService;
+
+// 系统服务定义文件
+// 服务在完成全局初始化之后执行
+return [
+    AppService::class,
+];

+ 0 - 0
app/system/.htaccess


+ 32 - 0
app/system/common.php

@@ -0,0 +1,32 @@
+<?php
+// 这是系统自动生成的公共文件
+
+
+
+if (!function_exists('sort_list_tier')) {
+    /**
+     * 分级排序
+     * @param $data
+     * @param int $pid
+     * @param string $field
+     * @param string $pk
+     * @param string $html
+     * @param int $level
+     * @param bool $clear
+     * @return array
+     */
+    function sort_list_tier($data, $pid = 0, $field = 'pid', $pk = 'id', $html = '|-----', $level = 1, $clear = true)
+    {
+        static $list = [];
+        if ($clear) $list = [];
+        foreach ($data as $k => $res) {
+            if ($res[$field] == $pid) {
+                $res['html'] = str_repeat($html, $level);
+                $list[] = $res;
+                unset($data[$k]);
+                sort_list_tier($data, $res[$pk], $field, $pk, $html, $level + 1, false);
+            }
+        }
+        return $list;
+    }
+}

+ 18 - 0
app/system/config/app.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-11-10 12:58
+// +----------------------------------------------------------------------
+return [
+
+    '__JS__'          => '/public/system/js',
+    '__ASSETS__'      => '/public/system/assets',
+    '__CSS__'         => '/public/system/css',
+    '__IMAGES__'      => '/public/system/img',
+
+];

+ 23 - 0
app/system/config/log.php

@@ -0,0 +1,23 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ 记录开关 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2021/2/9 下午4:25
+// +----------------------------------------------------------------------
+
+return [
+    //开启日志记录
+    'LOG'   => true,
+    //记录日志方式 1 记录全部日志(除了禁止记录之外和未设置拦截器) 2 只记录授权记录
+    'LOG_TYPE' => 1,
+    //允许访问记录日志 LOG_TYPE = 2有效
+    'LOG_ALLOW' => [],
+    //禁用记录访问日志 LOG_TYPE = 1 有效
+    'LOG_DISABLE' => ['log/list'],
+    //记录提交参数
+    'LOG_PARAM'  => true
+];

+ 21 - 0
app/system/config/route.php

@@ -0,0 +1,21 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ 路由配置  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 16:10
+// +----------------------------------------------------------------------
+
+return [
+    // 是否强制使用路由
+    'url_route_must'        => true,
+    // 合并路由规则
+    'route_rule_merge'      => true,
+    // 路由是否完全匹配
+    'route_complete_match'  => true,
+    // 是否自动转换URL中的控制器和操作名
+    'url_convert'           => false,
+];

+ 55 - 0
app/system/controller/AuthController.php

@@ -0,0 +1,55 @@
+<?php
+declare (strict_types = 1);
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+namespace app\system\controller;
+
+/**
+ * 基类 所有控制器继承的类
+ * Class AuthController
+ * @package app\adminapi\controller
+ */
+class AuthController extends \app\BaseController
+{
+    /**
+     * 当前登陆管理员信息
+     * @var
+     */
+    protected $adminInfo;
+
+    /**
+     * 当前登陆管理员ID
+     * @var
+     */
+    protected $adminId;
+
+    /**
+     * 当前管理员权限
+     * @var array
+     */
+    protected $auth = [];
+
+    /**
+     * 模型类名
+     * @var null
+     */
+    protected $bindModel = null;
+
+    /**
+     * 初始化
+     */
+    protected function initialize()
+    {
+        parent::initialize();
+        $this->adminInfo = $this->request->adminInfo;
+        event('AdminVisit', [$this->adminInfo, 'system']);
+    }
+
+}

+ 99 - 0
app/system/controller/Login.php

@@ -0,0 +1,99 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-08-25 17:23
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\system\controller;
+
+use app\BaseViewController;
+use app\model\system\Admin as AdminModel;
+use app\model\system\AdminMenu;
+use app\Request;
+use library\exceptions\GeneralException;
+use library\lib\hupun;
+use library\lib\weixina;
+use library\services\UtilService;
+use library\utils\Captcha;
+use library\utils\Qiniu;
+use think\facade\Db;
+
+class Login extends BaseViewController
+{
+
+    /**
+     * 后台登录
+     * @param Request $request
+     * @return mixed
+     * @throws \Psr\SimpleCache\InvalidArgumentException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index(Request $request)
+    {
+        [$account, $pwd, $imgcode] = UtilService::getMore([
+            ['account', '', 'empty', '请输入登录账户'],
+            ['pwd', '', 'empty', '请输入登录密码'],
+            ['imgcode', '', 'empty', '验证码不能为空'],
+        ], $request, true);
+        //验证码
+        if (!(new Captcha)->check($imgcode)) {
+               return app('json')->fail('验证码错误,请重新输入');
+        }
+        //获取登录
+        $adminInfo = AdminModel::login($account, $pwd);
+        if (empty($adminInfo)) {
+            return app('json')->fail(AdminModel::getErrorInfo('用户名错误,请重新输入'));
+        }
+        //生成令牌
+        $token = AdminModel::createToken($adminInfo, 'admin');
+        if (empty($token)) {
+            return app('json')->fail(AdminModel::getErrorInfo());
+        }
+        //获取管理菜单
+        $menuMenu = new AdminMenu();
+        [$menus, $paths] = $menuMenu->getRoute($adminInfo->role_id);
+        return app('json')->success([
+            'token'        => md5($token['token']),
+            'expires_time' => $token['params']['exp'],
+            'menus'        => $menus,
+            'paths'        => $paths,
+            'user_info'    => [
+                'id'       => $adminInfo->getData('id'),
+                'username' => $adminInfo->getData('username'),
+                'name'     => $adminInfo->getData('name'),
+                'avatar'   => $adminInfo->getData('avatar'),
+            ],
+        ]);
+    }
+
+
+    /**
+     * 用户发生退出
+     * @param Request $request
+     */
+    public function logut(Request $request)
+    {
+        echo 'a';
+        var_dump($request->post());
+        exit;
+    }
+
+
+    /**
+     * 验证码
+     * @return \app\adminapi\controller\Login|\think\Response
+     */
+    public function captcha()
+    {
+        return (new Captcha(["length"=>4]))->create();
+    }
+
+}

+ 103 - 0
app/system/controller/ShowTemplate.php

@@ -0,0 +1,103 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller;
+
+use app\BaseController;
+use app\model\api\ShowTemplate;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 皮肤模板管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class ShowTemplate extends  BaseController{
+    /**
+     * 商品列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $post = UtilService::getMore([
+            ['is_hot', '0'],
+            ['is_recommend', '0'],
+            ['page', 1],
+            ['pageSize', 50],
+        ], $request);
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
+        $where=[];
+        $where[]=["status","=",1];
+        if((int)$post["is_hot"]==1){
+            $where[]=["is_hot","=",1];
+        }
+        if((int)$post["is_recommend"]==1){
+            $where[]=["is_recommend","=",1];
+        }
+        
+        $totalCount = (new ShowTemplate)->where($where)->count();
+        $data=null;
+        if($totalCount>0){
+            $data = (new ShowTemplate)
+                ->field("*")
+                ->where($where)
+                ->order("id", "desc")
+                ->page((int)$page, $post["pageSize"])
+                ->select();
+            foreach($data as $k=>$v){
+                $data[$k]["is_use"] = 0;//是否已经购买或者可以使用
+                $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+    }
+
+    
+    /**
+     * 添加编辑商品
+     * @param Request $request
+     * @return type
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['title','','empty','请填写模板标题'],
+            ['price','0','is_numeric','请输入正确的模板售价'],
+            ['old_price','0','is_numeric','请输入正确的模板原价'],
+            ['img','','empty','请上传模板展示图'],
+            ['is_hot','0'],
+            ['is_recommend','0'],
+            ['status','0'],
+        ],$request);
+        $save=[];
+        $save["title"]        = $post["title"];
+        $save["price"]        = floatval($post["price"]);
+        $save["old_price"]    = floatval($post["old_price"]);
+        $save["status"]       = (int)$post["status"]==1?1:0;
+        $save["img"]          = empty($post["img"]) ? "" : $post["img"];
+        $save["is_hot"]       = (int)$post["is_hot"]==1?1:0;
+        $save["is_recommend"] = (int)$post["is_ip"]==1?1:0;
+        $save["admin_time"]   = time();
+        $save["admin_id"]     = $request->adminInfo['id'];
+        $id = $post["id"];
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $save["time"] = time();
+            $r = (new ShowTemplate)->insert($post);
+        }else{
+            $r = (new ShowTemplate)->where("id",$id)->update($save);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+}

+ 189 - 0
app/system/controller/v1/Activity.php

@@ -0,0 +1,189 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\User as UserModel;
+use app\model\api\Activity as ActivityModel;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 活动管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Activity extends  BaseController{
+    private $activityDefaultParms = [
+        ["title"=>"联系电话","type"=>"input","required"=>1,"content"=>"","parms"=>[]],
+        ["title"=>"联系人","type"=>"input","required"=>1,"content"=>"","parms"=>[]],
+    ];
+    private $activityFromType=[
+        ["title"=>"文本输入框","type"=>"input"],
+        ["title"=>"下拉选择框","type"=>"select"],
+        ["title"=>"文本域","type"=>"textarea"],
+    ];
+    /**
+     * 活动列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+                ['page',1],
+                ['title',''],
+                ['is_main',''],
+                ['status',''],
+                ['is_show',''],
+                ['time',[]],
+        ],$request);
+        $where = [];
+        //添加时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["c.add_time","between","{$startTime},{$endTime}"];
+        }
+        if (!empty($post["title"])){
+            $where[]=["c.title","like","%{$post['title']}%"];
+        }
+        if (!empty($post["is_main"]) && (int)$post["is_main"]==1){
+            $where[]=["c.is_main","=",1];
+        }
+        if(in_array((string)$post["status"],['1','0'])){
+            //活动已经结束
+            if((string)$post["status"]=="0"){
+                $where[]=["c.time","<=",time()];
+            }
+            //报名中
+            if((string)$post["status"]=="1"){
+                $where[]=["c.time",">",time()];
+            }
+        }
+        if(in_array((string)$post["is_show"],['1','0'])){
+            $where[]=["c.is_show","=",(int)$post["is_show"]];
+        }
+        $data = (new ActivityModel)
+                ->field("c.*,IFNULL(o.order_count,0) as order_count")
+                ->alias("c")
+                ->leftJoin("(select count(*) as order_count,activity_id  from table_activity_order where status > 0 group by activity_id) as o","o.activity_id = c.id")
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("c.is_main","desc")
+                ->order("c.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new ActivityModel)->alias("c")->where($where)->count();
+        $data = empty($data)?[]:$data;
+        $defaultParms=$this->activityDefaultParms;
+        foreach($data as $k=>$v){
+            $data[$k]["imgs"]     = empty($v["imgs"]) ? [] : explode(",",$v["imgs"]);
+            $data[$k]["descs"]    = empty($v["descs"]) ? [] : explode(",",$v["descs"]);
+            $data[$k]["labels"]   = empty($v["labels"]) ? [] : explode(",",$v["labels"]);
+            $data[$k]["time"]     = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["add_time"] = date("Y-m-d H:i:s",$v["add_time"]);
+            $data[$k]["status"]   = $v["time"] > time() ? 1 : 0;
+            $data[$k]["data"]        = empty($v["data"]) ? [] : unserialize($v["data"]);
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"],
+            'defaultParms' => $defaultParms,
+            'activityFromType'=>$this->activityFromType,
+        ]);
+    }
+
+    
+    /**
+     * 添加编辑活动
+     * @param Request $request
+     * @return type
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['title','','empty','请填写活动标题'],
+            ['mono',''],
+            ['deposits_price','0','is_numeric','请输入正确的活动定金'],
+            ['time','','empty','请选择活动时间'],
+            ['time_str',''],
+            ['address',''],
+            ['imgs',[],'empty','请上传活动主图'],
+            ['descs',[],'empty','请上传活动详情图'],
+            ['labels',[]],
+            ['is_show','0'],
+            ['is_main','0'],
+            ['data',[],'empty','请添加报名参数'],
+        ],$request);
+        $post["deposits_price"] = floatval($post["deposits_price"]);
+        $post["time"] = strtotime($post["time"]);
+        $post["imgs"] = empty($post["imgs"]) ? "" : implode(",", $post["imgs"]);
+        $post["descs"] = empty($post["descs"]) ? "" : implode(",", $post["descs"]);
+        $post["labels"] = empty($post["labels"]) ? "" : implode(",", $post["labels"]);
+        $post["is_show"] = (int)$post["is_show"];
+        $post["is_main"] = (int)$post["is_main"];
+        if($post["is_main"]==1){
+            (new ActivityModel)->where("is_main",1)->update(["is_main"=>0]);
+        }
+        //参数添加
+        $parmsAr = empty($post["data"]) ? [] : $post["data"];
+        $post["data"]=[];
+        $activityFromType = $this->activityFromType;
+        foreach($parmsAr as $k=>$v){
+            if(!empty($v["title"]) && !empty($v["type"])){
+                $check = false;
+                foreach($activityFromType as $k2=>$v2){
+                    if($v2["type"]==$v["type"]){
+                        $check = true;
+                        break;
+                    }
+                }
+                if(!$check){
+                    return app('json')->fail("请选择正确的参数类型");
+                }
+                if($v["type"]=="select" && (empty($v["parms"]) || !is_array($v["parms"]))){
+                    return app('json')->fail("请添加下拉选择框的选项值");
+                }
+                if($v["type"]!="select"){
+                    $v["parms"] = [];
+                }
+                $post["data"][]=[
+                    "title"   => trim($v["title"]),
+                    "content" => trim($v["content"]),
+                    "type"    => trim($v["type"]),
+                    "required"=> (int)$v["required"]==1?1:0,
+                    "parms"   => $v["parms"],
+                ];
+            }
+        }
+        $post["data"] = serialize($post["data"]);
+        
+        
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $post["add_time"] = time();
+            $r = (new ActivityModel)->insert($post);
+        }else{
+            $r = (new ActivityModel)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+
+    
+}

+ 201 - 0
app/system/controller/v1/Admin.php

@@ -0,0 +1,201 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\system\controller\v1;
+use app\model\system\AdminMenu;
+use app\model\system\AdminRole;
+use app\model\system\Admin as AdminModel;
+use app\Request;
+use app\system\controller\AuthController;
+use library\services\UtilService;
+use library\utils\IpLocation;
+use think\facade\Config;
+use think\facade\Cache;
+
+class Admin extends AuthController
+{
+    /**
+     * 退出登陆
+     * @return mixed
+     * @throws \Psr\SimpleCache\InvalidArgumentException
+     */
+    public function logout()
+    {
+        $key = trim(ltrim($this->request->header(Config::get('cookie.system_token_name')), ''));
+        $res = Cache::store('redis')->delete($key);
+        return app('json')->success("ok", []);
+    }
+
+    /**
+     * 获取登录信息 [自己]
+     * @param Request $request
+     * @return mixed
+     */
+    public function info(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id','','empty','参数错误']
+        ],$request,true);
+        if($id == $this->adminInfo['id']) {
+            return app('json')->success([
+               'id' => $id,
+               'username'  => $this->adminInfo['username'],
+               'nickname'  => $this->adminInfo['nickname'],
+               'name'      => $this->adminInfo['name'],
+               'avatar'    => $this->adminInfo['avatar'],
+               'regTime'   => empty($this->adminInfo['time']) ? '' : date('Y-m-d',$this->adminInfo['time']),
+               'lastTime'  => empty($this->adminInfo['last_time']) ? '' : date('Y-m-d',$this->adminInfo['last_time']),
+               'ip'        => $this->adminInfo['ip'],
+               'ipArea'    => (new IpLocation())->getlocation($this->adminInfo['ip'])['country'],
+               'roleName'  => (new  AdminRole())->getRoleId($this->adminInfo['role_id'],'name')
+            ]);
+        }
+    }
+
+    /**
+     * 修改信息 [自己]
+     * @param Request $request
+     * @return mixed
+     */
+    public function edit(Request $request) {
+        [$name,$avatar] = UtilService::getMore([
+            ['name','','empty','请输入管理姓名'],
+            ['avatar','']
+        ],$request,true);
+
+       $bool = AdminModel::update(['name'=>$name,'avatar'=>$avatar],['id'=>$this->adminInfo['id']]);
+        if($bool) {
+            return app('json')->success("修改成功", []);
+        }
+        return app('json')->fail("数据更新失败");
+    }
+
+    /**
+     * 修改密码 [自己]
+     * @param Request $request
+     * @return mixed
+     */
+    public function password(Request $request) {
+        [$oldPass,$newPass] = UtilService::getMore([
+            ['oldPass','','empty','请输入旧密码'],
+            ['newPass','','empty','请输入新密码']
+        ],$request,true);
+
+        if(!AdminModel::checkPassowrd($this->adminInfo['id'],$oldPass)){
+            return app('json')->fail("旧密码错误,请重新输入");
+        }
+        AdminModel::where('id',$this->adminInfo['id'])->save(['password'=>password_hash($newPass,PASSWORD_BCRYPT)]);
+        return app('json')->success("密码修改成功", []);
+    }
+
+    /**
+     * 获取管理列表 [筛选]
+     * @param Request $request
+     * @return mixed
+     */
+    public function list(Request $request)
+    {
+        $pageSize = 50;
+        [$page, $roleId, $keyword] = UtilService::getMore(
+            [
+                ['page', 1],
+                ['roleId', 0],
+                ['keyword', ''],
+            ], $request, true
+        );
+        list($pageCount, $data) = (new AdminModel)
+            ->getList($page,
+                ['role_id' => [$roleId, '!empty'], 'username' => [$keyword, '!empty']]
+                , $pageSize, ['*',""],'id desc');
+        $result = UtilService::getParam([
+            'id',
+            'username',
+            'name',
+            'avatar',
+            'nickname',
+            'status',
+            ['regTime', 'time', 'date("Y-m-d",$1)'],
+            ['lastTime', 'last_time', 'date("Y-m-d",$1)'],
+            'ip',
+            ['ipArea', 'ip',
+                function ($item) {
+                    return (new IpLocation())->getlocation($item)['country'];
+                },
+            ],
+            ['roleName', 'role_id',
+                function ($item) {
+                    return (new  AdminRole())->getRoleId($item, 'name');
+                },
+            ],
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $page,
+        ]);
+    }
+
+    /**
+     * 获取管理数据 [某一管理]
+     * @param Request $request
+     * @return mixed
+     */
+    public function getInfo(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id','','empty','参数错误']
+        ],$request,true);
+        $adminInfo = AdminModel::get(compact('id'));
+        return app('json')->success([
+            'id' => $id,
+            'username'  => $adminInfo['username'],
+            'nickname'  => $adminInfo['nickname'],
+            'name'      => $adminInfo['name'],
+            'avatar'    => $adminInfo['avatar'],
+            'role_id'   => $adminInfo['role_id'],
+            'status'    => $adminInfo['status']
+        ]);
+    }
+
+    /**
+     * 保存数据 [某一个管理]
+     * @param Request $request
+     * @return mixed
+     */
+    public function  save(Request $request) {
+        $post = UtilService::getMore(
+            [
+                ['id','0'],
+                ['name','','empty','请输入姓名'],
+                ['username','','empty','请输入账户'],
+                ['nickname',''],
+                ['status','0'],
+                ['role_id','','empty','请选择管理角色'],
+                ['password',''],
+                ['avatar',''],
+            ],
+            $request
+        );
+        $bool = AdminModel::saveAdmin($post);
+        if($bool)
+            return app('json')->success("操作成功", []);
+        else
+            return app('json')->fail(AdminModel::getErrorInfo());
+    }
+    /**
+     * 删除数据 [删除管理员]
+     * @param Request $request
+     * @return mixed
+     */
+    public function del(Request $request) {
+       [$id] = UtilService::getMore(
+            [
+                ['id','0'],
+            ],
+            $request,true
+        );
+        AdminModel::del($id);
+        return app('json')->success("删除成功", []);
+    }
+
+
+}

+ 157 - 0
app/system/controller/v1/Adver.php

@@ -0,0 +1,157 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\AdverPage;
+use app\model\api\Advert;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 广告管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Adver extends  BaseController{
+
+    /**
+     * 分类列表数据
+     */
+    public function page(Request $request){
+        [$cate_name,$pid,$is_show] = UtilService::getMore([
+            ['cate_name',''],
+            ['pid','0'],
+            ['is_show','0']
+        ],$request,true);
+        $menuMenu = new AdverPage();
+        $menus = $menuMenu->getArMenu($cate_name,$pid,$is_show);
+        return app('json')->success($menus);
+    }
+
+    /**
+     * 获取树级分类
+     */
+    public function page_tree() {
+        $menuAr = (new AdverPage())->order("sort","desc")->select()->toArray();
+        $data = sort_list_tier($menuAr, '顶级', 'pid', 'id');
+        return app('json')->success($data);
+    }
+
+    /**
+     * 获取详情栏目数据
+     */
+    public function page_info(Request $request){
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $data = (new AdverPage())->find(compact('id'))->toArray();
+        return app('json')->success($data);
+    }
+
+    /**
+     * 保存数据
+     */
+    public function page_save(Request $request){
+        $post = UtilService::getMore([
+            ['cate_name','','empty','商品分类'],
+            ['pid','0'],
+            ['sort','0'],
+            ['id','0'],
+            ['type','1'],
+            ['max_count',0],
+            ['json','[]'],
+            ['mono','']
+        ],$request);
+        (new AdverPage())->savePage($post);
+        return app('json')->success("数据保存成功");
+    }
+
+    /**
+     * 栏目删除
+     * @param Request $request
+     */
+    public function page_del(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new AdverPage())->delAdver($id);
+        return app('json')->success("栏目删除成功");
+    }
+
+
+
+
+    public function list(Request $request) {
+        $pageSize = 50;
+        [$page,$page_id,$title,$sassid] =  UtilService::getMore(
+            [
+                ['page',1],
+                ['page_id','0'],
+                ['title',''],
+                ['sassid','0']
+            ],$request,true
+        );
+        $where = compact('page_id','title','sassid');
+        list($pageCount,$data) = (new Advert)
+            ->getList($page,$where,$pageSize,'id desc');
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $page
+        ]);
+    }
+
+
+
+    /**
+     * 获取详情栏目数据
+     */
+    public function info(Request $request){
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $data = (new Advert())->find(compact('id'))->toArray();
+        return app('json')->success($data);
+    }
+
+    /**
+     * 保存数据
+     */
+    public function save(Request $request){
+        $post = UtilService::getMore([
+            ['title','','empty','广告'],
+            ['page_id','0'],
+            ['sort','0'],
+            ['sex',0],
+            ['id','0'],
+            ['text',''],
+            ['url',''],
+            ['code',''],
+            ['img',''],
+            ['data',''],
+            ['is_show','0']
+        ],$request);
+        (new Advert())->savePage($post);
+        return app('json')->success("数据保存成功");
+    }
+
+    /**
+     * 栏目删除
+     * @param Request $request
+     */
+    public function del(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new Advert)->where("id",$id)->delete();
+        return app('json')->success("栏目删除成功");
+    }
+
+}

+ 138 - 0
app/system/controller/v1/Circle.php

@@ -0,0 +1,138 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\AdverPage;
+use app\model\api\Advert;
+use app\model\api\User as UserModel;
+use app\model\api\GoodsCate;
+use app\model\api\UserCircle;
+use app\Request;
+use library\services\UtilService;
+use think\facade\Db;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 圈子管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Circle extends  BaseController{
+    
+    /**
+     * 动态列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+                ['page',1],
+//                ['title',''],
+                ['nickname',''],
+                ['status',''],
+                ['uid',''],
+                ['mobile',''],
+                ['uip',''],
+                ['time',[]],
+        ],$request);
+        $where = [];
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["c.time","between","{$startTime},{$endTime}"];
+        }
+        //用户
+        if(!empty($post['uid'])){
+            $where[]=["c.uid","=",$post['uid']];
+        }else if (!empty($post['uip'])) {
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["c.uid","=",$m['uid']];
+            }
+        }else if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["c.uid","=",$m['uid']];
+            }
+        }else if(!empty($post['nickname'])){
+            $m  = Db::name("user")->where("nickname",$post['nickname'])->find();
+            if(!empty($m)) {
+                $where[]=["c.uid","=",$m['uid']];
+            }
+        }
+//        if (!empty($post["title"])){
+//            $where[]=["c.title","like","%{$post['title']}%"];
+//        }
+        $where2 = $where;
+        $where2[]=["c.status","=",0];//待审核
+        if(in_array((string)$post["status"],['0','1','-1'])){
+            $where[]=["c.status","=",(int)$post["status"]];
+        }
+        $data = (new UserCircle)
+                ->field("c.*,u.nickname,g.imgs as pro_imgs,g.title as pro_title")
+                ->alias("c")
+                ->where($where)
+                ->leftJoin("user u", "u.uid = c.uid")
+                ->leftJoin("goods g", "g.id = c.pro_id")
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("c.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserCircle)->alias("c")->where($where)->count();
+        $waitCount = (new UserCircle)->alias("c")->where($where2)->count();
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["imgs"] = empty($v["imgs"])?[]:explode(",",$v["imgs"]);
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["pro_img"] = empty($v["pro_imgs"]) ? "" : explode(",", $v["pro_imgs"])[0];
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"],
+            'waitCount' => $waitCount,
+        ]);
+    }
+    /**
+     * 审核动态
+     * @param Request $request
+     */
+    public function editStatus(Request $request) {
+        [$id,$status] = UtilService::getMore([
+            ['id',0,'empty','参数错误'],
+            ['status','','empty','参数错误']
+        ],$request,true);
+        
+        $data = (new UserCircle)->where("id",$id)->find();
+        if(empty($data)){
+            return app('json')->fail("数据不存在");
+        }
+        //禁用
+        if($status==-1){
+            (new UserCircle)->where("id",$id)->update(["status"=>-1]);
+        }
+        //删除
+        if($status==-10){
+            (new UserCircle)->where("id",$id)->delete();
+        }
+        //发布
+        if($status==1){
+            (new UserCircle)->where("id",$id)->update(["status"=>1]);
+        }
+        return app('json')->success("操作成功");
+    }
+    
+    
+
+    
+}

+ 371 - 0
app/system/controller/v1/Goods.php

@@ -0,0 +1,371 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\User;
+use app\model\api\GoodsCate;
+use app\model\api\Coupon as CouponModel;
+use app\model\api\Goods as GoodsModel;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 商城管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Goods extends  BaseController{
+    
+    private $goodsDefaultParms = [
+        ["title"=>"赋意","content"=>""],
+        ["title"=>"盆","content"=>""],
+        ["title"=>"配花","content"=>""],
+        ["title"=>"配草","content"=>""],
+        ["title"=>"插件","content"=>""],
+        ["title"=>"IP","content"=>""],
+        ["title"=>"时间","content"=>""],
+        ["title"=>"花开","content"=>""],
+    ];
+    /**
+     * 商品列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+                ['page',1],
+                ['title',''],
+                ['is_hot',''],
+                ['is_hot_sell',''],
+                ['is_ip',''],
+                ['status',''],
+                ['cate_id',''],
+                ['uip',''],
+                ['time',[]],
+        ],$request);
+        $where = [];
+        
+        if (!empty($post["title"])){
+            $where[]=["g.title","like","%{$post['title']}%"];
+        }
+        if(in_array((string)$post["is_hot"],['1','0'])){
+            $where[]=["g.is_hot","=",(int)$post["is_hot"]];
+        }
+        if(in_array((string)$post["is_hot_sell"],['1','0'])){
+            $where[]=["g.is_hot_sell","=",(int)$post["is_hot_sell"]];
+        }
+        if(in_array((string)$post["is_ip"],['1','0'])){
+            $where[]=["g.is_ip","=",(int)$post["is_ip"]];
+        }
+        if(in_array((string)$post["status"],['1','0'])){
+            $where[]=["g.status","=",(int)$post["status"]];
+        }
+        if (!empty($post["cate_id"])){
+            $where[]=["g.cate_id","=",$post['cate_id']];
+        }
+        if (!empty($post["uip"])){
+            $where[]=["g.uip","=",$post['uip']];
+        }
+        //更新时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["g.update_time","between","{$startTime},{$endTime}"];
+        }
+        $data = (new GoodsModel)
+                ->field("g.*")
+                ->alias("g")
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("g.update_time","desc")
+                ->order("g.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new GoodsModel)->alias("g")->where($where)->count();
+        $defaultParms=$this->goodsDefaultParms;
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["imgs"]        = empty($v["imgs"]) ? [] : explode(",",$v["imgs"]);
+            $data[$k]["descs"]       = empty($v["descs"]) ? [] : explode(",",$v["descs"]);
+            $data[$k]["time"]        = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["update_time"] = date("Y-m-d H:i:s",$v["update_time"]);
+            $data[$k]["cate_id"]     = empty($v["cate_id"])?"":$v["cate_id"];
+            $data[$k]["data"]        = empty($v["data"]) ? [] : unserialize($v["data"]);
+        }
+        return app('json')->success([
+            'list'         => $data,
+            'pageCount'    => $pageCount,
+            'pageSize'     => $pageSize,
+            'page'         => $post["page"],
+            'defaultParms' => $defaultParms,
+        ]);
+    }
+
+    
+    /**
+     * 添加编辑商品
+     * @param Request $request
+     * @return type
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['cate_id','','empty','请选择商品分类'],
+            ['title','','empty','请填写商品标题'],
+            ['describe',''],
+            ['price','0','is_numeric','请输入正确的售价'],
+            ['old_price','0','is_numeric','请输入正确的原价'],
+            ['imgs',[],'empty','请上传商品主图'],
+            ['descs',[],'empty','请上传商品详情图'],
+            ['is_hot','0'],
+            ['is_hot_sell','0'],
+//            ['uip',''],
+            ['is_ip','0'],
+            ['ip_title',''],
+            ['ip_price','0'],
+            ['ip_income_per','0','is_numeric','请输入IP收益百分比'],
+            ['status','0'],
+            ['give_score','0','is_numeric','请输入正确的赠送积分'],
+            ['data',[]],
+        ],$request);
+        if($post["is_ip"]==1 && (!is_numeric(trim($post["ip_price"])) || trim($post["ip_price"])<=0)){
+            return app('json')->fail("'请输入买断售价");
+        }
+        if($post["is_ip"]==1){
+            $post["ip_price"] = floatval(trim($post["ip_price"]));
+        }else{
+            $post["ip_price"] = 0;
+        }
+        
+        
+        $post["ip_income_per"] = empty($post["ip_income_per"])?0:(int)$post["ip_income_per"];
+        $post["price"] = floatval($post["price"]);
+        $post["old_price"] = floatval($post["old_price"]);
+        $post["imgs"] = empty($post["imgs"]) ? "" : implode(",", $post["imgs"]);
+        $post["descs"] = empty($post["descs"]) ? "" : implode(",", $post["descs"]);
+        $post["is_hot"] = (int)$post["is_hot"]==1?1:0;
+        $post["is_hot_sell"] = (int)$post["is_hot_sell"]==1?1:0;
+        $post["is_ip"] = (int)$post["is_ip"]==1?1:0;
+        $post["ip_price"] = floatval($post["ip_price"]);
+        $post["status"] = (int)$post["status"]==1?1:0;
+        $post["give_score"] = (int)$post["give_score"];
+        $post["update_time"] = time();
+        if($post["is_ip"]==1 && $post["ip_price"]<=0){
+            return app('json')->fail("请输入正确的买断售价");
+        }
+        if($post["is_ip"]==1 && ($post["ip_income_per"]<0 || $post["ip_income_per"]>100)){
+            return app('json')->fail("请输入正确的IP分成比例");
+        }
+        if(!empty($post["uip"])){
+            $udata = (new User)->where("uip",$post["uip"])->find();
+            if(empty($udata)){
+                return app('json')->fail("用户不存在");
+            }
+            $post["uid"] = $udata["uid"];
+            $post["uip"] = $udata["uip"];
+        }
+        $parmsAr = empty($post["data"]) ? [] : $post["data"];
+        $post["data"]=[];
+        foreach($parmsAr as $k=>$v){
+            if(!empty($v["title"]) && !empty($v["content"])){
+                $post["data"][]=[
+                    "title"   => trim($v["title"]),
+                    "content" => trim($v["content"]),
+                ];
+            }
+        }
+        $post["data"] = serialize($post["data"]);
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $post["time"] = time();
+            $r = (new GoodsModel)->insert($post);
+        }else{
+            $r = (new GoodsModel)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+    /**
+     * 删除商品
+     * @param Request $request
+     */
+    public function del(Request $request) {
+        
+    }
+    /**
+     * 优惠券列表
+     * @param Request $request
+     * @return type
+     */
+    public function coupon(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+            ['page',1],
+            ['status',''],
+        ],$request);
+        $where=[];
+        if((string)$post["status"]!=""){
+            $where[]=["status","=",(int)$post["status"] == 1 ? 1 : 0];
+        }
+        $data = (new CouponModel)
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("id","desc")
+                ->order("seq","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new CouponModel)->where($where)->count();
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"]
+        ]);
+    }
+    /**
+     * 添加编辑优惠券
+     * @param Request $request
+     */
+    public function couponAdd(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['title','','empty','请填写优惠券标题'],
+            ['price','','is_numeric','请填写正确的优惠券面值'],
+            ['limit_price','','is_numeric','请填写正确的满减标准'],
+            ['day','','is_numeric','请填写正确的有效天数'],
+            ['seq','0'],
+            ['status','0']
+        ],$request);
+        $id = (int)$post["id"];
+        unset($post["id"]);
+        $post["price"] = floatval($post["price"]);
+        $post["limit_price"] = floatval($post["limit_price"]);
+        $post["day"] = intval($post["day"]);
+        $post["seq"] = intval($post["seq"]);
+        $post["status"] = intval($post["status"])==1?1:0;
+        if($post["price"]<=0){
+            return app('json')->fail("请输入正确的优惠券面值");
+        }
+        $r=0;
+        if(empty($id)){
+            $post["time"] = time();
+            $r = (new CouponModel)->insert($post);
+        }else{
+            $r = (new CouponModel)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+    /**
+     * 删除优惠券
+     * @param Request $request
+     */
+    public function couponDel(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new CouponModel)->where("id",$id)->delete();
+        return app('json')->success("删除成功");
+    }
+    
+    
+    /**
+     * 商品分类列表
+     * @param Request $request
+     * @return type
+     */
+    public function cate(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+                ['page',1],
+                ['title',''],
+        ],$request);
+        $data = (new GoodsCate)
+                ->when(1 == 1, function ($query) use ($request, $post) {
+                    if (!empty($post["title"])){
+                        $query->where("title",$post["title"]);
+                    }
+                })
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("sort","desc")
+                ->order("id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new GoodsCate)
+                ->when(1 == 1, function ($query) use ($request, $post) {
+                    if (!empty($post["title"])){
+                        $query->where("title",$post["title"]);
+                    }
+                })
+                        ->count();
+        $data = empty($data)?[]:$data;
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"]
+        ]);
+    }
+
+    /**
+     * 添加分类
+     */
+    public function cateAdd(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['title','','empty','请填写分类名称'],
+            ['sort','0'],
+            ['code',''],
+            ['img','','empty','请上传分类图标'],
+            ['is_show','0']
+        ],$request);
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $r = (new GoodsCate)->insert($post);
+        }else{
+            $r = (new GoodsCate)->where("id",$id)->update($post);
+        }
+        
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+
+    /**
+     * 分类删除
+     * @param Request $request
+     */
+    public function cateDel(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new GoodsCate)->where("id",$id)->delete();
+        return app('json')->success("分类删除成功");
+    }
+
+}

+ 48 - 0
app/system/controller/v1/Index.php

@@ -0,0 +1,48 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 首页管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\model\system\AdminMenu;
+use app\model\api\Sys as SysModel;
+use app\Request;
+use app\system\controller\AuthController;
+use library\services\UtilService;
+use think\Cache;
+
+class Index extends AuthController
+{
+
+    /**
+     * 基本数据
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function init()
+    {
+        $menuMenu = new AdminMenu;
+        [$menus, $paths] = $menuMenu->getRoute($this->adminInfo['role_id']);
+        return app('json')->success([
+            'menus'     => $menus,
+            'paths'     => $paths,
+            'user_info' => [
+                'id'       => $this->adminInfo['id'],
+                'username' => $this->adminInfo['username'],
+                'name'     => $this->adminInfo['name'],
+                'avatar'   => $this->adminInfo['avatar'],
+            ],
+        ]);
+    }
+}

+ 99 - 0
app/system/controller/v1/Label.php

@@ -0,0 +1,99 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\AdverPage;
+use app\model\api\Label as LabelModel;
+use app\model\api\GoodsCate;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 标签管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Label extends  BaseController{
+    
+    /**
+     * 标签列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+                ['page',1],
+                ['name',''],
+                ['is_show',''],
+        ],$request);
+        $where=[];
+        if(in_array((string)$post["is_show"],['0','1'])){
+            $where[]=["is_show","=",(int)$post["is_show"]];
+        }
+        if(!empty($post["name"])){
+            $where[]=["name","like","%{$post["name"]}%"];
+        }
+        $data = (new LabelModel)
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("seq","desc")
+                ->order("id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new LabelModel)->where($where)->count();
+        $data = empty($data)?[]:$data;
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"]
+        ]);
+    }
+
+    /**
+     * 标签添加
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['name','','empty','请输入标签名称'],
+            ['seq','0'],
+            ['type','activity'],
+            ['is_show','1']
+        ],$request);
+        $id = $post["id"];
+        unset($post["id"]);
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $r = (new LabelModel)->insert($post);
+        }else{
+            $r = (new LabelModel)->where("id",$id)->update($post);
+        }
+        
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+
+    /**
+     * 标签删除
+     * @param Request $request
+     */
+    public function del(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new LabelModel)->where("id",$id)->delete();
+        return app('json')->success("分类删除成功");
+    }
+
+}

+ 224 - 0
app/system/controller/v1/Log.php

@@ -0,0 +1,224 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\system\AdminLog;
+use app\model\api\UserLogin;
+use app\model\api\User as UserModel;
+use library\services\UtilService;
+use library\utils\IpLocation;
+
+class Log extends BaseController
+{
+
+    public function list()
+    {
+        $pageSize = 50;
+        $post     = UtilService::getMore([
+            ['page', 1],
+            ['data', ''],
+            ['action', ''],
+            ['username', ''],
+            ['ip', ''],
+        ]);
+        list($pageCount, $data) = (new AdminLog())
+            ->getList($post['page'], [function ($query) use ($post) {
+                if ($post['data'] == "lately7") {
+                    $sTime = date('Y-m-d', strtotime('-7 day'));
+                    $eTime = date('Y-m-d');
+                    $query->whereBetweenTime('time', $sTime, $eTime);
+                } else if ($post['data'] == "lately30") {
+                    $sTime = date('Y-m-d', strtotime('-30 day'));
+                    $eTime = date('Y-m-d');
+                    $query->whereBetweenTime('time', $sTime, $eTime);
+                } else if ($post['data'] == "today") {
+                    $query->whereTime('time', 'today');
+                } else if ($post['data'] == "yesterday") {
+                    $query->whereTime('time', 'yesterday');
+                } else if ($post['data'] == "month") {
+                    $query->whereMonth('time');
+                } else if ($post['data'] == "year") {
+                    $query->whereYear('time');
+                } else {
+                    $split = explode('-', $post['data']);
+                    if (count($split) == 2) {
+                        $sTime = $split[0];
+                        $eTime = $split[1];
+                        $query->whereBetweenTime('time', $sTime, $eTime);
+                    }
+                }
+                if (!empty($post['username'])) {
+                    $query->whereLike('admin_username', "%{$post['username']}%");
+                }
+
+                if (!empty($post['action'])) {
+                    $query->whereLike('action', "%{$post['action']}%");
+                }
+
+                if (!empty($post['ip'])) {
+                    $query->whereLike('ip', "%{$post['ip']}%");
+                }
+            },
+            ], $pageSize, '*', 'id desc');
+        $result = UtilService::getParam([
+            'id',
+            'ip',
+            'admin_username',
+            'action',
+            'controller',
+            'title',
+            'post',
+            'get',
+            ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+            ['ipara', 'ip', function ($item) {
+                return "";
+//                return (new IpLocation())->getlocation($item)['country'];
+            }],
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+
+    /**
+     * 清理一个月之前的数据
+     */
+    public function delMonth()
+    {
+        $time = strtotime('- 1 month');
+        AdminLog::where('time', '<', $time)->delete();
+        return app('json')->success('清理成功');
+    }
+    
+    
+    
+    public function listLoginLog()
+    {
+        $pageSize = 50;
+        $post     = UtilService::getMore([
+            ['page', 1],
+            ['data', ''],
+            ['uid', ''],
+            ['uip', ''],
+            ['mobile', ''],
+        ]);
+        $where = [];
+        if(!empty($post["uid"])){
+            $where["l.uid"] = $post["uid"];
+        }
+        if(!empty($post["uip"])){
+            $udata = (new UserModel)->where("uip",$post["uip"])->find();
+            if(!empty($udata)){
+                $where["l.uid"] = $udata["uid"];
+            }
+        }
+        if(!empty($post["mobile"])){
+            $udata = (new UserModel)->where("mobile",$post["mobile"])->find();
+            if(!empty($udata)){
+                $where["l.uid"] = $udata["uid"];
+            }
+        }
+        $data = (new UserLogin)
+                ->alias("l")
+                ->field("l.*,u.uip,u.mobile,u.nickname")
+                ->leftJoin("user u","u.uid = l.uid")
+                ->where($where)
+                ->when(!empty($post["data"]), function ($query) use ($post) {
+                    if ($post['data'] == "lately7") {
+                        $sTime = date('Y-m-d', strtotime('-7 day'));
+                        $eTime = date('Y-m-d');
+                        $query->whereBetweenTime('l.time', $sTime, $eTime);
+                    } else if ($post['data'] == "lately30") {
+                        $sTime = date('Y-m-d', strtotime('-30 day'));
+                        $eTime = date('Y-m-d');
+                        $query->whereBetweenTime('l.time', $sTime, $eTime);
+                    } else if ($post['data'] == "today") {
+                        $query->whereTime('l.time', 'today');
+                    } else if ($post['data'] == "yesterday") {
+                        $query->whereTime('l.time', 'yesterday');
+                    } else if ($post['data'] == "month") {
+                        $query->whereMonth('l.time');
+                    } else if ($post['data'] == "year") {
+                        $query->whereYear('l.time');
+                    } else {
+                        $split = explode('-', $post['data']);
+                        if (count($split) == 2) {
+                            $sTime = $split[0];
+                            $eTime = $split[1];
+                            $query->whereBetweenTime('l.time', $sTime, $eTime);
+                        }
+                    }
+                })
+                ->page((int)$post["page"], $pageSize)
+                ->order("l.id desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserLogin)
+                ->alias("l")
+                ->where($where)
+                ->when(!empty($post["data"]), function ($query) use ($post) {
+                    if ($post['data'] == "lately7") {
+                        $sTime = date('Y-m-d', strtotime('-7 day'));
+                        $eTime = date('Y-m-d');
+                        $query->whereBetweenTime('l.time', $sTime, $eTime);
+                    } else if ($post['data'] == "lately30") {
+                        $sTime = date('Y-m-d', strtotime('-30 day'));
+                        $eTime = date('Y-m-d');
+                        $query->whereBetweenTime('l.time', $sTime, $eTime);
+                    } else if ($post['data'] == "today") {
+                        $query->whereTime('l.time', 'today');
+                    } else if ($post['data'] == "yesterday") {
+                        $query->whereTime('l.time', 'yesterday');
+                    } else if ($post['data'] == "month") {
+                        $query->whereMonth('l.time');
+                    } else if ($post['data'] == "year") {
+                        $query->whereYear('l.time');
+                    } else {
+                        $split = explode('-', $post['data']);
+                        if (count($split) == 2) {
+                            $sTime = $split[0];
+                            $eTime = $split[1];
+                            $query->whereBetweenTime('l.time', $sTime, $eTime);
+                        }
+                    }
+                })
+                ->order("l.id desc")
+                ->count();
+                
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            $data[$k]["title"] = "{$v['nickname']}[{$v['uip']}]进行了登录";
+        }
+
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+
+    /**
+     * 清理一个月之前的登录数据
+     */
+    public function delMonthLoginLog()
+    {
+        $time = strtotime('- 1 month');
+        (new UserLogin)->where('time', '<', $time)->delete();
+        return app('json')->success('清理成功');
+    }
+
+}

+ 761 - 0
app/system/controller/v1/Member.php

@@ -0,0 +1,761 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\lib\OrderLib;
+use app\model\api\PayTrade;
+use app\model\api\UserShop as UserShopModel;
+use app\model\api\Order as OrderModel;
+use app\model\api\ActivityOrder as ActivityOrderModel;
+use library\utils\weixinPay as wxpayApi;
+use app\model\api\User as UserModel;
+use app\model\api\UserDetail as UserDetailModel;
+use app\model\api\UserScoreDetail as UserScoreDetailModel;
+use library\services\UtilService;
+use app\Request;
+use think\facade\Db;
+
+class Member extends BaseController
+{
+    /**
+     * 会员列表
+     * @param Request $request
+     * @return mixed
+     */
+    public function list(Request $request)
+    {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+            ['page',1],
+            ['nickname',''],
+            ['uip',''],
+            ['uid',''],
+            ['parent_uid',''],
+            ['parent_uip',''],
+            ['mobile',''],
+            ['status',''],
+            ['time',[]],
+        ],$request);
+        $where = [];
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["u.regtime","between","{$startTime},{$endTime}"];
+        }
+        if(!empty($post['nickname'])){
+            $where[]=["u.nickname","like","%{$post['nickname']}%"];
+        }
+        if(!empty($post['uid'])){
+            $where[]=["u.uid","=",$post['uid']];
+        }
+        if(!empty($post['mobile'])){
+            $where[]=["u.mobile","=",$post['mobile']];
+        }
+        if(!empty($post['uip'])){
+            $where[]=["u.uip","=",$post['uip']];
+        }
+        if(!empty($post['parent_uid'])){
+            $where[]=["u.parent_uid","=",$post['parent_uid']];
+        }else if(!empty($post['parent_uip'])){
+            $m  = Db::name("user")->where("uip",$post['parent_uip'])->find();
+            if(!empty($m)) {
+                $where[]=["u.parent_uid","=",$m['uid']];
+            }
+        }
+        if(in_array((string)$post["status"],['1','0','-1'])){
+            $where[]=["u.status","=",(int)$post["status"]];
+        }
+        $data = (new UserModel)
+                ->field("u.uid,u.uip,u.nickname,u.regtime,u.score,u.money,u.status,u.avatar,u.ercode,u.mobile,u.parent_uid"
+                        . ",s.id as shop_id,s.name as shop_name,s.lx_name as shop_lx_name,s.address as shop_address,s.tel as shop_tel,s.longitude as shop_longitude,s.latitude as shop_latitude,IFNULL(s.is_show,0) as shop_is_show"
+                        . ",p.nickname as p_nickname,p.mobile as p_mobile,p.uip as p_uip"
+                        . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount")
+                ->alias("u")
+                ->leftJoin("user p","p.uid = u.parent_uid")
+                ->leftJoin("user_shop s","s.uid = u.uid")
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("u.uid","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserModel)->alias("u")->where($where)->count();
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["regtime"] = date("Y-m-d H:i:s",$v["regtime"]);
+            $data[$k]["mobile"]  = empty($v["mobile"])?"未绑定":$v["mobile"];
+            $data[$k]["p_mobile"]  = empty($v["mobile"])?"未绑定":$v["p_mobile"];
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"],
+        ]);
+    }
+
+    /**
+     * 编辑
+     */
+    public function save(Request $request){
+        $post = UtilService::getMore([
+            ['uid','0'],
+            ['status',''],
+            
+            ['shop_name',''],
+            ['shop_tel',''],
+            ['shop_lx_name',''],
+            ['shop_address',''],
+            ['shop_longitude',''],
+            ['shop_latitude',''],
+            ['shop_is_show',''],
+        ],$request);
+        $uid = (int)$post["uid"];
+        if(empty($uid)){
+            return app('json')->fail("参数错误");
+        }
+        unset($post["uid"]);
+        $r=0;
+        if(!in_array((string)$post["status"],['1','-1'])){
+            return app('json')->success("状态错误");
+        }
+        //开启门店
+        $shopData = (new UserShopModel)->where("uid",$uid)->find();
+        $shopSave=[
+            "name"      => $post["shop_name"],
+            "tel"       => $post["shop_tel"],
+            "lx_name"   => $post["shop_lx_name"],
+            "address"   => $post["shop_address"],
+            "longitude" => $post["shop_longitude"],
+            "latitude"  => $post["shop_latitude"],
+            "is_show"   => $post["shop_is_show"]==1?1:0,
+        ];
+        if($shopSave["is_show"]==1){
+            if(empty($shopSave["name"])){
+                return app('json')->fail("请输入门店名称");
+            }
+            if(empty($shopSave["tel"])){
+                return app('json')->fail("请输入门店联系电话");
+            }
+            if(empty($shopSave["lx_name"])){
+                return app('json')->fail("请输入门店联系人");
+            }
+            if(empty($shopSave["address"])){
+                return app('json')->fail("请输入门店地址");
+            }
+            if(empty($shopData)){
+                $shopSave["time"]=time();
+                (new UserShopModel)->insert($shopSave);
+            }else{
+                (new UserShopModel)->where("id",$shopData["id"])->update($shopSave);
+            }
+        }else{
+            if(!empty($shopData)){
+                (new UserShopModel)->where("id",$shopData["id"])->update($shopSave);
+            }
+        }
+        //用户信息
+        $save=[];
+        $save["status"] = $post["status"];
+        $r = (new UserModel)->where("uid",$uid)->update($save);
+        return app('json')->success("数据保存成功");
+    }
+
+    /**
+     * 会员收益明细列表
+     * @param Request $request
+     * @return mixed
+     */
+    public function moneyDetail (Request $request)
+    {
+        $pageSize = 50;
+        $post     = UtilService::getMore(
+            [
+                ['page', '1'],
+                ['uid', '0'],
+                ['uip', ''],
+                ['mobile', ''],
+                ['time', []],
+                ['type', ''],
+                ['code', ''],
+            ], $request
+        );
+        $where    = [];
+        if (!empty($post['uid'])){
+            $where[]=["d.uid","=",$post['uid']];
+        }
+        if (!empty($post['uip'])) {
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["d.uid","=",$m['uid']];
+            }
+        }
+        if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["d.uid","=",$m['uid']];
+            }
+        }
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+           $startTime =  strtotime($post['time'][0]);
+           $endTime = strtotime($post['time'][1]);
+           $where[]=["d.time","between","{$startTime},{$endTime}"];
+        }
+        if (!empty($post['type']) && in_array(strval($post['type']), ["1","-1"])) {
+            $where[]=["d.type","=",$post['type']];
+        }
+        if(!empty($post['code']) && $post['code']!="all"){
+            $where[]=["d.code","=",$post['code']];
+        }
+        $data = (new UserDetailModel)
+                ->alias("d")
+                ->field("d.*,u.mobile,u.uip")
+                ->leftJoin("user u", "u.uid = d.uid")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("d.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserDetailModel)->alias("d")->where($where)->count();
+        foreach($where as $k=>$v){
+            if($v[0]=="d.type"){
+                array_splice($where,$k,1);
+            }
+        }
+        //收入
+        $inWhere = $where;
+        $inWhere[]=["d.type","=",1];
+        $inTotal   = (new UserDetailModel)->alias("d")->where($inWhere)->sum("d.into");
+        //支出
+        $outWhere = $where;
+        $outWhere[]=["d.type","=",-1];
+        $outTotal  = (new UserDetailModel)->alias("d")->where($outWhere)->sum("d.into");     
+        $result = UtilService::getParam(
+            [
+                'id',
+                'uid',
+                'uip',
+                'mobile',
+                'title',
+                'content',
+                'type',
+                'into',
+                'money',
+                ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+            ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+            'inTotal'   => empty($inTotal) ? 0 : floatval($inTotal),
+            'outTotal'  => empty($outTotal)? 0 : floatval($outTotal),
+        ]);
+    }
+    /**
+     * 收益增/减
+     * @param Request $request
+     */
+    public function moneyDetailSave(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['uid', '', 'empty', '参数错误'],
+            ['type', '1'],
+            ['into', '0', 'gt|0', '输入值错误'],
+            ['othen', ''],
+        ], $request);
+        $userData = (new UserModel)->where("uid",$post["uid"])->find();
+        if(empty($userData)){
+            $userData = (new UserModel)->where("uip",$post["uip"])->find();
+            if(empty($userData)){
+                return app('json')->fail('用户不存在,请输入正确的用户uid');
+            }
+        }
+        if(!in_array((string)$post["type"],["1","-1"])){
+            return app('json')->fail('请选择增减');
+        }
+        if ($post['type'] == 1)
+            $bool = (new UserDetailModel)->adminAddMoney($userData['uid'], $post['into'],  $request->adminInfo['id'],$post['othen']);
+
+        if ($post['type'] == -1)
+            $bool = (new UserDetailModel)->adminCutMoney($userData['uid'], $post['into'],  $request->adminInfo['id'],$post['othen']);
+
+        if ($bool)
+            return app('json')->success('操作成功');
+        else
+            return app('json')->fail('操作失败');
+    }
+    
+    /**
+     * 钻石收益明细列表
+     * @param Request $request
+     * @return mixed
+     */
+    public function scoreDetail (Request $request)
+    {
+        $pageSize = 50;
+        $post     = UtilService::getMore(
+            [
+                ['page', '1'],
+                ['uid', '0'],
+                ['uip', ''],
+                ['mobile', ''],
+                ['type', ''],
+                ['code', ''],
+                ['time', []],
+            ], $request
+        );
+        $where    = [];
+        if (!empty($post['uid'])){
+            $where[]=["d.uid","=",$post['uid']];
+        }else if (!empty($post['uip'])) {
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["d.uid","=",$m['uid']];
+            }
+        }else if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["d.uid","=",$m['uid']];
+            }
+        }
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+           $startTime =  strtotime($post['time'][0]);
+           $endTime = strtotime($post['time'][1]);
+           $where[]=["d.time","between","{$startTime},{$endTime}"];
+        }
+        if (!empty($post['type']) && in_array(strval($post['type']), ["1","-1"])) {
+            $where[]=["d.type","=",$post['type']];
+        }
+        if (!empty($post['code'])) {
+            $where[]=["d.code","=",$post['code']];
+        }
+        $data = (new UserScoreDetailModel)
+                ->alias("d")
+                ->field("d.*,u.mobile,u.uip")
+                ->leftJoin("user u", "u.uid = d.uid")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("d.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserScoreDetailModel)->alias("d")->where($where)->count();
+        foreach($where as $k=>$v){
+            if($v[0]=="d.type"){
+                array_splice($where,$k,1);
+            }
+        }
+        //收入
+        $inWhere = $where;
+        $inWhere[]=["d.type","=",1];
+        $inTotal   = (new UserScoreDetailModel)->alias("d")->where($inWhere)->sum("d.v");
+        //支出
+        $outWhere = $where;
+        $outWhere[]=["d.type","=",-1];
+        $outTotal  = (new UserScoreDetailModel)->alias("d")->where($outWhere)->sum("d.v");
+        $result = UtilService::getParam(
+            [
+                'id',
+                'uid',
+                'uip',
+                'mobile',
+                'title',
+                'content',
+                'type',
+                ['into','v'],
+                'money',
+                ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+            ], $data);
+
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+            'inTotal'   => empty($inTotal) ? 0 : floatval($inTotal),
+            'outTotal'  => empty($outTotal)? 0 : floatval($outTotal),
+        ]);
+    }
+    /**
+     * 积分增/减
+     * @param Request $request
+     */
+    public function scoreDetailSave(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['uid', '', 'empty', '参数错误'],
+            ['type', '1'],
+            ['into', '0', 'gt|0', '输入值错误'],
+            ['othen', ''],
+        ], $request);
+        $userData = (new UserModel)->where("uid",$post["uid"])->find();
+        if(empty($userData)){
+            $userData = (new UserModel)->where("uip",$post["uid"])->find();
+            if(empty($userData)){
+                return app('json')->fail('用户不存在,请输入正确的用户uid');
+            }
+        }
+        if ($post['type'] == 1)
+            $bool = (new UserScoreDetailModel)->adminAddMoney($userData['uid'], intval($post['into']),  $request->adminInfo['id'],$post['othen']);
+
+        if ($post['type'] == -1)
+            $bool = (new UserScoreDetailModel)->adminCutMoney($userData['uid'], intval($post['into']),  $request->adminInfo['id'],$post['othen']);
+
+        if ($bool)
+            return app('json')->success('操作成功');
+        else
+            return app('json')->fail('操作失败');
+    }
+    
+    /**
+     * 获取会员数据
+     * @param Request $request
+     * @return mixed
+     */
+    public function getItem(Request $request)
+    {
+        $post   = UtilService::getMore([
+            ['uid', 1],
+        ]);
+        $data = (new UserModel)
+                ->alias("u")
+                ->field("u.uid,u.mobile,u.nickname,u.avatar,u.status,u.regtime,u.lasttime,u.parent_uid.p.nickname as parent_nickname")
+                ->leftJoin("user p","p.uid = u.parent_uid")
+                ->where("u.uid",$post["uid"])
+                ->find()
+                ->toArray();
+        if(!empty($data)){
+            $data["regtime"] = date("Y-m-d H:i:s",$data["regtime"]);
+            $data["lasttime"] = date("Y-m-d H:i:s",$data["lasttime"]);
+        }
+        return app('json')->success(empty($data) ? [] : $data);
+    }
+    public function shopSave(Request $request){
+        $post = UtilService::getMore([
+            ['id','','empty','参数错误'],
+            ['name','','empty','请输入名称'],
+            ['tel','','empty','请输入联系电话'],
+            ['lx_name','','empty','请输入联系人'],
+            ['address','','empty','请输入门店地址'],
+            ['longitude',''],
+            ['latitude',''],
+            ['is_show',''],
+        ],$request);
+        $id = (int)$post["id"];
+        if(empty($id)){
+            return app('json')->fail("参数错误");
+        }
+        unset($post["id"]);
+        $shopSave=[
+            "name"      => $post["name"],
+            "tel"       => $post["tel"],
+            "address"   => $post["address"],
+            "lx_name"   => $post["lx_name"],
+            "longitude" => $post["longitude"],
+            "latitude"  => $post["latitude"],
+            "is_show"   => $post["is_show"]==1?1:0,
+        ];
+        if(empty($shopSave["name"])){
+            return app('json')->fail("请输入门店名称");
+        }
+        if(empty($shopSave["tel"])){
+            return app('json')->fail("请输入门店联系电话");
+        }
+        if(empty($shopSave["address"])){
+            return app('json')->fail("请输入门店地址");
+        }
+        if(empty($shopSave["lx_name"])){
+            return app('json')->fail("请输入门店联系人");
+        }
+        (new UserShopModel)->where("id",$id)->update($shopSave);
+        return app('json')->success("数据保存成功");
+        
+    }
+    public function shopList(Request $request){
+        $pageSize = 50;
+        $post     = UtilService::getMore(
+            [
+                ['page', '1'],
+                ['uid', ''],
+                ['is_show', ''],
+                ['mobile', ''],
+                ['name', ''],
+                ['pageSize', ''],
+            ], $request);
+        $where    = [];
+        if(!empty($post["pageSize"]) && $post["pageSize"]>50){
+            $pageSize = (int)$post["pageSize"];
+        }
+        //用户
+        if (!empty($post['uid'])){
+            $where[]=["t.uid","=",$post['uid']];
+        }else if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["t.uid","=",$m['uid']];
+            }
+        }
+        if(is_numeric($post['is_show']) && in_array((string)$post['is_show'],['0','1'])) {
+            $where[]=["t.is_show","=",(int)$post['is_show']];
+        }
+         if(!empty($post['name'])){
+            $where[]=["t.name","like","%{$post['name']}%"];
+        }
+        $data = (new UserShopModel)
+                ->alias("t")
+                ->field("t.*,u.nickname as nickname,u.uip as uip")
+                ->leftJoin("user u" , "u.uid = t.uid")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("t.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new UserShopModel)->alias("t")->where($where)->count();
+        $result = UtilService::getParam(
+            [
+                'id',
+                'uid',
+                'nickname',
+                'name',
+                'area',
+                'address',
+                'tel',
+                'lx_name',
+                'longitude',
+                "latitude",
+                'is_show',
+                ['time', 'time', function($item){
+                    return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
+                }],
+            ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+        
+    }
+    
+    
+    /**
+     * 支付任务列表
+     * @param \app\model\api\Request $request
+     */
+    public function payTradeList(Request $request){
+        $pageSize = 50;
+        $post     = UtilService::getMore(
+            [
+                ['page', '1'],
+                ['uid', ''],
+                ['uip', ''],
+                ['status', ''],
+                ['mobile', ''],
+                ['type', ''],
+                ['pay_no', ''],
+                ['order_id', ''],
+                ['time', []],
+            ], $request);
+        $where    = [];
+        //用户
+        if (!empty($post['uid'])){
+            $where[]=["t.uid","=",$post['uid']];
+        }else if (!empty($post['uip'])) {
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["t.uid","=",$m['uid']];
+            }
+        }else if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["t.uid","=",$m['uid']];
+            }
+        }
+        if(is_numeric($post['status']) && in_array((string)$post['status'],['0','1'])) {
+            $where[]=["t.status","=",(int)$post['status']];
+        }
+        if(!empty($post['pay_type']) && in_array($post['pay_type'],['wxpay','system'])) {
+            $where[]=["t.pay_type","=",$post['pay_type']];
+        }
+        if(!empty($post['type']) && in_array($post['type'],['pro','ip','activity'])) {
+            $where[]=["t.type","=",$post['type']];
+        }
+        if(!empty($post['pay_no'])){
+            $where[]=["t.pay_no","=",$post['pay_no']];
+        }
+        if(!empty($post['order_id'])){
+            $where[]=["t.order_id","=",$post['order_id']];
+        }
+        
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+           $startTime =  strtotime($post['time'][0]);
+           $endTime = strtotime($post['time'][1]);
+           $where[]=["t.time","between","{$startTime},{$endTime}"];
+        }
+        $data = (new PayTrade)
+                ->alias("t")
+                ->field("t.*,u.nickname as nickname,u.uip as uip,a.username as admin_name")
+                ->leftJoin("user u" , "u.uid = t.uid")
+                ->leftJoin("admin a", "a.id  = t.admin_id")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("t.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new PayTrade)->alias("t")->where($where)->count();
+        $result = UtilService::getParam(
+            [
+                'id',
+                'uid',
+                'uip',
+                'nickname',
+                "admin_id",
+                "admin_name",
+                'pay_no',
+                'out_trade_no',
+                'pay_no',
+                'order_id',
+                'pay_type',
+                'type',
+                'money',
+                'content',
+                "d_json",
+                'status',
+                'mono',
+                ['time', 'time', function($item){
+                    return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
+                }],
+                ['pay_time' , 'pay_time', function($item){
+                    return empty($item) ? "--" : date("Y-m-d H:i:s",$item);
+                }],
+                ['pay_json', 'pay_json', function($item){
+                    if(empty($item)){
+                        return "";
+                    }
+                    $payData = json_decode($item,true);
+                    return $payData;
+                }],
+            ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 搜索交易数据
+     * @param Request $request
+     */
+    public function searchPayTrade(Request $request){
+        $post     = UtilService::getMore(
+            [
+                ['id', '','empty',''],
+            ], $request);
+        $data = (new PayTrade)->where("id",$post["id"])->find();
+        if(empty($data)){
+            return app("json")->fail("数据不存在");
+        }
+        if($data["status"]==1 && !empty($data["pay_json"])){
+            return app("json")->success("交易支付成功", json_decode($data["pay_json"],true));
+        }
+        $out_trade_no = $data["out_trade_no"];
+        //微信支付
+        if($data["pay_type"]=="wxpay"){
+            $wxpay = new wxpayApi();
+            $res = $wxpay->searchOrder($out_trade_no);
+            if(empty($res)){
+                return app("json")->fail("查询失败:".$wxpay->errorMsg);
+            }
+            $resAr = json_decode($res,true);
+            if(empty($resAr) || !is_array($resAr)){
+                return app("json")->fail("查询失败");
+            }
+            if(empty($resAr["trade_state"])){
+                return app("json")->fail("查询状态错误");
+            }
+            if($resAr["trade_state"]=="NOTPAY"){
+                return app("json")->fail("未支付");
+            }
+            if($resAr["trade_state"]=="REFUND"){
+                return app("json")->fail("转入退款");
+            }
+            if($resAr["trade_state"]=="CLOSED"){
+                return app("json")->fail("已关闭");
+            }
+            if($resAr["trade_state"]=="REVOKED"){
+                return app("json")->fail("已撤销(付款码支付)");
+            }
+            if($resAr["trade_state"]=="USERPAYING"){
+                return app("json")->fail("用户支付中(付款码支付)");
+            }
+            if($resAr["trade_state"]=="PAYERROR"){
+                return app("json")->fail("支付失败(其他原因,如银行返回失败)");
+            }
+            if($resAr["trade_state"]=="ACCEPT"){
+                return app("json")->fail("已接收,等待扣款");
+            }
+            if($resAr["trade_state"]=="SUCCESS"){
+                if(empty($resAr["amount"]) || empty($resAr["amount"]["total"])){
+                    return app("json")->fail("交易支付成功,但是查询金额信息");
+                }
+                $returnData = [
+                    'totalMoney' =>$resAr["amount"]["total"]/100,
+                    'payMoney'   =>empty($resAr["amount"]["payer_total"])?'未返回':$resAr["amount"]["payer_total"]/100,
+                    'payTradeNo' =>$resAr["transaction_id"],
+                    'outTradeNo' =>$resAr["out_trade_no"],
+                    "tradeStatus"=>$resAr["trade_state"],
+                    "payTime"    =>$resAr["success_time"],
+                ];
+                $save=[
+                    "status"=>1,
+                    "pay_json"=>json_encode($returnData),
+                ];
+                if(!empty($returnData["payTime"])){
+                    $save["pay_time"] = strtotime($returnData["payTime"]);
+                }
+                (new PayTrade)->where("id",$post["id"])->save($save);
+                $saveOrderModel = null;
+                if(!empty($data["o_id"]) && $data["status"]!=1){
+                    if($data["type"]=="activity"){
+                        $saveOrderModel = new ActivityOrderModel();
+                    }
+                    if($data["type"]=="pro" || $data["type"]=="ip"){
+                        $saveOrderModel = new OrderModel();
+                    }
+                }
+                if(!empty($saveOrderModel)){
+                    $orderData = $saveOrderModel->where("id",$data["o_id"])->find();
+                    if(!empty($orderData) && $orderData["status"]<1){
+                        $saveOrderModel->where("id",$data["o_id"])->update(["status"=>1,"pay_time"=>$save["pay_time"]]);
+                    }
+                }
+                return app("json")->success("交易支付成功",$returnData);
+            }
+            return app("json")->fail("支付状态未知");
+        }
+        return app("json")->fail("查询失败");
+    }
+
+    
+    
+}

+ 73 - 0
app/system/controller/v1/News.php

@@ -0,0 +1,73 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\Request;
+use library\services\UtilService;
+use app\model\api\News as NewsModel;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 展示信息管理
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class News extends  BaseController{
+    /**
+     * 公告列表
+     * @param Request $request
+     */
+    public function list(Request $request){
+        $post = UtilService::getMore([
+            ['status', ''],
+        ],$request);
+        $where=[];
+        if(is_numeric($post["status"]) && in_array((string)$post["status"],["0","1"])){
+            $where["status"] = $post["status"];
+        }
+        $data = (new NewsModel)->where($where)->order("time","desc")->select()->toArray();
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+        }
+        return app("json")->success(["list"=>$data]);
+    }
+    /**
+     * 公告添加
+     * @param Request $request
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id', ''],
+            ['title', '','empty','请输入标题'],
+            ['content', '','empty','请输入内容'],
+            ['status', '','is_numeric','参数错误'],
+        ],$request);
+        $save = [];
+        $save["title"]   = $post["title"];
+        $save["content"] = $post["content"];
+        $save["status"]  = empty($post["status"]) ? 0 : 1;
+        $save["time"]    = time();
+        if(empty($post["id"])){
+            (new NewsModel)->insert($save);
+        }else{
+            (new NewsModel)->where("id",$post["id"])->update($save);
+        }
+        return app("json")->success("操作成功");
+    }
+    /**
+     * 公告删除
+     * @param Request $request
+     */
+    public function del(Request $request){
+        $post = UtilService::getMore([
+            ['id', '','empty','参数错误'],
+        ],$request);
+        (new NewsModel)->where("id",$post["id"])->delete();
+        return app("json")->success("删除成功");
+    }
+}

+ 710 - 0
app/system/controller/v1/Order.php

@@ -0,0 +1,710 @@
+<?php
+declare (strict_types=1);
+
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use app\model\api\MemberDetail;
+//use app\model\api\Express;
+use app\model\api\Order as OrderModel;
+use app\model\api\ActivityOrder as ActivityOrderModel;
+use app\model\api\OrderInfo;
+use app\model\api\OrderMono;
+
+use app\Request;
+use library\services\UtilService;
+use library\utils\Region;
+use think\db\exception\DbException;
+use think\Exception;
+use think\facade\Db;
+use function GuzzleHttp\Psr7\str;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class Order extends BaseController
+{
+
+    /**
+     * 获取订单数据
+     * @param Request $request
+     * @return mixed
+     * @throws DbException
+     */
+    public function list(Request $request)
+    {
+        $pageSize = 50;
+        $post = UtilService::getMore(
+            [
+                ['page', 1],
+                ['uid',0],
+                ['uip',''],
+                ['order_id', ''],
+                ['status',''],
+                ['type',''],
+                ['shop_id',''],
+                ['is_ip_buy',''],
+                ['mobile',''],
+                ['name',''],
+                ['tel',''],
+                ['time',[]],
+            ], $request
+        );
+        $where = [];
+        if(!empty($post['uid'])){
+            $where[]=["o.uid","=",$post['uid']];
+        }else if(!empty($post['uip'])){
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["o.uid","=",$m['uid']];
+            }
+        }else if(!empty($post['mobile'])){
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["o.uid","=",$m['uid']];
+            }
+        }
+        if(!empty($post['order_id'])){
+            $where[]=["o.order_id","=",$post['order_id']];
+        }
+        if(in_array((string)$post['status'],["0","1","2","3","-1"])){
+            $where[]=["o.status","=",(int)$post['status']];
+        }
+        if($post['is_ip_buy']!="" && in_array((string)$post['is_ip_buy'],["0","1"])){
+            $where[]=["o.is_ip_buy","=",(int)$post['is_ip_buy']];
+        }
+        if($post['type']!="" && in_array((string)$post['type'],["shop","send"])){
+            $where[]=["o.type","=",$post['type']];
+        }
+        if(!empty($post['name'])){
+            $where[]=["o.name","=",$post['name']];
+        }
+        if(!empty($post['tel'])){
+            $where[]=["o.tel","=",$post['tel']];
+        }
+        if(!empty($post['shop_id'])){
+            $where[]=["o.shop_id","=",$post['shop_id']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["o.time","between","{$startTime},{$endTime}"];
+        }
+        $order = new OrderModel;
+        $data  = $order
+                ->alias("o")
+                ->field("o.*,u1.mobile,u1.uip,u1.nickname")
+                ->leftJoin("user u1","u1.uid = o.uid")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("o.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = $order->alias("o")->where($where)->count();
+        $result = UtilService::getParam([
+            "id",
+            "order_id",
+            "uid",
+            "uip",
+            "mobile",
+            "nickname",
+            
+            "total_money",
+            "all_money",
+            "pay_money",
+            "postage",
+            "name",
+            "tel",
+            "address",
+            "coupon_money",
+            "is_ip_buy",
+            "status",
+            "score",
+            "give_score",
+            "mono",
+            "express_num",
+            "type",
+            "shop_id",
+            "content",
+            ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+            ['pay_time', 'pay_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['fa_time', 'fa_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['ok_time', 'ok_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 搜索统计
+     */
+    public function total(Request $request)
+    {
+        $post = UtilService::getMore(
+            [
+                ['uid',0],
+                ['uip',''],
+                ['mobile',''],
+                ['tel',''],
+                ['name',''],
+                ['type',''],
+                ['shop_id',''],
+                ['order_id', ''],
+                ['status',''],
+                ['is_ip_buy',''],
+                ['time',[]],
+            ], $request
+        );
+        $order       = new OrderModel;
+        $totalWhere = [];
+        if(!empty($post['uid'])){
+            $totalWhere[]=["uid","=",$post['uid']];
+        }else if(!empty($post['uip'])){
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $totalWhere[]=["uid","=",$m['uid']];
+            }
+        }else if(!empty($post['mobile'])){
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $totalWhere[]=["uid","=",$m['uid']];
+            }
+        }
+        if(!empty($post['order_id'])){
+            $totalWhere[]=["order_id","=",$post['order_id']];
+        }
+        if($post['is_ip_buy']!="" && in_array((string)$post['is_ip_buy'],["0","1"])){
+            $totalWhere[]=["is_ip_buy","=",(int)$post['is_ip_buy']];
+        }
+        if($post['type']!="" && in_array((string)$post['type'],["shop","send"])){
+            $totalWhere[]=["type","=",$post['type']];
+        }
+        if(in_array((string)$post['status'],["0","1","2","3","-1"])){
+            $totalWhere[]=["status","=",$post['status']];
+        }
+        if(!empty($post['name'])){
+            $totalWhere[]=["name","=",$post['name']];
+        }
+        if(!empty($post['tel'])){
+            $totalWhere[]=["tel","=",$post['tel']];
+        }
+        if(!empty($post['shop_id'])){
+            $totalWhere[]=["shop_id","=",$post['shop_id']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $totalWhere[]=["time","between","{$startTime},{$endTime}"];
+        }
+        foreach($totalWhere as $k=>$v){
+            if($v[0]=="status"){
+                array_splice($totalWhere,$k,1);
+            }
+        }
+        //全部
+        $orderCount = $order->where($totalWhere)->count();
+        //待支付
+        $waitPayWhere   = $totalWhere;
+        $waitPayWhere[] = ["status","=","0"];
+        $waitPayCount   = $order->where($waitPayWhere)->count();
+        //待发货
+        $waitSendWhere    = $totalWhere;
+        $waitSendWhere[]  = ["status","=",1];
+        $waitSendCount    = $order->where($waitSendWhere)->count();
+        //待收货
+        $waitAcceptWhere    = $totalWhere;
+        $waitAcceptWhere[]  = ["status","=",2];
+        $waitAcceptCount    = $order->where($waitAcceptWhere)->count();
+        //已完成
+        $okWhere    = $totalWhere;
+        $okWhere[]  = ["status","=",3];
+        $okCount    = $order->where($okWhere)->count();
+        
+        
+        //已取消
+        $closeWhere    = $totalWhere;
+        $closeWhere[]  = ["status","=",-1];
+        $closeCount    = $order->where($closeWhere)->count();
+        return app('json')->success([
+            'orderCount' => $orderCount,
+            'waitPayCount'=> $waitPayCount,
+            'waitSendCount' => $waitSendCount,
+            'waitAcceptCount'=>$waitAcceptCount,
+            'okCount'=>$okCount,
+            'closeCount' => $closeCount,
+        ]);
+    }
+
+    /**
+     * 订单详情
+     * @param Request $request
+     */
+    public function info(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', '', 'empty', '参数错误'],
+        ], $request, true);
+        $oData = (new OrderModel)
+                ->alias("o")
+                ->field("o.*,u1.mobile,u1.uip,u1.nickname")
+                ->leftJoin("user u1","u1.uid = o.uid")
+                ->where("o.id",$id)
+                ->find();
+        if (empty($oData)) {
+            return app('json')->fail('找不到订单号');
+        }
+        //主订单数据
+        $data                 = [];
+        $data['id']           = $oData['id'];
+        $data['order_id']     = $oData['order_id'];
+        $data['uid']          = $oData['uid'];
+        $data['mobile']       = $oData['mobile'];
+        $data['nickname']     = $oData['nickname'];
+        $data['total_money']  = $oData['total_money'];
+        $data['all_money']    = $oData['all_money'];
+        $data['pay_money']    = $oData['pay_money'];
+        $data['postage']      = $oData['postage'];
+        $data['name']         = $oData['name'];
+        $data['tel']          = $oData['tel'];
+        $data['address']      = $oData['address'];
+        $data['coupon_money'] = $oData['coupon_money'];
+        $data['is_ip_buy']    = $oData['is_ip_buy'];
+        $data['status']       = $oData['status'];
+        $data['score']        = $oData['score'];
+        $data['give_score']   = $oData['give_score'];
+        $data['mono']         = $oData['mono'];
+        $data['express_num']  = $oData['express_num'];
+        $data['content']      = $oData['content'];
+        $data['time']         = date('Y-m-d H:i:s', $oData['time']);
+        $data['pay_time']     = empty($oData['pay_time'])?"-":date('Y-m-d H:i:s', $oData['pay_time']);
+        $data['fa_time']      = empty($oData['fa_time'])?"-":date('Y-m-d H:i:s', $oData['fa_time']);
+        $data['ok_time']      = empty($oData['ok_time'])?"-":date('Y-m-d H:i:s', $oData['ok_time']);
+        //订单详情
+        $info                 = (new OrderInfo)->where("o_id", $oData['id'])->select()->toArray();
+        $infoData             = [];
+        foreach ($info as $v) {
+            $d               = [];
+            $d['id']         = $v['id'];
+            $d['p_id']       = $v['p_id'];
+            $d['title']      = $v['title'];
+            $d['img']        = $v['img'];
+            $d['count']      = $v['count'];
+            $d['price']      = $v['price'];
+            $d['money']      = $v['money'];
+            $d['is_ip_buy']  = $v['is_ip_buy'];
+            $d['give_score'] = $v['give_score'];
+            $infoData[] = $d;
+        }
+        $data['info'] = $infoData;
+        return app('json')->success($data);
+    }
+    
+    /**
+     * 订单备注记录
+     * @param Request $request
+     * @return mixed
+     */
+    public function log(Request $request){
+        $pageSize = 20;
+        $post     = UtilService::getMore([
+            ['page', 1],
+            ['o_id', '','empty','参数错误']
+        ], $request);
+        $where=[];
+        $where['m.o_id'] = $post['o_id'];
+        $where['m.code'] = "shop";
+        $pageCount = (new OrderMono)->alias("m")->where($where)->count();
+        $data = (new OrderMono)
+                ->alias("m")
+                ->where($where)
+                ->order("id","desc")
+                ->page((int)$post["page"], $pageSize)
+                ->select()
+                ->toArray();
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 进行发货
+     * @global type $_A
+     * @param Request $request
+     */
+    public function fahuo(Request $request) {
+        $post = UtilService::getMore([
+            ['id','','empty','参数错误'],
+            ['express_num',''],
+            ['remark',''],
+        ],$request);
+        $oData = (new OrderModel)->where("id",$post["id"])->where("status",1)->find();
+        if (empty($oData)) {
+            return app('json')->fail('当前订单不可发货');
+        }
+        if($oData["type"]=='send' && empty($post["express_num"])){
+            return app('json')->fail('请输入物流单号');
+        }
+        $r = (new OrderModel)->where("id",$post["id"])->update([
+            "status"=>2,
+            "express_num"=>$post["express_num"],
+            "fa_time"=>time(),
+        ]);
+        if(!$r){
+            return app('json')->fail('操作失败');
+        }
+        $saveData=[];
+        
+        $saveData[]=[
+            "o_id"=>$oData["id"],
+            "order_id"=>$oData["order_id"],
+            "mono"=>$oData["type"]=='send'?"确定发货, 物流单号:" . $post["express_num"]:"门店确定清点完毕",
+            "time"=>time(),
+            "admin_id"=>$request->adminInfo['id'],
+            "admin_name"=>$request->adminInfo['name'],
+            "type"=>1,
+            "code"=>"shop",
+        ];
+        if(!empty($post["remark"])){
+            $saveData[]=[
+                "o_id"=>$oData["id"],
+                "order_id"=>$oData["order_id"],
+                "mono"=>$post["remark"],
+                "time"=>time(),
+                "admin_id"=>$request->adminInfo['id'],
+                "admin_name"=>$request->adminInfo['name'],
+                "type"=>1,
+                "code"=>"shop",
+            ];
+        }
+        (new OrderMono)->insertAll($saveData);
+        return app('json')->success('操作成功');
+    }
+    /**
+     * 订单备注提交
+     * @param Request $request
+     * @return mixed
+     */
+    public function mono(Request $request) {
+       $post = UtilService::getMore([
+            ['remark','','empty','请输入备注内容'],
+            ['id','','empty','参数错误']
+        ],$request);
+        $oData = (new OrderModel)->where("id",$post["id"])->find();
+        if (empty($oData)) {
+            return app('json')->fail('订单不存在');
+        }
+        (new OrderMono)->insert([
+            "o_id"=>$oData["id"],
+            "order_id"=>$oData["order_id"],
+            "mono"=>$post["remark"],
+            "time"=>time(),
+            "admin_id"=>$request->adminInfo['id'],
+            "admin_name"=>$request->adminInfo['name'],
+            "type"=>1,
+            "code"=>"shop",
+        ]);
+        return app('json')->success('处理成功');
+    }
+    
+    /**
+     * 获取活动订单数据
+     * @param Request $request
+     * @return mixed
+     * @throws DbException
+     */
+    public function activityList(Request $request)
+    {
+        $pageSize = 50;
+        $post = UtilService::getMore(
+            [
+                ['page', 1],
+                ['uid',0],
+                ['activity_id',''],
+                ['uip',''],
+                ['order_id', ''],
+                ['status',''],
+                ['mobile',''],
+                ['time',[]],
+            ], $request
+        );
+        $where = [];
+        if(!empty($post['uid'])){
+            $where[]=["o.uid","=",$post['uid']];
+        }else if(!empty($post['uip'])){
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=["o.uid","=",$m['uid']];
+            }
+        }else if(!empty($post['mobile'])){
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=["o.uid","=",$m['uid']];
+            }
+        }
+        if(!empty($post['activity_id'])){
+            $where[]=["o.activity_id","=",$post['activity_id']];
+        }
+        if(!empty($post['order_id'])){
+            $where[]=["o.order_id","=",$post['order_id']];
+        }
+        if(in_array((string)$post['status'],["0","1","-1"])){
+            $where[]=["o.status","=",(int)$post['status']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["o.time","between","{$startTime},{$endTime}"];
+        }
+        $order = new ActivityOrderModel;
+        $data  = $order
+                ->alias("o")
+                ->field("o.*,u1.mobile,u1.uip,u1.nickname,a.title as activity_title,a.imgs as activity_imgs")
+                ->leftJoin("user u1","u1.uid = o.uid")
+                ->leftJoin("activity a","a.id = o.activity_id")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("o.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = $order->alias("o")->where($where)->count();
+        $result = UtilService::getParam([
+            "id",
+            "order_id",
+            "uid",
+            "uip",
+            "mobile",
+            "nickname",
+            "total_money",
+            "all_money",
+            "pay_money",
+            "status",
+            "activity_id",
+            "activity_title",
+            "activity_imgs",
+            ['activity_imgs', 'activity_imgs', function ($item) {
+                return empty($item) ? [] : explode(",", $item);
+            }],
+            ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
+            ['pay_time', 'pay_time', function ($item) {
+                return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
+            }],
+            ['data', 'data', function ($item) {
+                $jsonData = empty($item)?[]: unserialize($item);
+                return $jsonData;
+            }],
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 搜索统计
+     */
+    public function activityTotal(Request $request)
+    {
+        $post = UtilService::getMore(
+            [
+                ['uid',0],
+                ['uip',''],
+                ['mobile',''],
+                ['order_id', ''],
+                ['status',''],
+                ['activity_id',''],
+                ['time',[]],
+            ], $request
+        );
+        $order       = new ActivityOrderModel;
+        $totalWhere = [];
+        if(!empty($post['uid'])){
+            $totalWhere[]=["uid","=",$post['uid']];
+        }else if(!empty($post['uip'])){
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $totalWhere[]=["uid","=",$m['uid']];
+            }
+        }else if(!empty($post['mobile'])){
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $totalWhere[]=["uid","=",$m['uid']];
+            }
+        }
+        if(!empty($post['activity_id'])){
+            $totalWhere[]=["activity_id","=",$post['activity_id']];
+        }
+        if(!empty($post['order_id'])){
+            $totalWhere[]=["order_id","=",$post['order_id']];
+        }
+        if(in_array((string)$post['status'],["0","1","-1"])){
+            $totalWhere[]=["status","=",$post['status']];
+        }
+        //创建时间
+        $startTime="";
+        $endTime="";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $totalWhere[]=["time","between","{$startTime},{$endTime}"];
+        }
+        foreach($totalWhere as $k=>$v){
+            if($v[0]=="status"){
+                array_splice($totalWhere,$k,1);
+            }
+        }
+        //全部
+        $orderCount = $order->where($totalWhere)->count();
+        //待支付
+        $waitPayWhere   = $totalWhere;
+        $waitPayWhere[] = ["status","=","0"];
+        $waitPayCount   = $order->where($waitPayWhere)->count();
+        //待发货
+        $waitSendWhere    = $totalWhere;
+        $waitSendWhere[]  = ["status","=",1];
+        $waitSendCount    = $order->where($waitSendWhere)->count();
+        //已取消
+        $closeWhere    = $totalWhere;
+        $closeWhere[]  = ["status","=",-1];
+        $closeCount    = $order->where($closeWhere)->count();
+        return app('json')->success([
+            'orderCount' => $orderCount,
+            'waitPayCount'=> $waitPayCount,
+            'waitSendCount' => $waitSendCount,
+            'closeCount' => $closeCount,
+        ]);
+    }
+
+    /**
+     * 活动订单详情
+     * @param Request $request
+     */
+    public function activityInfo(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', '', 'empty', '参数错误'],
+        ], $request, true);
+        $oData = (new ActivityOrderModel)
+                ->alias("o")
+                ->field("o.*,u1.mobile,u1.uip,u1.nickname,a.title as activity_title,a.imgs as activity_imgs")
+                ->leftJoin("user u1","u1.uid = o.uid")
+                ->leftJoin("activity a","a.id = o.activity_id")
+                ->where("o.id",$id)
+                ->find();
+        if (empty($oData)) {
+            return app('json')->fail('找不到订单号');
+        }
+        //主订单数据
+        $data                   = [];
+        $data['id']             = $oData['id'];
+        $data['order_id']       = $oData['order_id'];
+        $data['uid']            = $oData['uid'];
+        $data['mobile']         = $oData['mobile'];
+        $data['nickname']       = $oData['nickname'];
+        $data['total_money']    = $oData['total_money'];
+        $data['all_money']      = $oData['all_money'];
+        $data['pay_money']      = $oData['pay_money'];
+        $data['status']         = $oData['status'];
+        $data['activity_id']    = $oData['activity_id'];
+        $data['activity_title'] = $oData['activity_title'];
+        $data['activity_imgs']  = empty($oData['activity_imgs'])?[]: explode(",", $oData['activity_imgs']);
+        $data['status']         = $oData['status'];
+        $data['time']           = date('Y-m-d H:i:s', $oData['time']);
+        $data['pay_time']       = empty($oData['pay_time'])?"-":date('Y-m-d H:i:s', $oData['pay_time']);
+        //订单详情
+        $data['info']         = empty($oData["data"]) ? [] : unserialize($oData["data"]);
+        return app('json')->success($data);
+    }
+    
+    /**
+     * 活动订单备注记录
+     * @param Request $request
+     * @return mixed
+     */
+    public function activityLog(Request $request){
+        $pageSize = 20;
+        $post     = UtilService::getMore([
+            ['page', 1],
+            ['o_id', '','empty','参数错误']
+        ], $request);
+        $where=[];
+        $where['m.o_id'] = $post['o_id'];
+        $where['m.code'] = "activity";
+        $pageCount = (new OrderMono)->alias("m")->where($where)->count();
+        $data = (new OrderMono)
+                ->alias("m")
+                ->where($where)
+                ->order("id","desc")
+                ->page((int)$post["page"], $pageSize)
+                ->select()
+                ->toArray();
+        $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+        }
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 报名订单备注提交
+     * @param Request $request
+     * @return mixed
+     */
+    public function activityMono(Request $request) {
+       $post = UtilService::getMore([
+            ['remark','','empty','请输入备注内容'],
+            ['id','','empty','参数错误']
+        ],$request);
+        $oData = (new ActivityOrderModel)->where("id",$post["id"])->find();
+        if (empty($oData)) {
+            return app('json')->fail('订单不存在');
+        }
+        (new OrderMono)->insert([
+            "o_id"=>$oData["id"],
+            "order_id"=>$oData["order_id"],
+            "mono"=>$post["remark"],
+            "time"=>time(),
+            "admin_id"=>$request->adminInfo['id'],
+            "admin_name"=>$request->adminInfo['name'],
+            "type"=>1,
+            "code"=>"activity",
+        ]);
+        return app('json')->success('处理成功');
+    }
+}

+ 53 - 0
app/system/controller/v1/Pub.php

@@ -0,0 +1,53 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\Request;
+use app\system\controller\AuthController;
+use library\services\UtilService;
+use library\utils\Region;
+use think\Cache;
+
+class Pub extends  AuthController
+{
+
+    /**
+     * 获取位置信息
+     */
+    public function getArea(){
+        $tAr = [];
+        $region = new Region;
+        $data = $region->getLevel(1);
+        foreach ($data as $v) {
+            $d['label'] = $v['Name'];
+            $d['value'] = $v['ID'];
+            $d['children'] = [];
+            $data2 = $region->getChild($v['ID']);
+            foreach ($data2 as $v2) {
+                $d2['label'] = $v2['Name'];
+                $d2['value'] = $v2['ID'];
+                $d2['children'] = [];
+                $data3 = $region->getChild($v2['ID']);
+                foreach ($data3 as $v3) {
+                    $d3['label'] = $v3['Name'];
+                    $d3['value'] = $v3['ID'];
+                    $d2['children'][] = $d3;
+                }
+                $d['children'][] = $d2;
+            }
+            $tAr[] = $d;
+        }
+        return app('json')->success($tAr);
+    }
+}

+ 121 - 0
app/system/controller/v1/Role.php

@@ -0,0 +1,121 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 权限管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\model\system\AdminRole;
+use app\model\system\RolePath;
+use app\Request;
+use library\services\UtilService;
+
+class Role extends BaseController
+{
+
+    /**
+     * 列表数据
+     * @return mixed
+     */
+    public function list()
+    {
+        $listAr = (new AdminRole)->getRoleData();
+        $result = [];
+        foreach ($listAr as $v) {
+            $d              = [];
+            $d['name']      = $v['name'];
+            $d['status']    = $v['status'];
+            $d['is_system'] = $v['is_system'];
+            $d['id']        = $v['id'];
+            $result[]       = $d;
+        }
+        return app('json')->success($result);
+    }
+
+    /**
+     * 保存角色数据
+     * @param Request $request
+     * @return mixed
+     */
+    public function save(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['id', '0'],
+            ['name', '', 'empty', '请输入角色名'],
+            ['status', 0],
+        ], $request);
+        $bool = (new AdminRole)->saveRole($post);
+        return $bool ? app('json')->success("操作成功", []) : app('json')->fail(AdminRole::getErrorInfo());
+    }
+
+    /**
+     * 删除数据
+     * @param Request $request
+     * @return mixed
+     */
+    public function del(Request $request)
+    {
+        [$id] = UtilService::getMore(
+            [
+                ['id', '0'],
+            ],
+            $request, true
+        );
+        if(in_array(strval($id),["1","53","54","55"])){
+            return app("json")->fail("当前角色不能删除");
+        }
+        AdminRole::del($id);
+        return app('json')->success("删除成功", []);
+    }
+
+
+    /**
+     * 配置管理
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function setingList()
+    {
+        $post          = UtilService::getMore([
+            ['id', '0'],
+        ]);
+        $rolePath = new RolePath;
+        $rolePath->getAll();
+        $listAr        = $rolePath->getRoleData();
+        $rData         = AdminRole::where('id', $post['id'])->find();
+        $rAr           = [];
+        $rAr['data']   = $listAr;
+        $rAr['seting'] = empty($rData) ? [] : json_decode($rData['module'], true);
+        return app('json')->success($rAr);
+    }
+
+
+    /**
+     * 保存配置
+     * @param Request $request
+     * @return mixed
+     */
+    public function setingSave(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['id', '0'],
+            ['data', '', 'empty', '请输入参数'],
+        ]);
+        $iAr  = [];
+        foreach ($post['data'] as $k => $v) {
+            if (!empty($v)) $iAr[$k] = true;
+        }
+        AdminRole::where('id', $post['id'])->save(['module' => json_encode($iAr)]);
+        return app('json')->success("保存数据成功", []);
+    }
+}

+ 104 - 0
app/system/controller/v1/RolePath.php

@@ -0,0 +1,104 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\model\system\AdminRole;
+use app\model\system\RolePath as RolePathModel;
+use app\Request;
+use library\services\UtilService;
+
+class RolePath extends BaseController
+{
+
+    /**
+     * 基本设置
+     */
+    public function list()
+    {
+        $menuMenu = new RolePathModel();
+        $menus    = $menuMenu->getArMenu();
+        return app('json')->success($menus);
+    }
+
+    /**
+     * 获取树级分类
+     */
+    public function treeList()
+    {
+        $menuAr = (new RolePathModel())->order("seq", "desc")->select()->toArray();
+        $data   = sort_list_tier($menuAr, '顶级', 'pid', 'id');
+        return app('json')->success($data);
+    }
+
+    /**
+     * 获取详情栏目数据
+     */
+    public function info(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', 0, 'empty', '参数错误'],
+        ], $request, true);
+        $data = (new RolePathModel())->find(compact('id'))->toArray();
+        return app('json')->success($data);
+    }
+
+    /**
+     * 保存数据
+     */
+    public function save(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['id',''],
+            ['title', ''],
+            ['pid', '0'],
+            ['seq', '0'],
+            ['role_path', ''],
+            ['menu_id', ''],
+            ['is_show', '0']
+        ], $request);
+        (new RolePathModel())->saveModel($post);
+        return app('json')->success("数据保存成功");
+    }
+
+    /**
+     * 栏目删除
+     * @param Request $request
+     * @return mixed
+     */
+    public function del(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', 0, 'empty', '参数错误'],
+        ], $request, true);
+        $bool = (new RolePathModel())->delMenu($id);
+        return app('json')->success("栏目删除成功");
+    }
+
+    /**
+     * 系统分类显示 | 关闭
+     */
+    public function status(Request $request)
+    {
+        [$id, $is_show] = UtilService::getMore([
+            ['id', '0', 'empty', '参数错误'],
+            ['is_show', '0'],
+        ], $request, true);
+        $bool = (new RolePathModel())->setStatus($id, $is_show);
+        if ($bool) {
+            return app('json')->success('操作成功');
+        } else {
+            return app('json')->fail('提交失败');
+        }
+    }
+}

+ 103 - 0
app/system/controller/v1/ShowTemplate.php

@@ -0,0 +1,103 @@
+<?php
+declare (strict_types = 1);
+namespace app\system\controller;
+
+use app\BaseController;
+use app\model\api\ShowTemplate;
+use app\Request;
+use library\services\UtilService;
+
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 皮肤模板管理 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-09-06 21:53
+// +----------------------------------------------------------------------
+
+class ShowTemplate extends  BaseController{
+    /**
+     * 商品列表
+     * @param Request $request
+     * @return type
+     */
+    public function list(Request $request) {
+        $post = UtilService::getMore([
+            ['is_hot', '0'],
+            ['is_recommend', '0'],
+            ['page', 1],
+            ['pageSize', 50],
+        ], $request);
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
+        $where=[];
+        $where[]=["status","=",1];
+        if((int)$post["is_hot"]==1){
+            $where[]=["is_hot","=",1];
+        }
+        if((int)$post["is_recommend"]==1){
+            $where[]=["is_recommend","=",1];
+        }
+        
+        $totalCount = (new ShowTemplate)->where($where)->count();
+        $data=null;
+        if($totalCount>0){
+            $data = (new ShowTemplate)
+                ->field("*")
+                ->where($where)
+                ->order("id", "desc")
+                ->page((int)$page, $post["pageSize"])
+                ->select();
+            foreach($data as $k=>$v){
+                $data[$k]["is_use"] = 0;//是否已经购买或者可以使用
+                $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+    }
+
+    
+    /**
+     * 添加编辑商品
+     * @param Request $request
+     * @return type
+     */
+    public function add(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['title','','empty','请填写模板标题'],
+            ['price','0','is_numeric','请输入正确的模板售价'],
+            ['old_price','0','is_numeric','请输入正确的模板原价'],
+            ['img','','empty','请上传模板展示图'],
+            ['is_hot','0'],
+            ['is_recommend','0'],
+            ['status','0'],
+        ],$request);
+        $save=[];
+        $save["title"]        = $post["title"];
+        $save["price"]        = floatval($post["price"]);
+        $save["old_price"]    = floatval($post["old_price"]);
+        $save["status"]       = (int)$post["status"]==1?1:0;
+        $save["img"]          = empty($post["img"]) ? "" : $post["img"];
+        $save["is_hot"]       = (int)$post["is_hot"]==1?1:0;
+        $save["is_recommend"] = (int)$post["is_ip"]==1?1:0;
+        $save["admin_time"]   = time();
+        $save["admin_id"]     = $request->adminInfo['id'];
+        $id = $post["id"];
+        $r=0;
+        if(empty($id) || $id=="0"){
+            $save["time"] = time();
+            $r = (new ShowTemplate)->insert($post);
+        }else{
+            $r = (new ShowTemplate)->where("id",$id)->update($save);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+}

+ 149 - 0
app/system/controller/v1/Sys.php

@@ -0,0 +1,149 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | [ 系统配置 ]
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\Request;
+use library\services\UtilService;
+use app\model\api\Sys as SysModel;
+use app\model\api\Bank as BankModel;
+
+
+class Sys extends BaseController
+{
+
+    /**
+     * 基本设置
+     */
+    public function index(){
+        $sys = (new SysModel)->where("id", 1)->find();
+        return app('json')->success($sys->toArray());
+    }
+    /**
+     * 编辑用户条款
+     * @param Request $request
+     */
+    public function agreeSave(Request $request){
+        $post = UtilService::getMore([
+            ['user_agreement', '','empty','请输入用户协议'],
+            ['privacy_policy', '','empty','请输入用户隐私声明'],
+        ], $request);
+        (new SysModel())->saveSys($post);
+        return app('json')->success("数据保存成功");
+    }
+    /**
+     * 保存数据
+     */
+    public function save(Request $request){
+        $post = UtilService::getMore([
+            ['title', ''],
+            ['system_url', ''],
+            ['tag', ''],
+            ['custom_tel', ''],
+            ['ip_income_per',0,'empty','IP商品收益百分比大于0'],
+            ['tree_income_per',0],
+            ['tree_income_per_two',0],
+            ['money_to_score_per',0,'empty','消费转积分百分比大于0'],
+            ['tx_limit_money',0],
+            ['tx_process_per',0],
+            ['tx_process_max',0],
+        ], $request);
+        $post["tx_limit_money"] = (int)$post["tx_limit_money"];
+        $post["tx_process_per"] = (int)$post["tx_process_per"];
+        $post["tx_process_max"] = (int)$post["tx_process_max"];
+        if(!empty($post["custom_tel"])){
+            $post["custom_tel"] = str_replace(",", ",", $post["custom_tel"]);
+        }
+        
+        (new SysModel())->saveSys($post);
+        return app('json')->success("数据保存成功");
+    }
+    
+    /**
+     * 提现方式列表
+     * @param Request $request
+     * @return type
+     */
+    public function bankList(Request $request) {
+        $pageSize = 50;
+        $post =  UtilService::getMore([
+            ['page',1],
+            ['status',''],
+        ],$request);
+        $where=[];
+        if((string)$post["status"]!=""){
+            $where[]=["status","=",(int)$post["status"] == 1 ? 1 : 0];
+        }
+        $data = (new BankModel)
+                ->where($where)
+                ->page((int)$post["page"], (int)$pageSize)
+                ->order("seq","desc")
+                ->order("id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new BankModel)->where($where)->count();
+        $data = empty($data)?[]:$data;
+        return app('json')->success([
+            'list'      => $data,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post["page"]
+        ]);
+    }
+    /**
+     * 添加编辑提现方式
+     * @param Request $request
+     */
+    public function bankSave(Request $request){
+        $post = UtilService::getMore([
+            ['id','0'],
+            ['name','','empty','请填写银行名称'],
+            ['code','','empty','请填写银行编码'],
+            ['seq','0'],
+            ['status','0']
+        ],$request);
+        $id = (int)$post["id"];
+        unset($post["id"]);
+        $post["seq"] = intval($post["seq"]);
+        $post["status"] = intval($post["status"])==1?1:0;
+        $r=0;
+        $count = (new BankModel)->where("id","<>",$id)->where("code",$post["code"])->count();
+        if($count>0){
+            return app('json')->fail("银行编码不能重复");
+        }
+        
+        if(empty($id)){
+            $r = (new BankModel)->insert($post);
+        }else{
+            $r = (new BankModel)->where("id",$id)->update($post);
+        }
+        if($r){
+            return app('json')->success("数据保存成功");
+        }else{
+            return app('json')->fail("数据保存失败");
+        }
+    }
+    /**
+     * 删除提现方式
+     * @param Request $request
+     */
+    public function bankDel(Request $request) {
+        [$id] = UtilService::getMore([
+            ['id',0,'empty','参数错误']
+        ],$request,true);
+        $bool =   (new BankModel)->where("id",$id)->delete();
+        return app('json')->success("删除成功");
+    }
+    
+
+}

+ 107 - 0
app/system/controller/v1/SysMenu.php

@@ -0,0 +1,107 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// | 
+// +----------------------------------------------------------------------
+// | Date: 2020-08-31 20:43
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\model\system\AdminMenu;
+use app\Request;
+use library\services\UtilService;
+use library\utils\Dtree;
+
+class SysMenu extends BaseController
+{
+
+    /**
+     * 基本设置
+     */
+    public function list()
+    {
+        $menuMenu = new AdminMenu();
+        $menus    = $menuMenu->getArMenu();
+        return app('json')->success($menus);
+    }
+
+    /**
+     * 系统分类显示 | 关闭
+     */
+    public function status(Request $request)
+    {
+        [$id, $is_show] = UtilService::getMore([
+            ['id', '0', 'empty', '参数错误'],
+            ['is_show', '0'],
+        ], $request, true);
+        $bool = (new AdminMenu())->setStatus($id, $is_show);
+        if ($bool) {
+            return app('json')->success('操作成功');
+        } else {
+            return app('json')->fail('提交失败');
+        }
+    }
+
+
+    /**
+     * 获取树级分类
+     */
+    public function treeList()
+    {
+        $menuAr = (new AdminMenu())->order("seq", "desc")->select()->toArray();
+        $data   = sort_list_tier($menuAr, '顶级', 'pid', 'id');
+        return app('json')->success($data);
+    }
+
+    /**
+     * 获取详情栏目数据
+     */
+    public function info(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', 0, 'empty', '参数错误'],
+        ], $request, true);
+        $data = (new AdminMenu())->field("title,id,icon,path,is_show,pid,code,seq")->find(compact('id'))->toArray();
+        return app('json')->success($data);
+    }
+
+    /**
+     * 保存数据
+     */
+    public function save(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['title', ''],
+            ['pid', '0'],
+            ['seq', '0'],
+            ['path', ''],
+            ['icon', ''],
+            ['is_show', '0'],
+            ['code', ''],
+            ['id', '0'],
+        ], $request);
+        (new AdminMenu())->saveMenu($post);
+        return app('json')->success("数据保存成功");
+    }
+
+    /**
+     * 栏目删除
+     * @param Request $request
+     * @return mixed
+     */
+    public function del(Request $request)
+    {
+        [$id] = UtilService::getMore([
+            ['id', 0, 'empty', '参数错误'],
+        ], $request, true);
+        $bool = (new AdminMenu())->delMenu($id);
+        return app('json')->success("栏目删除成功");
+    }
+
+}

+ 311 - 0
app/system/controller/v1/Tx.php

@@ -0,0 +1,311 @@
+<?php
+// +----------------------------------------------------------------------
+// | [ WE CAN DO IT MORE SIMPLE  ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2018-2020 rights reserved.
+// +----------------------------------------------------------------------
+// |
+// +----------------------------------------------------------------------
+// | Date: 2020-11-08 12:56
+// +----------------------------------------------------------------------
+
+namespace app\system\controller\v1;
+
+
+use app\BaseController;
+use app\model\api\Tx as TxModel;
+use app\model\api\User as UserModel;
+use app\model\api\Sys as SysModel;
+use app\model\api\Bank as BankModel;
+use app\model\api\UserDetail as UserDetailModel;
+use app\model\api\TuserDetail as TuserDetailModel;
+use think\db\exception\DbException;
+use think\facade\Db;
+use app\Request;
+use library\services\UtilService;
+
+class Tx extends BaseController
+{
+    /**
+     * 初始化
+     * @param Request $request
+     * @return type
+     */
+    public function init(Request $request)
+    {
+        [$isTuser] = UtilService::getMore(
+            [
+                ['isTuser',0],
+            ], $request,true);
+        $isTuser = empty($isTuser) ? 0 : 1;
+        $where=[];
+        //获取全部提现
+        $allTx = (new TxModel)->where($where)->count();
+        $noTx  = (new TxModel)->where($where)->where('status', 0)->count();
+        $yeTx  = (new TxModel)->where($where)->where('status', 1)->count();
+        $errTx = (new TxModel)->where($where)->where('status', -1)->count();
+        
+        $bankList = (new BankModel)
+//                ->where("status",1)
+                ->order("seq","desc")
+                ->order("id","desc")
+                ->select()
+                ->toArray();
+        $bankList = empty($bankList)?[]:$bankList;
+        
+        
+        return app('json')->success([
+            'all_tx' => $allTx,
+            'no_tx'  => $noTx,
+            'yes_tx' => $yeTx,
+            'err_tx' => $errTx,
+            'bankList'=>$bankList,
+        ]);
+    }
+
+    /**
+     * 获取提现列表
+     * @param Request $request
+     */
+    public function list(Request $request)
+    {
+        $pageSize = 50;
+        $post     = UtilService::getMore(
+            [
+                //公共参数
+                ['page', 1],
+                ['status', ''],
+                ['bank_type', ''],
+                ['time',[]],
+                //手机用户
+                ['mobile',''],
+                ['uip', ''],
+                ['uid', ''],
+            ], $request
+        );
+        $where=[];
+        //公共参数
+        if(is_numeric($post['status'])) {
+            $where[]=['t.status',"=",$post['status']];
+        }
+        if(!empty($post['bank_type'])) {
+            $where[]=['t.bank_type',"=",$post['bank_type']];
+        }
+        //提现时间
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime =  strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=['t.time',"between","{$startTime},{$endTime}"];
+        }
+        //用户uid
+        if(is_numeric($post['uid'])) {
+            $where[]=['t.uid',"=",$post['uid']];
+        }else if (!empty($post['uip'])) {
+            $m  = Db::name("user")->where("uip",$post['uip'])->find();
+            if(!empty($m)) {
+                $where[]=['t.uid',"=",$m['uid']];
+            }
+        }else if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where[]=['t.uid',"=",$m['uid']];
+            }
+        }
+        $data = (new TxModel)
+                ->alias("t")
+                ->field("t.*,u.uip,u.nickname,u.mobile,a.username as admin_name,b.name as bank_type_name")
+                ->leftJoin("user u", "u.uid = t.uid")
+                ->leftJoin("admin a", "a.id = t.admin_id")
+                ->leftJoin("bank b", "b.code = t.bank_type")
+                ->where($where)
+                ->page((int)$post["page"], $pageSize)
+                ->order("t.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new TxModel)->alias("t")->where($where)->count();
+        $result = UtilService::getParam([
+            "id",
+            "uid",
+            "bank_type",
+            "bank_type_name",
+            "bank_num",
+            "bank_name",
+            "bank_ad",
+            "money",
+            "tx_money",
+            "hand_money",
+            "status",
+            ["time", "time", "date('Y-m-d H:i:s',$1)"],
+            "admin_id",
+            "admin_remark",
+            ["admin_time", "admin_time", function ($item) {
+                return empty($item) ? '' : date('Y-m-d H:i:s', $item);
+            }],
+            "admin_name",
+            "mobile",
+            "nickname",
+            "uip",
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    /**
+     * 提现处理
+     * @param Request $request
+     */
+    public function dealSub(Request $request)
+    {
+        $post   = UtilService::getMore(
+            [
+                ['id', '', 'empty', '参数错误'],
+                ['mono'],
+                ['type', 0],
+            ], $request);
+        $txData = (new TxModel)->where('id', $post['id'])->find();
+        if (empty($txData)) {
+            return app('json')->fail('数据不存在');
+        }
+        if ($txData['status']!=0) {
+            return app('json')->success( '当前提现申请已处理');
+        }
+        //提现通过
+        if ($post['type'] == 1) {
+            (new TxModel)
+                ->where('id', $post['id'])
+                ->save([
+                    'status'        => 1,
+                    'admin_remark' => empty($post['mono'])?"已确认打款":$post['mono'],
+                    'admin_time'    => time(),
+                    'admin_id'     => $request->adminInfo['id'],
+                ]);
+            return app('json')->success('操作成功');
+        }
+        //提现驳回
+        if ($post['type'] == -1) {
+            //添加事件回滚
+            try{
+                Db::startTrans();
+                (new TxModel)
+                    ->where('id', $post['id'])
+                    ->save([
+                        'status'        => -1,
+                        'admin_remark' => empty($post['mono'])?"已驳回申请":$post['mono'],
+                        'admin_time'    => time(),
+                        'admin_id'     => $request->adminInfo['id'],
+                    ]);
+                if($txData["uid"]>0){
+                    //用户提现驳回
+                    (new UserDetailModel)->txRefundMoney($txData['uid'],$txData["money"],$txData["id"]);
+                }else{
+                    return app("json")->fail("提现用户不存在");
+                }
+                Db::commit();
+                return app('json')->success('操作成功');
+            }catch(DbException $db){
+                Db::rollback();
+                return app("json")->fail("操作失败");
+            }
+        }
+    }
+    /**
+     * 获取订单数据
+     * @param Request $request
+     */
+    public function down(Request $request)
+    {
+        $pageSize = 40000;
+        $post     = UtilService::getMore(
+            [
+                ['page', 1],
+                ['mobile',''],
+                ['status', ''],
+                ['bank_type', ''],
+                ['uid', ''],
+                ['time',[]],
+            ], $request
+        );
+        $where    = [];
+        $where=[];
+
+        if(is_numeric($post['status'])) {
+            $where['t.status'] = $post['status'];
+        }
+        if(is_numeric($post['uid'])) {
+            $where['t.uid'] = $post['uid'];
+        }
+
+        if (!empty($post['mobile'])) {
+            $m  = Db::name("user")->where("mobile",$post['mobile'])->find();
+            if(!empty($m)) {
+                $where['t.uid'] = $m['uid'];
+            }
+        }
+        
+        if(!empty($post['bank_type'])) {
+            $where['t.bank_type'] = $post['bank_type'];
+        }
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+           $startTime =  strtotime($post['time'][0]);
+           $endTime = strtotime($post['time'][1]);
+        }
+        $data = (new TxModel)
+                ->alias("t")
+                ->field("t.*,u.uip,u.nickname,u.mobile,a.username as admin_name")
+                ->leftJoin("user u", "u.uid = t.uid")
+                ->leftJoin("admin a", "a.id = t.admin_id")
+                ->where($where)
+                ->when((!empty($startTime) && !empty($endTime)),function($query)use($startTime,$endTime){
+                    $query->whereBetween("t.time","{$startTime},{$endTime}");
+                })
+                ->limit(0,30000)
+                ->order("t.id","desc")
+                ->select()
+                ->toArray();
+        $pageCount = (new TxModel)
+                ->alias("t")
+                ->leftJoin("user u", "u.uid = t.uid")
+                ->leftJoin("admin a", "a.id = t.admin_id")
+                ->where($where)
+                ->when((!empty($startTime) && !empty($endTime)),function($query)use($startTime,$endTime){
+                    $query->whereBetween("t.time","{$startTime},{$endTime}");
+                })
+                ->count();
+        $result = UtilService::getParam([
+            "id",
+            "uid",
+            "bank_type",
+            "bank_num",
+            "bank_name",
+            "bank_ad",
+            "money",
+            "tx_money",
+            "hand_money",
+            "status",
+            ["time", "time", "date('Y-m-d H:i:s',$1)"],
+            "admin_id",
+            "admin_remark",
+            ["admin_time", "admin_time", function ($item) {
+                return empty($item) ? '' : date('Y-m-d H:i:s', $item);
+            }],
+            "admin_name",
+            "mobile",
+            "nickname",
+            "uip",
+        ], $data);
+        return app('json')->success([
+            'list'      => $result,
+            'pageCount' => $pageCount,
+            'pageSize'  => $pageSize,
+            'page'      => $post['page'],
+        ]);
+    }
+    
+}

Some files were not shown because too many files changed in this diff