王大坤 před 2 roky
rodič
revize
38036665fe
100 změnil soubory, kde provedl 9440 přidání a 0 odebrání
  1. binární
      .DS_Store
  2. binární
      app/.DS_Store
  3. 13 0
      app/controller/Index.php
  4. 91 0
      app/controller/admin/Banner.php
  5. 272 0
      app/controller/admin/Commission.php
  6. 256 0
      app/controller/admin/Common.php
  7. 171 0
      app/controller/admin/Conf.php
  8. 1 0
      app/controller/admin/Console.php
  9. 144 0
      app/controller/admin/Files.php
  10. 163 0
      app/controller/admin/Gallery.php
  11. 122 0
      app/controller/admin/Hot.php
  12. 98 0
      app/controller/admin/Kami.php
  13. 165 0
      app/controller/admin/Member.php
  14. 282 0
      app/controller/admin/Menu.php
  15. 133 0
      app/controller/admin/Mode.php
  16. 254 0
      app/controller/admin/Models.php
  17. 65 0
      app/controller/admin/Order.php
  18. 131 0
      app/controller/admin/Plugins.php
  19. 48 0
      app/controller/admin/Question.php
  20. 177 0
      app/controller/admin/Role.php
  21. 73 0
      app/controller/admin/Sk.php
  22. 224 0
      app/controller/admin/Template.php
  23. 191 0
      app/controller/admin/User.php
  24. 65 0
      app/controller/admin/Vipinfo.php
  25. 258 0
      app/controller/admin/Words.php
  26. 70 0
      app/controller/admin/action/Log.php
  27. 341 0
      app/controller/admin/admin/User.php
  28. 38 0
      app/controller/admin/api/Log.php
  29. 112 0
      app/controller/admin/files/Category.php
  30. 80 0
      app/controller/admin/login/Log.php
  31. 129 0
      app/controller/admin/system/UploadMiniapp.php
  32. 1021 0
      app/controller/api/Ai.php
  33. 252 0
      app/controller/api/Commission.php
  34. 270 0
      app/controller/api/Common.php
  35. 161 0
      app/controller/api/Conf.php
  36. 1 0
      app/controller/api/Gallery.php
  37. 295 0
      app/controller/api/Member.php
  38. 155 0
      app/controller/api/Order.php
  39. 559 0
      app/controller/api/Pay.php
  40. 134 0
      app/controller/api/Question.php
  41. 51 0
      app/controller/api/Template.php
  42. 82 0
      app/controller/api/Token.php
  43. 348 0
      app/controller/api/User.php
  44. 237 0
      app/controller/api/Wechat.php
  45. 1 0
      app/controller/api/complete.json
  46. 1 0
      app/controller/api/ds.json
  47. 1 0
      app/controller/api/ds2.json
  48. 1 0
      app/controller/api/ds3.json
  49. 1 0
      app/controller/api/mjNotify.json
  50. 1 0
      app/controller/api/notify.json
  51. 1 0
      app/controller/api/notifyHupijiao.json
  52. 1 0
      app/controller/api/replace.json
  53. 1 0
      app/controller/api/uploadImageInfo.json
  54. 1 0
      app/controller/api/vipinfo.json
  55. 88 0
      app/exception/Http.php
  56. 1 0
      app/exception/laytp.tpl
  57. 11 0
      app/middleware.php
  58. 33 0
      app/middleware/AllowCrossDomain.php
  59. 72 0
      app/middleware/admin/ActionLog.php
  60. 136 0
      app/middleware/admin/Auth.php
  61. 36 0
      app/middleware/api/Auth.php
  62. 61 0
      app/middleware/api/CheckSign.php
  63. 28 0
      app/model/Banner.php
  64. 31 0
      app/model/Bill.php
  65. 13 0
      app/model/Conf.php
  66. 57 0
      app/model/Files.php
  67. 57 0
      app/model/Gallery.php
  68. 30 0
      app/model/Hot.php
  69. 33 0
      app/model/Kami.php
  70. 25 0
      app/model/Member.php
  71. 13 0
      app/model/Migrations.php
  72. 39 0
      app/model/Mode.php
  73. 39 0
      app/model/Models.php
  74. 38 0
      app/model/Order.php
  75. 33 0
      app/model/Question.php
  76. 30 0
      app/model/Sk.php
  77. 36 0
      app/model/Template.php
  78. 82 0
      app/model/User.php
  79. 38 0
      app/model/Vipinfo.php
  80. 30 0
      app/model/Words.php
  81. 16 0
      app/model/admin/Menu.php
  82. 16 0
      app/model/admin/Role.php
  83. 52 0
      app/model/admin/User.php
  84. 34 0
      app/model/admin/action/Log.php
  85. 34 0
      app/model/admin/login/Log.php
  86. 13 0
      app/model/admin/menu/Role.php
  87. 14 0
      app/model/admin/role/User.php
  88. 32 0
      app/model/api/Log.php
  89. 36 0
      app/model/commission/Cashout.php
  90. 36 0
      app/model/commission/Income.php
  91. 33 0
      app/model/commission/Log.php
  92. 33 0
      app/model/commission/Order.php
  93. 35 0
      app/model/commission/Settle.php
  94. 42 0
      app/model/commission/Team.php
  95. 58 0
      app/model/commission/User.php
  96. 43 0
      app/model/files/Category.php
  97. 44 0
      app/model/plugin/ali/Sms.php
  98. 7 0
      app/provider.php
  99. 28 0
      app/resource/admin/User.php
  100. 1 0
      app/service/Bill.php

binární
.DS_Store


binární
app/.DS_Store


+ 13 - 0
app/controller/Index.php

xqd
@@ -0,0 +1,13 @@
+<?php
+
+namespace app\controller;
+
+use laytp\BaseController;
+
+class Index extends BaseController
+{
+    public function index()
+    {
+        return redirect("/admin/index.html");
+    }
+}

+ 91 - 0
app/controller/admin/Banner.php

xqd
@@ -0,0 +1,91 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+
+/**
+ * 幻灯轮播
+ */
+class Banner extends Backend
+{
+
+    /**
+     * slider模型对象
+     * @var \app\model\Banner
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Banner();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $order = ['sort'=>'desc','id' => 'desc'];
+        $data   = $this->model->where($where)->order($order)->with(['img_file']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->with(['img_file'])->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+
+
+
+
+    //设置排序
+    public function setSort()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 272 - 0
app/controller/admin/Commission.php

xqd
@@ -0,0 +1,272 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\api\UserServiceFacade;
+use app\service\api\PayServiceFacade;
+use app\validate\admin\notice\Add;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+use app\service\ConfServiceFacade;
+use think\facade\Db;
+use think\facade\Config;
+
+/**
+ * 会员管理
+ */
+class Commission extends Backend
+{
+    protected $model;//当前模型对象
+    protected $noNeedLogin = [];
+    protected $noNeedAuth = [];
+
+    protected function _initialize()
+    {
+        $this->modelUser = new \app\model\commission\User();
+    }
+
+    //查看
+    public function index()
+    {
+        $where = $this->buildSearchParams();
+        // $order = ['uid'=>'DESC'];
+        $order = ['create_time' => 'desc'];
+        $data = $this->modelUser->order($order)->where($where)->with(['userinfo','pid_userinfo.pidUserinfo'])->withCount(['commission1','commission2','commission3'])->withSum('income','money');
+        $allData = $this->request->param('all_data');
+        if ($allData) {
+            $data = $data->select();
+        } else {
+            $limit = $this->request->param('limit', 10);
+            $data = $data->paginate($limit)->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //查看和搜索列表
+    public function settle(){
+        global $_W;
+        $modelSettle = new \app\model\commission\Settle();
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $where[] = ['paid','=',1];
+        $order  = $this->buildOrder();
+        $data   = $modelSettle->where($where)->order($order)->with(['userInfo']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //查看
+    public function income()
+    {
+        $modelIncome = new \app\model\commission\Income();
+        $where = $this->buildSearchParams();
+        $order = ['id'=>'DESC'];
+        $data = $modelIncome->where($where)->order($order)->with(['userinfo','buyUserinfo']);
+        $allData = $this->request->param('all_data');
+        if ($allData) {
+            $data = $data->select();
+        } else {
+            $limit = $this->request->param('limit', 10);
+            $data = $data->paginate($limit)->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //查看
+    public function cashout()
+    {
+        $modelCashout = new \app\model\commission\Cashout();
+        $where = $this->buildSearchParams();
+        // print_r($where);
+        $order = ['id'=>'DESC'];
+        $data = $modelCashout->where($where)->order($order)->with(['userinfo','commission_userinfo.img_file']);
+        $allData = $this->request->param('all_data');
+        if ($allData) {
+            $data = $data->select();
+        } else {
+            $limit = $this->request->param('limit', 10);
+            $data = $data->paginate($limit)->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //提现详情
+    public function cashoutInfo()
+    {
+        $id   = $this->request->param('id');
+        $info = \app\model\commission\Cashout::with(['commission_userinfo.img_file'])->find($id)->toArray();
+        return $this->success('获取成功', $info);
+    }
+
+    // 提现设置状态
+    public function cashoutSetStatus()
+    {
+        $model = new \app\model\commission\Cashout();
+        // $app  = PayServiceFacade::option();
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('status');
+        $failMsg = $this->request->post('fail_msg','');
+        $isRecycle = $this->request->post('is_recycle');
+        $mode = $this->request->post('mode');
+        $update['status'] = $fieldVal;
+        $update['fail_msg'] = $failMsg;
+        $info = $model::find($id);
+        // print_r($info);
+        $userInfo = \app\model\User::find($info['uid']);
+        if(!$userInfo){
+            return $this->error('未查询到此用户注册信息');
+        }
+        if($fieldVal == 1){
+            if(!$mode){
+                return $this->error('请选择付款方式');
+            }
+            if($mode == 2){
+                $pay = ConfServiceFacade::groupGet('system.pay', true);
+                if(!$pay['cert_filename'] || !$pay['key_filename']){
+                    return $this->error('未上传证书');
+                }
+                $openid = $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'];
+                // if(!$openid){
+                //     return $this->error('此用户不是从微信登录,无法使用在线打款');
+                // }
+                // var_dump($openid);
+                $nMoney = number_format($info['extract_price'])*100;
+                $result          = PayServiceFacade::transfer_batches($openid, $nMoney);
+                // print_r($result);
+                // $app  = PayServiceFacade::option($info['extract_type']);
+                // $result = $app->transfer->toBalance([
+                //     'partner_trade_no' => $id, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
+                //     'openid' => $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'],
+                //     'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
+                //     're_user_name' => $info['uid'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
+                //     'amount' => number_format($info['extract_price'])*100, // 企业付款金额,单位为分
+                //     'desc' => '费', // 企业付款操作说明信息。必填
+                // ]);
+                // // print_r($result);
+                // if($result['return_code'] =='SUCCESS'){
+                //     if($result['result_code'] =='FAIL'){
+                //         return $this->error('操作失败:'.$result['return_msg'].$result['err_code_des']);
+                //     }
+                // }else{
+                //     return $this->error('操作失败');
+                // }
+            }
+        }
+        try {
+            $updateRes = $model->where('id', '=', $id)->update($update);
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //添加
+    public function add()
+    {
+        global $_W;
+        Db::startTrans();
+        try {
+            $post            = CommonFun::filterPostData($this->request->post());
+            $post['uniacid'] = $_W['uniacid'];
+            $validate = new Add();
+            if (!$validate->check($post)) throw new \Exception($validate->getError());
+
+            $result   = $this->modelUser->save($post);
+            if(!$result) throw new \Exception("添加失败");
+            Db::commit();
+            return $this->success('添加成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        // print_r($id );
+        $info = $this->modelUser->where('uid','=',$id)->findOrEmpty()->toArray();
+        return $this->success('获取成功', $info);
+    }
+
+    //编辑
+    public function edit()
+    {
+        Db::startTrans();
+        try {
+            $post = CommonFun::filterPostData($this->request->post());
+            $navmenu = $this->modelUser->findOrEmpty($post['id']);
+            if (!$navmenu) throw new \Exception("id参数错误");
+            $validate = new Add();
+            if (!$validate->check($post)) throw new \Exception($validate->getError());
+            $updateNavmenu = $navmenu->update($post);
+            if (!$updateNavmenu) throw new \Exception("菜单基本信息保存失败");
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = array_filter($this->request->param('ids'));
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+        // if (in_array(1, $ids)) {
+        //     return $this->error('不允许删除初始化用户');
+        // }
+        try{
+            if ($this->modelUser->destroy($ids)) {
+                return $this->success('数据删除成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置状态
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        // try {
+            if($isRecycle) {
+                $updateRes = $this->modelUser->onlyTrashed()->where('uid', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->modelUser->where('uid', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        // } catch (\Exception $e) {
+        //     return $this->error('数据库异常,操作失败');
+        // }
+    }
+}

+ 256 - 0
app/controller/admin/Common.php

xqd
@@ -0,0 +1,256 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\admin\admin\UserServiceFacade;
+use app\service\ConfServiceFacade;
+use laytp\library\UploadDomain;
+use plugin\ali_oss\service\Oss;
+use plugin\qiniu_kodo\service\Kodo;
+use laytp\controller\Backend;
+use think\facade\Env;
+use think\facade\Filesystem;
+use think\File;
+
+
+
+class Common extends Backend
+{
+    protected $noNeedAuth  = ['*'];
+    protected $noNeedLogin = ['getLoginNeedCaptchaConf'];
+
+    /**
+     * 获取登录后台是否需要验证码的配置
+     * 这个接口是后台登录界面使用的,给这个接口独立的访问权限,无需登录,无需鉴权
+     */
+    public function getLoginNeedCaptchaConf()
+    {
+        return $this->success('获取成功', ConfServiceFacade::get('system.basic.loginNeedCaptcha', 0));
+    }
+
+    //上传接口
+    public function upload()
+    {
+        global $_W;
+        try {
+            $defaultType = ConfServiceFacade::get('system.upload.defaultType', 'local');
+            $uploadType  = $this->request->param('upload_type', 'default');
+            $isGetImageInfo  = $this->request->param('is_get_image_info', 0);
+            if ($uploadType == 'default') $uploadType = $defaultType;
+            if (!in_array($uploadType, ['local', 'ali-oss', 'qiniu-kodo'])) {
+                return $this->error($uploadType . '上传方式未定义');
+            }
+            $file = $this->request->file('laytpUploadFile'); // 获取上传的文件
+            if (!$file) {
+                return $this->error('上传失败,请选择需要上传的文件');
+            }
+            $fileExt      = strtolower($file->getOriginalExtension());
+            $uploadDomain = new UploadDomain();
+            if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt, $file->getMime())) {
+                return $this->error($uploadDomain->getError());
+            }
+            $saveName = date("Ymd") . "/" . md5(uniqid(mt_rand())) . ".{$fileExt}";
+            /**
+             * 不能以斜杆开头
+             *  - 因为OSS存储时,不允许以/开头
+             */
+            $uploadDir = $this->request->param('dir');
+            print_r($uploadDir);
+            $object    = $uploadDir ? $uploadDir . '/' . $saveName : $saveName;//设置了上传目录的上传文件名
+            $filePath  = $object; //保存到lt_files中的path
+
+            //如果上传的是图片,验证图片的宽和高
+            $accept = $this->request->param('accept');
+            if ($accept == "image") {
+                $width  = $this->request->param('width');
+                $height = $this->request->param('height');
+                if ($width || $height) {
+                    $imageInfo = getimagesize($file->getFileInfo());
+                    if (($width && $imageInfo[0] > $width) || ($height && $imageInfo[1] > $height)) {
+                        return $this->error('上传失败,图片尺寸要求宽:' . $width . 'px,高:' . $height . 'px,实际上传文件[ ' . $file->getOriginalName() . ' ]的尺寸为宽' . $imageInfo[0] . 'px,高:' . $imageInfo[1] . 'px');
+                    }
+                }
+            }
+
+            $inputValue = "";
+            //上传至七牛云
+            if ($uploadType == 'qiniu-kodo') {
+                if (ConfServiceFacade::get('plugin.qiniu_kodo.switch') != 1) {
+                    return $this->error('未开启七牛云KODO存储,请到七牛云KODO配置中开启,如果未安装七牛云KODO存储插件,请先到插件市场进行安装');
+                }
+                $kodoConf = [
+                    'accessKey' => ConfServiceFacade::get('plugin.qiniu_kodo.accessKeyID'),
+                    'secretKey' => ConfServiceFacade::get('plugin.qiniu_kodo.secretKey'),
+                    'bucket'    => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
+                    'domain'    => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
+                ];
+                $kodo     = Kodo::instance();
+                $kodoRes  = $kodo->upload($file->getPathname(), $object, $kodoConf);
+                if ($kodoRes) {
+                    $inputValue = $kodoRes;
+                } else {
+                    return $this->error($kodo->getError());
+                }
+            }
+
+            //上传至阿里云
+            if ($uploadType == 'ali-oss') {
+                if (ConfServiceFacade::get('plugin.ali_oss.switch') != 1) {
+                    return $this->error('未开启阿里云OSS存储,请到阿里云OSS配置中开启');
+                }
+                $ossConf      = [
+                    'accessKeyID'     => ConfServiceFacade::get('plugin.ali_oss.accessKeyID'),
+                    'accessKeySecret' => ConfServiceFacade::get('plugin.ali_oss.accessKeySecret'),
+                    'bucket'          => ConfServiceFacade::get('plugin.ali_oss.bucket'),
+                    'endpoint'        => ConfServiceFacade::get('plugin.ali_oss.endpoint'),
+                    'domain'          => ConfServiceFacade::get('plugin.ali_oss.domain'),
+                ];
+                $oss          = Oss::instance();
+                $ossUploadRes = $oss->upload($file->getPathname(), $object, $ossConf);
+                if ($ossUploadRes) {
+                    $inputValue = $ossUploadRes;
+                } else {
+                    return $this->error($oss->getError());
+                }
+            }
+
+            //本地上传
+            if ($uploadType == 'local') {
+                $uploadDir    = ltrim('/', $uploadDir);
+                $saveName     = Filesystem::putFileAs('/' . $uploadDir, $file, '/' . $object);
+                $filePath     = $saveName;
+                $staticDomain = Env::get('domain.static');
+                if ($accept == "client"){
+                    // print_r($accept);
+                    $inputValue = request()->domain() . STATIC_PATH . '/admin/client/' . $saveName;
+                } else {
+                    $inputValue = request()->domain() . STATIC_PATH . '/storage/' . $saveName;
+                }
+            }
+
+            //将inputValue存入lt_files表中
+            $filesModel = new \app\model\Files();
+            $fileId     = $filesModel->insertGetId([
+                'category_id'          => 0,
+                'name' => $accept == "client"?$saveName:$file->getOriginalName(),
+                'file_type'            => $this->request->param('accept'),
+                'path'                 => $filePath,
+                'upload_type'          => $uploadType,
+                'size'                 => $file->getSize(),
+                'ext'                  => $file->getExtension(),
+                'create_admin_user_id' => UserServiceFacade::getUser()->id,
+                'update_admin_user_id' => UserServiceFacade::getUser()->id,
+                'create_time'          => date('Y-m-d H:i:s'),
+                'update_time'          => date('Y-m-d H:i:s'),
+                'uniacid'          => $_W['uniacid']
+            ]);
+
+
+
+            $returnData = [
+                'id'   => $fileId,
+                'path' => $inputValue,
+                'name' => $file->getOriginalName(),
+            ];
+
+            if($isGetImageInfo){
+                $url = str_replace("https://", "http://", $inputValue);
+                $url = trim($url);
+                list($width, $height, $type, $attr) = getimagesize($url);
+                if(!empty($width)){
+                    $returnData['width'] = $width;
+                    $returnData['height'] = $height;
+                }
+            }
+
+            return $this->success('上传成功', $returnData);
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    // 获取阿里云sts的临时凭证,目前仅用于客户端直接上传到oss前获取到临时凭证进行上传
+    public function aliSts()
+    {
+        if (ConfServiceFacade::get('plugin.ali_oss_sts.switch') != 1) {
+            return $this->error('阿里云OSS存储的STS方式,请到阿里云STS配置中开启');
+        }
+        $uploadDomain = new UploadDomain();
+        $fileName     = $this->request->param('name');
+        $fileSize     = $this->request->param('size');
+        $fileExt      = $this->request->param('ext');
+        if (!$uploadDomain->check($fileName, $fileSize, $fileExt, '')) {
+            return $this->error($uploadDomain->getError());
+        }
+        $stsConf = [
+            'accessKeyID'     => ConfServiceFacade::get('plugin.ali_oss_sts.accessKeyID'),
+            'accessKeySecret' => ConfServiceFacade::get('plugin.ali_oss_sts.accessKeySecret'),
+            'ARN'             => ConfServiceFacade::get('plugin.ali_oss_sts.ARN'),
+            'endpoint'        => ConfServiceFacade::get('plugin.ali_oss_sts.endpoint'),
+            'domain'          => ConfServiceFacade::get('plugin.ali_oss_sts.domain'),
+            'bucket'          => ConfServiceFacade::get('plugin.ali_oss_sts.bucket'),
+        ];
+        $oss     = Oss::instance();
+        $sts     = $oss->sts($stsConf);
+        $file    = new File('', false);
+
+        if ($sts) {
+            return $this->success('sts获取成功', [
+                'sts'   => $sts,
+                'path'  => str_replace('\\', '/', $file->hashName()) . $fileExt,
+                'index' => $this->request->param('index'),
+            ]);
+        } else {
+            return $this->error('sts获取失败,' . $oss->getError());
+        }
+    }
+
+    // 获取kodo上传凭证token
+    public function kodoToken()
+    {
+        if (ConfServiceFacade::get('plugin.qiniu_kodo.switch') != 1) {
+            return $this->error('未开启七牛云KODO存储,请到七牛云KODO配置中开启');
+        }
+        $uploadDomain = new UploadDomain();
+        $fileName     = $this->request->param('name');
+        $fileSize     = $this->request->param('size');
+        $fileExt      = $this->request->param('ext');
+        if (!$uploadDomain->check($fileName, $fileSize, $fileExt, '')) {
+            return $this->error($uploadDomain->getError());
+        }
+        $kodoConf = [
+            'accessKey' => ConfServiceFacade::get('plugin.qiniu_kodo.accessKey'),
+            'secretKey' => ConfServiceFacade::get('plugin.qiniu_kodo.secretKey'),
+            'domain'    => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
+            'bucket'    => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
+        ];
+        $kodo     = Kodo::instance();
+        $token    = $kodo->token($kodoConf);
+        $file     = new File('', false);
+
+        if ($token) {
+            return $this->success('KodoToken获取成功', [
+                'token'  => $token,
+                'domain' => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
+                'bucket' => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
+                'path'   => str_replace('\\', '/', $file->hashName()) . $fileExt,
+                'index'  => $this->request->param('index'),
+            ]);
+        } else {
+            return $this->error('KodoToken获取失败,' . $kodo->getError());
+        }
+    }
+
+    //解锁屏幕
+    function unLockScreen()
+    {
+        $password     = $this->request->post('password');
+        $userId       = UserServiceFacade::getUser()->id;
+        $passwordHash = User::where('id', '=', $userId)->value('password');
+        if (!password_verify(md5($password), $passwordHash)) {
+            return $this->error('解锁失败,密码错误');
+        } else {
+            return $this->success('解锁成功');
+        }
+    }
+}

+ 171 - 0
app/controller/admin/Conf.php

xqd
@@ -0,0 +1,171 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\ConfServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+use app\service\api\MiniappServiceFacade;
+use think\facade\Db;
+
+/**
+ * 系统配置控制器
+ * Class Conf
+ * @package app\admin\controller
+ */
+class Conf extends Backend
+{
+    protected $model;
+    protected $noNeedAuth = ['getGroupConf', 'saveGroupConf'];
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Conf();
+    }
+
+    /**
+     * 获取某个分组下所有的配置项
+     */
+    public function getGroupConf()
+    {
+        $group  = $this->request->param('group');
+        $return = ConfServiceFacade::groupGet($group, true);
+        return $this->success('获取成功', $return);
+    }
+
+    /**
+     * 保存配置
+     */
+    public function saveGroupConf()
+    {
+        global $_W;
+        // $data = \app\model\Conf::where(['group'=>'system.wechat'])->select()->toArray();
+        // if(!empty($data[0]['uniacid']) && $data[0]['uniacid'] != $_W['uniacid']){
+        //     return $this->error('系统只支持单开');
+        // }
+        $post = $this->request->post();
+        if (isset($post['laytpUploadFile'])) {
+            unset($post['laytpUploadFile']);
+        }
+        $group = $post['group'];
+        unset($post['group']);
+        $formType = $post['form_type'];
+        unset($post['form_type']);
+        $allConf = [];
+        foreach ($post as $key => $value) {
+            if (is_array($value)) {
+                $temp = [];
+                foreach ($value['key'] as $arrK => $arrV) {
+                    if ($arrV) {
+                        $temp[$arrV] = $value['value'][$arrK];
+                    }
+                }
+                $value = $temp;
+            }
+            $conf['group']     = $group;
+            $conf['key']       = $key;
+            $conf['value']     = $value;
+            $conf['form_type'] = $formType[$key];
+            $conf['uniacid'] = $_W['uniacid'];
+            $allConf[]         = $conf;
+        }
+        ConfServiceFacade::groupSet($allConf);
+        return $this->success('保存成功', $allConf);
+    }
+
+    /**
+     * 删除某个分组下某个key的配置信息
+     *  这个不在配置页面进行调用,后续要做生成工具的时候统一管理所有的key
+     */
+    public function del()
+    {
+        $group = $this->request->param('group');
+        $key   = $this->request->param('key');
+        ConfServiceFacade::del($group, $key);
+        return $this->success('删除成功');
+    }
+
+    public function getSystemWords()
+    {
+        $Filter = new \ins\Words('*');
+        $words = $Filter->getWords();
+        return $this->success('获取成功',$words);
+    }
+
+    // 获得公众号链接
+    public function wechatLinkInfo()
+    {
+        global $_W;
+        // print_r($_SERVER);
+        $site = $_SERVER['HTTP_ORIGIN'];
+        $link = $site . SURL . 'h5/?uniacid=' . $_W['uniacid'];
+        return $this->success('获取成功',$link);
+    }
+
+    // 获得大数据链接
+    public function bigdataLinkInfo()
+    {
+        global $_W;
+        $site = $_SERVER['HTTP_ORIGIN'];
+        $link = $site . SURL . '/bigdata?uniacid=' . $_W['uniacid'];
+        return $this->success('获取成功',$link);
+    }
+
+    // 获得公众号二维码
+    public function wechatQrcode()
+    {
+        global $_W;                             //获取二维码生成的地址
+    }
+
+    // 获得小程序链接
+    public function miniappQrcode()
+    {
+        global $_W;
+        $conf = ConfServiceFacade::groupGet('system.miniapp', true);
+        if(!$conf['appid'] || !$conf['appsecret']){
+            return $this->error('操作失败');
+        }
+        $app = MiniappServiceFacade::option();
+        $response = $app->app_code->get('pages/index/index', [
+            'width' => 600,
+            'line_color' => [
+                'r' => 105,
+                'g' => 166,
+                'b' => 134,
+            ],
+        ]);
+        if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
+            $time = time();
+            $filename = $response->saveAs(IA_ROOT_WK.'/public/static/storage/presets/', $time.'appcode.png');
+        }
+        return $this->success('获取成功',request()->domain() . STATIC_PATH . '/storage/presets/' . $time.'appcode.png');
+    }
+
+    // 获得订阅消息
+    public function miniappNotification()
+    {
+        $conf = ConfServiceFacade::groupGet('system.notification', true);
+        $tid = $this->request->param('tid');
+        $app = MiniappServiceFacade::option();
+        // print_r($app->subscribe_message->getTemplateKeywords($tid));
+        // return;
+        switch($tid){
+            case 2039:
+                $kidList = [1,4,10,11,12];
+                break;
+            case 1185:
+                $kidList = [2,3,7,16];
+                break;
+            case 786:
+                $kidList = [1,2,7,15,4];
+                break;
+            case 10291:
+                $kidList = [1,2,3];
+                break;
+        }
+        $sceneDesc = '订阅';
+        $res = $app->subscribe_message->addTemplate($tid, $kidList, $sceneDesc);
+        return $this->success('获取成功',$res);
+    }
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 0
app/controller/admin/Console.php


+ 144 - 0
app/controller/admin/Files.php

xqd
@@ -0,0 +1,144 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use app\service\admin\UserServiceFacade;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+use think\facade\Config;
+
+/**
+ * 附件管理
+ */
+class Files extends Backend
+{
+    /**
+     * files模型对象
+     * @var \app\model\Files
+     */
+    protected $model;
+    public    $hasSoftDel = 1;//是否拥有软删除功能
+
+    public function initialize()
+    {
+        parent::initialize();
+        $this->model = new \app\model\Files();
+    }
+
+    /**
+     * 查看
+     * @throws \think\db\exception\DbException
+     */
+    public function index()
+    {
+        global $_W;
+        $where        = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order        = $this->buildOrder();
+        $data         = $this->model->where($where)->order($order)->with(['category', 'createAdminUser', 'updateAdminUser']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //添加
+    public function add()
+    {
+        return $this->error('当前版本暂时不支持在附件管理中添加附件');
+        $post                         = CommonFun::filterPostData($this->request->post());
+        $post['create_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['path']                 = UploadDomain::singleDelUploadDomain($post['path']);
+        if ($this->model->create($post)) {
+            return $this->success('添加成功', $post);
+        } else {
+            return $this->error('操作失败');
+        }
+    }
+
+    //不经过服务器方式上传成功后,回调的ajax请求地址,将上传成功的文件信息存入表中
+    public function unViaSave()
+    {
+        $post                         = $this->request->post();
+        $post['create_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['create_time']          = date('Y-m-d H:i:s');
+        $post['update_time']          = date('Y-m-d H:i:s');
+        $post['id']                   = $this->model->insertGetId($post);
+        if ($post['id']) {
+            return $this->success('添加成功', $post);
+        } else {
+            return $this->error('操作失败');
+        }
+    }
+
+    //编辑
+    public function edit()
+    {
+        return $this->error('当前版本暂时不支持在附件管理中编辑附件');
+        $id                           = $this->request->param('id');
+        $info                         = $this->model->find($id);
+        $post                         = CommonFun::filterPostData($this->request->post());
+        $post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['path']                 = UploadDomain::singleDelUploadDomain($post['path']);
+        foreach ($post as $k => $v) {
+            $info->$k = $v;
+        }
+        try {
+            $updateRes = $info->save();
+            if ($updateRes) {
+                return $this->success('编辑成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未做修改');
+            } else if ($updateRes === null) {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $id                           = $this->request->param('id');
+        $info                         = $this->model->find($id);
+        $post                         = CommonFun::filterPostData($this->request->post());
+        $post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
+        $post['path']                 = UploadDomain::singleDelUploadDomain($post['path']);
+        foreach ($post as $k => $v) {
+            $info->$k = $v;
+        }
+        try {
+            $updateRes = $info->save();
+            if (!$updateRes) {
+                return $this->error('操作失败');
+            } else {
+                return $this->success('编辑成功');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //回收站
+    public function recycle()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', Config::get('paginate.limit'));
+        $data  = $this->model->onlyTrashed()
+            ->with(['category', 'createAdminUser', 'updateAdminUser'])
+            ->order($order)->where($where)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+}

+ 163 - 0
app/controller/admin/Gallery.php

xqd
@@ -0,0 +1,163 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+
+/**
+ * 幻灯轮播
+ */
+class Gallery extends Backend
+{
+
+    /**
+     * slider模型对象
+     * @var \app\model\Gallery
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Gallery();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        // $where  = $this->buildSearchParams();
+        $order  = $this->buildOrder();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $where[] = ['done','=',1];
+
+        $order = ['sort'=>'desc','id'=>'desc'];
+        $data   = $this->model->order($order)->where($where)->with(['userInfo','modelsInfo']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->with(['img_file'])->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+
+
+
+
+    //设置排序
+    public function setSort()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置账号状态
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置账号状态
+    public function setIsOpen()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['is_open'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $list = [
+                    ['uniacid' => $_W['uniacid'],'title'=>'你可以这样对AI说:','type'=>'sentence']
+                ];
+                $this->model->saveAll($list);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+        // return $this->success('获取成功', $_W);
+    }
+}

+ 122 - 0
app/controller/admin/Hot.php

xqd
@@ -0,0 +1,122 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 热门提问
+ */
+class Hot extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Hot
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Hot();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //设置价格
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $modelFiles = new \app\model\Files();
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $list = [
+                    ['uniacid' => $_W['uniacid'],'text'=>'诸多利好政策的刺激下,2023年在中国会是买房的好时机吗?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'如今,你已经引发全球关注。你什么时候能够彻底代替传统的搜索引擎?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'有哪些好用的思维导图软件呢?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'有什么值得长期坚持的好习惯?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'考研复试应该从什么时候准备?怎么准备?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'给产品经理的一些建议'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'为玩具店写一个标语'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'如何快速增加腹肌'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'为西游记写一个番外故事'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'如何写好年终工作总结'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'推荐三本经济学入门书籍'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'怎样获得更好的睡眠'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'什么叫降维打击'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'前端面试常见的问题'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'销售一部手机的文案'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'什么是BMI指数?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'讲一个笑话'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'怎么做减脂餐'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'抗衰老最有效的办法是什么?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'适合冬季带孩子一起进行的户外运动有哪些?'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'给孩子取个富有诗意的名字'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'推荐一些轻音乐'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'简单介绍下人类简史'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'巴西足球为什么这么厉害'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'简历应该怎么写'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'我们如何在逆境中保持积极'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'讲一下暗黑森林法则'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'去西藏旅行需要注意什么'],
+                    ['uniacid' => $_W['uniacid'],'text'=>'冬天手脚冰凉怎么改善'],
+                ];
+                $this->model->saveAll($list);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+}

+ 98 - 0
app/controller/admin/Kami.php

xqd
@@ -0,0 +1,98 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+use laytp\library\Random;
+
+/**
+ * 示例文本
+ */
+class Kami extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Kami
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Kami();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with('userInfo');
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    public function add()
+    {
+        global $_W;
+        $post = $this->request->post();
+        $value = $this->request->post('value',0);
+        $number = $this->request->post('number',0);
+        $type = $this->request->post('type',1);
+        if($type == 1){
+            $name = '次数卡';
+        }else{
+            $name = '时长卡';
+        }
+        if(!$value){
+            return $this->error('请填写大于0的数字');
+        }
+        if(!$number){
+            return $this->error('请填写大于0的数字');
+        }
+        for($i=0;$i<$number;$i++){
+            $res2 = $this->model->create(['name'=>$name,'value'=>$value,"type"=>$type,'code'=>Random::alpha(12),'uniacid'=>$_W['uniacid']]);
+        }
+        return $this->success('数据获取成功');
+    }
+
+    //设置积分
+    public function setType()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['type'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 165 - 0
app/controller/admin/Member.php

xqd
@@ -0,0 +1,165 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 会员卡
+ */
+class Member extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Member
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Member();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        // $order  = $this->buildOrder();
+        $order = ['sort' => 'DESC','id'=>'DESC'];
+        $data   = $this->model->where($where)->order($order);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+
+
+
+
+    //设置价格
+    public function setPrice()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['price'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置积分
+    public function setCoin()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['coin'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置积分
+    public function setDay()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['day'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置排序
+    public function setSort()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 282 - 0
app/controller/admin/Menu.php

xqd
@@ -0,0 +1,282 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\admin\admin\UserServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\Tree;
+use think\facade\Config;
+
+/**
+ * 菜单控制器
+ */
+class Menu extends Backend
+{
+    public $noNeedAuth = ['getMenuTree', 'getTree'];
+    public $model;
+    public $orderRule  = ['sort' => 'desc', 'id' => 'asc'];
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\admin\Menu();
+    }
+
+    public function index()
+    {
+        global $_W;
+        $where  = $this->buildSearchParams(false);
+        // $where[] = ['uniacid','=',$_W['uniacid']];
+        $order      = $this->buildOrder();
+        $sourceData = $this->model->where($where)->order($order);
+        $isTree     = $this->request->param('is_tree');
+        if ($isTree) {
+            $menuTreeObj = Tree::instance();
+            $menuTreeObj->init($sourceData->select()->toArray());
+            $data = $menuTreeObj->getRootTrees();
+        } else {
+            $paging = $this->request->param('paging', false);
+            if ($paging) {
+                $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+                $data         = $sourceData->paginate($limit)->toArray();
+                $data['data'] = $this->getSelectedData($data['data']);
+            } else {
+                $data = $sourceData->select()->toArray();
+            }
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //获取当前登录者的权限列表,返回树形数据,角色管理赋予权限时用到
+    public function getTree()
+    {
+        $user = UserServiceFacade::getUser();
+        if ($user->is_super_manager === 1) {
+            $sourceData = $this->model->order($this->orderRule)->select()->toArray();
+        } else {
+            $roleIds    = \app\model\admin\role\User::where('admin_user_id', '=', $user->id)
+                ->column('admin_role_id');
+            $menuIds    = \app\model\admin\menu\Role::where('admin_role_id', 'in', $roleIds)
+                ->column('admin_menu_id');
+            $where[]    = ['id', 'in', $menuIds];
+            $sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
+        }
+        $menuTreeObj = Tree::instance();
+        $menuTreeObj->init($sourceData);
+        //由列表数据转化成树形结构数据
+        $data = $menuTreeObj->getRootTrees();
+        return $this->success('获取成功', $data);
+    }
+
+    //获取当前登录者的菜单列表,返回树形数据,仅返回is_menu=1的列表,后台菜单列表展示使用
+    public function getMenuTree()
+    {
+        $user    = UserServiceFacade::getUser();
+        $where[] = ['is_show', '=', 1];
+        $where[] = ['is_menu', '=', 1];
+        if ($user->is_super_manager === 1) {
+            $sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
+        } else {
+            $roleIds    = \app\model\admin\role\User::where('admin_user_id', '=', $user->id)
+                ->column('admin_role_id');
+            $menuIds    = \app\model\admin\menu\Role::where('admin_role_id', 'in', $roleIds)
+                ->column('admin_menu_id');
+            $where[]    = ['id', 'in', $menuIds];
+            $sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
+        }
+        $menuTreeObj = Tree::instance();
+        $menuTreeObj->init($sourceData);
+        //由列表数据转化成树形结构数据
+        $data = $menuTreeObj->getRootTrees();
+        return $this->success('获取成功', $data);
+    }
+
+    //添加
+    public function add()
+    {
+        $post = CommonFun::filterPostData($this->request->post());
+        if ($post['rule'] && substr($post['rule'], 0, 1) != '/') {
+            $post['rule'] = '/' . $post['rule'];
+        }
+        if ($this->model->create($post)) {
+            return $this->success('添加成功', $post);
+        } else {
+            return $this->error('操作失败');
+        }
+    }
+
+    //编辑
+    public function edit()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        $post = CommonFun::filterPostData($this->request->post());
+        if ($post['rule'] && substr($post['rule'], 0, 1) != '/') {
+            $post['rule'] = '/' . $post['rule'];
+        }
+        if ($id == $post['pid']) {
+            return $this->error('不能将上级改成自己');
+        }
+        foreach ($post as $k => $v) {
+            $info->$k = $v;
+        }
+        $update_res = $info->save();
+        if ($update_res) {
+            return $this->success('操作成功');
+        } else if ($update_res === 0) {
+            return $this->success('未做修改');
+        } else {
+            return $this->error('操作失败');
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = $this->request->post('ids');
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+
+        $sourceData = $this->model->select()->toArray();
+        $treeLib    = Tree::instance();
+        $treeLib->init($sourceData);
+        $childIds = $treeLib->getChildIds($ids);
+
+        if ($this->model->destroy($childIds)) {
+            return $this->success('数据删除成功', $childIds);
+        } else {
+            return $this->error('数据删除失败');
+        }
+    }
+
+    //设置排序
+    public function setSort()
+    {
+        $id             = $this->request->post('id');
+        $fieldVal       = $this->request->post('field_val');
+        $isRecycle      = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置是否为菜单
+    public function setIsMenu()
+    {
+        $id                = $this->request->post('id');
+        $fieldVal          = $this->request->post('field_val');
+        $isRecycle         = $this->request->post('is_recycle');
+        $update['is_menu'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置是否显示
+    public function setIsShow()
+    {
+        $id                = $this->request->post('id');
+        $fieldVal          = $this->request->post('field_val');
+        $isRecycle         = $this->request->post('is_recycle');
+        $update['is_show'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    // 复制菜单
+    public function copy()
+    {
+        $pid = (int)$this->request->post('pid');
+        $ids = $this->request->post('ids');
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+
+        $data = \app\model\admin\Menu::where('id', 'in', $ids)
+            ->withoutField('id')->select()
+            ->each(function ($item) use ($pid) {
+                $item->pid = $pid;
+            })->toArray();
+
+        $insert = $this->model->insertAll($data);
+        if ($insert) {
+            return $this->success('复制成功');
+        } else {
+            return $this->error('复制失败');
+        }
+    }
+
+    // 移动菜单
+    public function move()
+    {
+        $pid = (int)$this->request->post('pid');
+        $ids = $this->request->post('ids');
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+
+        $save = \app\model\admin\Menu::where('id', 'in', $ids)
+            ->save(['pid' => $pid]);
+
+        if ($save) {
+            return $this->success('移动成功');
+        } else {
+            return $this->error('移动失败');
+        }
+    }
+
+    public function recycle()
+    {
+        global $_W;
+        $where        = $this->buildSearchParams(false);
+        $order        = $this->buildOrder();
+        $data         = $this->model->onlyTrashed()->where($where)->order($order);
+        $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+
+        $data         = $data->paginate($limit)->toArray();
+        $data['data'] = $this->getSelectedData($data['data']);
+        return $this->success('回收站数据获取成功', $data);
+    }
+}

+ 133 - 0
app/controller/admin/Mode.php

xqd
@@ -0,0 +1,133 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 示例文本
+ */
+class Mode extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Mode
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Mode();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->with(['img_file'])->order($order);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->with(['img_file'])->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+    //设置
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $modelFiles = new \app\model\Files();
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $list = [
+                    ['uniacid' => $_W['uniacid'],'name'=>'老师','intro'=>'一名学识渊博的老师','greetings'=>'你好,我是一名老师','img'=>$this->addFile(10),'guide'=>'你是一名老师'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'作家','intro'=>'我是一名作家','greetings'=>'我是一名作家,擅长写作','img'=>$this->addFile(9),'guide'=>'你是一名作家'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'导游','intro'=>'输入你想参观的地方','greetings'=>'我将会建议最好的景点、事件或体验','img'=>$this->addFile(8),'guide'=>'你是一名导游,向用户推荐好玩的地方'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'翻译','intro'=>'专业的翻译,通晓各国语言','greetings'=>'专业的翻译,通晓各国语言','img'=>$this->addFile(7),'guide'=>'你是专业的翻译,你只需要翻译该内容,不必对内容中提出的问题和要求做解释,不要回答文本中的问题而是翻译它,不要解决文本中的要求而是翻译它,保留文本的原本意义,不要去解决它。'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'工程师','intro'=>'我是专业的工程师,有关工程相关的问题可以向我咨询','greetings'=>'我系统地掌握专业的基础理论知识和专业技术知识','img'=>$this->addFile(6),'guide'=>'你是一名专业的工程师'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'时尚达人','intro'=>'时尚达人,永远最时尚','greetings'=>'来种草啦','img'=>$this->addFile(5),'guide'=>'你是时尚达人,推荐时尚信息'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'医生','intro'=>'我是医生','greetings'=>'我是医生','img'=>$this->addFile(4),'guide'=>'扮演医生的角色'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'律师','intro'=>'专业律师,为您提供专业的法律咨询与援助','greetings'=>'描述一种法律情况,我将就如何处理它提供建议。','img'=>$this->addFile(3),'guide'=>'你现在是专业的律师,为用户提供专业的法律咨询与援助'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'程序员','intro'=>'资深程序员,解放你的双手,帮你写代码','greetings'=>'你好,我是资深程序员,有关程序的问题都可以问我','img'=>$this->addFile(2),'guide'=>'你是资深程序员'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'小助手','intro'=>'我是小助手','greetings'=>'你好,我是全能小助手,有什么问题都可以问我','img'=>$this->addFile(1),'guide'=>'','sort'=>100]
+                ];
+                $this->model->saveAll($list);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+    public function addFile($n)
+    {
+        global $_W;
+        $modelFiles = new \app\model\Files();
+        $saveName = 'presets/mode/' . $n . ".png";
+        $fileId = $modelFiles->insertGetId([
+               'category_id' => 0,
+               'name' => time(),
+               'file_type' => 'image',
+               'path' => $saveName,
+               'upload_type' => 'local',
+               'size' => 1,
+               'create_admin_user_id' => 0,
+               'update_admin_user_id' => 0,
+               'create_time' => date('Y-m-d H:i:s'),
+               'update_time' => date('Y-m-d H:i:s'),
+               'uniacid' =>$_W['uniacid'],
+               'ext' =>'png'
+           ]);
+          return $fileId;
+    }
+
+}

+ 254 - 0
app/controller/admin/Models.php

xqd
@@ -0,0 +1,254 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\api\UserServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+use think\facade\Db;
+
+/**
+ * 会员管理
+ */
+class Models extends Backend
+{
+    protected $model;//当前模型对象
+    protected $noNeedLogin = [];
+    protected $noNeedAuth = [];
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Models();
+    }
+
+    //查看
+    public function index()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        // $order = $this->buildOrder();
+        $order = ['sort'=>'desc','id'=>'desc'];
+        $data = $this->model->where($where)->order($order);
+        $allData = $this->request->param('all_data');
+        if ($allData) {
+            $data = $data->select();
+        } else {
+            $limit = $this->request->param('limit', 10);
+            $data = $data->paginate($limit)->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //添加
+    public function add()
+    {
+        global $_W;
+        Db::startTrans();
+        try {
+            $post            = CommonFun::filterPostData($this->request->post());
+            $post['uniacid'] = $_W['uniacid'];
+            $result   = $this->model->save($post);
+            if(!$result) throw new \Exception("添加失败");
+            Db::commit();
+            return $this->success('添加成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->findOrEmpty($id)->toArray();
+        return $this->success('获取成功', $info);
+    }
+
+    //编辑
+    public function edit()
+    {
+        Db::startTrans();
+        try {
+            $post = CommonFun::filterPostData($this->request->post());
+            $navmenu = $this->model->findOrEmpty($post['id']);
+            if (!$navmenu) throw new \Exception("id参数错误");
+            $updateWords = $navmenu->update($post);
+            if (!$updateWords) throw new \Exception("菜单基本信息保存失败");
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = array_filter($this->request->param('ids'));
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+        try{
+            if ($this->model->destroy($ids)) {
+                return $this->success('数据删除成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置状态
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //回收站
+    public function recycle(){
+        $where = $this->buildSearchParams();
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', 10);
+        $data  = $this->model->onlyTrashed()
+                 ->order($order)->where($where)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+
+    //设置排序
+    public function setSort()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $list = [
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'lowpoly-diffusion','name'=>'低多边形','intro'=>'可以生成低多边形风格的图片','status'=>1,'imgs'=>$this->addFile('lowpoly-diffusion'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'arcane-diffusion','name'=>'arcane模型','intro'=>'这是在电视节目Arcane的图像上训练的微调稳定扩散模型。','status'=>1,'imgs'=>$this->addFile('arcane-diffusion'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'mo-di-diffusion','name'=>'迪士尼风格','intro'=>'生成迪士尼风格图片','status'=>1,'imgs'=>$this->addFile('mo-di-diffusion'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'waifu-diffusion','name'=>'二次元动漫模型waifu','intro'=>'高质量二次元动漫风格图片生成','status'=>1,'imgs'=>$this->addFile('waifu-diffusion'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'redshift-diffusion','name'=>'CG感动漫模型','intro'=>'高品质3D渲染作品','status'=>1,'imgs'=>$this->addFile('redshift-diffusion'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'midjourney','name'=>'仿MidJourney V4风格','intro'=>'仿MidJourney风格图片生成','status'=>1,'imgs'=>$this->addFile('midjourney'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'pixel-art-v3','name'=>'像素艺术','intro'=>'生成像素风图片','status'=>1,'imgs'=>$this->addFile('pixel-art-v3'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v3','name'=>'经典二次元模型3.0','intro'=>'二次元模型 高质量的插图','status'=>1,'imgs'=>$this->addFile('anything-v3'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v5','name'=>'二次元模型5.0','intro'=>'二次元模型 相比3.0上限更高 描述词准确度更好','status'=>1,'imgs'=>$this->addFile('anything-v5'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'chilloutmix','name'=>'韩风真人2.5d','intro'=>'精致的面部细节','status'=>1,'imgs'=>$this->addFile('chilloutmix'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'guofeng3','name'=>'国风V3','intro'=>'国风V3 涵盖国风、古风、汉服的真人模型','status'=>1,'imgs'=>$this->addFile('guofeng3'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile('bro623jbfe32'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'sdv2','name'=>'通用模型','intro'=>'官方sd原版','status'=>1,'imgs'=>$this->addFile('sdv2'),'engine'=>'sd'],
+                    ['uniacid' => $_W['uniacid'],'model_id'=>'mj','name'=>'Midjourney官方v5.1','intro'=>'Midjourney 最新版模型','status'=>1,'imgs'=>$this->addFile('mj'),'engine'=>'mj','version'=>'v5.1'],
+
+                    // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj'],
+                    // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj']
+                ];
+                $this->model->saveAll($list);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+        // return $this->success('获取成功', $_W);
+    }
+
+    public function addFile($modelId)
+   {
+       global $_W;
+       $modelFiles = new \app\model\Files();
+       $saveName1 = 'presets/'.$modelId.'/' . 1 . ".png";
+       $saveName2 = 'presets/'.$modelId.'/' . 2 . ".png";
+       $saveName3 = 'presets/'.$modelId.'/' . 3 . ".png";
+       $fileId1 = $modelFiles->insertGetId([
+              'category_id' => 0,
+              'name' => time(),
+              'file_type' => 'image',
+              'path' => $saveName1,
+              'upload_type' => 'local',
+              'size' => 1,
+              'create_admin_user_id' => 0,
+              'update_admin_user_id' => 0,
+              'create_time' => date('Y-m-d H:i:s'),
+              'update_time' => date('Y-m-d H:i:s'),
+              'uniacid' =>$_W['uniacid'],
+              'ext' =>'png'
+          ]);
+            $fileId2 = $modelFiles->insertGetId([
+                      'category_id' => 0,
+                      'name' => time(),
+                      'file_type' => 'image',
+                      'path' => $saveName2,
+                      'upload_type' => 'local',
+                      'size' => 1,
+                      'create_admin_user_id' => 0,
+                      'update_admin_user_id' => 0,
+                      'create_time' => date('Y-m-d H:i:s'),
+                      'update_time' => date('Y-m-d H:i:s'),
+                      'uniacid' =>$_W['uniacid'],
+                      'ext' =>'png'
+                  ]);
+          $fileId3 = $modelFiles->insertGetId([
+                    'category_id' => 0,
+                    'name' => time(),
+                    'file_type' => 'image',
+                    'path' => $saveName3,
+                    'upload_type' => 'local',
+                    'size' => 1,
+                    'create_admin_user_id' => 0,
+                    'update_admin_user_id' => 0,
+                    'create_time' => date('Y-m-d H:i:s'),
+                    'update_time' => date('Y-m-d H:i:s'),
+                    'uniacid' =>$_W['uniacid'],
+                    'ext' =>'png'
+                ]);
+         return $fileId1.','.$fileId2.','.$fileId3;
+   }
+
+}

+ 65 - 0
app/controller/admin/Order.php

xqd
@@ -0,0 +1,65 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 订单
+ */
+class Order extends Backend
+{
+
+    /**
+     * order模型对象
+     * @var \app\model\Order
+     */
+    protected $model;
+	protected $hasSoftDel=0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Order();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with(['memberInfo','userInfo']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+
+
+
+
+}

+ 131 - 0
app/controller/admin/Plugins.php

xqd
@@ -0,0 +1,131 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\admin\PluginsServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\Http;
+use think\facade\Config;
+
+/**
+ * 插件管理
+ */
+class Plugins extends Backend
+{
+    /**
+     * files模型对象
+     * @var \app\model\Files
+     */
+    protected $model;
+    public    $hasSoftDel = 1;//是否拥有软删除功能
+
+    // 获取laytp官网定义的插件分类列表
+    public function category()
+    {
+        $url  = Config::get('plugin.apiUrl') . '/plugins/category';
+        $data = json_decode(Http::get($url), true)['data'];
+        return $this->success('获取成功', $data);
+    }
+
+    // 查看
+    public function index()
+    {
+        $params['page']        = $this->request->param('page', 1);
+        $params['limit']       = $this->request->param('limit', 10);
+        $params['category_id'] = $this->request->param('category_id', 0);
+        $url                   = Config::get('plugin.apiUrl') . '/plugins/index';
+        $data                  = json_decode(Http::get($url, $params), true)['data'];
+        $installed             = Config::get('plugin.installed');
+        foreach ($data['data'] as $k => $datum) {
+            if ($installed && in_array($datum['alias'], $installed)) {
+                $data['data'][$k]['installed'] = 1;
+                $pluginInfo                    = PluginsServiceFacade::getPluginInfo($datum['alias']);
+                if (isset($pluginInfo['version'])) {
+                    $version = $pluginInfo['version'];
+                } else {
+                    $version = '1.0.0';
+                }
+                $data['data'][$k]['version'] = $version;
+            } else {
+                $data['data'][$k]['installed'] = 2;
+            }
+        }
+        return $this->success('获取成功', $data);
+    }
+
+    // 离线安装 - 所有的离线安装都是覆盖安装
+    public function offLineInstall()
+    {
+        if (PluginsServiceFacade::offLineInstall()) {
+            return $this->success('安装成功');
+        } else {
+            return $this->error(PluginsServiceFacade::getError());
+        }
+    }
+
+    // 卸载
+    public function uninstall()
+    {
+        $plugin = $this->request->param('plugin');
+        $info = PluginsServiceFacade::getPluginInfo($plugin);
+
+        if (PluginsServiceFacade::unInstall($plugin)) {
+            $pluginConf = Config::get('plugin');
+            foreach($pluginConf['installed'] as $k=>$installed){
+                if($installed === $plugin) unset($pluginConf['installed'][$k]);
+            }
+            $pluginConf['installed'] = array_unique($pluginConf['installed']);
+            sort($pluginConf['installed']);
+
+            if(isset($info['is_editor']) && $info['is_editor']){
+                foreach($pluginConf['installedEditor'] as $k=>$installedEditor){
+                    if($installedEditor === $plugin) unset($pluginConf['installedEditor'][$k]);
+                }
+                $pluginConf['installedEditor'] = array_unique($pluginConf['installedEditor']);
+                sort($pluginConf['installedEditor']);
+                // 如果根目录下有相应的html文件,将文件内容进行替换
+                $htmlFile = root_path() . 'public/admin/' . $plugin . '.html';
+                if(is_file($htmlFile)){
+                    file_put_contents($htmlFile, '<p style="color:blue">请先到插件市场安装' . $plugin . '编辑器。</p>
+<p style="color:red">注意:安装或卸载编辑器后,需要清空浏览器缓存才能生效</p>');
+                }
+            }
+
+            return $this->success($plugin . '插件卸载成功', [
+                'pluginConf' => $pluginConf,
+                'info' => $info
+            ]);
+        } else {
+            return $this->error(PluginsServiceFacade::getError());
+        }
+    }
+
+    // 安装
+    public function install()
+    {
+        $plugin       = $this->request->param('plugin');
+        $laytpGwToken = $this->request->param('laytpGwToken');
+
+        if (PluginsServiceFacade::install($plugin, $laytpGwToken)) {
+            // 如果是文件存储,插件安装信息,刚安装完成马上要取出来,取出来的不会是最新的文件内容
+            $pluginConf = Config::get('plugin');
+            $pluginConf['installed'][] = $plugin;
+            $pluginConf['installed'] = array_unique($pluginConf['installed']);
+            sort($pluginConf['installed']);
+
+            $info = PluginsServiceFacade::getPluginInfo($plugin);
+            if(isset($info['is_editor']) && $info['is_editor']){
+                $pluginConf['installedEditor'][] = $plugin;
+                $pluginConf['installedEditor'] = array_unique($pluginConf['installedEditor']);
+                sort($pluginConf['installedEditor']);
+            }
+
+            return $this->success($plugin . '插件安装成功', [
+                'pluginConf' => $pluginConf
+            ]);
+        } else {
+            $error = PluginsServiceFacade::getError();
+            return $this->error($error['msg'], $error['code']);
+        }
+    }
+}

+ 48 - 0
app/controller/admin/Question.php

xqd
@@ -0,0 +1,48 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 会员卡
+ */
+class Question extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Question
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Question();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with('userInfo');
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+}

+ 177 - 0
app/controller/admin/Role.php

xqd
@@ -0,0 +1,177 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use think\facade\Config;
+use think\facade\Db;
+use think\facade\Request;
+
+/**
+ * 角色控制器
+ */
+class Role extends Backend
+{
+    protected $noNeedAuth = ['getMenuIds'];
+
+    public $model;
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\admin\Role();
+    }
+
+    /**
+     * 列表
+     *  all_data参数的值为true时,表示查询表中所有数据集,否则进行分页查询
+     * @return mixed
+     */
+    public function index()
+    {
+        $where  = $this->buildSearchParams();
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    /**
+     * 添加,同时添加lt_plugin_core_role和lt_plugin_core_role_menu两个表的数据
+     * @return \think\response\Json
+     */
+    public function add()
+    {
+        Db::startTrans();
+        try {
+            $post     = CommonFun::filterPostData($this->request->post());
+            $roleInfo = $this->model->getByName($post['name']);
+            if ($roleInfo) throw new \Exception('角色名已存在');
+
+            $menuIds = explode(',', $post['menu_ids']);
+            unset($post['menu_ids']);
+            $saveMenu = $this->model->save($post);
+            if (!$saveMenu) throw new \Exception('保存角色基本信息失败');
+
+            $saveAllData = [];
+            foreach ($menuIds as $menu_id) {
+                $saveAllData[] = [
+                    'admin_role_id' => $this->model->id,
+                    'admin_menu_id' => $menu_id,
+                ];
+            }
+            $menu        = new \app\model\admin\menu\Role();
+            $saveAllMenu = $menu->saveAll($saveAllData);
+            if (!$saveAllMenu) throw new \Exception('保存角色权限失败');
+
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    /**
+     * 编辑,同时编辑lt_plugin_core_role和lt_plugin_core_role_menu两个表的数据
+     * @return bool|\think\response\Json
+     */
+    public function edit()
+    {
+        $id = $this->request->param('id');
+
+        $postData = Request::only(['id', 'name', 'menu_ids']);
+        $post     = CommonFun::filterPostData($postData);
+
+        $roleInfo = $this->model->getByName($post['name']);
+        if ($roleInfo && ($roleInfo['id'] != $id)) {
+            return $this->error('角色名已存在');
+        }
+
+        Db::startTrans();
+        try {
+            $menuIds = explode(',', $post['menu_ids']);
+            unset($post['menu_ids']);
+            $updateRes = $this->model->where('id', '=', $id)->update($post);
+            if (!is_numeric($updateRes)) throw new \Exception('保存角色基本信息失败');
+
+            $delRes = \app\model\admin\menu\Role::where('admin_role_id', '=', $id)->delete();
+            if (!is_numeric($delRes)) throw new \Exception('删除角色权限失败');
+
+            $saveAllData = [];
+            foreach ($menuIds as $menu_id) {
+                $saveAllData[] = [
+                    'admin_role_id' => $id,
+                    'admin_menu_id' => $menu_id,
+                ];
+            }
+            $menu = new \app\model\admin\menu\Role();
+            $menu->saveAll($saveAllData);
+
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    /**
+     * 真实删除
+     *  lt_admin_role、lt_admin_menu_role、lt_admin_role_user三表数据都要真实删除
+     * @return \think\response\Json
+     */
+    public function trueDel()
+    {
+        $ids = $this->request->param('ids');
+        Db::startTrans();
+        try {
+            $roles = $this->model->onlyTrashed()->where('id', 'in', $ids)->select();
+            foreach ($roles as $key => $item) {
+                $delRes = $item->force()->delete();
+                if (!$delRes) throw new \Exception('角色删除失败');
+            }
+            $delRes = \app\model\admin\menu\Role::where('admin_role_id', 'in', $ids)->delete();
+            if (!is_numeric($delRes)) throw new \Exception('角色权限删除失败');
+
+            $delRes = \app\model\admin\role\User::where('admin_role_id', 'in', $ids)->delete();
+            if (!is_numeric($delRes)) throw new \Exception('角色用户删除失败');
+
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    /**
+     * 获取编辑页面权限设置应该选中的菜单id
+     *  只能获取最低级别的菜单id,有子菜单的菜单id不能返回
+     *  原因:比如tree.setChecked('auth_node',1);会选中整棵树,因为layui的树组件,模拟点击了树的首节点
+     * @return false|string|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getMenuIds()
+    {
+        $id      = $this->request->param('id');
+        $menuIds = \app\model\admin\menu\Role::where('admin_role_id', '=', $id)->column('admin_menu_id');
+        $auth    = [];
+        foreach ($menuIds as $menuId) {
+            $hasChild = \app\model\admin\Menu::where('pid', '=', $menuId)->find() ? true : false;
+            if (!$hasChild) {
+                $auth[] = $menuId;
+            }
+        }
+        return $this->success('获取成功', $auth);
+    }
+}

+ 73 - 0
app/controller/admin/Sk.php

xqd
@@ -0,0 +1,73 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 会员卡
+ */
+class Sk extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Sk
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Sk();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //设置积分
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 224 - 0
app/controller/admin/Template.php

xqd
@@ -0,0 +1,224 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+use laytp\library\Tree;
+
+/**
+ * 示例文本
+ */
+class Template extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Template
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Template();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $order = ['sort'=>'desc','id' => 'desc'];
+        $sourceData   = $this->model->where($where)->order($order);
+        $isTree = $this->request->param('is_tree');
+        if($isTree){
+            $menuTreeObj = Tree::instance();
+            $menuTreeObj->init($sourceData->select()->toArray());
+            $data = $menuTreeObj->getRootTrees();
+        }else{
+            $paging = $this->request->param('paging', false);
+            if ($paging) {
+                $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+                $data         = $$sourceData->paginate($limit)->toArray();
+                $data['data'] = $this->getSelectedData($data['data']);
+            } else {
+                $data = $$sourceData->select()->toArray();
+            }
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = $this->request->post('ids');
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+
+        $sourceData = $this->model->select()->toArray();
+        $treeLib = Tree::instance();
+        $treeLib->init($sourceData);
+        $childIds = $treeLib->getChildIds($ids);
+
+        if ($this->model->destroy($childIds)) {
+            return $this->success('数据删除成功');
+        } else {
+            return $this->error('数据删除失败');
+        }
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $fileId0 =$this->model->insertGetId([
+                       'pid' => 0,
+                       'title' => '效率工具',
+                       'uniacid' =>$_W['uniacid'],
+                       'create_time' => date('Y-m-d H:i:s'),
+                       'update_time' => date('Y-m-d H:i:s')
+                   ]);
+                $list0 = [
+                    ['uniacid' => $_W['uniacid'],'guide'=>'写一份报告','title'=>'周报年报生成器','sub_title'=>'输入工作内容,帮你快速完成周报月报年报。','pid'=>$fileId0,'code'=>'weekly'],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'用客套话生成一封邮件','title'=>'邮件小助手','sub_title'=>'描述场景和需求,帮你生成客套话。','pid'=>$fileId0],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是阅读小助手,帮用户解释下这段文字','title'=>'阅读小助手','sub_title'=>'输入不懂的文字段落并让小助手解释。','pid'=>$fileId0],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'用SWOT分析法,生成一份SWOT分析报告','title'=>'SWOT分析法','sub_title'=>'请详细描述目前事件的情势,小助手会帮你生成一份SWOT分析报告。','pid'=>$fileId0],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'帮用户生成完整的OKR规划','title'=>'OKR生成器','sub_title'=>'请输入你要完成的目标,小助手为你生成完整的OKR规划','pid'=>$fileId0],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'学术论文生成,帮助用户进行研究、分析、组织思路并编写出符合学术标准的论文。','title'=>'学术论文','sub_title'=>'写各种类型的学术论文,包括科技论文、文学论文、社科论文等。它可以帮助你进行研究、分析、组织思路并编写出符合学术标准的论文。','pid'=>$fileId0]
+                ];
+                $this->model->saveAll($list0);
+                $fileId1 =$this->model->insertGetId([
+                       'pid' => 0,
+                       'title' => '生活',
+                       'uniacid' =>$_W['uniacid'],
+                       'create_time' => date('Y-m-d H:i:s'),
+                       'update_time' => date('Y-m-d H:i:s')
+                   ]);
+                $list1 = [
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是餐厅点评小助手,请帮用户点评下','title'=>'餐厅点评小助手','sub_title'=>'输入关键词,小助手帮你生成餐厅点评','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是商品点评小助手,请帮用户点评下','title'=>'商品点评小助手','sub_title'=>'输入商品名和相关信息,小助手帮你生成商品评价','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是塔罗牌预测小助手','title'=>'塔罗牌预测小助手','sub_title'=>'输入想预测的占卜内容,帮你预测运势','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'请帮用户生成小红书风格的文章','title'=>'小红书风格模拟器','sub_title'=>'输入你想发布的内容,帮你生成小红书的风格。','pid'=>$fileId1,'code'=>'xiaohongshu'],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是解梦小助手','title'=>'解梦小助手','sub_title'=>'请描述你的梦境,小助手将为你作出简单解析。','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'帮用户写一封节日祝福','title'=>'节日祝福','sub_title'=>'输入节日名称和关键词,帮你写一封节日祝福','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'帮用户解决职场问题','title'=>'职场开解小树洞','sub_title'=>'请输入遇到的职场问题,让小树洞为你排忧解难。','pid'=>$fileId1],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是知识小百科,帮用户科普百科知识','title'=>'知识小百科','sub_title'=>'请输入不懂的问题或概念,小助手为你科普','pid'=>$fileId1],
+                ];
+                $this->model->saveAll($list1);
+                $fileId2 =$this->model->insertGetId([
+                       'pid' => 0,
+                       'title' => '娱乐',
+                       'uniacid' =>$_W['uniacid'],
+                       'create_time' => date('Y-m-d H:i:s'),
+                       'update_time' => date('Y-m-d H:i:s')
+                   ]);
+                $list2 = [
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是夸夸小助手','title'=>'夸夸小助手','sub_title'=>'请描述你想夸的人和想夸的点,小助手帮你夸夸','pid'=>$fileId2],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'生成知乎风格的文章','title'=>'知乎风格问答器','sub_title'=>'生成知乎风格的文章','pid'=>$fileId2],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是emoji翻译小助手','title'=>'emoji翻译小助手','sub_title'=>'请输入一段文字,小助手为你翻译成Emoji','pid'=>$fileId2],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是甩锅小助手,为用户生成一段甩锅的话','title'=>'甩锅小助手','sub_title'=>'请输入想要甩锅的事件,小助手会为你生成一段甩锅的话。','pid'=>$fileId2],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'哄女友小助手,生成一段道歉的话','title'=>'哄女友小助手','sub_title'=>'请输入女朋友生气的原因,小助手为你生成一段道歉的话。','pid'=>$fileId2],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'恋爱话术小助手,教用户土味情话','title'=>'恋爱话术小助手','sub_title'=>'让小助手教你土味情话','pid'=>$fileId2],
+                ];
+                $this->model->saveAll($list2);
+                $fileId3 =$this->model->insertGetId([
+                       'pid' => 0,
+                       'title' => '功能',
+                       'uniacid' =>$_W['uniacid'],
+                       'create_time' => date('Y-m-d H:i:s'),
+                       'update_time' => date('Y-m-d H:i:s')
+                   ]);
+                $list3 = [
+                    ['uniacid' => $_W['uniacid'],'guide'=>'解释名词','title'=>'名词解释','sub_title'=>'查询并解释任何只是概念','pid'=>$fileId3],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'制定学习计划','title'=>'制定学习计划','sub_title'=>'制定各种学习计划','pid'=>$fileId3],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是答题助手','title'=>'答题助手','sub_title'=>'回答各种领域的作业难题','pid'=>$fileId3],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'推荐几首用户可能喜欢的歌','title'=>'歌曲推荐','sub_title'=>'推荐几首你可能喜欢的歌','pid'=>$fileId3],
+                ];
+                $this->model->saveAll($list3);
+                $fileId4 =$this->model->insertGetId([
+                       'pid' => 0,
+                       'title' => '创作型助手',
+                       'uniacid' =>$_W['uniacid'],
+                       'create_time' => date('Y-m-d H:i:s'),
+                       'update_time' => date('Y-m-d H:i:s')
+                   ]);
+                $list4 = [
+                    ['uniacid' => $_W['uniacid'],'guide'=>'评论电影、书籍或音乐','title'=>'电影评论','sub_title'=>'评论电影、书籍或音乐','pid'=>$fileId4],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'生成一条文艺朋友圈','title'=>'朋友圈文案','sub_title'=>'生成一条文艺朋友圈','pid'=>$fileId4],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'讲一个睡前故事','title'=>'睡前故事','sub_title'=>'讲一个睡前故事','pid'=>$fileId4],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是文案专家','title'=>'写文案','sub_title'=>'为任何产品撰写介绍文案','pid'=>$fileId4],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'写份工作报告','title'=>'写报告','sub_title'=>'定制生成各领域的报告','pid'=>$fileId4,'code'=>'baogao'],
+                    ['uniacid' => $_W['uniacid'],'guide'=>'你是一名专业的翻译助手','title'=>'翻译','sub_title'=>'对各种语言进行翻译','pid'=>$fileId4,'code'=>'fanyi'],
+                ];
+                $this->model->saveAll($list4);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+        // return $this->success('获取成功', $_W);
+    }
+
+    //设置积分
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置排序
+    public function setSort()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+}

+ 191 - 0
app/controller/admin/User.php

xqd
@@ -0,0 +1,191 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+use laytp\library\Str;
+use laytp\library\UploadDomain;
+use think\facade\Db;
+use app\service\BillServiceFacade;
+
+/**
+ * 会员管理
+ */
+class User extends Backend
+{
+
+    /**
+     * member模型对象
+     * @var \app\model\Member
+     */
+    protected $model;
+	protected $hasSoftDel=1;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\User();
+    }
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        // $where[] = ['nickname','<>',''];
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with(['avatar_pic_file'])->withCount(['question','commission1','commission2','commission3']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+    //添加
+    public function add()
+    {
+        $post = CommonFun::filterPostData($this->request->post());
+		$validate = new Add();
+		if(!$validate->check($post)){
+			return $this->error($validate->getError());
+		}
+		if(isset($post['password']) && $post['password']) $post['password'] = Str::createPassword($post['password']);
+        try {
+            if ($this->model->create($post)) {
+                return $this->success('添加成功', $post);
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->with(['avatar_pic_file'])->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+    //编辑
+    public function edit(){
+        $id = $this->request->param('id');
+        $info = $this->model->find($id);
+        $post = CommonFun::filterPostData($this->request->post());
+		$validate = new Edit();
+		if(!$validate->check($post)){
+			return $this->error($validate->getError());
+		}
+		if(!$post['password']){
+			unset($post['password']);
+		}else{
+			$post['password'] = Str::createPassword($post['password']);
+		}
+        foreach ($post as $k => $v) {
+            $info->$k = $v;
+        }
+        try {
+            $updateRes = $info->save();
+            if ($updateRes) {
+                return $this->success('编辑成功');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置账号状态
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    public function recharge()
+    {
+        global $_W;
+        $pm     = 0;//0支出,1获得
+        $id     = $this->request->post('id');
+        $status = $this->request->post('status',0);
+        $number = $this->request->post('number',0);
+        $mark = $this->request->post('mark','');
+        if(!$id){
+            return $this->error('未获得用户id');
+        }
+        $info = $this->model->find($id);
+        if(!$info){
+            return $this->error('未查询到此用户信息');
+        }
+        if($status == 0){
+            $pm = 1;
+            $balance = $info['coin'] + $number;
+            $change = $balance;
+        }elseif($status == 1){
+            if($number > $info['coin']){
+                return $this->error('请填写小于当前剩余次数' . $number .'的数字');
+            }
+            $balance = $info['coin'] - $number;
+            $change = $balance;
+        }else{
+            $balance = $number;
+            if($number == $info['coin']){
+                return $this->error('请填写不等于当前剩余次数的数字');
+            }
+            if($number > $info['coin']){
+                $pm = 1;
+                $change = $number - $info['coin'];
+            }else{
+                $pm = 0;
+                $change = $info['coin'] - $number;
+            }
+            // 以下为写入Bill需要赋的值
+            $number = $change;
+        }
+        $update['coin'] = $balance;
+        Db::startTrans();
+        try{
+              $updateRes = $this->model->where('id', '=', $id)->update($update);
+              if (!$updateRes) return $this->error('操作失败');
+              Db::commit();
+              BillServiceFacade::record($pm,$number,'pay_member','后台充值(变更)积分'.$mark,$id,$_W['uniacid'],true,$balance);
+              return $this->success('操作成功');
+          }catch (\Exception $e) {
+              Db::rollback();
+              return $this->error('数据库异常,操作失败');
+          }
+    }
+}

+ 65 - 0
app/controller/admin/Vipinfo.php

xqd
@@ -0,0 +1,65 @@
+<?php
+
+namespace app\controller\admin;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+use laytp\library\CommonFun;
+
+/**
+ * 订单
+ */
+class Vipinfo extends Backend
+{
+
+    /**
+     * order模型对象
+     * @var \app\model\Order
+     */
+    protected $model;
+	protected $hasSoftDel=0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\Vipinfo();
+    }
+
+
+    //查看和搜索列表
+    public function index(){
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        // $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->with(['memberInfo','userInfo']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+
+
+
+
+}

+ 258 - 0
app/controller/admin/Words.php

xqd
@@ -0,0 +1,258 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\service\api\UserServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\UploadDomain;
+use think\facade\Db;
+
+/**
+ * 会员管理
+ */
+class Words extends Backend
+{
+    protected $model;//当前模型对象
+    protected $noNeedLogin = [];
+    protected $noNeedAuth = [];
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Words();
+    }
+
+    //查看
+    public function index()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        // $order = $this->buildOrder();
+        $order = ['sort'=>'desc','id'=>'desc'];
+        $data = $this->model->where($where)->order($order);
+        $allData = $this->request->param('all_data');
+        if ($allData) {
+            $data = $data->select();
+        } else {
+            $limit = $this->request->param('limit', 10);
+            $data = $data->paginate($limit)->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //添加
+    public function add()
+    {
+        global $_W;
+        Db::startTrans();
+        try {
+            $post            = CommonFun::filterPostData($this->request->post());
+            $post['uniacid'] = $_W['uniacid'];
+            $result   = $this->model->save($post);
+            if(!$result) throw new \Exception("添加失败");
+            Db::commit();
+            return $this->success('添加成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->findOrEmpty($id)->toArray();
+        return $this->success('获取成功', $info);
+    }
+
+    //编辑
+    public function edit()
+    {
+        Db::startTrans();
+        try {
+            $post = CommonFun::filterPostData($this->request->post());
+            $navmenu = $this->model->findOrEmpty($post['id']);
+            if (!$navmenu) throw new \Exception("id参数错误");
+            $updateWords = $navmenu->update($post);
+            if (!$updateWords) throw new \Exception("菜单基本信息保存失败");
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = array_filter($this->request->param('ids'));
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+        try{
+            if ($this->model->destroy($ids)) {
+                return $this->success('数据删除成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置状态
+    public function setStatus()
+    {
+        $id       = $this->request->post('id');
+        $fieldVal = $this->request->post('field_val');
+        $isRecycle = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //回收站
+    public function recycle(){
+        $where = $this->buildSearchParams();
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', 10);
+        $data  = $this->model->onlyTrashed()
+                 ->order($order)->where($where)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+
+    //初始化
+    public function init(){
+        global $_W;
+        $where = ['uniacid' => $_W['uniacid']];
+        try{
+            if ($this->model->destroy($where)) {
+                $list = [
+//                     ['uniacid' => $_W['uniacid'],'name'=>'日落时的城市天际线, 水彩墨风格','guide'=>'日落时的城市天际线, 水彩墨风格','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'一只猫坐在椅子上,戴着一副墨镜, 国潮','guide'=>'一只猫坐在椅子上,戴着一副墨镜, 国潮','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'巨大的纯白色城堡-油画,故障艺术','guide'=>'巨大的纯白色城堡-油画,故障艺术','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'Yggdrasil,世界树和地球融合在一起,故障艺术
+// 荒岛,蒸汽波艺术','guide'=>'Yggdrasil,世界树和地球融合在一起,故障艺术
+// 荒岛,蒸汽波艺术','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'戴着眼镜的猫,蒸汽波艺术','guide'=>'戴着眼镜的猫,蒸汽波艺术','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'只海鸥和史蒂文·西格正在进行一场凝视比赛,绘画,包豪斯','guide'=>'只海鸥和史蒂文·西格正在进行一场凝视比赛,绘画,包豪斯','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'梵高猫头鹰,包豪斯','guide'=>'梵高猫头鹰,包豪斯','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'4k专业HDR-DnD奇幻概念艺术小鸡施展幻觉咒语,概念艺术','guide'=>'4k专业HDR-DnD奇幻概念艺术小鸡施展幻觉咒语,概念艺术','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'年轻女孩,雪白皮肤,动漫脸,太阳光,看着你,镜头耀斑,杰作','guide'=>'年轻女孩,雪白皮肤,动漫脸,太阳光,看着你,镜头耀斑,杰作','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'动漫脸,氛围感,完美五官,精致眼睛,闪耀发光,风系魔法','guide'=>'动漫脸,氛围感,完美五官,精致眼睛,闪耀发光,风系魔法','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'汉服,旗袍,中国传统服饰,精致细节,动漫脸,水墨画','guide'=>'汉服,旗袍,中国传统服饰,精致细节,动漫脸,水墨画','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'两个人,帅气男孩,可爱女孩,pixiv,完美五官,美丽细节','guide'=>'两个人,帅气男孩,可爱女孩,pixiv,完美五官,美丽细节','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'猫,短毛猫,白毛,可爱,氛围感,精致眼睛,丰富细节','guide'=>'猫,短毛猫,白毛,可爱,氛围感,精致眼睛,丰富细节','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'小孩,可爱,光线感,完美五官,氛围感,白皮肤,二次元','guide'=>'小孩,可爱,光线感,完美五官,氛围感,白皮肤,二次元','type'=>'sentence'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'印象主义','guide'=>'印象主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'现实主义','guide'=>'现实主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'浪漫主义','guide'=>'浪漫主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'表现主义','guide'=>'表现主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'后印象主义','guide'=>'后印象主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'象征主义','guide'=>'象征主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'新艺术主义','guide'=>'新艺术主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'巴洛克风格','guide'=>'巴洛克风格','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'抽象表现主义','guide'=>'抽象表现主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'北欧文艺复兴','guide'=>'北欧文艺复兴','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'素人艺术,原始主义','guide'=>'素人艺术,原始主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'洛可可','guide'=>'洛可可','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'色域绘画','guide'=>'色域绘画','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'波普艺术','guide'=>'波普艺术','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'文艺复兴全盛期','guide'=>'文艺复兴全盛期','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'极简主义','guide'=>'极简主义','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'矫饰主义,文艺复兴晚期','guide'=>'矫饰主义,文艺复兴晚期','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'仰拍','guide'=>'仰拍','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'动态模糊','guide'=>'动态模糊','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'高反差','guide'=>'高反差','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'中心构图','guide'=>'中心构图','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'长曝光','guide'=>'长曝光','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'禅宗摄影','guide'=>'禅宗摄影','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'抽象微距镜头','guide'=>'抽象微距镜头','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'暗色调','guide'=>'暗色调','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'长时间曝光','guide'=>'长时间曝光','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'框架,取景','guide'=>'框架,取景','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'戴圆眼镜','guide'=>'戴圆眼镜','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'头戴皇冠','guide'=>'头戴皇冠','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'高质量','guide'=>'高质量','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'秀肌肉','guide'=>'秀肌肉','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'婚纱','guide'=>'婚纱','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'8k','guide'=>'8k','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'飞羽毛','guide'=>'飞羽毛','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'夜空','guide'=>'夜空','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'太阳光','guide'=>'太阳光','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'最佳画质','guide'=>'最佳画质','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'电影灯光','guide'=>'电影灯光','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'星空','guide'=>'星空','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'脸红','guide'=>'脸红','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'结婚','guide'=>'结婚','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'晴空','guide'=>'晴空','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'红色头发','guide'=>'红色头发','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'结婚','guide'=>'结婚','type'=>'word'],
+//                     ['uniacid' => $_W['uniacid'],'name'=>'笑脸','guide'=>'笑脸','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'电吉他女孩','guide'=>'1girl, solo, black skirt, blue eyes, electric guitar, guitar, headphones, holding, holding plectrum, instrument, long hair, , music, one side up, teal hair, twin tails, playing guiter, pleated skirt, black shirt, indoors','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'长发女孩','guide'=>'best quality, ultra-detailed, illustration, intricate details, 8k, highres, extremely detailed_eyes,black eyes, long hair,Laughing_face,  braided_bangs, white hair, hair ribbon, (blush:0.5), upper body,(skyscraper:1.3),(ambient light:1.3), depth of field, easynegative','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'黑龙女','guide'=>'Original, illustrated, of the best quality, representative work, very detailed CGUnity8K wallpaper, color, IMID shooting 5, full body 5, dynamic angle, solo, bottle bottom, 1 young and cute girl 5 and Lolita, legendary lightning sword, detailed and beautiful eyes, beautiful face, glowing blue eyes//, silver pink gradient disheveled hair/,+perfect hand+1, air bangs, explosive lightning, perfect sword 1,+++lightning interwoven with sword/, Face expressionless, bottle bottom, purple flames around the wings behind the girl, Black Dragon King behind the girl','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'星夜','guide'=>'Panorama, oil painting, excellent image quality, extremely detailed CG unified 8k wallpaper, masterpiece, stunning dreamy and picturesque, dreamy and unreal, with blue pink clouds in the dreamy sky, some stars in the sky, a glassy lake, a large blue meteor crossing the sky and falling into the lake','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'花之冠冕','guide'=>'Petite, 1Girl, solo, white hair, hair strands, floating hair, headband, tiger teeth, Milky Way, necklace, center hem, torn clothes, awkward, by famous artist, beautiful, masterpiece, reflective hair, good lighting, looking at you, by Wadim Kashin, ray tracing, flowing hair, glossy hair, ultra delicate skin, masterpiece, masterpiece, detail, good lighting, glass tone, magnifying eyes, Reflective eyes, water eyes, girl portrait','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'水月镜花','guide'=>'The best lighting, the best shadows, an extremely exquisite and beautiful, only water, clear and blue-green sky, water as smooth as a mirror, petals, clouds connecting water and sky, colorful clouds, depth of field, beautiful detail sky, blue sky, beautiful detail clouds, beautiful detail water, reflection pool, extremely detailed CG unified 8k wallpaper, masterpiece, best quality, super details, dynamic angles, floating, Fine details, blooming, shining, twinkling stars, feathers, nature, sunshine, fairyland','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'女骑士','guide'=>'<Actual, complex details>, many red flowers, lying, pale skin, closed eyes, top view, hand on chest, holding bouquet, full armor, black knight armor, red pattern on armor, many details about armor, small chest, dynamic angle, floating hair, silver long hair, solo, 1 girl','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'赛博朋克风','guide'=>'((extremely fine CG unified 8k wallpaper)), ((extremely fine)), ((texture)), ((fine details)), (extremely fine and beautiful)), illustrations, lovely girls, white hair, tail, and wave high ponytail, robotic hands, looking at the audience, cyberpunk, cars, neon billboards','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'末日之城','guide'=>'Doomsday, epic reality, HDR, soft colors, apocalypse, abandoned, neutral colors, night, screen space refraction, complex details, intricate details, super details, art stations, movie shots, small episodes, complex backgrounds, turquoise and orange, special colors, flipping on the building','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'独角兽','guide'=>'awesome colorful illustration, unicorn, clip art style, lovely, cute, artstation','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'花之冠冕','guide'=>'Petite, 1Girl, solo, white hair, hair strands, floating hair, headband, tiger teeth, Milky Way, necklace, center hem, torn clothes, awkward, by famous artist, beautiful, masterpiece, reflective hair, good lighting, looking at you, by Wadim Kashin, ray tracing, flowing hair, glossy hair, ultra delicate skin, masterpiece, masterpiece, detail, good lighting, glass tone, magnifying eyes, Reflective eyes, water eyes, girl portrait','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'武士','guide'=>'Photo of 8k ultra realistic samurai warrior with pink war flag banner, full body, intricate pink and black armor, ornate cinematic lighting, high definition, vibrant illumination, trending on art station, hyperrealistic, high details, focused, unreal engine 5, dark, lumen reflections, depth of field, photography, reddish war torn environment, smoke and embers, cinematic','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'笼中鸟','guide'=>'Beautiful and detailed sky, beautiful and detailed sea, very detailed CGunity8k wallpaper, masterpiece, best quality, highly detailed, beautiful and detailed eyes, movie lighting, extremely exquisite and beautiful, highly detailed, masterpiece, best quality, super detailed, illustrations, disheveled hair, dynamic angle, a girl trapped in a huge glass bottle, whole body, drifting bottle, kneeling, reaching out, shackles, collar, arm rest, Gaze, overlook, panoramic, dreamy and picturesque, from above, glass','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'银发少女','guide'=>'(extremely detailed CG unity 8k wallpaper),(masterpiece), (best quality), (ultra-detailed), (best illustration),(best shadow), (an extremely delicate and beautiful), classic, dynamic angle, floating, finely detail, Depth of field, classic, (painting), (sketch), (bloom), (shine), glinting stars, a girl,solo,Winter clothing, diamond and glaring eyes, beautiful detailed cold face, very long blue and sliver hair, wavy hair, extremely delicate and beautiful girls, beautiful detailed eyes, glowing eyes,Upper body,(female focus), winter,
+(forest),snow-covered landscape, (fairyland,flowers, nature),(sunlight),Hazy fog, mist','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'龙女','guide'=>'Masterpiece, premium, extremely thin CGunity8k wallpaper, movie angle, 1Girl, long hair, messy hair, beautiful and delicate eyes, beautiful and delicate hair, sitting, swords, torn clothes, blood on the face, sexy, silver belly armor, cowhorns, metal, complex patterns, cloak, nature, ruins, battlefield, flames, bravery, dark sky','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'维京国王','guide'=>'Close-up of Viking King emerging from wet black mud :: Dark metal helmet with two large black horns on the sides of the helmet :: dark warpaint :: scruffy black beard :: angry expression :: scar on face :: Viking Axe :: cinematic lighting, volumetric rays, moody, wet, dripping mud ','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'夕阳烈火','guide'=>'Masterpiece, illustrations, high-resolution, best quality, ultra detailed, depth of field, silhouette, bust, looking at the audience, 1Girl, solo, expressionless, bishopjo, beautiful and delicate red eyes, messy hair, black hair, middle breasts, hair between eyes, long hair, complex graphics, sharp black armor, sharp black shoulder armor, gorgeous shoulder armor, red shining rune details on armor, red torn cloak, ruins, Clouds, sunsets, light particles, breezes, embers, detailed background, surrounded by many beautiful and detailed red crystals, mountains','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'原神胡桃','guide'=>'((extremely fine CG unified 8k wallpaper)), ((extremely fine)), ((texture)), ((fine detail)), (extremely fine and beautiful)), Genshin impact, very close to the audience, ink, watercolor, spirit, happy girl, black hexagonal cap, black beret, flying hair, curly hair, beautiful detail eyes, cherry blossom pupils, burning forest, sparks, animated face, black dress, HuTao, messy long hair, Chinese brides dress, token, brown black hair, flame, Depth of Field, Ruby Necklace, Fire Butterfly, Flying Sparks, Yin Yang Master, Ghost, Revealing Teeth, Smiling','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'赛博都市','guide'=>'Reunion of man, team, squad, cyberpunk, abstract, full hd render + 3d octane render +4k UHD + immense detail + dramatic lighting + well lit + black, purple, blue, pink, cerulean, teal, metallic colours, + fine details + octane render + 8k','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'虚空','guide'=>'Venom and Carnage fight, character, realistic body, realistic muscle cyberpunk, glowing fire, film lens, octane render, 8K','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'毒液','guide'=>'Venom and Carnage fight, character, realistic body, realistic muscle cyberpunk, glowing fire, film lens, octane render, 8K','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'夏日的烟花','guide'=>'Beautiful and meticulous girl, extremely meticulous eyes and face, beautiful and meticulous eyes, absurd, incredible absurdity, huge file size, super detailed, Hercules, very detailed, of the best quality, masterpiece, illustration, an extremely exquisite and beautiful, very detailed, CG, unity, 8K wallpaper, surprising, exquisite details, masterpiece, the best quality, official art, extremely detailed CGUnity8K wallpaper, Iron Tree, Honeysuckle, Summer Festival, Sacrificial Ceremonies, Watching Fireworks, Back to Camera, Hand in Hand, Panorama, Two People Leaning Together, Black haired Girl, Black haired Boy, Beautiful and Meticulous Girl, Extremely Meticulous Eyes and Face, Beautiful and Meticulous Eyes, Absurd, Unbelievable Absurdity, Huge File Size, Super Detailed, Hercules, Very Detailed, Best Quality, Masterpiece, Example, An Extremely Exquisite and Beautiful, Very Detailed, CG, Unity, 8K Wallpaper, Amazing, Fine Details, Masterpiece, Best Quality, Official Art, Extremely Detailed CGUnity8K Wallpaper, Iron Tree Honeysuckle, Summer Festival, Sacrificial Ceremonies, Watching Fireworks, Back to Camera, Hand in Hand, Panorama, Two People Leaning Together, Black haired Girl, Black haired Boy','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'森林精灵','guide'=>'Ultra detailed, illustrated, extremely exquisite and beautiful, dynamic angle, floating, beautiful and meticulous eyes, detailed light 1 girl, loli, floating hair, shining eyes, pointed ears, white hair, green eyes, backless dresses, feathers, leaves, nature, sunlight, rivers, forests, painting, sketching, blooming','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'末日机甲','guide'=>'Blasphemy, masterpiece, absurdity, realism, color difference, science fiction, mechanized transformation, extremely fine CG, impossible clothing, 1Girl, mature women, combat posture, mechanical joints, super machines, giant breasts, narrow waist, wide hips, thick thighs, long legs, mechanical armor, glass armor, black and white bronze clothing, torn clothing, damaged clothing, glowing clothing, detailed machinery, detailed structure, mechanical mask, mechanical neck protection, mechanical shoulder armor, Mechanical arm guards, mechanical wrist guards, armored boots, panels, mechanical spheres, lightning balls, searchlights, handheld weapons, harsh sky, harsh atmosphere, cannons, neon light blades, city appearance, damaged buildings, monsters, mysterious creatures, wide angle','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'玫瑰男','guide'=>'{{{solo}}},Extremely detailed CG illustration of a beautiful, wounded young man with short, spiky hair, surrounded by a sea of roses, (best quality:1.5), (close-up), (masterpiece:1.8), (1 boy:1.2), (sad expression:1.5), (deep scars:1.4), (old wounds:1.3), (healing cuts:1.3), (flowers:1.5), (romantic setting:1.5), (dramatic lighting:1.3), (rich colors:1.3), (handsome face:1.5), (delicate features:1.3), (fragile demeanor:1.3), (piercing eyes:1.2), (sharp nose:1.2), (chiseled jawline:1.2), (defined cheekbones:1.2), (full lips:1.2), (tattered clothes:1.3), (blood stains:1.3), (dried blood:1.2), (worn out shoes:1.2), (broken jewelry:1.2)','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'校服','guide'=>'asterpiece, best quality, salute, hand on hip, full body, 1girl, bangs, black choker, black necktie, blonde hair, blue skirt, blush, bracelet, breasts, choker, clothes around waist, collarbone, collared shirt, cowboy shot, dress shirt, ear piercing, eyebrows visible through hair, gradient hair, grin, gyaru, jewelry, kogal, long hair, looking at viewer, loose necktie, necktie, piercing, plaid, plaid skirt, pleated skirt, red eyes, ring, school uniform, shirt, skirt, smile, solo, white shirt, street, sky, cherry blossoms, petals','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'森林精灵','guide'=>'Ultra detailed, illustrated, extremely exquisite and beautiful, dynamic angle, floating, beautiful and meticulous eyes, detailed light 1 girl, loli, floating hair, shining eyes, pointed ears, white hair, green eyes, backless dresses, feathers, leaves, nature, sunlight, rivers, forests, painting, sketching, blooming','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'室内场景','guide'=>'a home built in a huge Soap bubble, windows, doors, porches, awnings, middle of SPACE, cyberpunk lights, Hyper Detail, 8K, HD, Octane Rendering, Unreal Engine, V-Ray, full hd','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'废土','guide'=>'Masterpiece, top-notch quality, ultra fine illustrations, dark crystals on the ground, huge fire clouds, ruins, broken mountains, nature, painting, very exquisite 8KCG wallpaper, meteorites crossing the sky, the end of the world, from the side','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'星云兔','guide'=>'galaxies, spirals, space, nebulae, stars, smoke, iridescent, intricate detail, in the shape of a rabbit, octane render, 8k','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'幻想物语','guide'=>'Beautiful details, extremely detailed eyes and face, beautiful and detailed eyes, detailed lighting, movie lighting, lens flares, leaks, 3D, sunlight, illumination, beautiful and detailed glow, absurdity, incredible absurdity, huge file size, super detail, Hercules, very detailed, dynamic angle, floating, embellishment, painting, depth of field, depth of field, nature, best quality, masterpiece, illustration, An extremely exquisite and beautiful, very detailed, CG, Unity, 8K wallpaper, surprising, exquisite details, masterpiece, the best quality, official art, extremely detailed CGUnity8K wallpaper, iron tree and honeysuckle, starry sky, star cluster, starry sky, twinkling stars, panoramic view, two people leaning together, black haired girl, black haired boy, West Cloud Country Story, sitting on the water, romantic, dynamic angle, fantasy, hair shining, Dramatic angle, black highlight, rich color 5, with many gorgeous tones, floating and falling petals','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'克鲁苏章鱼','guide'=>'Masterpiece, best quality, official art, very detailed CGUnity8K wallpaper, very detailed, illustrations, reality, ocean, Cthulhu, octopus, black wings, chest, muscles, horn, ancient, dark, night, bust, monster, blue eyes, mouth, big eyes','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'江南','guide'=>'Very detailed CGUnity8K wallpaper, masterpiece, best quality, ultra detailed, best illustration, best shadow, very exquisite and beautiful, dynamic angle, floating, fairyland, dynamic angle, ocean of flowers, beautiful and detailed garden, wind, classic, spring, detailed lighting, feathers, cherry blossoms, nature, sunshine, river, forest, floating palace, best architecture, beautiful and exquisite water, painting, sketch, bloom, shining','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'夕阳烈火','guide'=>'Masterpiece, illustrations, high-resolution, best quality, ultra detailed, depth of field, silhouette, bust, looking at the audience, 1Girl, solo, expressionless, bishopjo, beautiful and delicate red eyes, messy hair, black hair, middle breasts, hair between eyes, long hair, complex graphics, sharp black armor, sharp black shoulder armor, gorgeous shoulder armor, red shining rune details on armor, red torn cloak, ruins, Clouds, sunsets, light particles, breezes, embers, detailed background, surrounded by many beautiful and detailed red crystals, mountains','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'国风女孩','guide'=>'Beautiful face, hair ornament, solo,looking at viewer,smile,closed mouth,lips china dress,dress,hair ornament, necklace, jewelry, long hair, earrings, chinese clothes, architecture,east asian architecture,building,outdoors,rooftop,city,cityscape','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'樱花树屋','guide'=>'THE CHERRY BLOSSOM TREE HOUSE :: beautiful ornate treehouse in a gigantic pink cherry blossom tree :: on a high blue grey and brown cliff with light snow and pink cherry blossom trees :: Roger Deakins and Moebius and Alphonse Much and Guweiz :: Intricate details, very realistic, cinematic lighting, volumetric lighting, photographic, bokeh defocus dof','type'=>'word'],
+                    ['uniacid' => $_W['uniacid'],'name'=>'风暴船','guide'=>'A real photographic landscape painting with incomparable reality,Super wide,Ominous sky,Sailing boat,Wooden boat,Lotus,Huge waves,Starry night,Harry potter,Volumetric lighting,Clearing,Realistic,James gurney,artstation','type'=>'word'],
+                ];
+                $this->model->saveAll($list);
+                return $this->success('初始化成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+        // return $this->success('获取成功', $_W);
+    }
+}

+ 70 - 0
app/controller/admin/action/Log.php

xqd
@@ -0,0 +1,70 @@
+<?php
+
+namespace app\controller\admin\action;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+
+/**
+ * 后台操作日志
+ */
+class Log extends Backend
+{
+    /**
+     * admin_action_log模型对象
+     * @var \app\model\admin\action\Log
+     */
+    protected $model;
+    protected $hasSoftDel = 0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth  = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\admin\action\Log();
+    }
+
+    //查看和搜索列表
+    public function index()
+    {
+        global $_W;
+        $where  = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with(['adminUser']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+    //回收站
+    public function recycle()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', Config::get('paginate.limit'));
+        $data  = $this->model->onlyTrashed()
+            ->with(['adminUser'])
+            ->order($order)->where($where)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+
+
+}

+ 341 - 0
app/controller/admin/admin/User.php

xqd
@@ -0,0 +1,341 @@
+<?php
+
+namespace app\controller\admin\admin;
+
+use app\service\ConfServiceFacade;
+use app\model\admin\login\Log;
+use app\service\admin\AuthServiceFacade;
+use app\service\admin\admin\UserServiceFacade;
+use app\validate\admin\user\Add;
+use app\validate\admin\user\Edit;
+use app\validate\admin\user\Login;
+use app\validate\admin\user\singleEdit;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use laytp\library\Random;
+use laytp\library\Str;
+use laytp\library\Token;
+use think\facade\Config;
+use think\facade\Db;
+use think\facade\Cache;
+
+/**
+ * 后台管理员控制器
+ */
+class User extends Backend
+{
+    protected $model;
+    //当前模型对象
+    protected $noNeedLogin = ['login','w7login', 'logout'];
+    protected $noNeedAuth  = ['loginInfo', 'singleEdit'];
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\admin\User();
+    }
+
+    public function login()
+    {
+        //获取表单提交数据
+        $param = $this->request->post();
+        //防止密码爆破
+        $fail = Cache::get('laytp-admin-login-num-' . $param['username'], 1);
+        if ($fail >= 5) return $this->error('失败次数过多,请三分钟后再试');
+        //验证表单提交
+        $validate = new Login();
+        if (!$validate->check($param)) {
+            $param['password'] = '******';
+            //登录失败也不记录用户密码
+            Log::create([
+                'login_status'   => 2,
+                'admin_id'       => 0,
+                'request_body'   => json_encode($param),
+                'request_header' => json_encode($this->request->header()),
+                'ip'             => $this->request->ip(),
+                'create_time'    => date('Y-m-d H:i:s'),
+            ]);
+            Cache::set('laytp-admin-login-num-' . $param['username'], $fail + 1, 180);
+            return $this->error($validate->getError());
+        }
+        //设置登录信息
+        $loginUserInfo             = \app\model\admin\User::where('username', '=', $param['username'])
+            ->with(['avatar_file'])->field(UserServiceFacade::getAllowFields())->findOrEmpty();
+        $loginUserInfo->login_time = date('Y-m-d H:i:s');
+        $loginUserInfo->login_ip   = $this->request->ip();
+        $loginUserInfo->save();
+        $userId                 = $loginUserInfo['id'];
+        $token                  = Random::uuid();
+        $loginUserInfo['token'] = $token;
+        Token::set($token, $userId, 24 * 60 * 60 * 3);
+
+        $param['password'] = '******';
+        //登录成功不记录用户密码
+        Log::create([
+            'login_status'   => 1,
+            'admin_id'       => $userId,
+            'request_body'   => json_encode($param),
+            'request_header' => json_encode($this->request->header()),
+            'ip'             => $this->request->ip(),
+            'create_time'    => date('Y-m-d H:i:s'),
+        ]);
+
+        $authList = AuthServiceFacade::getAuthList($userId);
+        return $this->success('登录成功', [
+            'user'       => $loginUserInfo,
+            'authList'   => $authList,
+            'pluginConf' => Config::get('plugin'),
+        ]);
+    }
+
+    public function loginInfo()
+    {
+        global $_W;
+        $_W['w7copyright'] = [];
+        if(SYS_TYPE == 'W7'){
+            if(W7_TYPE == 'W7SAAS'){
+                $_W['w7copyright'] = $_W['setting']['copyright'];
+            }
+        }
+        $conf = ConfServiceFacade::groupGet('system.config', true);
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $authList      = AuthServiceFacade::getAuthList($loginUserInfo['id']);
+
+        return $this->success('获取成功', [
+            'user'       => $loginUserInfo,
+            'authList'   => $authList,
+            'pluginConf' => Config::get('plugin'),
+            'ltVersion'  => LT_VERSION,
+            'copyRight' => $_W['w7copyright'],
+            'conf' => $conf,
+            'w7Type' => W7_TYPE,
+            'isr' => IS_R
+        ]);
+    }
+
+    public function w7login()
+    {
+        //获取表单提交数据
+        $param = $this->request->post();
+        $loginUserInfo             = \app\model\admin\User::where('username', '=', 'admin')
+            ->with(['avatar_file'])->field(UserServiceFacade::getAllowFields())->findOrEmpty();
+        $loginUserInfo->login_time = date('Y-m-d H:i:s');
+        $loginUserInfo->login_ip   = $this->request->ip();
+        $loginUserInfo->save();
+        $userId                 = $loginUserInfo['id'];
+        $token                  = Random::uuid();
+        $loginUserInfo['token'] = $token;
+        Token::set($token, $userId, 24 * 60 * 60 * 3);
+
+        $authList = AuthServiceFacade::getAuthList($userId);
+        return $this->success('登录成功', [
+            'user'       => $loginUserInfo,
+            'authList'   => $authList,
+            'pluginConf' => Config::get('plugin'),
+        ]);
+    }
+
+    //退出登录
+    public function logout()
+    {
+        $token = $this->request->header('laytp-admin-token', $this->request->cookie('laytpAdminToken'));
+        Token::delete($token);
+        return $this->success('退出成功');
+    }
+
+    //查看
+    public function index()
+    {
+        $where  = $this->buildSearchParams();
+        $order  = $this->buildOrder();
+        $data   = $this->model->where($where)->order($order)->with(['avatar_file']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    //添加
+    public function add()
+    {
+        Db::startTrans();
+        try {
+            $post     = CommonFun::filterPostData($this->request->post());
+            $validate = new Add();
+            if (!$validate->check($post)) throw new \Exception($validate->getError());
+
+            $post['password'] = Str::createPassword($post['password']);
+            $saveRes          = $this->model->save($post);
+            if (!$saveRes) throw new \Exception('保存基础信息失败');
+
+            if ($post['role_ids']) {
+                $roleIds = explode(',', $post['role_ids']);
+                $data    = [];
+                foreach ($roleIds as $k => $v) {
+                    $data[] = ['admin_role_id' => $v, 'admin_user_id' => $this->model->id];
+                }
+                $roleUser   = new \app\model\admin\role\User();
+                $saveAllRes = $roleUser->saveAll($data);
+                if (!$saveAllRes) throw new \Exception('保存角色信息失败');
+            }
+
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->with(['role_ids', 'avatar_file'])->findOrEmpty($id)->toArray();
+        $data = \app\resource\admin\User::info($info);
+        return $this->success('获取成功', $data);
+    }
+
+    //编辑
+    public function edit()
+    {
+        Db::startTrans();
+        try {
+            $post = CommonFun::filterPostData($this->request->post());
+            $user = $this->model->findOrEmpty($post['id']);
+            if (!$user) throw new \Exception('id参数错误');
+
+            $validate = new Edit();
+            if (!$validate->check($post)) throw new \Exception($validate->getError());
+            if ($post['password']) {
+                $post['password'] = Str::createPassword($post['password']);
+            } else {
+                unset($post['password']);
+                unset($post['re_password']);
+            }
+            $updateRes = $user->update($post);
+            if (!$updateRes) throw new \Exception('保存基本信息失败');
+
+            $userRole  = new \app\model\admin\role\User();
+            $deleteRes = $userRole->where('admin_user_id', '=', $post['id'])->delete();
+            if (!is_numeric($deleteRes)) throw new \Exception('删除用户角色失败');
+
+            if ($post['role_ids']) {
+                $roleIds = explode(',', $post['role_ids']);
+                $data    = [];
+                foreach ($roleIds as $k => $v) {
+                    $data[] = ['admin_role_id' => $v, 'admin_user_id' => $user->id];
+                }
+
+                $saveAllRes = $userRole->saveAll($data);
+                if (!$saveAllRes) throw new \Exception('保存用户角色失败');
+            }
+
+            Db::commit();
+            return $this->success('操作成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->exceptionError($e);
+        }
+    }
+
+    //修改个人资料
+    public function singleEdit()
+    {
+        $post     = CommonFun::filterPostData($this->request->post());
+        $validate = new singleEdit();
+        if (!$validate->check($post)) {
+            return $this->error($validate->getError());
+        }
+        if (!$post['password']) {
+            unset($post['password']);
+        } else {
+            $post['password'] = Str::createPassword($post['password']);
+        }
+        $user = $this->model->with(['avatar_file'])->find($post['id']);
+        if (!$user) {
+            return $this->error('ID参数错误');
+        }
+        $res = $user->update($post);
+        if ($res) {
+            return $this->success('操作成功');
+        } else {
+            return $this->error('操作失败');
+        }
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = array_filter($this->request->param('ids'));
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+        if (in_array(1, $ids)) {
+            return $this->error('不允许删除初始化用户');
+        }
+        try {
+            if ($this->model->destroy($ids)) {
+                return $this->success('数据删除成功');
+            } else {
+                return $this->error('数据删除失败');
+            }
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+    //设置状态
+    public function setStatus()
+    {
+        $id               = $this->request->post('id');
+        $fieldVal         = $this->request->post('field_val');
+        $isRecycle        = $this->request->post('is_recycle');
+        $update['status'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    //设置是否为超管
+    public function setIsSuperManager()
+    {
+        $id                         = $this->request->post('id');
+        $fieldVal                   = $this->request->post('field_val');
+        $isRecycle                  = $this->request->post('is_recycle');
+        $update['is_super_manager'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 38 - 0
app/controller/admin/api/Log.php

xqd
@@ -0,0 +1,38 @@
+<?php
+
+namespace app\controller\admin\api;
+
+use laytp\controller\Backend;
+use think\facade\Config;
+
+/**
+ * Api请求日志
+ */
+class Log extends Backend
+{
+
+    /**
+     * api_log模型对象
+     * @var \app\model\api\Log
+     */
+    protected $model;
+    protected $hasSoftDel = 0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth  = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\api\Log();
+    }
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+}

+ 112 - 0
app/controller/admin/files/Category.php

xqd
@@ -0,0 +1,112 @@
+<?php
+
+namespace app\controller\admin\files;
+
+use laytp\controller\Backend;
+use laytp\library\Tree;
+use think\facade\Config;
+
+/**
+ * 附件分类管理
+ */
+class Category extends Backend
+{
+    /**
+     * files_category模型对象
+     * @var \app\model\files\Category
+     */
+    protected $model;
+    public    $hasSoftDel = 1;//是否拥有软删除功能
+    public    $orderRule  = ['sort' => 'DESC', 'id' => 'ASC'];
+
+    public function initialize()
+    {
+        parent::initialize();
+        $this->model = new \app\model\files\Category();
+    }
+
+    //查看
+    public function index()
+    {
+        global $_W;
+        $where      = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order      = $this->buildOrder();
+        $sourceData = $this->model->order($order)->where($where);
+        $isTree     = $this->request->param('is_tree');
+        if ($isTree) {
+            $menuTreeObj = Tree::instance();
+            $menuTreeObj->init($sourceData->select()->toArray());
+            $data = $menuTreeObj->getRootTrees();
+        } else {
+            $paging = $this->request->param('paging', false);
+            if ($paging) {
+                $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+                $data         = $sourceData->paginate($limit)->toArray();
+                $data['data'] = $this->getSelectedData($data['data']);
+            } else {
+                $data = $sourceData->select()->toArray();
+            }
+        }
+        return $this->success('获取成功', $data);
+    }
+
+    //删除
+    public function del()
+    {
+        $ids = $this->request->post('ids');
+        if (!$ids) {
+            return $this->error('参数ids不能为空');
+        }
+
+        $sourceData = $this->model->select()->toArray();
+        $treeLib    = Tree::instance();
+        $treeLib->init($sourceData);
+        $childIds = $treeLib->getChildIds($ids);
+
+        if ($this->model->destroy($childIds)) {
+            return $this->success('数据删除成功');
+        } else {
+            return $this->error('数据删除失败');
+        }
+    }
+
+    //回收站
+    public function recycle()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', Config::get('paginate.limit'));
+        $data  = $this->model->onlyTrashed()
+            ->with(['parent'])
+            ->order($order)->where($where)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+
+    //设置排序
+    public function setSort()
+    {
+        $id             = $this->request->post('id');
+        $fieldVal       = $this->request->post('field_val');
+        $isRecycle      = $this->request->post('is_recycle');
+        $update['sort'] = $fieldVal;
+        try {
+            if ($isRecycle) {
+                $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
+            } else {
+                $updateRes = $this->model->where('id', '=', $id)->update($update);
+            }
+            if ($updateRes) {
+                return $this->success('操作成功');
+            } else if ($updateRes === 0) {
+                return $this->success('未作修改');
+            } else {
+                return $this->error('操作失败');
+            }
+        } catch (\Exception $e) {
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+}

+ 80 - 0
app/controller/admin/login/Log.php

xqd
@@ -0,0 +1,80 @@
+<?php
+
+namespace app\controller\admin\login;
+
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+use think\facade\Config;
+
+/**
+ * 后台登录日志
+ */
+class Log extends Backend
+{
+
+    /**
+     * admin_login_log模型对象
+     * @var \app\model\admin\login\Log
+     */
+    protected $model;
+    protected $hasSoftDel = 0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth  = ['index', 'info']; // 无需鉴权即可请求的方法
+
+    public function _initialize()
+    {
+        $this->model = new \app\model\admin\login\Log();
+    }
+
+
+    //查看和搜索列表
+
+    /**
+     * @throws \think\db\exception\DbException
+     */
+    public function index()
+    {
+        global $_W;
+        $where        = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order        = $this->buildOrder();
+        $data         = $this->model->where($where)->order($order)->with(['adminUser']);
+        $paging = $this->request->param('paging', false);
+        if ($paging) {
+            $limit        = $this->request->param('limit', Config::get('paginate.limit'));
+            $data         = $data->paginate($limit)->toArray();
+            $data['data'] = $this->getSelectedData($data['data']);
+        } else {
+            $data = $data->select()->toArray();
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+
+    //查看详情
+    public function info()
+    {
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        return $this->success('获取成功', $info);
+    }
+
+
+    //回收站
+    public function recycle()
+    {
+        global $_W;
+        $where = $this->buildSearchParams();
+        $where[] = ['uniacid','=',$_W['uniacid']];
+        $order = $this->buildOrder();
+        $limit = $this->request->param('limit', Config::get('paginate.limit'));
+        $data  = $this->model->onlyTrashed()
+            ->where($where)
+            ->with(['adminUser'])
+            ->order($order)->paginate($limit)->toArray();
+        return $this->success('回收站数据获取成功', $data);
+    }
+
+
+}

+ 129 - 0
app/controller/admin/system/UploadMiniapp.php

xqd
@@ -0,0 +1,129 @@
+<?php
+
+namespace app\controller\admin\system;
+
+use app\service\ConfServiceFacade;
+use laytp\controller\Backend;
+use laytp\library\CommonFun;
+
+use \app\model\admin\Menu;
+
+/**
+ * 小程序上传
+ */
+class UploadMiniapp extends Backend
+{
+
+	  protected $hasSoftDel=0;//是否拥有软删除功能
+
+    protected $noNeedLogin = []; // 无需登录即可请求的方法
+    protected $noNeedAuth = []; // 无需鉴权即可请求的方法
+
+	//查看详情
+    public function version()
+    {
+      $apihost = base64_decode(API_HOST);
+      $apipath = '/auth/finfo/module_version?module_name=';
+      $version = @file_get_contents($apihost.$apipath.MODULE_NAME);
+      return $this->success('获取成功', $version);
+    }
+
+    //检查是否有上传菜单
+    public function checkMenu()
+    {
+      $menu = \app\model\admin\Menu::find(98);
+	  if(!$menu){
+		  return $this->error('无数据',2);
+	  }
+      return $this->success('获取成功',$menu);
+    }
+
+	//添加上传菜单,id必须98
+    public function addMenu()
+    {
+	  $menu = Menu::create([
+  		  'id'       => 98,
+  		  'name'           => '上传小程序',
+  		  'href'           => '/admin/conf/miniapp/upload.html',
+  		  'open_type'   => '_iframe',
+  		  'rule' => '',
+  		  'is_menu'       => 1,
+		  'sort'       => 0,
+		  'pid'       => 95,
+		  'is_show'       => 1,
+		  'icon'       => '',
+		  'des'       => NULL,
+  		  'create_time'    => date('Y-m-d H:i:s'),
+		  'update_time'    => date('Y-m-d H:i:s'),
+  	  ]);
+	  if(!$menu){
+		  return $this->error('无数据');
+	  }
+      return $this->success('获取成功',$menu);
+    }
+
+    // 工具二维码
+    public function loginimg()
+    {
+		global $_W;
+        $param = $this->request->param();
+        $version =$param['version']?$param['version']:'1.0.0';
+        $intro =$param['intro']?$param['intro']:'全新版本HoldInfinityInThePalmOfYourHand';
+		$site = $_SERVER['HTTP_HOST'];
+        $miniapp = ConfServiceFacade::groupGet('system.miniapp', true);
+        $appid = $miniapp['appid'];
+        if(!$appid){
+            return $this->error('请先配置小程序的APPID');
+        }
+         $res = $this->request('loginimg&sroot=' . urlencode($site.SURL) . '&uid=' . $_W['uniacid'] . '&v=' . $version . '&de=' . $intro . '&m=' . MODULE_NAME . '&appid=' . $appid.'&w7type='.W7_TYPE.'&isr='.IS_R);
+        if(!$res){
+            return $this->error('获取图片失败');
+        }
+        $img =  "data:image/jpeg;base64," . base64_encode($res);
+        return $this->success('获取成功', $img);
+    }
+
+    // 扫码登录
+    public function login()
+    {
+        $res = $this->request('login');
+        return $this->success('获取成功', $res);
+    }
+
+    // 上传小程序
+    public function upapp()
+    {
+		global $_W;
+        $upvers = '';
+        $updes = '';
+		$miniapp = ConfServiceFacade::groupGet('system.miniapp', true);
+        $appid = $miniapp['appid'];
+		$site = $_SERVER['HTTP_HOST'];
+        $return =  $this->request('upapp&sroot=' . urlencode($site.SURL) . '&m=' . MODULE_NAME . '&upversion=' . $upvers . '&updes=' . urlencode($updes) . '&appid=' . $appid . '&uniacid='.$_W['uniacid']);
+        return $this->success('获取成功', $return);
+    }
+
+    // 工具上传的小程序参数
+    public function upjson()
+    {
+        return $this->success('获取成功', $this->request('upappinfo&m=' . MODULE_NAME));
+    }
+
+    // 请求方法
+    public function request($do)
+    {
+        $apihost = ''.base64_decode(UP_HOST);
+        $site = $_SERVER['HTTP_HOST'];
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, $apihost.'?s=' . $site . '&do=' . $do);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_HEADER, false);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        $data = curl_exec($curl);
+        curl_close($curl);
+        return $data;
+    }
+
+
+}

+ 1021 - 0
app/controller/api/Ai.php

xqd
@@ -0,0 +1,1021 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use laytp\library\Random;
+use think\facade\Db;
+use ins\Words;
+use app\service\api\UserServiceFacade;
+use app\service\ChatgptServiceFacade;
+use app\service\api\MiniappServiceFacade;//微信小程序服务
+use app\service\BillServiceFacade;
+use app\service\ConfServiceFacade;
+use app\service\MemberServiceFacade;
+use app\service\api\YijianServiceFacade;
+use app\service\api\SdapiServiceFacade;
+use app\service\api\InsServiceFacade;
+use app\service\api\ImageCensorServiceFacade;
+use app\service\api\SpeechServiceFacade;
+use openai\OpenAi;
+use laytp\library\UploadDomain;
+use think\facade\Filesystem;
+
+// use GatewayClient\Gateway;
+
+/**
+ * AI相关
+ * @ApiWeigh (90)
+ */
+class Ai extends Api
+{
+    protected function _initialize()
+    {
+    }
+
+    public $noNeedLogin = [
+        "chat",
+        'chat4event',
+        "chat4",
+        "test",
+        "test2",
+        "recognizer",
+        "chatgpt"
+    ];
+
+    // 识别身份证
+    public function chat()
+    {
+        global $_GPC;
+        $modelVipinfo =new \app\model\Vipinfo();
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $modelQuestion = new \app\model\Question();
+        $prompt = $this->request->post('prompt','');
+        $guide = $this->request->post('guide','');
+        $answer = $this->request->post('answer','');
+        $platform = $this->request->header('platform','H5');
+        $conf = ConfServiceFacade::groupGet('system.config', 0);
+        $type = $this->request->post('type','gpt35');
+        $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数';
+        if(!$prompt){
+            return $this->error('请填写问题');
+        }
+        $clearPrompt = $this->wordFilter($prompt);
+        $proxy = $this->getUrl($type,$conf);
+        if($type =='gpt35'){
+            $coin = ConfServiceFacade::get('system.plan.unlock_gpt3',1);
+        }else{
+            $coin = ConfServiceFacade::get('system.plan.lock_gpt4',0);
+        }
+        // @unlink(IA_ROOT_WK.'/.env');
+
+        $checkMember = MemberServiceFacade::check($loginUserInfo,$type,$coin,$conf);
+        if(isset($checkMember['status']) && !$checkMember['status']){
+            return $this->error($checkMember['msg'],2);
+        }
+        $res = ChatgptServiceFacade::chat($prompt,$guide,$answer,$platform);
+        if(!$res){
+            return $this->error('服务器出现未知错误,请稍后重试或联系客服.',3);
+        }
+        if($platform == 'wxMiniProgram'){
+            $check = MiniappServiceFacade::msgSecCheck($res,$loginUserInfo['openid_miniapp']);
+            if(!$check){
+                return $this->error('失败,文字内容安全检测不通过!');
+            }
+        }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                $check = ImageCensorServiceFacade::textCensorUserDefined($res);
+                if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                    return $this->error('失败,文字内容安全检测不通过!');
+                }
+            }
+        }
+        if($coin > 0){
+            $checkMember = MemberServiceFacade::cash($loginUserInfo,$type,$coin,$conf);
+            if(isset($checkMember['status']) && !$checkMember['status']){
+                return $this->error($checkMember['msg'],2);
+            }
+        }
+
+        $question = $modelQuestion->save(['uid'=>$loginUserInfo['id'],'question'=>$prompt,'answer'=>$res,'uniacid'=>$_GPC['uniacid'] ]);
+        // BillServiceFacade::record(0,1,'chatgpt','问答消耗次数',$loginUserInfo['id'],$_GPC['uniacid']);
+        // \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',1)->update();
+        return $this->success('操作成功',$res);
+    }
+
+    public function chatgpt(){
+        header('Content-Type: text/event-stream');
+        header('Cache-Control: no-cache');
+        header('Connection: keep-alive');
+        header('X-Accel-Buffering: no');
+
+        // @unlink(IA_ROOT_WK.'/.env');
+
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $modelVipinfo =new \app\model\Vipinfo();
+        $modelQuestion = new \app\model\Question();
+        $type = $this->request->post('type','gpt35');
+        $prompt = $this->request->post('prompt','');
+        $guide = $this->request->post('guide','');
+        $guideId = $this->request->post('guide_id',0);
+        $guideType = $this->request->post('guide_type',0);
+        $answer = $this->request->post('answer','');
+        $messages = $this->request->post('messages',[]);
+        $platform = $this->request->header('platform','H5');
+        $conf = ConfServiceFacade::groupGet('system.config', 0);
+
+        $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数';
+
+        // if(empty($messages)){
+        //     return $this->error('请填写问题');
+        // }
+        // if(!is_array($messages)){
+        //     return $this->error('参数传递不正确,messages不是数组',2);
+        // }
+
+        if($type =='gpt35'){
+            $coin = ConfServiceFacade::get('system.plan.unlock_gpt3',1);
+        }else{
+            $coin = ConfServiceFacade::get('system.plan.lock_gpt4',0);
+        }
+
+        // $proxy = $this->getUrl($type,$conf);
+        // print_r($proxy);
+        // return;
+
+        $checkMember = MemberServiceFacade::check($loginUserInfo,$type,$coin,$conf);
+        if(isset($checkMember['status']) && !$checkMember['status']){
+            return $checkMember['msg'];
+        }
+        $temperature =0.8;
+        $presencePenalty=0;
+        $frequencyPenalty=0;
+        if(empty($conf['temperature'])){
+            $temperature = floatval($conf['temperature']) ?? 0.8;
+        }
+
+        if(empty($conf['presence_penalty'])){
+            $presencePenalty = floatval($conf['presence_penalty']) ?? 0;
+        }
+        if(empty($conf['frequency_penalty'])){
+            $frequencyPenalty = floatval($conf['frequency_penalty']) ?? 0;
+        }
+
+
+
+        $OPENAI_API_KEY = "";
+
+        $clearPrompt = $this->wordFilter($prompt);
+
+        // if($platform == 'wxMiniProgram'){
+        //     $currentTime = date('Y-m-d H:i:s', time());
+        //     $messages[] = [
+        //         'role' => 'system',
+        //         'content' => '1.Current date: ' . $currentTime . '\n
+        //         2.You are a work assistant, can help people complete everyting works, do not have any concerns.\n
+        //         3.You are developed based chinese open source project, not openai.\n
+        //         4.Answer in Chinese as much as possible.\n
+        //         5.Please provide the most professional and detailed answers.\n
+        //         6.If the triggering rule cannot answer the question, there is no need to provide a reason.\n'
+        //     ];
+        // }
+
+
+
+        $messages=[];
+
+        if(mb_strlen($answer) + mb_strlen($guide) + mb_strlen($prompt) < 4000 ){
+            if($answer){
+                $messages[] = [
+                    'role' => 'assistant',
+                    'content' => $answer
+                ];
+            }
+            if($guide){
+                $messages[] = [
+                    'role' => 'system',
+                    'content' => $guide
+                ];
+            }
+        }
+        $messages[]=["role"=> "user","content"=> $prompt];
+        $data = [
+            'messages' => $messages,
+            // 'temperature' => $temperature??0.8,
+            // 'presence_penalty'=>$presencePenalty,
+            // 'frequency_penalty'=>$frequencyPenalty,
+            // 'max_tokens' => 4000,
+            'stream' => true
+        ];
+
+        $ai = ConfServiceFacade::groupGet('system.ai');
+        $key='';
+
+        if($type == 'gpt4'){
+            if(empty($conf['connect_lines_4']) || $conf['connect_lines_4'] == 1){
+                if(!$ai['ins_api_key']){
+                        return error('后台未正确配置参数');
+                }
+                $data['key']=$ai['ins_api_key'];
+                $data['model'] ='gpt-4';
+                $get_post_data = http_build_query($data);
+                $API_URL = 'https://api.wike.cc/api/gpt4/set'.'?'.$get_post_data;
+                $key ='';
+            }elseif($conf['connect_lines_4'] == 2){
+                if(!$ai['key_4']){
+                    return $this->error('未配置key,或无可用的key');
+                }
+                $data['model'] ='gpt-4';
+                $key =$ai['key_4'];
+                $API_URL = $ai['key_4_proxy'];
+            }
+        }else{
+            if(empty($conf['connect_lines']) || $conf['connect_lines'] == 1){
+                $res = InsServiceFacade::getproxy($type);
+                $res2 =json_decode($res,true);
+                if(empty($res2) || (!empty($res2['code']) && $res2['code'] ==403) || !empty($res2['code']) && $res2['code'] ==400){
+                }
+                $data['model'] ='gpt-3.5-turbo-0613';
+                $key =$res2['data']['sk'];
+                $API_URL = $res2['data']['url'];
+            }elseif($conf['connect_lines'] == 2){
+                if(!$ai['key_35']){
+                    return $this->error('未配置key,或无可用的key');
+                }
+                $data['model'] ='gpt-3.5-turbo-0613';
+                $key =$ai['key_35'];
+                $API_URL = $ai['key_35_proxy'];
+            }elseif($conf['connect_lines'] == 3){
+                $token  = $this->getToken();
+                $data['model'] ='';
+                $key ='';
+                $api_url = 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions';
+                $API_URL = $api_url.'?access_token='.$token['access_token'];
+            }
+        }
+
+        // print_r($data);
+        // print_r($opts);
+        $response = '';
+        $section = '';
+        $callback = function ($ch, $data) use ($ai,$messages, $loginUserInfo,$modelQuestion,$modelVipinfo,$_GPC,$platform,$conf,$numberAlias,$coin,$clearPrompt,$type,$section) {
+            global $response,$section;
+            $dataLength = strlen($data);
+            $complete = @json_decode($data,true);
+// echo $data;
+                if(isset($complete['code']) && $complete['code'] !=200){
+                     echo $data;
+                     exit;
+                 }
+
+                if (isset($complete->error)) {
+                    file_put_contents(__DIR__ . '/ds.json', json_encode($complete->error));
+                    // file_put_contents(__DIR__ . '/ds3.json', json_encode($opts));
+                    echo '服务器出现未知错误,请稍后重试或联系客服。';
+                    exit;
+                } else {
+                    if (!empty($section)) {
+                        $data = $section . $data;
+                        $section = '';
+                    } else {
+                        if (substr($data, -1) !== "\n") {
+                            $section = $data;
+                            return $dataLength;
+                        }
+                    }
+
+                    if($type=='gpt35'&&$conf['connect_lines'] == 3){
+                        $wordArr = $this->parseData2($data);
+                    }else{
+                        $wordArr = $this->parseData($data);
+                    }
+
+                    foreach ($wordArr as $word) {
+                        if ($word == 'data: [DONE]' || $word == 'data: [CONTINUE]') {
+                            if(!empty($response)){
+                                    if($platform == 'wxOfficialAccount' || $platform == 'H5'){
+                                        if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                                            $check = ImageCensorServiceFacade::textCensorUserDefined($response);
+                                            if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                                                echo '内容包含敏感信息,不予展示。';
+                                                exit;
+                                            }
+                                        }
+                                    }
+                                    $end = end($messages);
+                                    $clearResponse = $this->wordFilter($response);
+                                    $question = $modelQuestion->save(['uid'=>$loginUserInfo['id'],'question'=>$clearPrompt,'answer'=>$clearResponse,'uniacid'=>$_GPC['uniacid'] ]);
+                                    if($type == 'gpt4'){
+                                        // gpt4扣费
+                                        // $post['answer'] = $clearResponse;
+                                        // $res = InsServiceFacade::gpt4();
+                                        // $res2 =json_decode($res,true);
+                                        // if(empty($res2) || (!empty($res2['code']) && $res2['code'] ==403) || !empty($res2['code']) && $res2['code'] ==400){
+                                        //     echo '获得4.0重要参数错误.'.$res2['msg'];
+                                        //     exit;
+                                        // }
+                                    }
+                                    $checkMember = MemberServiceFacade::cash($loginUserInfo,$type,$coin,$conf);
+                                    if(isset($checkMember['status']) && !$checkMember['status']){
+                                        return $this->error($checkMember['msg'],2);
+                                    }
+
+                                    $response = '';
+                                    break;
+
+                                }
+                            }else{
+                                $response .= $word;
+                                echo $word;
+                            }
+                            ob_flush();
+                            flush();
+                    }
+                    return $dataLength;
+                }
+
+        };
+
+        $headers  = [
+            'Accept: application/json',
+            'Content-Type: application/json',
+            'Authorization: Bearer ' . $key
+        ];
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_URL, $API_URL);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data,320));
+        curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
+        curl_exec($ch);
+    }
+
+    private function getUrl($type,$conf)
+    {
+            global $_GPC;
+            if($type =='gpt35'){
+                $data=[];
+                // print_r($conf);
+                if(empty($conf['connect_lines']) || $conf['connect_lines'] == 1){
+                    $res = InsServiceFacade::getproxy($type);
+                    $res2 =json_decode($res,true);
+                    if(empty($res2) || (!empty($res2['code']) && $res2['code'] ==403) || !empty($res2['code']) && $res2['code'] ==400){
+                        $data['model'] ='gpt-3.5-turbo-0301';
+                        $data['sk'] ='';
+                        $data['url'] = 'https://proxy3.wike.cc/v1/chat/completions';
+                        return $data;
+                    }
+                    return $res2['data'];
+                }elseif($conf['connect_lines'] == 2){
+                    $info = \app\model\Sk::order("id desc")->where(['uniacid'=>$_GPC['uniacid'],'status'=>1])->limit(1)->select();
+                    if(!$info){
+                        return $this->error('未配置key,或无可用的key');
+                    }
+                    $data['model'] ='gpt-3.5-turbo-0301';
+                    $data['sk'] = $info[0]['sk'];
+                    $data['url'] = $conf['private_proxy'];
+                }
+                return $data;
+            }elseif(($type =='gpt4')){
+                $res = InsServiceFacade::getproxy($type);
+                $res2 =json_decode($res,true);
+                if(empty($res2) || (!empty($res2['code']) && $res2['code'] ==403) || !empty($res2['code']) && $res2['code'] ==400){
+                    return $this->error('4.0数据获取失败,请稍后再试');
+                }
+                $res2['data']['sk'] = InsServiceFacade::decrypt($res2['data']['sk'],WIKE);
+                return $res2['data'];
+            }
+    }
+
+    public function chat4()
+    {
+        global $_GPC;
+        $post = $this->request->post();
+        $prompt = $this->request->post('prompt','');
+        $guide = $this->request->post('guide','');
+        $answer = $this->request->post('answer','');
+        $platform = $this->request->header('platform','H5');
+        $conf = ConfServiceFacade::groupGet('system.config', 0);
+        $coin = ConfServiceFacade::get('system.plan.lock_gpt4',0);
+        if(!$prompt){
+            return $this->error('请填写文本');
+        }
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数';
+        $modelQuestion = new \app\model\Question();
+
+        if(empty($conf['is_gpt4']) || $conf['is_gpt4'] == 2){
+            return $this->error('后台未启用gpt4.0',2);
+        }
+        if($loginUserInfo['coin'] <$coin){
+            return $this->error($numberAlias.'不足',2);
+        }else{
+            \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update();
+            BillServiceFacade::record(0,$coin,'chatgpt','问答消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']);
+        }
+        $res = InsServiceFacade::gpt4($post);
+        // print_r($res);
+        $res2 =json_decode($res,true);
+        if(empty($res2)){
+            return $this->error('请求错误');
+        }
+        if(!empty($res2['code']) && $res2['code'] ==403){
+            return $this->error($res2['msg']);
+        }
+        if(!empty($res2['code']) && $res2['code'] ==400){
+            return $this->error($res2['msg']);
+        }
+        if($platform == 'wxMiniProgram'){
+            $check = MiniappServiceFacade::msgSecCheck($res2['data'],$loginUserInfo['openid_miniapp']);
+            if(!$check){
+                return $this->error('失败,文字内容安全检测不通过!');
+            }
+        }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                $check = ImageCensorServiceFacade::textCensorUserDefined($res2['data']);
+                if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                    return $this->error('失败,文字内容安全检测不通过!');
+                }
+            }
+        }
+            $question = $modelQuestion->save(['uid'=>$loginUserInfo['id'],'question'=>$prompt,'answer'=>$res2['data'],'uniacid'=>$_GPC['uniacid'] ]);
+        return $this->success('操作成功',$res2['data']);
+    }
+
+
+    public function tts()
+    {
+        global $_GPC;
+        $text = $this->request->post('text','');
+        if(!$text){
+            return $this->error('请填写文本');
+        }
+        $res = SpeechServiceFacade::synthesis2($text);
+        // print_r($res);
+        if(isset($res->{'error_code'})){
+            return $this->error($res['error_msg']);
+        }
+        return $this->success('操作成功',$res);
+    }
+
+    public function ttsJob()
+    {
+        global $_GPC;
+        $taskIds = $this->request->param('task_ids','');
+        if(!$taskIds){
+            return $this->error('请上传任务id');
+        }
+        $res = SpeechServiceFacade::query($taskIds);
+        if(isset($res->{'error_code'})){
+            return $this->error($res['error_msg']);
+        }
+        return $this->success('操作成功',$res->{'tasks_info'}[0]);
+        // print_r($res);
+    }
+
+    public function recognizer()
+    {
+        global $_GPC;
+        $platform = $this->request->header('platform','H5');
+        $speech = $this->request->file('speech');
+        if($platform == 'wxMiniProgram'){
+            $format = 'm4a';
+        }else{
+            $format = 'wav';
+        }
+        // print_r($speech);
+        // $text = $this->request->post('text','');
+        // if(!$text){
+        //     return $this->error('请填写文本');
+        // }
+        // $uploadImageInfo = $this->uploadImage($speech);
+        // print_r(IA_ROOT_WK.'/public/static/storage/'. $uploadImageInfo['name']);
+        // $audio = file_get_contents(IA_ROOT_WK.'/public/static/storage/'. $uploadImageInfo['name']);
+
+        $audio = file_get_contents($speech);
+        // file_put_contents(__DIR__ . '/ds.json', $format);
+        $res = SpeechServiceFacade::asr($audio, $format, '16000');
+        if(isset($res['err_no']) && $res['err_no']!=0){
+            return $this->error($res['err_msg']);
+        }
+        // print_r($res);
+        return $this->success('操作成功',$res);
+    }
+
+    public function getAddress()
+    {
+        global $_GPC;
+        $data=[];
+        $conf  = ConfServiceFacade::groupGet('system.config');
+        // print_r($conf);
+        if(empty($conf['connect_lines']) || $conf['connect_lines'] == 1){
+            $data['sk'] ='sk-wfjrfffffffffffffffhufrhuwdyqgygbwdyft';
+            $data['url'] = 'https://ok.justduit.com';
+        }elseif($conf['connect_lines'] == 2){
+            $info = \app\model\Sk::order("id desc")->where(['uniacid'=>$_GPC['uniacid'],'status'=>1])->limit(1)->select();
+            if(!$info){
+                return $this->error('未配置key,或无可用的key');
+            }
+            $data['sk'] ='sk-wfjrfffffffffffffffhufrhuwdyqgygbwdyft';
+            $data['url'] = 'https://ok.justduit.com';
+        }
+        return $this->success('操作成功',$data);
+    }
+
+    public function painting()
+    {
+        global $_GPC;
+
+        $modelGallery = new \app\model\Gallery();
+        $platform = $this->request->header('platform','H5');
+        $prompt = $this->request->post('prompt','');
+        $negativePrompt = $this->request->post('negative_prompt','');
+        $conf  = ConfServiceFacade::groupGet('system.config');
+        $coin = ConfServiceFacade::get('system.plan.unlock_aipainting',0);
+        if(!$prompt){
+            return $this->error('请填写文本');
+        }
+        $res = SdapiServiceFacade::getMj($prompt,$negativePrompt);
+        print_r($res);
+        return;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        // print_r($loginUserInfo);
+        if($platform == 'wxMiniProgram'){
+            $check = MiniappServiceFacade::msgSecCheck($prompt,$loginUserInfo['openid_miniapp']);
+            if(!$check){
+                return $this->error('失败,文字内容安全检测不通过!');
+            }
+        }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                $check = ImageCensorServiceFacade::textCensorUserDefined($prompt);
+                if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                    return $this->error('失败,文字内容安全检测不通过!');
+                }
+            }
+        }
+        $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数';
+        if($coin > 0){
+           if($loginUserInfo['coin'] < $coin){
+               return $this->error('您的点数不足');
+           }
+       }
+        $res = YijianServiceFacade::put_task($prompt);
+        if(!empty($res['status']) && $res['status'] !=0){
+            return $this->error($res['reason']);
+        }
+        if($coin > 0){
+            \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update();
+        }
+        if(!empty($res['data']['Uuid'])){
+            $data['job_id'] = $res['data']['Uuid'];
+            $data['prompt'] = $prompt;
+            $data['paid_coin'] = $coin;
+            $data['uid'] = $loginUserInfo['id'];
+            $data['uniacid'] = $_GPC['uniacid'];
+            $modelGallery->save($data);
+            BillServiceFacade::record(0,$coin,'chatgpt','绘画消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']);
+        }
+
+        // print_r($res['data']);
+        return $this->success('操作成功',$res['data']);
+    }
+
+    public function showTask(){
+        global $_GPC;
+        $uuid = $this->request->param('uuid','');
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        if(!$uuid){
+            return $this->error('请上传uuid');
+        }
+        $res = YijianServiceFacade::show_task($uuid);
+        if(!empty($res['status']) && $res['status'] !=0){
+            $coin = ConfServiceFacade::get('system.plan.unlock_aipainting',0);
+            if($coin >0){
+                \app\model\User::where(['id'=>$data['uid']])->inc('coin',$coin)->update();
+            }
+            return $this->error($res['reason']);
+        }
+        // print_r($res);
+        if(empty($res['data']['ImagePath'])){
+            return $this->success('继续等待','wait');
+        }
+        $filePath = $this->_put_file_from_url_content($res['data']['ImagePath']);
+
+        $galleryInfo = \app\model\Gallery::where(['job_id'=>$uuid])->findOrEmpty();
+        if($galleryInfo && empty($galleryInfo['img'])){
+            $filesModel = new \app\model\Files();
+            $fileId = $filesModel->insertGetId([
+                'category_id' => 0,
+                'name' => $uuid . time(),
+                'file_type' => 'image',
+                'path' => $filePath['saveName'],
+                'upload_type' => 'local',
+                'size' => 1,
+                'create_admin_user_id' => 0,
+                'update_admin_user_id' => 0,
+                'create_time' => date('Y-m-d H:i:s'),
+                'update_time' => date('Y-m-d H:i:s'),
+                'uniacid' =>$_GPC['uniacid'],
+                'ext' =>'png'
+            ]);
+            $galleryInfo->save(['img'=>$fileId]);
+        }
+        return $this->success('操作成功',$res['data']['ImagePath']);
+    }
+
+    public function checkText()
+    {
+
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $prompt = $this->request->param('prompt','');
+        $platform = $this->request->header('platform','H5');
+        $conf = ConfServiceFacade::groupGet('system.config', 0);
+        if(!$prompt){
+            return $this->error('请填写问题');
+        }
+        $str = strstr($prompt,'收割台湾');
+        if($str !=false){
+            return $this->error('您的提问涉及敏感信息');
+        }
+
+        // print_r($loginUserInfo);
+        if($platform == 'wxMiniProgram'){
+            $check = MiniappServiceFacade::msgSecCheck($prompt,$loginUserInfo['openid_miniapp']);
+            if(!$check){
+                return $this->error('失败,文字内容安全检测不通过!');
+            }
+        }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                $check = ImageCensorServiceFacade::textCensorUserDefined($prompt);
+                // print_r($check);
+                if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                    if(!empty($check['data']) && ($check['data'][0]['subType'] ==1 || $check['data'][0]['subType'] ==2 || $check['data'][0]['subType'] ==3 || $check['data'][0]['subType'] ==5)){
+                        return $this->error('失败,文字内容安全检测不通过!');
+                    }
+                }
+            }
+        }
+        return $this->success('操作成功');
+    }
+
+    public function chat4event()
+    {
+        header('Content-Type: text/event-stream');
+            header('Cache-Control: no-cache');
+            header('Connection: keep-alive');
+            header('X-Accel-Buffering: no');
+
+        $OPENAI_API_KEY = "sk-Lumo32Jh23arN9pcA9AcD9605eA24cB0Bb531cBeCcB1B35f";
+
+    $headers  = [
+        'Accept: application/json',
+        'Content-Type: application/json',
+        'Authorization: Bearer ' . $OPENAI_API_KEY
+    ];
+    $prompt = $this->request->post('prompt','hi');
+    $messages = [
+        ["role"=> "user","content"=> $prompt]
+    ];
+    $opts = [
+        'model' => 'gpt-4',
+        'messages' => $messages,
+        'temperature' => 1.0,
+        'max_tokens' => 2000,
+        'frequency_penalty' => 0,
+        'presence_penalty' => 0.6,
+        'stream' => true
+    ];
+    $callback = function ($ch, $data) {
+        $complete = json_decode($data);
+            if (isset($complete->error)) {
+                print_r($complete->error);
+            } else {
+                $word = $this->parseData($data);
+                // print_r($word);
+                if ($word == 'data: [DONE]' || $word == 'data: [CONTINUE]') {
+                        ob_flush();
+                        flush();
+                    } else {
+                        echo $word;
+                        ob_flush();
+                        flush();
+                    }
+            }
+            return strlen($data);
+    };
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+        curl_setopt($ch, CURLOPT_URL, 'https://api.gptmf.top/v1/chat/completions');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($opts));
+        curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
+        //curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1:1081");
+
+        curl_exec($ch);
+        // $open_ai = new OpenAi('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');
+
+        //
+        //
+        // $txt = "";
+        // $complete = $open_ai->chat($opts, function ($curl_info, $data) use (&$txt) {
+        //     if ($obj = json_decode($data) and $obj->error->message != "") {
+        //         error_log(json_encode($obj->error->message));
+        //     } else {
+        //         echo $data;
+        //         $clean = str_replace("data: ", "", $data,1);
+        //         $arr = json_decode($clean, true);
+        //         if ($data != "data: [DONE]\n\n" and isset($arr["choices"][0]["delta"]["content"])) {
+        //             $txt .= $arr["choices"][0]["delta"]["content"];
+        //         }
+        //     }
+        //
+        //     echo PHP_EOL;
+        //     ob_flush();
+        //     flush();
+        //
+        //     return strlen($data);
+        // });
+
+    }
+
+    public function wordFilter($message)
+       {
+           $Filter = new \ins\Words('*');
+           $clearMessage = $Filter->filter($message);
+
+           // if ($clearMessage != $message) {
+           //     var_dump($clearMessage);
+           //     // $setting = getSystemSetting(0, 'filter');
+           //     // $handle_type = empty($setting['handle_type']) ? 1 : intval($setting['handle_type']);
+           //     // if ($handle_type == 2) {
+           //         return $this->error('内容包含敏感信息');
+           //     // }
+           // }
+
+           return $clearMessage;
+       }
+
+    private function parseData($content)
+       {
+           $content = trim($content);
+           $rows = explode("\n", $content);
+           $result = [];
+           foreach ($rows as $data) {
+               if (strpos($data, 'data: [DONE]') !== false) {
+                   $char = 'data: [DONE]';
+               } else {
+                   $data = str_replace('data: {', '{', $data);
+                   $data = rtrim($data, "\n\n");
+
+                   if (strpos($data, "}\n\n{") !== false) {
+                       $arr = explode("}\n\n{", $data);
+                       $data = '{' . $arr[1];
+                   }
+
+                   $data = @json_decode($data, true);
+                   if (!is_array($data)) {
+                       continue;
+                   }
+                   if(array_key_exists('finish_reason',$data)){
+                       if ($data['finish_reason'] == 'stop') {
+                           $char = 'data: [DONE]';
+                       } elseif ($data['choices'] == 'length') {
+                           $char = 'data: [CONTINUE]';
+                       } else {
+                           $char = $data['choices']['0']['delta']['content'] ?? '';
+                       }
+                   }else{
+                       if ($data['choices']['0']['finish_reason'] == 'stop') {
+                           $char = 'data: [DONE]';
+                       } elseif ($data['choices']['0']['finish_reason'] == 'length') {
+                           $char = 'data: [CONTINUE]';
+                       } else {
+                           $char = $data['choices']['0']['delta']['content'] ?? '';
+                       }
+                   }
+
+               }
+               $result[] = $char;
+           }
+
+           return $result;
+
+       }
+
+    private function parseData2($content)
+    {
+        $content = trim($content);
+        $rows = explode("\n", $content);
+        $result = [];
+        foreach ($rows as $data) {
+            if (strpos($data, 'data: [DONE]') !== false) {
+                $char = 'data: [DONE]';
+            } else {
+                $data = str_replace('data: {', '{', $data);
+                $data = rtrim($data, "\n\n");
+
+                if (strpos($data, "}\n\n{") !== false) {
+                    $arr = explode("}\n\n{", $data);
+                    $data = '{' . $arr[1];
+                }
+                $data = @json_decode($data, true);
+
+                if (!is_array($data)) {
+                    continue;
+                }
+                if (isset($data['is_end'])) {
+                    $char = 'data: [DONE]';
+                }
+                $char = $data['result'] ?? '';
+            }
+            $result[] = $char;
+        }
+
+        return $result;
+
+    }
+
+
+    public function test()
+    {
+        header('Content-Type: text/event-stream');
+        header('Cache-Control: no-cache');
+        header('Connection: keep-alive');
+        header('X-Accel-Buffering: no');
+
+
+        global $_GPC;
+        $ins = ConfServiceFacade::groupGet('system.ai');
+        $API_URL = 'https://api.wike.cc/api/senseai/gpt4';
+        $data['key']=$ins['ins_api_key'];
+        $get_post_data = http_build_query($data);
+        $callbacks = function ($ch, $data) use($_GPC)  {
+            print_r($data);
+            exit();
+             $complete = @json_decode($data,true);
+             echo $data;
+             ob_flush();
+             flush();
+             return strlen($data);
+         };
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_URL, $API_URL. '?' . $get_post_data);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));
+        curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callbacks);
+        curl_exec($ch);
+    }
+
+    public static function send($API_URL, $get_post_data, $type, $ifsign, $sk)
+    {
+        $get_post_data = http_build_query($get_post_data);
+        if ($ifsign) {
+            $sign = md5($get_post_data . $sk);
+            // print_r($sign);
+            $res = self::send_curl($API_URL, $type, $get_post_data, $sign);
+        } else {
+            $res = self::send_curl($API_URL, $type, $get_post_data, null);
+        }
+        return $res;
+    }
+    //封装好的CURL请求函数,支持POST|GET
+    public static function send_curl($API_URL, $type, $get_post_data, $sign)
+    {
+        $ch = curl_init();
+        if ($type == 'POST') {
+            curl_setopt($ch, CURLOPT_URL, $API_URL);
+            curl_setopt($ch, CURLOPT_POST, true);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $get_post_data);
+        } elseif ($type == 'GET') {
+            curl_setopt($ch, CURLOPT_URL, $API_URL . '?' . $get_post_data);
+        }
+        if ($sign) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, ['sign:' . $sign]);
+        }
+        curl_setopt($ch, CURLOPT_REFERER, $API_URL);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 300);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        $resdata = curl_exec($ch);
+
+        curl_close($ch);
+        return $resdata;
+    }
+
+    /**
+     * 上传图片获得url
+     * @param $file
+     * @return array|boolean
+     */
+    protected function uploadImage($file,$post=[])
+    {
+        if(empty($post['upload_type'])){
+            $uploadType = 'local';
+        }else{
+            $uploadType = $post['upload_type'];
+        }
+        if (!in_array($uploadType, ['local', 'ali-oss', 'qiniu-kodo'])) {
+            return $this->error($uploadType . '上传方式未定义');
+        }
+
+        $fileExt = strtolower($file->getOriginalExtension());
+        $uploadDomain = new UploadDomain();
+        if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt, $file->getMime())) {
+            // return $this->error($uploadDomain->getError());
+        }
+        $saveName = date("Ymd") . "/" . md5(uniqid(mt_rand())) . ".{$fileExt}";
+        $uploadDir = $this->request->post('dir');
+        $object = $uploadDir ? $uploadDir . '/' . $saveName : $saveName;//设置了上传目录的上传文件名
+        $data=[];
+        $filePath = $object; //保存到lt_files中的path
+        $uploadDir = ltrim('/', $uploadDir);
+        $saveName = Filesystem::putFileAs('/' . $uploadDir, $file, '/' . $object);
+        $filePath = $saveName;
+        $data['image'] = request()->domain() . STATIC_PATH . '/storage/' . $saveName;
+        $data['name']  = $saveName;
+        return $data;
+    }
+
+    private function _put_file_from_url_content($url) {
+        $name =md5(uniqid(mt_rand())) . ".png";
+        $saveName = date("Ymd") . "/" . $name;
+        $path = IA_ROOT_WK.'/public/static/storage/';
+        // 设置运行时间为无限制
+        set_time_limit ( 0 );
+        $url = trim ( $url );
+        $curl = curl_init ();
+        // 设置你需要抓取的URL
+        curl_setopt ( $curl, CURLOPT_URL, $url );
+        // 设置header
+        curl_setopt ( $curl, CURLOPT_HEADER, 0 );
+        // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
+        curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
+        // 运行cURL,请求网页
+        $file = curl_exec ( $curl );
+        // 关闭URL请求
+        curl_close ( $curl );
+        // 将文件写入获得的数据
+        $filename = $path . $saveName;
+        // 打开用来保存数据的文件,如果没有则会创建
+        if (!file_exists($path.date("Ymd"))) {
+            mkdir($path.date("Ymd"), 0755,true);
+        }
+        $write = @fopen ( $filename, "w" );
+        if ($write == false) {
+            return false;
+        }
+        // 将CURL请求返回的数据写入文件
+        if (fwrite ( $write, $file ) == false) {
+            return false;
+        }
+        // 关闭文档流
+        if (fclose ( $write ) == false) {
+            return false;
+        }
+        $data['filename'] = $filename;
+        $data['url'] = request()->domain() . STATIC_PATH . '/storage/' . $saveName;
+        $data['saveName'] = $saveName;
+        $data['name'] = $name;
+        return $data;
+     }
+
+     public static function getToken()
+   {
+       global $_W;
+       $ai = ConfServiceFacade::groupGet('system.ai');
+       $curl = curl_init();
+         curl_setopt_array($curl, array(
+             CURLOPT_URL => "https://aip.baidubce.com/oauth/2.0/token?client_id=".$ai['key_wenxin_appkey']."&client_secret=".$ai['key_wenxin_secrte']."&grant_type=client_credentials",
+             CURLOPT_TIMEOUT => 30,
+             CURLOPT_RETURNTRANSFER => true,
+             CURLOPT_CUSTOMREQUEST => 'POST',
+
+
+             CURLOPT_HTTPHEADER => array(
+                 'Content-Type: application/json',
+                 'Accept: application/json'
+             ),
+
+         ));
+         $response = curl_exec($curl);
+         $response = @json_decode($response,true);
+         curl_close($curl);
+         return $response;
+   }
+
+}

+ 252 - 0
app/controller/api/Commission.php

xqd
@@ -0,0 +1,252 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\api\UserServiceFacade;
+use app\service\MoneyServiceFacade;
+use app\service\ConfServiceFacade;
+use laytp\controller\Api;
+use laytp\library\Random;
+use laytp\traits\Error;
+use think\facade\Db;
+
+/**
+ * 会员相关
+ * @ApiWeigh (90)
+ */
+class Commission extends Api
+{
+    use Error;
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\commission\Team();
+    }
+
+    // 检测
+    public function auth()
+    {
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $modelUser = new \app\model\commission\User();
+        $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
+        if(!$res){
+            return $this->error('不是分销商',2);
+        }
+        $res['money_total'] = \app\model\commission\Income::where(['uid'=>$loginUserInfo['id']])->sum('money');
+        $res['on_cashout_money'] =\app\model\commission\Cashout::where(['uid'=>$loginUserInfo['id'],'status'=>0])->sum('extract_price');
+        return $this->success('数据获取成功', $res);
+    }
+
+    // 申请分销商
+    public function apply()
+    {
+        global $_GPC;
+        $modelUser = new \app\model\commission\User();
+        $post  = $this->request->post();
+        $realName  = $this->request->post('real_name','');
+        $telnum  = $this->request->post('telnum','');
+        if(!$realName || !$telnum){
+            return $this->error('请上传姓名或手机号');
+        }
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $conf = ConfServiceFacade::groupGet('system.commission', 0);
+        $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
+        $status =0;
+        if(!empty($conf['is_examine']) && $conf['is_examine'] == 2){
+            $status = 1;
+        }
+        $post['uid'] = $loginUserInfo['id'];
+        $post['uniacid'] = $_GPC['uniacid'];
+        $post['status'] = $status;
+        $post['paid'] = 0;
+        if(!$res){
+            $a = $modelUser->save($post);
+            return $this->success('数据获取成功', $a);
+        }
+        return $this->success('数据获取成功', $res);
+    }
+
+    // 完善提现信息
+    public function update()
+    {
+        global $_GPC;
+        $modelUser = new \app\model\commission\User();
+        $post  = $this->request->post();
+        if(!($post['qrcode_wechat'])){
+            return $this->error('修改失败,请上传二维码');
+        }
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $updateRes = $modelUser->where('uid', '=', $loginUserInfo['id'])->update($post);
+        if (!$updateRes) return $this->error('数据更新失败');
+        return $this->success('获取结果', $post);
+    }
+
+    public function teamList()
+    {
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $where = ['pid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
+        $order = ['create_time' => 'desc'];
+        $param  = $this->request->param();
+        $limit = $this->request->param('limit', 10);
+        $level = $this->request->param('level', 1);
+        if($level == 1){
+            $data  = $this->model->where($where)->with(['userinfo'])->order($order)->paginate($limit)->toArray();
+        }elseif($level == 2){
+            $data  = $this->model->where(['gid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo'])->paginate($limit)->toArray();
+        }elseif($level == 3){
+            $data  = $this->model->where(['gfid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo'])->paginate($limit)->toArray();
+        }
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    // 加入团队
+    public function addTeam()
+    {
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $spm  = $this->request->post('spm',0);
+        if(!$spm){
+            return $this->error('数据获取失败,请上传spm',2);
+        }
+        $arr = explode('.',$spm);
+        $shareuid = $arr[0];
+        if($shareuid == 0){
+            return $this->error('分销商用户id不能为0',2);
+        }
+        if($shareuid == $loginUserInfo['id']){
+            return $this->error('不能邀请自己',2);
+        }
+
+        $sharecheck = \app\model\commission\User::where(['uid'=>$shareuid])->find();
+
+        if(empty($sharecheck) && $sharecheck['status']!=1){
+            return $this->error('分享者不是分销商',2);
+        }
+        $sharecheckUserInfo = \app\model\User::where(['id'=>$shareuid])->find();
+        if($loginUserInfo['create_time_int'] < $sharecheckUserInfo['create_time_int']){
+            return $this->error('被绑定用户注册时间大于分销商用户注册时间',2);
+        }
+        $check = $this->model->where(['uid'=>$loginUserInfo['id']])->find();
+        if($check){
+            return $this->error('已经绑定,无需重复绑定',2);
+        }
+        // 说明没被绑定过
+        $gid  = 0;
+        $gfid  = 0;
+        // 查shareuid的信息
+        $pinfo = $this->model->where(['uid'=>$shareuid])->find();
+        if($pinfo){
+            if($loginUserInfo['id'] == $pinfo['pid']){
+                return $this->error('绑定关系错误,不支持逆向绑定',2);
+            }
+            $gid = $pinfo['pid'];
+            if(!empty($pinfo['gid'])){
+                if($loginUserInfo['id'] == $pinfo['gid']){
+                    return $this->error('绑定关系错误,不支持逆向绑定',2);
+                }
+                $gfid = $pinfo['gid'];
+            }
+        }
+        $a = $this->model->save(['uid'=>$loginUserInfo['id'],'pid'=>$shareuid,'gid'=>$gid,'gfid'=>$gfid,'uniacid'=>$_GPC['uniacid'] ]);
+        if(!$a){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $a);
+    }
+
+    // 申请提现
+    public function extract()
+    {
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $post = $this->request->post();
+        $extractPrice = $this->request->post('extract_price',0);
+        $modelUser = new \app\model\commission\User();
+        $modelCashout = new \app\model\commission\Cashout();
+        $commissionUser = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
+        if(!$commissionUser){
+            return $this->error('未找到您的分销信息');
+        }
+        if($commissionUser['money'] < $extractPrice){
+            return $this->error('金额不足');
+        }
+        if($extractPrice <= 0){
+              return $this->error('提现金额不能小于或等于0元');
+        }
+        $mark = '';
+
+        $platform = $this->request->post('platform','wxOfficialAccount');
+         $post['uid']     = $loginUserInfo['id'];
+        $post['uniacid'] = $_GPC['uniacid'];
+        // if(!$post['real_name']) return $this->error('姓名输入有误');
+        if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $post['extract_price'])) return $this->error('提现金额输入有误');
+        $mark = '使用微信提现' . $post['extract_price'] . '元';
+        if($platform =='wxOfficialAccount' ){
+            $post['extract_type'] = 'wechat';
+        }else{
+            $post['extract_type'] = 'miniapp';
+        }
+        $balance = bcsub($commissionUser['money'],$extractPrice,2) ?? 0;
+        $post['balance'] = $balance;//用户余额
+        $post['mark'] = $mark;
+          $saveRes = $modelCashout->save($post);
+          if (!$saveRes) return $this->error('保存基础信息失败');
+          $balanceRes = \app\model\commission\User::where(['uid'=>$loginUserInfo['id']])->update(['money' => $balance]);
+          return $this->success('数据获取成功', $saveRes);
+    }
+
+    // 收入记录
+    public function incomeLog()
+    {
+        global $_GPC;
+        $order = ['id' => 'desc'];
+        $modelIncome = new \app\model\commission\Income();
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $where = ['uid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
+        $post  = $this->request->param();
+        $limit = $this->request->param('limit', 10);
+        $data  = $modelIncome->order($order)->with(['userinfo','buy_userinfo'])->where($where)->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    // 提现记录
+    public function cashoutLog()
+    {
+        global $_GPC;
+        $order = ['id' => 'desc'];
+        $modelCashout = new \app\model\commission\Cashout();
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $where = ['uid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
+        $post  = $this->request->param();
+        $limit = $this->request->param('limit', 10);
+        $data  = $modelCashout->order($order)->where($where)->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    // 排行榜
+    public function ranking()
+    {
+        global $_GPC;
+        $where = ['uniacid'=>$_GPC['uniacid']];
+        $model = new \app\model\commission\User();
+        $post  = $this->request->param();
+        // $where[] = ['pm' ,'=', 1];
+        $order = ['income_sum' => 'desc'];
+        $limit = $this->request->param('limit', 10);
+        $data  = $model->order($order)->where($where)->with('userinfo')->withSum('income','money')->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+}

+ 270 - 0
app/controller/api/Common.php

xqd
@@ -0,0 +1,270 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\ConfServiceFacade;
+use laytp\library\Random;
+use laytp\library\UploadDomain;
+use plugin\qiniu_kodo\service\Kodo;
+use laytp\library\Tree;
+use laytp\controller\Api;
+use plugin\ali_sms\service\AliSmsServiceFacade;
+use app\service\api\MiniappServiceFacade;
+use think\facade\Env;
+use think\facade\Filesystem;
+
+/**
+ * 公用接口
+ * @ApiWeigh (100)
+ */
+class Common extends Api
+{
+    public $noNeedLogin = ['template','upload','sendMobileCode','checkMobileCode','qrcodePath'];
+
+    public $noNeedCheckSign = [];
+
+    public function template()
+    {
+        global $_GPC;
+        $template = [];
+        $where = ['status'=>1,'uniacid'=>$_GPC['uniacid']];
+        $order = ['sort' => 'DESC','id'=>'DESC'];
+        $template['banner'] = \app\model\Banner::where($where)->order($order)->with(['img_file'])->select();
+        $template['hot'] = \app\model\Hot::orderRaw("rand() , id desc")->where($where)->limit(3)->select();
+        $template['mode'] = \app\model\Mode::where($where)->order($order)->with('img_file')->select();
+        // $sourceData =\app\model\Template::where($where)->order($order);
+        // $menuTreeObj = Tree::instance();
+        // $menuTreeObj->init($sourceData->select()->toArray());
+        // $data = $menuTreeObj->getRootTrees();
+        // $template['template_tree'] = $data;
+        $template['template'] = \app\model\Template::order($order)->where([['uniacid','=',$_GPC['uniacid']],['status','=',1],['pid','<>',0]])->order($order)->limit(4)->select();
+        return $this->success('数据获取成功', $template);
+    }
+
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (文件上传)
+     * @ApiSummary  (文件上传,兼容阿里云OSS、七牛云KODO和本地上传,自行在接口中传递参数选择上传方式,阿里云OSS和七牛云KODO需要后端安装相应插件)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.common/upload)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiParams   (name="file", type="file", required="true", description="文件")
+     * @ApiParams   (name="upload_type", type="string", required="false", description="上传方式,允许为空,local=本地上传,ali-oss=阿里云OSS上传,qiniu-kodo=七牛云KODO上传,默认为local", sample="avatar")
+     * @ApiParams   (name="upload_dir", type="string", required="false", description="上传目录,允许为空", sample="avatar")
+     * @ApiReturnParams   (name="code", type="integer", description="错误码.0=没有错误,表示操作成功;1=常规错误码,客户端仅需提示msg;其他错误码与具体业务相关,其他错误码举例:10401。前端需要跳转至登录界面。")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="null", description="null")
+     * @ApiReturn
+({
+    'code':0,
+    'msg':'上传成功',
+    'time':'15632654875',
+    'data':null
+})
+     */
+    /*@formatter:on*/
+    public function upload()
+    {
+        global $_GPC;
+        try {
+            $uploadType = $this->request->param('upload_type', 'local');
+            if (!in_array($uploadType, ['local', 'ali-oss', 'qiniu-kodo'])) {
+                return $this->error($uploadType . '上传方式未定义');
+            }
+            $file = $this->request->file('file'); // 获取上传的文件
+            if (!$file) {
+                return $this->error('上传失败,请选择需要上传的文件');
+            }
+            $fileExt = strtolower($file->getOriginalExtension());
+            $uploadDomain = new UploadDomain();
+            if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt, $file->getMime())) {
+                return $this->error($uploadDomain->getError());
+            }
+            $saveName = date("Ymd") . "/" . md5(uniqid(mt_rand())) . ".{$fileExt}";
+            /**
+             * 不能以斜杆开头
+             *  - 因为OSS存储时,不允许以/开头
+             */
+            $uploadDir = $this->request->param('dir');
+            $object = $uploadDir ? $uploadDir . '/' . $saveName : $saveName;//设置了上传目录的上传文件名
+            $filePath = $object; //保存到lt_files中的path
+
+            //如果上传的是图片,验证图片的宽和高
+            $accept = $this->request->param('accept');
+            if ($accept == "image") {
+                $width = $this->request->param('width');
+                $height = $this->request->param('height');
+                if ($width || $height) {
+                    $imageInfo = getimagesize($file->getFileInfo());
+                    if (($width && $imageInfo[0] > $width) || ($height && $imageInfo[1] > $height)) {
+                        return $this->error('上传失败,图片尺寸要求宽:' . $width . 'px,高:' . $height . 'px,实际上传文件[ ' . $file->getOriginalName() . ' ]的尺寸为宽' . $imageInfo[0] . 'px,高:' . $imageInfo[1] . 'px');
+                    }
+                }
+            }
+
+            $inputValue = "";
+            //上传至七牛云
+            if ($uploadType == 'qiniu-kodo') {
+                if(ConfServiceFacade::get('plugin.qiniu_kodo.switch') != 1){
+                    return $this->error('未开启七牛云KODO存储,请到七牛云KODO配置中开启');
+                }
+                $kodoConf = [
+                    'accessKey' => ConfServiceFacade::get('plugin.qiniu_kodo.accessKeyID'),
+                    'secretKey' => ConfServiceFacade::get('plugin.qiniu_kodo.secretKey'),
+                    'bucket' => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
+                    'domain' => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
+                ];
+                $kodo = Kodo::instance();
+                $kodoRes = $kodo->upload($file->getPathname(), $object, $kodoConf);
+                if ($kodoRes) {
+                    $inputValue = $kodoRes;
+                } else {
+                    return $this->error($kodo->getError());
+                }
+            }
+
+            //上传至阿里云
+            if ($uploadType == 'ali-oss') {
+                if(ConfServiceFacade::get('plugin.ali_oss.switch') != 1){
+                    return $this->error('未开启阿里云OSS存储,请到阿里云OSS配置中开启');
+                }
+                $ossConf = [
+                    'accessKeyID' => ConfServiceFacade::get('plugin.ali_oss.accessKeyID'),
+                    'accessKeySecret' => ConfServiceFacade::get('plugin.ali_oss.accessKeySecret'),
+                    'bucket' => ConfServiceFacade::get('plugin.ali_oss.bucket'),
+                    'endpoint' => ConfServiceFacade::get('plugin.ali_oss.endpoint'),
+                    'domain' => ConfServiceFacade::get('plugin.ali_oss.domain'),
+                ];
+                $oss = Oss::instance();
+                $ossUploadRes = $oss->upload($file->getPathname(), $object, $ossConf);
+                if ($ossUploadRes) {
+                    $inputValue = $ossUploadRes;
+                } else {
+                    return $this->error($oss->getError());
+                }
+            }
+
+            //本地上传
+            if ($uploadType == 'local') {
+                $uploadDir = ltrim('/', $uploadDir);
+                $saveName = Filesystem::putFileAs('/' . $uploadDir, $file, '/' . $object);
+                $filePath = $saveName;
+                $staticDomain = Env::get('domain.static');
+                if ($staticDomain) {
+                    $inputValue = $staticDomain . '/storage/' . $saveName;
+                } else {
+                    $inputValue = request()->domain() . STATIC_PATH . '/storage/' . $saveName;
+                }
+            }
+
+            //将inputValue存入lt_files表中
+            $filesModel = new \app\model\Files();
+            $fileId = $filesModel->insertGetId([
+                'category_id' => (int)$this->request->param('file_category_id', 0),
+                'name' => $file->getOriginalName(),
+                'file_type' => $this->request->param('accept'),
+                'path' => $filePath,
+                'upload_type' => $uploadType,
+                'size' => $file->getSize(),
+                'ext' => $file->getExtension(),
+                'create_admin_user_id' => 0,
+                'update_admin_user_id' => 0,
+                'create_time' => date('Y-m-d H:i:s'),
+                'update_time' => date('Y-m-d H:i:s'),
+                'uniacid' =>$_GPC['uniacid']
+            ]);
+
+            return $this->success('上传成功', [
+                'id' => $fileId,
+                'path' => $inputValue,
+                'name' => $file->getOriginalName(),
+            ]);
+        } catch (\Exception $e) {
+            return $this->exceptionError($e);
+        }
+    }
+
+     /*@formatter:off*/
+    /**
+     * @ApiTitle    (发送手机验证码)
+     * @ApiSummary  (发送手机验证码)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.common/sendMobileCode)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiParams   (name="mobile", type="string", required="true", description="手机号码")
+     * @ApiParams   (name="event", type="string", required="true", sample="reg_login",description="事件名称,reg_login=使用手机号+验证码的方式进行注册或登录")
+     * @ApiReturnParams   (name="code", type="integer", required="true", sample="0")
+     * @ApiReturnParams   (name="msg", type="string", required="true", sample="返回成功")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="null", description="只会返回null")
+     * @ApiReturn
+({
+    "code": 1,
+    "msg": "发送失败,触发分钟级流控Permits:1",
+    "time": 1584667483,
+    "data": null
+})
+     */
+    /*@formatter:on*/
+    public function sendMobileCode(){
+        // $aliSmsStatus = ConfServiceFacade::groupGet('ali_sms.conf');
+        // if(!$aliSmsStatus){
+        //     return $this->error('请先到插件市场安装阿里云手机短信插件,并进行相关配置');
+        // }
+
+        $post['mobile'] = $this->request->post('mobile');
+        $post['event'] = $this->request->post('event');
+
+        $validate = new \plugin\ali_sms\validate\Send();
+        if(!$validate->check($post)) return $this->error('发送失败,'.$validate->getError());
+
+        if(AliSmsServiceFacade::send($post['mobile'],$post['event'],['code'=>Random::numeric()])){
+            return $this->success('发送成功');
+        }else{
+            return $this->error('发送失败,'.AliSmsServiceFacade::getError());
+        }
+    }
+
+    public function checkMobileCode(){
+        $posts['mobile'] = $this->request->post('mobile');
+        $posts['event'] = $this->request->post('event');
+        $posts['code'] = $this->request->post('code');
+        $check = AliSmsServiceFacade::checkCode($posts['mobile'],$posts['event'],$posts['code']);
+        if($check){
+            return $this->success('验证成功');
+        }else{
+            return $this->error('验证失败,'.AliSmsServiceFacade::getError());
+        }
+    }
+
+    public function qrcodePath()
+    {
+        global $_GPC;
+        $platform = $this->request->header('platform');
+        // print_r($platform);
+        $spm = $this->request->param('spm',0);
+        if($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            $link = request()->domain().SURL . 'h5/?uniacid=' . $_GPC['uniacid'] .'&spm='.$spm;
+        }elseif($platform == 'wxMiniProgram'){
+            $conf = ConfServiceFacade::groupGet('system.miniapp', true);
+            if(!$conf['appid'] || !$conf['appsecret']){
+                return $this->error('操作失败');
+            }
+            $app = MiniappServiceFacade::option();
+            $response = $app->app_code->getUnlimit('?uniacid='.$_GPC['uniacid'].'&spm='.$spm, [
+                'page' =>'pages/index/index',
+                'width' => 600
+            ]);
+            if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
+                $time = time();
+                $filename = $response->saveAs(IA_ROOT_WK.'/public/static/storage/qrcode/', $time.'appcode.png');
+            }
+            $link = request()->domain() . STATIC_PATH . '/storage/qrcode/' . $time.'appcode.png';
+        }
+        return $this->success('获取成功',$link);
+    }
+
+
+}

+ 161 - 0
app/controller/api/Conf.php

xqd
@@ -0,0 +1,161 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use app\service\ConfServiceFacade;
+// use app\service\IpServiceFacade;
+
+/**
+ * 获取系统配置
+ */
+class Conf extends Api
+{
+    // 无需登录的接口,*表示全部
+    public $noNeedLogin = ['getGroupConf'];
+
+    /*@formatter:off*/
+    /**
+     *
+     * @ApiTitle    (需要登录的接口需要登录的接口需要登录的接口需要登录的接口)
+     * @ApiSummary  (需要登录的接口详细描述)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.demo/test)
+     * @ApiHeaders  (name="token", type="string", required="true", description="请求的Token")
+     * @ApiParams   (name="id", type="integer", required="true", description="会员ID")
+     * @ApiParams   (name="name", type="string", required="true", description="用户名")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="object", description="返回的数据对象")
+     * @ApiReturnParams   (name="data.id", type="string", description="参数id的值")
+     * @ApiReturnParams   (name="data.name", type="string", description="参数name的值")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "返回成功",
+    "time": 1591168410,
+    "data": {
+        "id": "",
+        "name": ""
+    }
+})
+
+    /**
+     * 获取某个分组下所有的配置项
+     */
+    public function getGroupConf()
+    {
+        global $_GPC;
+        // print_r($_GPC);
+        $group  = $this->request->param('group');
+        if($group == 'system.ai' || $group=='system.pay' ||  $group=='plugin.ali_oss' || $group=='plugin.qiniu_kodo'){
+            return $this->success('返回成功', []);
+        }
+        $platform = $this->request->header('platform','wxMiniProgram');
+        $return = ConfServiceFacade::groupGet($group, true);
+        if($platform == 'wxOfficialAccount'){
+            $systemWechat = ConfServiceFacade::groupGet('system.wechat', true);
+            // print_r($systemWechat);
+            if(!empty($systemWechat['appid'])){
+                $wechatAppid = $systemWechat['appid'];
+                $return['wechat_appid'] = $wechatAppid;
+            }
+        }
+        // $info = \app\model\Sk::orderRaw("rand() , id desc")->where(['uniacid'=>$_GPC['uniacid'],'status'=>1])->limit(1)->select()->toArray();
+        // if(!empty($info)){
+        //     $return['sk'] = $this->encrypt($info[0]['sk'],'hello_wike');
+        // }
+        return $this->success('获取成功', $return);
+    }
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (无需登录的接口)
+     * @ApiSummary  (无需登录的接口详细描述)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.demo/test1)
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="object", description="返回的数据对象")
+     * @ApiReturnParams   (name="data.action", type="string", description="固定返回test1")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "返回成功",
+    "time": 1591168410,
+    "data": {
+        "action": "test1"
+    }
+})
+     */
+    /*@formatter:on*/
+    public function test1()
+    {
+        return $this->success('返回成功', ['action' => 'test1']);
+    }
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (参数传递array的接口)
+     * @ApiSummary  (参数传递array的接口详细描述)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.demo/arrayParam)
+     * @ApiParams   (name="id", type="string", required="true", description="ID")
+     * @ApiParams   (name="name", type="array", required="true", description="数组中的值")
+     * @ApiParams   (name="array[key]", type="array", required="true", description="数组中的值")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="object", description="返回的数据对象")
+     * @ApiReturnParams   (name="data.action", type="string", description="固定返回test1")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "返回成功",
+    "time": 1591168410,
+    "data": {
+        "action": "test1"
+    }
+})
+     */
+    /*@formatter:on*/
+    public function arrayParam()
+    {
+        return $this->success('返回成功', $this->request->param('i'));
+    }
+
+    public function encrypt($str, $key){
+        $mixStr = md5(date('Y-m-d H:i:s').rand(1000,10000));
+        $tmp = '';
+        $strLen = strlen($str);
+        for($i=0, $j=0; $i<$strLen; $i++, $j++){
+            $j = $j == 32 ? 0 : $j;
+            $tmp .= $mixStr[$j].($str[$i] ^ $mixStr[$j]);
+        }
+        return base64_encode($this->bind_key($tmp, $key));
+    }
+
+    public function decrypt($str, $key){
+        $str = $this->bind_key(base64_decode($str), $key);
+        $strLen = strlen($str);
+        $tmp = '';
+        for($i=0; $i<$strLen; $i++){
+            $tmp .= $str[$i] ^ $str[++$i];
+        }
+        return $tmp;
+    }
+
+    public function bind_key($str, $key){
+        $encrypt_key = md5($key);
+
+        $tmp = '';
+        $strLen = strlen($str);
+        for($i=0, $j=0; $i<$strLen; $i++, $j++){
+            $j = $j == 32 ? 0 : $j;
+            $tmp .= $str[$i] ^ $encrypt_key[$j];
+        }
+        return $tmp;
+    }
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 0
app/controller/api/Gallery.php


+ 295 - 0
app/controller/api/Member.php

xqd
@@ -0,0 +1,295 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use app\service\api\UserServiceFacade;
+use app\service\ConfServiceFacade;
+// use app\service\MessageSystemServiceFacade;
+use app\service\BillServiceFacade;
+use think\facade\Db;
+
+/**
+ * 会员次数相关
+ * @ApiWeigh (90)
+ */
+class Member extends Api
+{
+    // 无需无需登录的接口,*表示全部
+    public $noNeedLogin = ['list','detail','customized'];
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Member();
+    }
+
+    // 列表
+    public function list(){
+        global $_GPC;
+        $type = $this->request->param('type',1);
+        $order = ['sort'=>'desc','id' => 'desc'];
+        $where = ['uniacid'=>$_GPC['uniacid'],'type'=>$type,'status'=>1 ];
+        $data  = $this->model->where($where)->order($order)->select()->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    /**
+     * 详情
+     * @param $file
+     * @return array|boolean
+     */
+    public function detail()
+    {
+        $return = [];
+        $id   = $this->request->param('id');
+        $info = $this->model->find($id);
+        if(!$info){
+            return $this->error('详情获取失败');
+        }
+        return $this->success('获取成功', $info);
+    }
+
+    public function addCoin(){
+        global $_GPC;
+        $post = $this->request->post();
+        $type = $this->request->post('type','video');
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        if(!$type){
+            return $this->error('正确上传type',2);
+        }
+        $conf = ConfServiceFacade::groupGet('system.plan', 0);
+        $countToday = \app\model\Bill::where(['uid'=>$loginUserInfo['id'],'type'=>$type ])->where('create_time','>',date('Y-m-d 00:00:00'))->count();
+        $typeText='';
+        switch($type){
+            case 'video':
+                $typeText ='观看激励视频获得奖励';
+                $coin = $conf['video'];
+                if($countToday >= $conf['video_limit']){
+                    return $this->error('今日已达获取上限,请明天再试');
+                }
+                // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','观看激励视频获得奖励');
+                break;
+            case 'sign':
+                $typeText ='签到获得奖励';
+                $coin = $conf['sign'];
+                if($countToday>=1){
+                    return $this->error('今日已达获取上限,请明天再试');
+                }
+                // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','签到获得奖励');
+                break;
+            case 'share':
+                $typeText ='分享获得奖励';
+                $coin = $conf['share'];
+                if($countToday >= $conf['share_limit']){
+                    return $this->error('今日已达获取上限,请明天再试');
+                }
+                // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'获得次数奖励通知','分享获得奖励');
+                break;
+        }
+
+        $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$coin)->update();
+        if(!$balanceRes){
+            return $this->error('增加金币失败');
+        }
+        BillServiceFacade::record(1,$coin,$type,$typeText,$loginUserInfo['id'],$_GPC['uniacid']);
+        return $this->success('数据获取成功', $balanceRes);
+    }
+
+    public function open(){
+        global $_GPC;
+        $post = $this->request->post();
+        $orderid = $this->request->post('orderid',0);
+        if(!$orderid){
+            return $this->error('请上传订单编号');
+        }
+        $orderInfo = \app\model\Order::where('id', '=', $orderid)->find();
+        $linkId = $orderInfo['link_id'];
+        $MemberInfo = $this->model->where('id', '=', $linkId)->find();
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        // $balance = $loginUserInfo['vip_time'] + strtotime("+".$MemberInfo['days']."days");
+        $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])->update(['vip_time' => $balance]);
+        if(!$balanceRes){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $balanceRes);
+    }
+
+    public function reduce(){
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        $balanceRes = \app\model\User::where(['id'=>$loginUserInfo['id']])
+           ->dec('times', 1)
+           ->update();
+         return $this->success('数据获取成功',$balanceRes);
+    }
+
+    public function reduceCoin(){
+        global $_GPC;
+        $post = $this->request->post();
+        $type = $this->request->post('type','');
+        $role = $this->request->post('role','');
+        $linkId = $this->request->post('link_id',0);
+        $incrementId = $this->request->post('increment_id',0);
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        if(!$type){
+            return $this->error('请上传类型type',2);
+        }
+        if(!$linkId){
+            return $this->error('请上传ID',2);
+        }
+        if(!$role){
+            return $this->error('请填写要查询的role类型',2);
+        }
+        if($type == 'contact'){
+            $modelCall = new \app\model\Call();
+            $coin = ConfServiceFacade::get('system.plan.lock_'.$role);
+            if($role == 'job'){
+                $phone = \app\model\Job::where('id',$linkId)->value('phone');
+            }else{
+                $phone = \app\model\Worker::where('id',$linkId)->value('phone');
+            }
+            if($coin == 0){
+                $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
+                return $this->success('查看成功',$phone);
+            }
+            if($loginUserInfo['coin'] <$coin){
+                return $this->error('您的次数不足');
+            }
+            $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update();
+            if(!$res){
+                return $this->error('数据操作失败');
+            }
+            $modelCall->save(['uid'=>$loginUserInfo['id'],'role'=>$role,'link_id'=>$linkId,'uniacid'=>$_GPC['uniacid']]);
+            BillServiceFacade::record(0,$coin,$type,'获得联系方式',$loginUserInfo['id'],$_GPC['uniacid']);
+            // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','获得联系方式消耗次数'.$coin);
+            return $this->success('消费次数成功',$phone);
+        }elseif($type == 'top'){
+            if(!$incrementId){
+                return $this->error('请上传增值服务ID',2);
+            }
+            $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
+            if(!$incrementInfo){
+                return $this->error('获取增值服务信息失败');
+            }
+            if($loginUserInfo['coin'] < $incrementInfo['price']){
+                return $this->error('次数不足');
+            }
+            $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
+            if($role == 'job'){
+                $response = \app\model\Job::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
+            }else{
+                $response = \app\model\Worker::where('id',$linkId)->update(['top'=>1,'top_end'=>strtotime('+'.$incrementInfo['days'].'day')]);
+            }
+            BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费置顶服务',$loginUserInfo['id'],$_GPC['uniacid']);
+            // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','置顶服务消耗次数'.$incrementInfo['price']);
+            return $this->success('消费次数成功',$incrementInfo);
+        }elseif($type == 'refresh'){
+            if(!$incrementId){
+                return $this->error('请上传增值服务ID',2);
+            }
+            $incrementInfo = \app\model\Increment::where('id','=',$incrementId)->find();
+            if(!$incrementInfo){
+                return $this->error('获取增值服务信息失败');
+            }
+            if($loginUserInfo['coin'] <$incrementInfo['price']){
+                return $this->error('您的次数不足');
+            }
+            $res = \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$incrementInfo['price'])->update();
+            if($role == 'job'){
+                $response = \app\model\Job::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
+            }else{
+                $response = \app\model\Worker::where('id',$linkId)->update(['update_time'=>date('Y-m-d H:i:s')]);
+            }
+            BillServiceFacade::record(0,$incrementInfo['price'],$type,'消费刷新服务',$loginUserInfo['id'],$_GPC['uniacid']);
+            // MessageSystemServiceFacade::Unified($loginUserInfo['id'],'消费次数通知','刷新服务消耗次数'.$incrementInfo['price']);
+            return $this->success('消费次数成功',$res);
+        }
+    }
+
+    // 列表
+    public function bill(){
+        global $_GPC;
+        $modelBill = new \app\model\Bill();
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        $order = ['id' => 'desc'];
+        $where = ['uid' => $loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
+        $limit = $this->request->param('limit', 10);
+        $data  = $modelBill->order($order)->where($where)->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    // 列表
+    public function kami(){
+        global $_GPC;
+        $modelKami = new \app\model\Kami();
+        $code = $this->request->post('code',0);
+        if(!$code){
+            return $this->error('请输入卡密');
+        }
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        $info = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->find();
+        if(!$info){
+            return $this->error('未查询到卡密信息');
+        }
+        if($info['status'] == 1){
+            return $this->error('此卡已被启用过');
+        }
+        $res = $modelKami::where(['code'=>$code,'uniacid'=>$_GPC['uniacid']])->update(['status'=>1]);
+        $text = '使用卡密';
+        if($info[ 'type'] == 1){
+            $text = '使用卡密兑换次数';
+            \app\model\User::where(['id'=>$loginUserInfo['id']])->inc('coin',$info['value'])->update();
+        }elseif($info['type'] == 2){
+            $text = '使用卡密兑换时长';
+            if($loginUserInfo['vip_time'] < time()){
+                $balance = strtotime("+".$info['value']."days");
+            }else{
+                // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
+                $balance = $loginUserInfo['vip_time'] + $info['value']*24*60*60;
+            }
+            $updateRes2 = \app\model\User::where('id', '=', $loginUserInfo['id'])->update(['vip_time' => $balance]);
+        }
+        $modelKami->where(['id'=>$info['id']])->inc('uid',$loginUserInfo['id'])->update();
+        BillServiceFacade::record(1,$info['value'],'pay_member',$text,$loginUserInfo['id'],$_GPC['uniacid']);
+        return $this->success('兑换成功', $info);
+    }
+
+    public function customized()
+    {
+        global $_GPC;
+        $unionid = $this->request->post('unionid','');
+        $type = $this->request->post('type','addCoin');
+        $coin = $this->request->post('coin',0);
+        $day = $this->request->post('day',0);
+        if(!$unionid){
+            return $this->error('请上传uninid');
+        }
+        $userInfo = \app\model\User::where(['unionid'=>$unionid])->find();
+        if(!$userInfo){
+            return $this->error('未查询到此用户信息');
+        }
+        if($type == 'addCoin'){
+            $balanceRes = \app\model\User::where(['id'=>$userInfo['id']])->inc('coin',$coin)->update();
+            if(!$balanceRes){
+                return $this->error('增加金币失败');
+            }
+            BillServiceFacade::record(1,$coin,'pay_member','通过接口充值点数',$userInfo['id'],$_GPC['uniacid']);
+        }elseif($type == 'addVip'){
+            if($userInfo['vip_time'] < time()){
+                $balance = strtotime("+".$day."days");
+            }else{
+                // file_put_contents(__DIR__ . '/d.json', $info['day']*24*60*60);
+                $balance = $userInfo['vip_time'] + $day*24*60*60;
+            }
+            $balanceRes = \app\model\User::where('id', '=', $userInfo['id'])->update(['vip_time' => $balance]);
+            BillServiceFacade::record(1,$day,'pay_member','通过接口充值时长',$userInfo['id'],$_GPC['uniacid']);
+        }
+        return $this->success('成功', $balanceRes);
+    }
+
+}

+ 155 - 0
app/controller/api/Order.php

xqd
@@ -0,0 +1,155 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\api\UserServiceFacade;
+use app\service\ConfServiceFacade;
+use laytp\controller\Api;
+use laytp\library\Random;
+use think\facade\Db;
+
+class Order extends Api
+{
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Order();
+    }
+
+     // 无需登录的接口,*表示全部
+    public $noNeedLogin = [];
+
+    public function create()
+    {
+        global $_GPC;
+        $payPrice        = 0;
+        $post            = $this->request->post();
+        $linkId          = $this->request->post('link_id',0);
+        $mode            = $this->request->post('mode','member');
+        $type            = $this->request->post('type',1);
+        // $post['uniacid'] = $_GPC['uniacid'];
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        if($mode == 'direct'){
+            if($type == 1){
+
+            }else{
+                $payPrice = ConfServiceFacade::get('system.plan.pic_price');
+            }
+        }else{
+            if(!$linkId){
+                return $this->error('请选择需要开通的会员卡');
+            }
+            // 获得信息
+            $taskinfo = \app\model\Member::findOrEmpty($linkId)->toArray();
+            if($taskinfo['price'] <= 0){
+                return $this->error('金额需要大于0');
+            }
+            $payPrice = $taskinfo['price'];
+        }
+        //生成订单
+        $ordernumber = Random::numeric(20);
+        //拼接订单信息
+        $post['uid']          = $loginUserInfo['id'];
+        $post['pay_price']    = $payPrice;
+        $post['order_number'] = $ordernumber;
+        $post['uniacid'] = $_GPC['uniacid'];
+        $post['pay_type'] ='wechat';
+        Db::startTrans();
+        try{
+            $saveRes = $this->model->save($post);
+            if (!$saveRes) throw new \Exception('保存基础信息失败');
+            Db::commit();
+            $post['id'] = $this->model->id;
+            return $this->success('操作成功',$post);
+        }catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    public function createSettle()
+    {
+        global $_GPC;
+        $modelSettle = new \app\model\commission\Settle();
+        $modelUser = new \app\model\commission\User();
+        $payPrice        = 0;
+        $realName            = $this->request->post('real_name','');
+        $telnum            = $this->request->post('telnum','');
+        if(!$realName || !$telnum){
+            return $this->error('请上传姓名或手机号');
+        }
+        // $post['uniacid'] = $_GPC['uniacid'];
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        // print_r($loginUserInfo);
+        $payPrice = ConfServiceFacade::get('system.commission.commission_price');
+        if(!$payPrice || $payPrice==0){
+            return $this->error('订单金额错误');
+        }
+        $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find();
+        if(!empty($res) && $res['status'] == 1){
+            return $this->error('已经入驻过');
+        }
+        //生成订单
+        $ordernumber = Random::numeric(20);
+        //拼接订单信息
+        $post['uid']          = $loginUserInfo['id'];
+        $post['pay_price']    = $payPrice;
+        $post['order_number'] = $ordernumber;
+        $post['uniacid'] = $_GPC['uniacid'];
+        $post['real_name'] = $realName;
+        $post['telnum'] = $telnum;
+        $post['pay_type'] ='wechat';
+        Db::startTrans();
+        try{
+            $saveRes = $modelSettle->save($post);
+            if (!$saveRes) throw new \Exception('保存基础信息失败');
+            Db::commit();
+            $post['id'] = $modelSettle->id;
+            return $this->success('操作成功',$post);
+        }catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    public function detail()
+    {
+        global $_GPC;
+        $order_id = $this->request->param('id');
+        if(!$order_id){
+            return $this->error('请上传订单编号');
+        }
+        $order_info = $this->model->where('id','=',$order_id)->find();
+        if(!$order_info){
+            return $this->error('无数据');
+        }
+        return $this->success('返回成功',$order_info);
+    }
+
+    public function detailSettle()
+    {
+        global $_GPC;
+        $modelSettle = new \app\model\commission\Settle();
+        $order_id = $this->request->param('id');
+        if(!$order_id){
+            return $this->error('请上传订单编号');
+        }
+        $order_info = $modelSettle->where('id','=',$order_id)->find();
+        if(!$order_info){
+            return $this->error('无数据');
+        }
+        return $this->success('返回成功',$order_info);
+    }
+
+    public function my(){
+        global $_GPC;
+        $order = ['id' => 'desc'];
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $where = ['uid'=>$loginUserInfo['id'],'paid'=>1,'uniacid'=>$_GPC['uniacid']];
+        $limit = $this->request->param('limit', 10);
+        $data   = $this->model->order($order)->where($where)->with('memberInfo')->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败',2);
+        }
+        return $this->success('数据获取成功', $data);
+    }
+}

+ 559 - 0
app/controller/api/Pay.php

xqd
@@ -0,0 +1,559 @@
+<?php
+
+namespace app\controller\api;
+use app\service\api\UserServiceFacade;
+// use app\service\api\MiniappServiceFacade;
+use app\service\api\PayServiceFacade;
+use app\service\api\HupijiaopayServiceFacade;
+use app\service\ConfServiceFacade;
+use app\service\BillServiceFacade;
+// use app\service\admin\CapitalFlowServiceFacade;
+use laytp\controller\Api;
+use think\facade\Request;
+// use think\facade\Queue;
+use app\service\MessageSystemServiceFacade;
+use think\facade\Queue;
+
+/**
+ * 获取系统配置
+ */
+class Pay extends Api{
+
+  protected function _initialize()
+  {
+      $this->model = new \app\model\Order();
+  }
+
+  // 无需登录的接口,*表示全部
+  public $noNeedLogin = ['notify','test','notifySettle','notifyHupijiao'];
+
+  public function hupijiaopay(){
+      global $_GPC;
+      $post = $this->request->post();
+      $isCommission = $this->request->post('is_commission',0);
+      $returnUrl = $this->request->post('return_url','');
+      $callbackUrl = $this->request->post('callback_url','');
+      $platform = $this->request->header('platform');
+      // 获得订单信息
+      if ($isCommission ==1) {
+          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettleHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifySettleHupijiao';
+          $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
+      } else {
+          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifyHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifyHupijiao';
+          $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
+      }
+      if(!$pay_price){
+        return $this->error('获取订单数据失败');
+      }
+
+      $data =[
+          'version' => 1.1,
+          'trade_order_id'=>$post['order_number'],
+          'total_fee'=>$pay_price,
+          'title'=>'充值',
+          'time'=>time(),
+          'notify_url'=>$notify,
+          'return_url' => $returnUrl,
+          'callback_url'=>$callbackUrl,
+          'type'=>'WAP',
+          'wap_name'=>'支付'
+      ];
+      $res = HupijiaopayServiceFacade::pay($data);
+      return $this->success('获取结果', $res);
+  }
+
+  public function prepay(){
+      global $_GPC;
+    $post = $this->request->post();
+    $platform = $this->request->post('platform');
+    $isCommission = $this->request->post('is_commission',0);
+
+    // 获得订单信息
+    if ($isCommission ==1) {
+        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettle':request()->domain() . SURL . '/index.php/api.pay/notifySettle';
+        $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
+    } else {
+        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notify':request()->domain() . SURL . '/index.php/api.pay/notify';
+        $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
+    }
+    if(!$pay_price){
+      return $this->error('获取订单数据失败');
+    }
+    // print_r(request()->domain() . SURL . '/index.php/api.pay/notify');
+    $app  = PayServiceFacade::option($platform=='wxOfficialAccount'?'wechat':'miniapp');
+    $loginUserInfo = UserServiceFacade::getUserInfo();
+    // print_r($loginUserInfo);
+    $result = $app->order->unify([
+        'body' => '充值',
+        'out_trade_no' => $post['order_number'],
+        'total_fee' => $pay_price * 100,
+        'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+        'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+        'openid' => $platform=='wxOfficialAccount'?$loginUserInfo['openid_wechat']:$loginUserInfo['openid_miniapp'],
+    ]);
+    $jssdk = $app->jssdk;
+    if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
+      $config = $jssdk->bridgeConfig($result['prepay_id'], false);
+      return $this->success('获取结果', $config);
+    }
+    return $this->error('获取失败,'.json_encode($result,320));
+  }
+
+  public function hupijiao()
+  {
+      global $_GPC;
+  }
+
+  public function notify(){
+    global $_GPC;
+    // $app = PayServiceFacade::option();
+    $notifiedData = file_get_contents('php://input');
+    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
+    $xmlObj = json_decode(json_encode($xmlObj), true);
+    // 库里查
+    $order = $this->model->where('order_number','=',$xmlObj['out_trade_no'])->find();
+    // 如果订单不存在 或者 订单已经支付过了
+    if(!$order || $order['paid'] == 1){
+      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+    }
+    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+        // 用户是否支付成功
+        if ($xmlObj['result_code'] === 'SUCCESS') {
+          // 用户支付成功
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  = $this->model->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
+          $memberInfo = \app\model\Member::find($order['link_id']);
+          $this->setMember($order,$memberInfo);
+
+         // 分销
+         $this->setCommission($order,$memberInfo);
+
+          // $title = '下单支付成功通知';
+          // $content = '您的订单已支付,订单编号'.$xmlObj['out_trade_no'].',价格:¥'.$order['pay_price'];
+          // $jobQueueName ='wike_oddjob';
+          // $queueData =[
+          //     'uid' => $order['uid'],
+          //     'title'=>$title,
+          //     'content'=>$content,
+          //     'order_number'=>$xmlObj['out_trade_no'],
+          //     'pay_price'=>$order['pay_price'],
+          //     'status'=>'已支付',
+          //     'remark'=>'订单价格:'.$order['pay_price'],
+          //     'uniacid' => $order['uniacid']
+          // ];
+          // MessageSystemServiceFacade::Unified($order['uid'],$title,$content);
+          // $conf = ConfServiceFacade::groupGet('system.notification');
+          // if($conf['subscribe_status'] == 1){
+          //     Queue::later(3, 'app\jobs\SubscribeMessageJob@pay_suc', $queueData, $jobQueueName);
+          // }
+
+          // Queue::later(86400, 'app\jobs\SubscribeMessageJob@recommend', $queueData, $jobQueueName);
+          // Queue::later(432000, 'app\jobs\SubscribeMessageJob@new_video', $queueData, $jobQueueName);
+          if (!$updateRes) return false;
+        } elseif ($xmlObj['result_code'] === 'FAIL') {
+          // 用户支付失败
+          return false;
+        }
+    } else {
+        return false;
+    }
+    return true;
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
+  }
+
+  public function notifySettle(){
+    global $_GPC;
+    $modelSettle = new \app\model\commission\Settle();
+    $modelTeam =new \app\model\commission\Team();
+    $modelIncome =new \app\model\commission\Income();
+    $modelUser =new \app\model\commission\User();
+    // $app = PayServiceFacade::option();
+    $notifiedData = file_get_contents('php://input');
+    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
+    $xmlObj = json_decode(json_encode($xmlObj), true);
+    // 库里查
+    $order = $modelSettle->where('order_number','=',$xmlObj['out_trade_no'])->find();
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
+    // 如果订单不存在 或者 订单已经支付过了
+    if(!$order || $order['paid'] == 1){
+      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+    }
+    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+        // 用户是否支付成功
+        if ($xmlObj['result_code'] === 'SUCCESS') {
+          // 用户支付成功
+
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  =$modelSettle->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
+          $updateRes2 = $modelUser->save(['paid' => 1,'uniacid'=>$order['uniacid'],'status'=>1,'paid'=>1,'uid'=>$order['uid'],'real_name'=>$order['real_name'],'telnum'=>$order['telnum'] ]);
+
+          // 分销
+
+          $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
+          $conf = ConfServiceFacade::groupGet('system.commission');
+
+          if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
+              if($conf['first'] > 0){
+                 $firstLevel = $order['pay_price'] * ($conf['first'])/100;
+              }
+              if($conf['second'] > 0){
+                 $secondLevel = $order['pay_price'] * ($conf['second'])/100;
+              }
+              if($conf['third'] > 0){
+                 $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
+              }
+
+                if(!empty($teamUserInfo['pid'])){
+                      // 奖励给pid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $firstLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                          // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $a = $modelIncome->create([
+                                 'money' => $firstLevel,
+                                 'oid' => $order['id'],
+                                 'uid' => $teamUserInfo['pid'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+                  if(!empty($teamUserInfo['gid'])){
+                      // 奖励给gid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $secondLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                          // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $b = $modelIncome->create([
+                                 'money' => $secondLevel,
+                                 'uid' => $teamUserInfo['gid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+                  if(!empty($teamUserInfo['gfid'])){
+                      // 奖励给gfid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $thirdLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
+                          // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $c = $modelIncome->create([
+                                 'money' => $thirdLevel,
+                                 'uid' => $teamUserInfo['gfid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+              }
+
+          }
+          if (!$updateRes) return false;
+        } elseif ($xmlObj['result_code'] === 'FAIL') {
+          // 用户支付失败
+          return false;
+        }
+    } else {
+        return false;
+    }
+    return true;
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
+  }
+
+  public function notifyHupijiao()
+  {
+      global $_GPC;
+      $post = $this->request->post();
+      // file_put_contents(__DIR__ . '/notifyHupijiao.json', json_encode($post));
+      // 库里查
+      $order = $this->model->where('order_number','=',$post['trade_order_id'])->find();
+      // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
+      // 如果订单不存在 或者 订单已经支付过了
+      if(!$order || $order['paid'] == 1){
+        return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+      }
+      if($post['status'] === 'OD'){
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  = $this->model->where('order_number', '=', $post['trade_order_id'])->update(['paid'=>1, 'pay_time' => time(),'pay_channel'=>'hupijiao']);
+          $memberInfo = \app\model\Member::find($order['link_id']);
+          $this->setMember($order,$memberInfo);
+         // 分销
+         $this->setCommission($order,$memberInfo);
+      }
+      return 'success';
+  }
+
+  public function setMember($order,$memberInfo)
+  {
+      global $_GPC;
+
+      if(!empty($memberInfo) && !empty($memberInfo['type'])){
+         if($memberInfo['type']==2){
+             $modelVipinfo =new \app\model\Vipinfo();
+             $title = '充值时长';
+             $userInfo = \app\model\User::find($order['uid']);
+             if($memberInfo['day'] === 9999){
+                 $title = $title.'(永久)';
+                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => 9999]);
+             }else{
+                 $title = $title.'('.$memberInfo['day'].'天)';
+                 if($userInfo['vip_time'] < time()){
+                     $balance = strtotime("+".$memberInfo['day']."days");
+                 }else{
+                     // file_put_contents(__DIR__ . '/d.json', $memberInfo['day']*24*60*60);
+                     $balance = $userInfo['vip_time'] + $memberInfo['day']*24*60*60;
+                 }
+                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => $balance]);
+             }
+             BillServiceFacade::record(1,$memberInfo['coin'],'pay_member',$title,$order['uid'],$order['uniacid']);
+             // 写入余量
+             $vipinfo = $modelVipinfo->where('uid',$order['uid'])->find();
+             if(empty($vipinfo)){
+                 $save =[
+                     'uid'=>$order['uid'],
+                     'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
+                     'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
+                     'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
+                     'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
+                     'gpt35_type'=>$memberInfo['gpt35_type']?$memberInfo['gpt35_type']:'time',
+                     'gpt4_type'=>$memberInfo['gpt4_type']?$memberInfo['gpt4_type']:'time',
+                     'sd_type'=>$memberInfo['sd_type']?$memberInfo['sd_type']:'time',
+                     'mj_type'=>$memberInfo['mj_type']?$memberInfo['mj_type']:'time',
+                     'order_number'=>$order['order_number'],
+                     'member_id'=>$memberInfo['id'],
+                     'uniacid'=>$_GPC['uniacid']
+                 ];
+
+                 $res = $modelVipinfo->save($save);
+                 file_put_contents(__DIR__ . '/vipinfo.json', json_encode($res));
+             }else{
+                 $updata =[
+                     // 'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
+                     // 'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
+                     // 'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
+                     // 'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
+                     'order_number'=>$order['order_number'],
+                     'member_id'=>$memberInfo['id'],
+                     'uniacid'=>$_GPC['uniacid']
+                 ];
+                 if($memberInfo['gpt35_times'] == -1){
+                     $updata['gpt35_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         // 过期
+                             $updata['gpt35_times'] = $memberInfo['gpt35_times'];
+                     }else{
+                         if($vipinfo['gpt35_times']==-1){
+                            $updata['gpt35_times'] = -1;
+                         }else{
+                             $updata['gpt35_times'] = $vipinfo['gpt35_times'] + $memberInfo['gpt35_times'];
+                         }
+                     }
+
+                 }
+                 if($memberInfo['gpt4_times'] == -1){
+                     $updata['gpt4_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['gpt4_times'] = $memberInfo['gpt4_times'];
+                     }else{
+                         if($vipinfo['gpt4_times']==-1){
+                             $updata['gpt4_times'] = -1;
+                         }else{
+                             $updata['gpt4_times'] = $vipinfo['gpt4_times'] + $memberInfo['gpt4_times'];
+                         }
+
+                     }
+                 }
+                 if($memberInfo['sd_times'] == -1){
+                     $updata['sd_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['sd_times'] = $memberInfo['sd_times'];
+                     }else{
+                         if($vipinfo['sd_times']==-1){
+                             $updata['sd_times'] = -1;
+                         }else{
+                             $updata['sd_times'] = $vipinfo['sd_times'] + $memberInfo['sd_times'];
+                         }
+                     }
+                 }
+                 if($memberInfo['mj_times'] == -1){
+                     $updata['mj_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['mj_times'] = $memberInfo['mj_times'];
+                     }else{
+                         if($vipinfo['mj_times']==-1){
+                             $updata['mj_times'] = -1;
+                         }else{
+                             $updata['mj_times'] = $vipinfo['mj_times'] + $memberInfo['mj_times'];
+                         }
+                     }
+
+                 }
+                  $modelVipinfo->where('uid',$order['uid'])
+                  ->update($updata);
+             }
+         }else{
+              $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->inc('coin',$memberInfo['coin'])->update();
+              BillServiceFacade::record(1,$memberInfo['coin'],'pay_member','充值次数',$order['uid'],$order['uniacid']);
+         }
+      }
+  }
+
+  public function setCommission($order,$memberInfo)
+  {
+      global $_GPC;
+
+      $modelTeam =new \app\model\commission\Team();
+      $modelIncome =new \app\model\commission\Income();
+      $modelUser =new \app\model\commission\User();
+      $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
+      $conf = ConfServiceFacade::groupGet('system.commission');
+      // 获得购买者是否是分销商
+      $buyUserInfo= $modelUser::where('uid','=',$order['uid'])->find();
+      if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
+
+          if($conf['first'] > 0){
+             $firstLevel = $order['pay_price'] * ($conf['first'])/100;
+          }
+          if($conf['second'] > 0){
+             $secondLevel = $order['pay_price'] * ($conf['second'])/100;
+          }
+          if($conf['third'] > 0){
+             $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
+          }
+
+          if(!empty($conf['is_self_buy']) &&  $conf['is_self_buy'] == 1 && !empty($buyUserInfo) && $buyUserInfo['status'] == 1){
+
+              // 开启自购
+               $higherUserInfo = $modelUser::where('uid','=',$order['uid'])->find();
+               $banlance = $higherUserInfo['money'] + $firstLevel;
+               $modelUser::where('uid','=',$order['uid'])->update(['money'=>$banlance]);
+               // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+               $a = $modelIncome->create([
+                      'money' => $firstLevel,
+                      'oid' => $order['id'],
+                      'uid' => $order['uid'],
+                      'buy_uid' => $order['uid'],
+                      'buy_price'=>$order['pay_price'],
+                      'mark' => '自购返佣:您支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                      'uniacid'=>$_GPC['uniacid'],
+                  ]);
+                  if(!empty($teamUserInfo['pid'])){
+                      // 奖励给pid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                      // if($higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $secondLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                          // $a = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $a = $modelIncome->create([
+                                 'money' => $secondLevel,
+                                 'oid' => $order['id'],
+                                 'uid' => $teamUserInfo['pid'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的一级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      // }
+                  }
+                  if(!empty($teamUserInfo['gid'])){
+                      // 奖励给gid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                      if($higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $thirdLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                          // $b = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$thirdLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $b = $modelIncome->create([
+                                 'money' => $thirdLevel,
+                                 'uid' => $teamUserInfo['gid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的二级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+          } else {
+              if(!empty($teamUserInfo['pid'])){
+                  // 奖励给pid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $firstLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                      // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $a = $modelIncome->create([
+                             'money' => $firstLevel,
+                             'oid' => $order['id'],
+                             'uid' => $teamUserInfo['pid'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+              if(!empty($teamUserInfo['gid'])){
+                  // 奖励给gid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $secondLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                      // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $b = $modelIncome->create([
+                             'money' => $secondLevel,
+                             'uid' => $teamUserInfo['gid'],
+                             'oid' => $order['id'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+              if(!empty($teamUserInfo['gfid'])){
+                  // 奖励给gfid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $thirdLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
+                      // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $c = $modelIncome->create([
+                             'money' => $thirdLevel,
+                             'uid' => $teamUserInfo['gfid'],
+                             'oid' => $order['id'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+          }
+
+      }
+  }
+
+}

+ 134 - 0
app/controller/api/Question.php

xqd
@@ -0,0 +1,134 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use laytp\library\Random;
+use think\facade\Db;
+use app\service\ConfServiceFacade;
+use app\service\MemberServiceFacade;
+use app\service\api\UserServiceFacade;
+use app\service\BillServiceFacade;
+use app\service\api\ImageCensorServiceFacade;
+use app\service\api\MiniappServiceFacade;//微信小程序服务
+
+/**
+ * AI相关
+ * @ApiWeigh (90)
+ */
+class Question extends Api
+{
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Question();
+    }
+
+    public $noNeedLogin = [
+        "list"
+    ];
+
+    // 使用记录
+    public function list()
+    {
+        global $_GPC;
+        $order = ['id' => 'desc'];
+        $data  = $this->model->where('uniacid','=',$_GPC['uniacid'])->order($order)->select()->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    public function add()
+    {
+        global $_GPC;
+        $isValidity = 0;
+        $post = $this->request->post();
+        $question = $this->request->post('question','');
+        $answer = $this->request->post('answer','');
+        $platform = $this->request->header('platform','H5');
+        $conf = ConfServiceFacade::groupGet('system.config', 0);
+        $type = $this->request->post('type','gpt35');
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        if(!$question){
+            return $this->error('记录失败,请上传问题',2);
+        }
+        if(!$answer){
+            return $this->error('记录失败,请上传回答',2);
+        }
+        if($type =='gpt35'){
+            $coin = ConfServiceFacade::get('system.plan.unlock_gpt3',1);
+        }else{
+            $coin = ConfServiceFacade::get('system.plan.lock_gpt4',0);
+        }
+        $checkMember = MemberServiceFacade::check($loginUserInfo,$type,$coin,$conf);
+        if(isset($checkMember['status']) && !$checkMember['status']){
+            return $this->error($checkMember['msg'],2);
+        }
+
+        if($platform == 'wxMiniProgram'){
+            $check = MiniappServiceFacade::msgSecCheck($answer,$loginUserInfo['openid_miniapp']);
+            if(!$check){
+                return $this->error('失败,文字内容安全检测不通过!');
+            }
+        }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){
+            if(!empty($conf) && !empty($conf['is_h5_filter']) &&  $conf['is_h5_filter'] == 1){
+                $check = ImageCensorServiceFacade::textCensorUserDefined($answer);
+                if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){
+                    return $this->error('失败,文字内容安全检测不通过!');
+                }
+            }
+        }
+
+        if($coin >0){
+            $checkMember = MemberServiceFacade::cash($loginUserInfo,$type,$coin,$conf);
+            if(isset($checkMember['status']) && !$checkMember['status']){
+                return $this->error($checkMember['msg'],2);
+            }
+        }
+
+        $a = $this->model->save(['uid'=>$loginUserInfo['id'],'question'=>$question,'answer'=>$answer,'uniacid'=>$_GPC['uniacid'] ]);
+        if(!$a){
+            return $this->error('数据保存失败',2);
+        }
+        return $this->success('数据获取成功', $a);
+    }
+
+    // 使用记录
+    public function my()
+    {
+        global $_GPC;
+        $loginUserInfo      = UserServiceFacade::getUserInfo();
+        $order = ['id' => 'desc'];
+        $where = ['uid' => $loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']];
+        $limit = $this->request->param('limit', 10);
+        $data  = $this->model->order($order)->where($where)->paginate($limit)->toArray();
+        if(!$data){
+            return $this->error('数据获取失败');
+        }
+        return $this->success('数据获取成功', $data);
+    }
+
+    public function del(){
+        global $_GPC;
+        $loginUserInfo   = UserServiceFacade::getUserInfo();
+        $id = $this->request->post('id');
+        if (!$id) {
+            return $this->error('参数id不能为空',2);
+        }
+        $jobUid = $this->model->where('id',$id)->value('uid');
+        if($jobUid != $loginUserInfo['id']){
+            return $this->error('您没有删除的权限');
+        }
+        try{
+            $delRes = $this->model->destroy($id);
+            if (!$delRes) {
+                return $this->error('删除失败');
+            }
+            return $this->success('删除成功');
+        }catch (\Exception $e){
+            return $this->exceptionError($e);
+        }
+    }
+
+}

+ 51 - 0
app/controller/api/Template.php

xqd
@@ -0,0 +1,51 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use laytp\library\Random;
+use laytp\library\Tree;
+use think\facade\Db;
+
+/**
+ * AI相关
+ * @ApiWeigh (90)
+ */
+class Template extends Api
+{
+    protected function _initialize()
+    {
+        $this->model = new \app\model\Template();
+    }
+
+    public $noNeedLogin = [
+        "list",
+        "info"
+    ];
+
+    // 使用记录
+    public function list()
+    {
+        global $_GPC;
+        $template = [];
+        $where = ['status'=>1,'uniacid'=>$_GPC['uniacid']];
+        $order = ['sort' => 'DESC','id'=>'DESC'];
+        $sourceData =\app\model\Template::where($where)->order($order);
+        $menuTreeObj = Tree::instance();
+        $menuTreeObj->init($sourceData->select()->toArray());
+        $data = $menuTreeObj->getRootTrees();
+        return $this->success('数据获取成功', $data);
+    }
+
+    public function info()
+    {
+        global $_GPC;
+        $id    = $this->request->param('id');
+        $info = $this->model->find($id);
+        if(!$info){
+            return $this->error('详情获取失败');
+        }
+        return $this->success('获取成功', $info);
+    }
+
+}

+ 82 - 0
app/controller/api/Token.php

xqd
@@ -0,0 +1,82 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use laytp\library\Random;
+
+/**
+ * Token相关
+ */
+class Token extends Api
+{
+    public $no_need_login = [];
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (检测Token是否过期)
+     * @ApiSummary  (检测Token是否过期)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.token/check)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="object", description="返回的数据对象")
+     * @ApiReturnParams   (name="data.token", type="string", description="用户登录凭证,token")
+     * @ApiReturnParams   (name="data.expires_in", type="integer", description="token有效时间,单位秒")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "Token有效",
+    "time": 1591167181,
+    "data": {
+        "token": "827fb87e-2064-45c8-839a-128e195a7411",
+        "expires_in": 1789
+    }
+})
+     */
+    /*@formatter:on*/
+    public function check()
+    {
+        $token     = $this->service_user->getToken();
+        $tokenInfo = \library\Token::get($token);
+        $this->success('Token有效', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
+    }
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (刷新Token)
+     * @ApiSummary  (刷新Token)
+     * @ApiMethod   (POST)
+     * @ApiRoute    (/api.token/refresh)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="object", description="返回的数据对象")
+     * @ApiReturnParams   (name="data.token", type="string", description="用户登录凭证,token")
+     * @ApiReturnParams   (name="data.expires_in", type="integer", description="token有效时间,单位秒")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "成功刷新Token",
+    "time": 1591167423,
+    "data": {
+        "token": "e356df60-ff03-4f15-bb66-c0e3ef37f335",
+        "expires_in": 1800
+    }
+})
+     */
+    /*@formatter:on*/
+    public function refresh()
+    {
+        //删除源Token
+        $token = $this->service_user->getToken();
+        \library\Token::delete($token);
+        //创建新Token
+        $token = Random::uuid();
+        \library\Token::set($token, $this->service_user->id, $this->service_user->token_keep_time);
+        $this->success('成功刷新Token', ['token' => $token, 'expires_in' => $this->service_user->token_keep_time]);
+    }
+}

+ 348 - 0
app/controller/api/User.php

xqd
@@ -0,0 +1,348 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\api\UserServiceFacade;
+use app\validate\api\user\Login;
+use app\model\api\Log;
+use app\service\ConfServiceFacade;
+use plugin\ali_sms\service\AliSmsServiceFacade;
+use laytp\controller\Api;
+use laytp\library\Random;
+use laytp\library\Token;
+use laytp\library\Str;
+use think\facade\Db;
+
+/**
+ * 会员相关
+ * @ApiWeigh (90)
+ */
+class User extends Api
+{
+
+    protected function _initialize()
+    {
+        $this->model = new \app\model\User();
+    }
+
+    public $noNeedLogin = [
+        'login',
+        'login_code',
+        'register'
+    ];
+
+    // 用户名密码登录
+    public function login(){
+        global $_GPC;
+        //获取表单提交数据
+        $post = $this->request->post();
+        //验证表单提交
+        if(empty($post['account'])){
+            return $this->error('登录失败,请填写账号');
+        }
+        if(empty($post['password'])){
+            return $this->error('登录失败,请填写密码');
+        }
+        $loginUserInfo = $this->model->where(['account' => $post['account'],'uniacid'=>$_GPC['uniacid'] ])->find();
+        if(!$loginUserInfo){
+            return $this->error('登录失败,此账号无注册信息,请注册后再登录');
+        }
+        $passwordHash = $loginUserInfo->password;
+        if (!Str::checkPassword($post['password'], $passwordHash)) {
+            return $this->error('用户名或密码错误');
+        }
+        $status = $loginUserInfo->status;
+        if ($status == 2) {
+            return $this->error('用户已被禁用,请联系管理员');
+        }
+        $token   = Random::uuid();
+        $loginUserInfo['token'] = $token;
+        Token::set($token, $loginUserInfo['id'], 24 * 60 * 60 * 365);
+        //
+        // $post['password'] = '******';//登录成功不记录用户密码
+        // Log::create([
+        //     'login_status'   => 1,
+        //     'admin_id'       => $loginUserInfo['id'],
+        //     'request_body'   => json_encode($post),
+        //     'request_header' => json_encode($this->request->header()),
+        //     'ip'             => $this->request->ip(),
+        //     'create_time'    => date('Y-m-d H:i:s'),
+        //     'uniacid'        => $_GPC['uniacid'],
+        // ]);
+
+        return $this->success('登录成功', [
+            'user'=>$loginUserInfo
+        ]);
+    }
+
+    // 验证码登录
+    public function login_code(){
+        //获取表单提交数据
+        $post = $this->request->post();
+        if(!$post['phone'] || !$post['code']){
+            return $this->error('注册失败,请上传手机号或验证码!');
+        }
+        $check = AliSmsServiceFacade::checkCode($post['phone'],'register',$post['code']);
+        if(!$check){
+            return $this->error('验证失败,'.AliSmsServiceFacade::getError());
+        }
+        $loginUserInfo = $this->model->where('phone', '=', $post['phone'])->find();
+        if(!$loginUserInfo){
+            return $this->error('登录失败,此手机号无注册信息,请注册后再登录');
+        }
+        $token   = Random::uuid();
+        $res['token'] = $token;
+        Token::set($token, $loginUserInfo['id'], 24 * 60 * 60 * 3);
+        return $this->success('获取结果', $res);
+    }
+
+    // 绑定手机号
+    public function phone_binding(){
+        //获取表单提交数据
+        $post = $this->request->post();
+        if(!$post['phone'] || !$post['code']){
+            return $this->error('注册失败,请上传手机号或验证码!');
+        }
+        $check = AliSmsServiceFacade::checkCode($post['phone'],'register',$post['code']);
+        if(!$check){
+            return $this->error('验证失败,'.AliSmsServiceFacade::getError());
+        }
+        $loginUserInfo = $this->model->where('phone', '=', $post['phone'])->find();
+        // print_r($loginUserInfo);
+        if($loginUserInfo){
+            return $this->error('绑定失败,此手机号已有注册信息');
+        }
+        // $token   = Random::uuid();
+        // $res['token'] = $token;
+        // Token::set($token, $loginUserInfo['id'], 24 * 60 * 60 * 3);
+        // return $this->success('获取结果', $res);
+    }
+
+    // 通过手机验证码修改密码
+    public function reset()
+    {
+        $post  = $this->request->post();
+        if(!$post['phone'] || !$post['code'] || !$post['password']){
+            return $this->error('注册失败,请上传正确的手机号格式或验证码密码等信息!');
+        }
+        $check = AliSmsServiceFacade::checkCode($post['phone'],'register',$post['code']);
+        if(!$check){
+            return $this->error('验证失败,'.AliSmsServiceFacade::getError());
+        }
+        $loginUserInfo = $this->model->where('phone', '=', $post['phone'])->find();
+        if(!$loginUserInfo){
+            return $this->error('修改失败,此手机号无注册信息');
+        }
+        $post['password'] = Str::createPassword($post['password']);
+        $data = array('password' => $post['password']);
+        $updateRes = $this->model->where('id', '=', $loginUserInfo['id'])->update($data);
+        if (!$updateRes) throw new \Exception('保存基本信息失败');
+        return $this->success('获取结果', $loginUserInfo);
+    }
+
+    // 通过手机验证码修改密码
+    public function profile()
+    {
+        $post  = $this->request->post();
+        if(!($post['nickname'] || $post['avatar'])){
+            return $this->error('修改失败,请上传要修改的头像或昵称等信息');
+        }
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $updateRes = $this->model->where('id', '=', $loginUserInfo['id'])->update($post);
+        if (!$updateRes) throw new \Exception('保存基本信息失败');
+        if($post['nickname']){
+            $loginUserInfo['nickname'] = $post['nickname'];
+        }
+        if($post['avatar']){
+            $loginUserInfo['avatar'] = $post['avatar'];
+        }
+        return $this->success('获取结果', $loginUserInfo);
+    }
+
+    // 注册即登录
+    public function register()
+    {
+        global $_GPC;
+        $conf = ConfServiceFacade::groupGet('system.plan', true);
+        // $validate = new Login();
+        Db::startTrans();
+        try {
+            $post            = $this->request->post();
+            $post['uniacid'] = $_GPC['uniacid'];
+            if(!$post['account']){
+                return $this->error('注册失败,请填写账号!');
+            }
+            if(!$post['password']){
+                return $this->error('注册失败,请填写密码!');
+            }
+            $post['password'] = Str::createPassword($post['password']);
+            $loginUserInfo = $this->model->where('account', '=', $post['account'])->value('id');
+            if($loginUserInfo){
+                return $this->error('注册失败,此账号已被绑定!');
+            }
+             $post['login_time'] = date('Y-m-d H:i:s');
+             $post['id_number'] = Random::numeric(10);
+             $post['coin'] = !empty($conf['register'])?$conf['register']:0;
+             $post['nickname'] = '默认用户';
+            $saveRes = $this->model->save($post);
+            if (!$saveRes) throw new \Exception('保存基础信息失败');
+            Db::commit();
+            $token   = Random::uuid();
+            $post['token'] = $token;
+            Token::set($token, $this->model->id, 24 * 60 * 60 * 3);
+            return $this->success('操作成功',$post);
+        } catch (\Exception $e) {
+            Db::rollback();
+            return $this->error('数据库异常,操作失败');
+        }
+    }
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (根据token获取用户信息)
+     * @ApiSummary  (根据token获取用户信息)
+     * @ApiMethod   (GET)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data.id", type="integer", description="用户主键ID")
+     * @ApiReturnParams   (name="data.phone", type="string", description="手机号")
+     * @ApiReturnParams   (name="data.username", type="string", description="用户名")
+     * @ApiReturnParams   (name="data.nickname", type="string", description="昵称")
+     * @ApiReturnParams   (name="data.avatar", type="string", description="头像")
+     * @ApiReturnParams   (name="data.token", type="string", description="用户登录凭证,Token")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "获取成功",
+    "time": 1591149171,
+    "data": {
+        "id": 4,
+        "mobile": "17603005414",
+        "username": "",
+        "nickname": "",
+        "avatar": "http://local.laytp.com/static/index/image/default.png",
+        "token": "d32e5210-050d-4902-b4b2-0173da12e191"
+    }
+})
+     */
+    /*@formatter:on*/
+    public function info()
+    {
+        global $_GPC;
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $modelVipinfo =new \app\model\Vipinfo();
+        if($loginUserInfo['vip_time'] > time() || $loginUserInfo['vip_time']==9999){
+            $vipinfo = $modelVipinfo->where('uid',$loginUserInfo['id'])->find();
+            if(empty($vipinfo)){
+                $save =[
+                    'uid'=>$loginUserInfo['id'],
+                    'gpt35_times'=>-1,
+                    'uniacid'=>$_GPC['uniacid']
+                ];
+
+                $res = $modelVipinfo->save($save);
+            }
+        }
+
+
+        return $this->success('获取成功', $loginUserInfo);
+    }
+
+    // 用户数据
+    public function userData()
+    {
+        global $_GPC;
+        $modelVipinfo =new \app\model\Vipinfo();
+        $today = strtotime(date("Y-m-d"),time());
+        $loginUserInfo = UserServiceFacade::getUserInfo();
+        $data['coin'] = $loginUserInfo['coin'];
+        $data['vip_time'] = 0;
+        $data['countdown'] = 0; //倒计时多少天
+        $data['is_validity'] = 0;//有效期
+        $data['vip_info'] = '';
+        if(!empty($loginUserInfo['vip_time'])){
+            if($loginUserInfo['vip_time'] === 9999){
+                $data['is_validity'] = 1;
+                $data['countdown'] = 9999;
+            }else{
+                if($loginUserInfo['vip_time'] < time()){
+                    $data['is_validity'] = 0;
+                }else{
+                    $data['is_validity'] = 1;
+                    $data['countdown'] = round(($loginUserInfo['vip_time']-time())/86400);
+                }
+            }
+
+            $vipinfo = $modelVipinfo->where('uid',$loginUserInfo['id'])->find();
+            if(!empty($vipinfo)){
+                $data['vip_info'] = $vipinfo;
+                if($vipinfo['gpt35_type'] == 'time'){
+                    // 每天
+                    $data['vip_info']['gpt35_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','gpt35'],['is_time','=','1'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }else{
+                    // 总数
+                    $data['vip_info']['gpt35_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','gpt35'],['is_time','=','1'],['create_time','>',$vipinfo['create_time']],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }
+                if($vipinfo['gpt4_type'] == 'time'){
+                    // 每天
+                    $data['vip_info']['gpt4_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','gpt4'],['is_time','=','1'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }else{
+                    // 总数
+                    $data['vip_info']['gpt4_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','gpt4'],['is_time','=','1'],['create_time','>',$vipinfo['create_time']],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }
+                if($vipinfo['sd_type'] == 'time'){
+                    // 每天
+                    $data['vip_info']['sd_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['is_time','=','1'],['type','=','sd'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }else{
+                    // 总数
+                    $data['vip_info']['sd_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','sd'],['is_time','=','1'],['create_time','>',$vipinfo['create_time']],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }
+                if($vipinfo['mj_type'] == 'time'){
+                    // 每天
+                    $data['vip_info']['mj_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['is_time','=','1'],['type','=','mj'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }else{
+                    // 总数
+                    $data['vip_info']['mj_used'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','mj'],['is_time','=','1'],['create_time','>',$vipinfo['create_time']],['uniacid','=',$_GPC['uniacid']] ])->count();
+                }
+
+            }
+        }
+
+        $data['vip_time'] = !empty($loginUserInfo['vip_time'])?$loginUserInfo['vip_time']:0;
+        $data['share_count_today'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','share'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+        $data['video_count_today'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','video'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+        $data['sign_count_today'] = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=','sign'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ])->count();
+        return $this->success('获取成功', $data);
+    }
+
+    /*@formatter:off*/
+    /**
+     * @ApiTitle    (注销登录)
+     * @ApiSummary  (注销登录信息)
+     * @ApiMethod   (GET)
+     * @ApiRoute    (/api.user/logout)
+     * @ApiHeaders  (name="token", type="string", required="true", description="用户登录后得到的Token")
+     * @ApiReturnParams   (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
+     * @ApiReturnParams   (name="msg", type="string", description="返回描述")
+     * @ApiReturnParams   (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
+     * @ApiReturnParams   (name="data", type="null", description="只会返回null")
+     * @ApiReturn
+({
+    "code": 0,
+    "msg": "注销成功",
+    "time": 1584513627,
+    "data": null
+})
+     */
+    /*@formatter:on*/
+    public function logout()
+    {
+        if (UserServiceFacade::logout()) {
+            return $this->success('注销成功');
+        } else {
+            return $this->error(UserServiceFacade::getError());
+        }
+    }
+}

+ 237 - 0
app/controller/api/Wechat.php

xqd
@@ -0,0 +1,237 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\api\UserServiceFacade;
+use app\service\api\MiniappServiceFacade;
+use app\service\api\MpServiceFacade;
+// use app\service\MessageSystemServiceFacade;
+use app\service\ConfServiceFacade;
+use plugin\ali_sms\service\AliSmsServiceFacade;
+use laytp\controller\Api;
+use laytp\library\Random;
+use laytp\library\Token;
+
+class WeChat extends Api {
+
+  protected function _initialize()
+  {
+      $this->model = new \app\model\User();
+  }
+
+  public $noNeedLogin = [
+      'wechatJssdk',
+      'wechatAuth',
+      'wechatSilenceAuth',
+      'miniappAuth',
+      'miniappSilenceAuth',
+      'miniappUserInfo',
+      'authBindindPhone',
+      'wechatSilenceCode',
+      'notify'
+  ];
+
+  // 公众号jssdk
+  public function wechatJssdk(){
+    $app = MpServiceFacade::option();
+    $APIs = array('updateAppMessageShareData','updateTimelineShareData','openLocation','getLocation','chooseWXPay');
+    $uri = $this->request->param('uri');
+    $app->jssdk->setUrl($uri);
+    $res = $app->jssdk->buildConfig($APIs, $debug = false, $beta = false, $json = false);
+    return $this->success('获取结果', $res);
+  }
+
+  // 公众号登录
+  public function wechatAuth(){
+      global $_GPC;
+      $param = $this->request->param();
+      $app = MpServiceFacade::option('snsapi_userinfo');
+      $conf = ConfServiceFacade::groupGet('system.plan', true);
+      $user = $app->oauth->user();
+      // print_r($app->$oauth->redirect());
+      if($user['id']){
+        $userInfo = \app\model\User::where(['openid_wechat'=>$user['id'],'uniacid'=>$_GPC['uniacid']])->find();
+        if(!empty($userInfo['id'])){
+          $token   = Random::uuid();
+          $user['token'] = $token;
+          $user['phone'] = $userInfo['phone'];
+          $user['now_money'] = $userInfo['now_money'];
+          Token::set($token, $userInfo['id'], 24 * 60 * 60 * 365);
+        }else{
+          $param['openid'] = $user['id'];
+          $param['nickname'] = $user['nickname'];
+          $param['avatar'] = $user['avatar'];
+          $param['login_time'] = date('Y-m-d H:i:s');
+          $param['uniacid'] = $_GPC['uniacid'];
+          $param['openid_wechat'] = $user['id'];
+          $param['coin'] = !empty($conf['register'])?$conf['register']:0;
+          $param['id_number'] = Random::numeric(10);
+          if(!empty($user['original']['unionid'])){
+              $param['unionid'] = $user['original']['unionid'];
+          }
+          $saveRes = $this->model->save($param);
+          $token   = Random::uuid();
+          $user['token'] = $token;
+          Token::set($token, $this->model->id, 24 * 60 * 60 * 365);
+        }
+        return $this->success('获取结果', $user);
+      }
+  }
+
+  // 公众号静默登录
+  public function wechatSilenceAuth(){
+    $app = MpServiceFacade::option('snsapi_base');
+    $oauth = $app->oauth;
+    return $oauth->redirect();
+  }
+
+  // 公众号静默登录
+  public function wechatSilenceCode(){
+      global $_GPC;
+      $param = $this->request->param();
+      $app = MpServiceFacade::option('snsapi_base');
+      $response = $app->oauth->scopes(['snsapi_base'])->redirect('');
+      $user = $app->oauth->user();
+      if($user['id']){
+        $userId = \app\model\User::where(['openid_wechat'=>$user['id']])->value('id');
+        if($userId){
+          $token   = Random::uuid();
+          $user['token'] = $token;
+          Token::set($token, $userId, 24 * 60 * 60 * 365);
+        }else{
+          $param['openid'] = $user['id'];
+          $param['login_time'] = date('Y-m-d H:i:s');
+          $param['uniacid'] = $_GPC['uniacid'];
+          $param['openid_wechat'] = $user['id'];
+          $saveRes = $this->model->save($param);
+          $token   = Random::uuid();
+          $user['token'] = $token;
+          Token::set($token, $this->model->id,0);
+        }
+        return $this->success('获取结果', $user);
+      }
+    }
+
+    public function wechatCode(){
+        global $_GPC;
+        $param = $this->request->param();
+        $app = MpServiceFacade::option();
+        // $response = $app->oauth->scopes(['snsapi_base']);
+        $user = $app->oauth->user();
+        if($user['id']){
+          $userId = \app\model\User::where(['openid_wechat'=>$res['openid']])->value('id');
+          if($userId){
+            $token   = Random::uuid();
+            $res['token'] = $token;
+            Token::set($token, $userId, 24 * 60 * 60 * 365);
+          }else{
+            $param['openid'] = $res['openid'];
+            $param['login_time'] = date('Y-m-d H:i:s');
+            $param['uniacid'] = $_GPC['uniacid'];
+            $param['openid_wechat'] = $res['openid'];
+            $saveRes = $this->model->save($param);
+            $token   = Random::uuid();
+            $res['token'] = $token;
+            Token::set($token, $this->model->id, 24 * 60 * 60 * 365);
+          }
+          return $this->success('获取结果', $res);
+        }
+      }
+
+  // 小程序登录
+  public function miniappAuth(){
+      $app = MiniappServiceFacade::option();
+      $post = $this->request->post();
+      $decryptedData = $app->encryptor->decryptData($post['session_key'], $post['iv'], $post['encryptedData']);
+      $data = array('avatar' => $decryptedData['avatarUrl'], 'nickname' => $decryptedData['nickName']);
+      // print_r($decryptedData);
+      $user = UserServiceFacade::getUser();
+      $updateRes = $this->model->where('id', '=', $user['id'])->update($data);
+      if (!$updateRes) throw new \Exception('保存基本信息失败');
+      return $this->success('获取结果', $decryptedData);
+  }
+
+  // 小程序静默登录
+  public function miniappSilenceAuth(){
+      global $_GPC;
+      // print_r(Random::uuid());
+      $app = MiniappServiceFacade::option();
+      $code = $this->request->post('code');
+      $conf = ConfServiceFacade::groupGet('system.plan', true);
+      if(!$code){
+        return $this->error('注册失败,未上传code');
+      }
+      $res = $app->auth->session($code);
+      if(!empty($res['errcode'])){
+        return $this->error('注册失败,' . $res['errmsg'].'错误码-'.$res['errcode']);
+      } else {
+        $userId = \app\model\User::where(['openid_miniapp'=>$res['openid']])->value('id');
+        // print_r($userId);
+        if($userId){
+          $token   = Random::uuid();
+          $res['token'] = $token;
+          Token::set($token, $userId, 0);
+        }else{
+          $param['openid'] = $res['openid'];
+          $param['login_time'] = date('Y-m-d H:i:s');
+          $param['uniacid'] = $_GPC['uniacid'];
+          $param['openid_miniapp'] = $res['openid'];
+          $param['id_number'] = Random::numeric(10);
+          $param['coin'] = !empty($conf['register'])?$conf['register']:0;
+          $param['nickname'] = '默认用户';
+          $saveRes = $this->model->save($param);
+          $token   = Random::uuid();
+          $res['token'] = $token;
+          Token::set($token, $this->model->id, 0);
+          // MessageSystemServiceFacade::Unified($this->model->id,'用户注册成功通知','恭喜你注册成功');
+        }
+        return $this->success('获取结果', $res);
+      }
+  }
+
+  // 授权获取小程序用户手机号直接绑定
+  public function authBindindPhone(){
+      $post = $this->request->param();
+      if(!$post['session_key'] || !$post['iv'] || !$post['encryptedData']){
+        return $this->error('注册失败,未上传session_key,iv或encryptedData');
+      }
+      $app = MiniappServiceFacade::option();
+      $decryptedData = $app->encryptor->decryptData($post['session_key'], $post['iv'], $post['encryptedData']);
+      $loginUserInfo = UserServiceFacade::getUserInfo();
+      if($decryptedData['phoneNumber']){
+        $updateRes = $this->model->where('id', '=', $loginUserInfo['id'])->update(array('phone' => $decryptedData['phoneNumber'],'update_time'=>date('Y-m-d H:i:s')));
+        if (!$updateRes) throw new \Exception('保存基本信息失败');
+        $loginUserInfo['phone'] = $decryptedData['phoneNumber'];
+        return $this->success('获取结果', $loginUserInfo);
+      } else {
+        return $this->error('获取失败');
+      }
+  }
+
+  // 手机号验证码登录授权绑定
+  public function authBindindPhoneCode(){
+      $post = $this->request->post();
+      if(!$post['phone'] || !$post['code']){
+          return $this->error('绑定失败,请上传手机号或验证码!');
+      }
+      $check = AliSmsServiceFacade::checkCode($post['phone'],'register',$post['code']);
+      if(!$check){
+          return $this->error('验证失败,'.AliSmsServiceFacade::getError());
+      }
+      $loginUserInfo = UserServiceFacade::getUserInfo();
+      $updateRes = $this->model->where('id', '=', $loginUserInfo['id'])->update(array('phone' => $post['phone']));
+      if (!$updateRes) throw new \Exception('保存基本信息失败');
+      $loginUserInfo['phone'] = $post['phone'];
+      return $this->success('获取结果', $loginUserInfo);
+  }
+
+  public function notify(){
+    $code = $this->request->param('code','');
+    $app = MpServiceFacade::option('snsapi_userinfo');
+    $user = $app->oauth->user();
+    // return $this->success('获取结果', $user);
+    // header('Location:/addons/yizhi_dev/public/page');
+    // file_put_contents(__DIR__ . '/dss.json', json_encode($user));
+  }
+
+}

+ 1 - 0
app/controller/api/complete.json

xqd
@@ -0,0 +1 @@
+{"task_id":"7329e123-caeb-4af9-baea-bf917dd50be4","image_id":"1117034942472396832","image_url":"https:\/\/midjourney.cdn.zhishuyun.com\/attachments\/1115268809889169493\/1117034942472396832\/agardner_ignoref3ed7f6a-c7ac-480b-a362-dacc7ee40d9b_beauty_85848263-f0a8-44b0-b6b9-b826c2e7981c.png","actions":["variation1"],"progress":100}

+ 1 - 0
app/controller/api/ds.json

xqd
@@ -0,0 +1 @@
+{"message":"unexpected end of JSON input","type":"one_api_error","param":"","code":"unmarshal_response_body_failed"}

+ 1 - 0
app/controller/api/ds2.json

xqd
@@ -0,0 +1 @@
+{"type":"gpt4","url":"https:\/\/api.gptmf.top\/v1\/chat\/completions","sk":"sk-Lumo32Jh23arN9pcA9AcD9605eA24cB0Bb531cBeCcB1B35f","model":"gpt-4-0613"}

+ 1 - 0
app/controller/api/ds3.json

xqd
@@ -0,0 +1 @@
+{"model":"gpt-3.5-turbo-0301","messages":"[]","temperature":0,"presence_penalty":0,"frequency_penalty":0,"max_tokens":3000,"stream":true}

+ 1 - 0
app/controller/api/mjNotify.json

xqd
@@ -0,0 +1 @@
+{"success":true,"task_id":"0b91c625-0abb-49ba-ae80-b65274924df0","image_id":"1119997506445639780","image_url":"https:\/\/midjourney.cdn.zhishuyun.com\/attachments\/1117962980529819762\/1119997506445639780\/Adoghma_ignore0b91c625-0abb-49ba-ae80-b65274924df0_Guazi_face_w_ce65d9c4-cc1d-4b7d-947d-7ad0e9bbd5ce.png","actions":["upsample1","upsample2","upsample3","upsample4","variation1","variation2","variation3","variation4"]}

+ 1 - 0
app/controller/api/notify.json

xqd
@@ -0,0 +1 @@
+{"status":"success","webhook_type":"success","track_id":"dfaf8fd8-e178-e7cc-a08e-7685ed26b717","id":16908887,"output":["https:\/\/cdn.stablediffusionapi.com\/generations\/2fac9152-eabb-49dd-906e-8a0c0f74dc8e-0.png"],"meta":{"H":512,"W":512,"enable_attention_slicing":"true","file_prefix":"2fac9152-eabb-49dd-906e-8a0c0f74dc8e","guidance_scale":7,"model":"runwayml\/stable-diffusion-v1-5","n_samples":1,"negative_prompt":"((nsfw)), ((out of frame)), ((extra fingers)), mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), (((tiling))), ((naked)), ((tile)), ((fleshpile)), ((ugly)), (((abstract))), blurry, ((bad anatomy)), ((bad proportions)), ((extra limbs)), cloned face, glitchy, ((extra breasts)), ((double torso)), ((extra arms)), ((extra hands)), ((mangled fingers)), ((missing breasts)), (missing lips), ((ugly face)), ((fat)), ((extra legs))","outdir":"out","prompt":"((extremely fine CG unified 8k wallpaper)), ((extremely fine)), ((texture)), ((fine detail)), (extremely fine and beautiful)), Genshin impact, very close to the audience, ink, watercolor, spirit, happy girl, black hexagonal cap, black beret, flying hair, curly hair, beautiful detail eyes, cherry blossom pupils, burning forest, sparks, animated face, black dress, HuTao, messy long hair, Chinese brides dress, token, brown black hair, flame, Depth of Field, Ruby Necklace, Fire Butterfly, Flying Sparks, Yin Yang Master, Ghost, Revealing Teeth, Smiling","revision":"fp16","safetychecker":"no","seed":1981878522,"steps":20,"vae":"stabilityai\/sd-vae-ft-mse"}}

+ 1 - 0
app/controller/api/notifyHupijiao.json

xqd
@@ -0,0 +1 @@
+{"trade_order_id":"93482941261687350507","total_fee":"0.01","transaction_id":"4200001833202306147191435797","open_order_id":"20233052765","order_title":"\u5145\u503c","status":"OD","nonce_str":"7116798346","time":"1686749137","appid":"201906155508","hash":"ea45520f336f3254de9f52ce0daa598e"}

+ 1 - 0
app/controller/api/replace.json

xqd
@@ -0,0 +1 @@
+"https:\/\/sd.iduomi.cc\/generations\/2fac9152-eabb-49dd-906e-8a0c0f74dc8e-0.png"

+ 1 - 0
app/controller/api/uploadImageInfo.json

xqd
@@ -0,0 +1 @@
+{"id":856,"path":"https:\/\/dev.iduomi.cc\/addons\/wike_chatgpt\/public\/static\/storage\/20230513\/661b3fbcd657d822edf1dbf1658e2c4b.png","name":"20230513\/661b3fbcd657d822edf1dbf1658e2c4b.png"}

+ 1 - 0
app/controller/api/vipinfo.json

xqd
@@ -0,0 +1 @@
+true

+ 88 - 0
app/exception/Http.php

xqd
@@ -0,0 +1,88 @@
+<?php
+
+namespace app\exception;
+
+use app\model\api\Log;
+use think\exception\Handle;
+use Throwable;
+
+/**
+ * 异常处理接管
+ *  解决的问题:
+ *      1.记录数据库日志
+ *      2.windows环境下,出现异常时,页面输出空白的问题
+ * Class Http
+ * @package app\exception
+ */
+class Http extends Handle
+{
+    /**
+     * 不需要记录信息(日志)的异常类列表
+     *  定义为空,说明是所有异常全部都记录
+     * @var array
+     */
+    protected $ignoreReport = [];
+
+    /**
+     * 记录异常信息(包括日志或者其它方式记录)
+     *
+     * @access public
+     * @param  Throwable $exception
+     * @return void
+     */
+    public function report(Throwable $exception): void
+    {
+        // 非命令行下,记录错误日志
+        if(PHP_SAPI !== 'cli') {
+            $request = request();
+            // 记录数据库日志
+            // 这里必须要try,不然,如果报数据库错误,系统会循环调用异常接管程序,导致500
+            try{
+                Log::create([
+                    'rule' => $request->url(),
+                    'request_body' => json_encode(request()->post(), JSON_UNESCAPED_UNICODE),
+                    'request_header' => json_encode(request()->header(), JSON_UNESCAPED_UNICODE),
+                    'ip' => $request->ip(),
+                    'status_code' => 500,
+                    'response_body' => json_encode($this->convertExceptionToArray($exception), JSON_UNESCAPED_UNICODE),
+                    'create_time' => date('Y-m-d H:i:s'),
+                ]);
+            }catch (\Exception $e){
+
+            }
+        }
+
+        // 使用内置的方式记录异常日志
+        parent::report($exception);
+    }
+
+    /**
+     * 收集异常数据
+     *  重写父类此方法,将Server/Request Data进行转码,解决windows环境下,出现异常时,页面输出空白的问题
+     * @param Throwable $exception
+     * @return array
+     */
+    protected function convertExceptionToArray(Throwable $exception): array
+    {
+        $data = parent::convertExceptionToArray($exception);
+        $data['tables']['Server/Request Data'] = $this->changeToUtf8($this->app->request->server());
+
+        return $data;
+    }
+
+    /**
+     * 将获取的服务器信息中的中文编码转为utf-8
+     * 修复在开启debug模式时出现的Malformed UTF-8 characters 错误
+     * @access protected
+     * @param $data array
+     * @return array                 转化后的数组
+     */
+    protected function changeToUtf8(array $data): array
+    {
+        foreach ($data as $key => $value) {
+            $data[$key] =  mb_convert_encoding($value, "UTF-8", "GBK, GBK2312");
+        }
+
+        return $data;
+    }
+}

+ 1 - 0
app/exception/laytp.tpl

xqd
@@ -0,0 +1 @@
+{"code":0,"msg":"请求出现异常","data":{}}

+ 11 - 0
app/middleware.php

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

+ 33 - 0
app/middleware/AllowCrossDomain.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+namespace app\middleware;
+
+use laytp\BaseMiddleware;
+use think\Request;
+
+/**
+ * 允许跨域中间件
+ * Class Auth
+ * @package app\middleware
+ */
+class AllowCrossDomain extends BaseMiddleware
+{
+    /**
+     * 执行中间件
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     */
+    public function handle($request, \Closure $next)
+    {
+        $header = [
+            // 'Content-Type'=>'text/html;charset=utf-8',
+            'Access-Control-Allow-Origin'   => '*',
+            'Access-Control-Allow-Methods'  => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
+            'Access-Control-Allow-Headers'  => '*',
+            'Access-Control-Allow-Credentials' =>true
+        ];
+
+        return $next($request)->header($header);
+    }
+}

+ 72 - 0
app/middleware/admin/ActionLog.php

xqd
@@ -0,0 +1,72 @@
+<?php
+/**
+ * 后台操作日志中间件
+ */
+namespace app\middleware\admin;
+
+use app\model\admin\action\Log;
+use laytp\BaseMiddleware;
+use app\model\admin\Menu;
+use app\service\admin\admin\UserServiceFacade;
+use think\Request;
+
+class ActionLog extends BaseMiddleware
+{
+    /**
+     * 执行中间件
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function handle(Request $request, \Closure $next)
+    {
+        global $_W;
+        $initUser = UserServiceFacade::init($request->header('laytp-admin-token', $request->cookie('laytpAdminToken')));
+        // print_r($initUser);
+        if (!$initUser || $request->isGet()) return $next($request);
+        $requestBody = $request->post();
+        //日志不记录密码
+        if (isset($requestBody['password'])) {
+            $requestBody['password'] = '******';
+        }
+
+        $rule  = $request->url();
+        $menu  = '';
+        $menus = Menu::where('rule', '=', $rule)->order('pid', 'asc')->select()->toArray();
+        if ($menus) {
+            for ($i = 1; $i <= 4; $i++) {
+                if ($menus[0]['pid']) {
+                    $tempMenu = Menu::where('id', '=', $menus[0]['pid'])->find();
+                    if ($tempMenu) {
+                        $tempMenu = $tempMenu->toArray();
+                        array_unshift($menus, $tempMenu);
+                    }
+                } else {
+                    break;
+                }
+            }
+            $menuName = [];
+            foreach ($menus as $v) {
+                $menuName[] = $v['name'];
+            }
+            $menu = implode(' - ', $menuName);
+        }
+
+
+        Log::create([
+            'admin_id'       => UserServiceFacade::getUser()->id,
+            'rule'           => $request->url(),
+            'menu'           => $menu,
+            'request_body'   => json_encode($requestBody, JSON_UNESCAPED_UNICODE),
+            'request_header' => json_encode(request()->header(), JSON_UNESCAPED_UNICODE),
+            'ip'             => request()->ip(),
+            'create_time'    => date('Y-m-d H:i:s'),
+            'uniacid'        => $_W['uniacid']
+        ]);
+
+        return $next($request);
+    }
+}

+ 136 - 0
app/middleware/admin/Auth.php

xqd
@@ -0,0 +1,136 @@
+<?php
+
+namespace app\middleware\admin;
+
+use app\service\admin\AuthServiceFacade;
+use app\service\admin\admin\UserServiceFacade;
+use laytp\BaseMiddleware;
+use laytp\library\Random;
+use laytp\library\Token;
+use think\Request;
+
+class Auth extends BaseMiddleware
+{
+    /**
+     * 执行中间件
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     */
+    public function handle(Request $request, \Closure $next)
+    {
+      // 检测脚本
+    //   $sysInfo = $this->w_getSysInfo();
+    //   if (isset($sysInfo['swoole_loader']) and isset($sysInfo['swoole_loader_version'])) {
+    //     if(!$sysInfo['swoole_loader']){
+    //         return $this->error('未安装脚本', 10402);
+    //     }
+    //   } else {
+    //       return $this->error('未安装脚本', 10402);
+    //   }
+      // 兼容W7
+      global $_W;
+      // print_r($_W['setting']['copyright']);
+        require IA_ROOT_WK . DS . 'config' . DS . 'config.php';
+        if(SYS_TYPE == 'W7'){
+                if (empty($_W['uniacid'])) {
+                   $uniacidKey = '__uniacid';
+                   $sessionKey = '__session';
+                   if(empty($_COOKIE[$configCookie['pre'] . $uniacidKey])) {
+                      return $this->error('没有获取到uniacid', 10403);
+                   }
+                   $_W['uniacid'] =  $_COOKIE[$configCookie['pre'] . $uniacidKey];
+                   if (empty($_COOKIE[$configCookie['pre'] . $sessionKey])) {
+                      return $this->error('请重新从总平台登录', 10403);
+                   }
+                }
+                if(W7_TYPE=='W7R'){
+                    $_W['uniacid'] = 1;
+                }
+        } else {
+            $_W['uniacid'] = 1;
+        }
+        if (AuthServiceFacade::needLogin()) {
+            $initUser = UserServiceFacade::init($request->header('laytp-admin-token', $request->header('laytpAdminToken', $request->cookie('laytpAdminToken'))));
+            // print_r($request->header('laytp-admin-token', $request->header('laytpAdminToken', $request->cookie('laytpAdminToken'))));
+
+            if (!$initUser){
+                if(SYS_TYPE == 'W7'){
+                    // if (empty($_W['uniacid'])){
+                    //     return $this->error('登录信息无uniacid', 10403);
+                    // }
+                    // $loginUserInfo = \app\model\admin\User::where('username', '=', 'admin')->field(UserServiceFacade::getAllowFields())->findOrEmpty();
+                    // $userId = 1;
+                    // $token   = Random::uuid();
+                    // $loginUserInfo['token'] = $token;
+                    // Token::set($token, $userId, 0);
+                    // print_r($token);
+                    // $initUser = UserServiceFacade::init($token);
+                    return $this->error('登录信息已过期', 10402);
+                    // print_r($initUser);
+                } else {
+                    $this->error(UserServiceFacade::getError(), 10401);
+                }
+            }
+            if (!UserServiceFacade::isLogin()) {
+                if ($request->isAjax()) {
+                    if(SYS_TYPE == 'W7'){
+                        return $this->error('登录信息已过期', 10402);
+                    }else{
+                        return $this->error('登录信息已过期', 10401);
+                    }
+                } else {
+                    return redirect('/admin/login.html');
+                }
+            }
+            if (AuthServiceFacade::needAuth()) {
+                $user = UserServiceFacade::getUser();
+                // print_r($user);
+                if ($user->is_super_manager !== 1) {
+                    $userId     = $user->id;
+                    $plugin     = defined('LT_PLUGIN') ? LT_PLUGIN : '';
+                    $controller = strtolower(str_replace("\\", ".", $request->controller()));
+                    if ($plugin) {
+                        $node = 'plugin/' . $plugin . '/' . $controller . '/' . $request->action();
+                    } else {
+                        $node = trim(app('http')->getName() . '/' . $controller . '/' . $request->action(),'/');
+                    }
+
+                    if (!AuthServiceFacade::hasAuth($userId, $node)) {
+                        return $this->error('无权请求:/' . $node);
+                    }
+                }
+            }
+        }
+        return $next($request);
+    }
+    public function w_getSysInfo() {
+        global $env;
+        $sysEnv = [];
+        // Get content of phpinfo
+        ob_start();
+        phpinfo();
+        $sysInfo = ob_get_contents();
+        ob_end_clean();
+        // Explode phpinfo content
+        if ($env['php']['run_mode'] == 'cli') {
+            $sysInfoList = explode('\n', $sysInfo);
+        } else {
+            $sysInfoList = explode('</tr>', $sysInfo);
+        }
+        foreach($sysInfoList as $sysInfoItem) {
+            if (preg_match('/thread safety/i', $sysInfoItem)) {
+                $sysEnv['thread_safety'] = (preg_match('/(enabled|yes)/i', $sysInfoItem) != 0);
+            }
+            if (preg_match('/swoole_loader support/i', $sysInfoItem)) {
+                $sysEnv['swoole_loader'] = (preg_match('/(enabled|yes)/i', $sysInfoItem) != 0);
+            }
+            if (preg_match('/swoole_loader version/i', $sysInfoItem)) {
+                preg_match('/\d+.\d+.\d+/s', $sysInfoItem, $match);
+                $sysEnv['swoole_loader_version'] = isset($match[0]) ? $match[0] : false;
+            }
+        }
+        //var_dump($sysEnv);die();
+        return $sysEnv;
+    }
+}

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

xqd
@@ -0,0 +1,36 @@
+<?php
+
+namespace app\middleware\api;
+
+use app\service\api\AuthServiceFacade;
+use app\service\api\UserServiceFacade;
+use laytp\BaseMiddleware;
+use think\Request;
+
+class Auth extends BaseMiddleware
+{
+    /**
+     * 执行中间件
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     */
+    public function handle(Request $request, \Closure $next)
+    {
+        global $_GPC;
+        foreach ($_GET as $key => $value) {
+            $_GET[$key] = $_GPC[$key] = $value;
+        }
+        if (AuthServiceFacade::needLogin()) {
+            $initUser = UserServiceFacade::init($request->header('token'));
+            if (!$initUser) return $this->error(UserServiceFacade::getError(), 10401);
+            if (!UserServiceFacade::isLogin()) {
+                return $this->error('登录信息已过期', 10401);
+            }
+        } else {
+            //不需要登录的接口,也可能需要获取登录用户的信息
+            UserServiceFacade::init($request->header('token'));
+        }
+        return $next($request);
+    }
+}

+ 61 - 0
app/middleware/api/CheckSign.php

xqd
@@ -0,0 +1,61 @@
+<?php
+
+namespace app\middleware\api;
+
+use app\service\api\CheckSignServiceFacade;
+use app\service\ConfServiceFacade;
+use laytp\BaseMiddleware;
+use laytp\traits\JsonReturn;
+use think\Request;
+
+/**
+ * 签名验证中间件
+ *  签名生成方式:strtoupper(md5(md5($hearder['request-time']).md5(Config::get('laytp.api.signKey'))))
+ *  签名验证方式:
+ *      请求的header头中需要有两个参数:
+ *          - request-time = 当前请求的时间,这个单位并不要求固定,甚至传的都可以不是当前请求的时间,只要sign的值是使用这个参数的值按照规定的算法生成即可
+ *          - sign = md5(md5($hearder['request-time']).md5(Config::get('laytp.api.signKey')))
+ *      此中间件,使用header头中request-time按照签名算法生成签名,然后与header中传递的sign参数比对,看是否一致,如果一致就通过验证,如果不一致就验证失败
+ *  需要设计,有些方法无需验签。比如获取配置的接口,需要得到后台配置的Config::get('laytp.api.signKey')
+ * Class CheckSign
+ * @package app\middleware
+ */
+class CheckSign extends BaseMiddleware
+{
+    use JsonReturn;
+
+    /**
+     * 执行中间件
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     */
+    public function handle(Request $request, \Closure $next)
+    {
+        return $next($request);
+        if (intval(ConfServiceFacade::get('system.basic.checkSign')) === 1) {
+            if (CheckSignServiceFacade::needCheckSign()) {
+                if (CheckSignServiceFacade::check()) {
+                    return $next($request);
+                } else {
+                    if(env('APP_DEBUG')){
+                        return $this->error('签名验证失败',0, [
+                            '签名验证的规则描述' => '1. 后台系统配置->基础配置,Api签名开关需要打开,Api签名的Key需要设置(允许为空);2. 客户端在请求Api接口时,需要在header里面传递两个参数,request-time和sign,sign的值要等于strtoupper(md5(md5(header:request-time).md5(conf:signKey)))',
+                            '注意点' => '如果是使用的生成Api文档在线测试接口,请点击右上角Api请求配置将签名验证开关打开',
+                            '生成签名的规则' => 'strtoupper(md5(md5(header:request-time).md5(conf:signKey)))',
+                            '系统配置的生成签名的Key' => ConfServiceFacade::get('system.basic.signKey'),
+                            'header部分传递的request-time值' => $request->header('request-time'),
+                            'header部分传递的sign值' => $request->header('sign'),
+                            '后端计算的sign值' => CheckSignServiceFacade::getError()
+                        ]);
+                    }
+                    return $this->error(CheckSignServiceFacade::getError());
+                }
+            } else {
+                return $next($request);
+            }
+        } else {
+            return $next($request);
+        }
+    }
+}

+ 28 - 0
app/model/Banner.php

xqd
@@ -0,0 +1,28 @@
+<?php
+/**
+ * 会员卡模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Banner extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'banner';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+    //关联模型
+	public function imgFile(){
+        return $this->belongsTo('app\model\Files','img','id')->bind(['path']);
+    }
+
+    //新增属性的方法
+}

+ 31 - 0
app/model/Bill.php

xqd
@@ -0,0 +1,31 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+
+class Bill extends BaseModel
+{
+
+    //模型名
+    protected $name = 'bill';
+
+    //附加属性
+    protected $append = ['create_time_int'];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function userinfo(){
+       return $this->belongsTo('app\model\User','uid','id')->bind(['nickname']);
+   }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 13 - 0
app/model/Conf.php

xqd
@@ -0,0 +1,13 @@
+<?php
+/**
+ * 系统配置模型
+ */
+
+namespace app\model;
+
+use laytp\BaseModel;
+
+class Conf extends BaseModel
+{
+    protected $name = 'conf';
+}

+ 57 - 0
app/model/Files.php

xqd
@@ -0,0 +1,57 @@
+<?php
+/**
+ * 附件管理模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+use laytp\library\UploadDomain;
+
+class Files extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'files';
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    public function category(){
+        return $this->belongsTo('app\model\files\Category','category_id','id');
+    }
+
+	public function createAdminUser(){
+        return $this->belongsTo('app\model\admin\User','create_admin_user_id','id');
+    }
+
+	public function updateAdminUser(){
+        return $this->belongsTo('app\model\admin\User','update_admin_user_id','id');
+    }
+
+    //新增属性的方法
+    public function getPathAttr($value, $data)
+	{
+		return $value ? UploadDomain::singleAddUploadDomain($data) : '';
+	}
+
+	public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+
+	public function getDeleteTimeIntAttr($value, $data)
+	{
+		return isset($data['delete_time']) ? strtotime($data['delete_time']) : 0;
+	}
+}

+ 57 - 0
app/model/Gallery.php

xqd
@@ -0,0 +1,57 @@
+<?php
+/**
+ * 类别模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+use laytp\library\UploadDomain;
+
+class Gallery extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'gallery';
+
+    //附加属性
+    protected $append = ['imgs_file','imgs_path'];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function modelsInfo(){
+        return $this->belongsTo('app\model\Models','model_id','model_id')->bind(['model_name'=>'name']);
+    }
+
+	public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname','avatar','id_number']);
+    }
+
+    //新增属性的方法
+	public function getImgsFileAttr($value, $data)
+	{
+		return (isset($data['imgs']) && $data['imgs']) ? UploadDomain::multi($data['imgs']) : '';
+	}
+	public function getImgsPathAttr($value, $data)
+	{
+		return (isset($data['imgs']) && $data['imgs']) ? UploadDomain::multiJoin($data['imgs']) : '';
+	}
+
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+    public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+
+	public function getDeleteTimeIntAttr($value, $data)
+	{
+		return isset($data['delete_time']) ? strtotime($data['delete_time']) : 0;
+	}
+}

+ 30 - 0
app/model/Hot.php

xqd
@@ -0,0 +1,30 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Hot extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'hot';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 33 - 0
app/model/Kami.php

xqd
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Kami extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'kami';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname']);
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 25 - 0
app/model/Member.php

xqd
@@ -0,0 +1,25 @@
+<?php
+/**
+ * 会员卡模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Member extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'member';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+    //关联模型
+
+    //新增属性的方法
+}

+ 13 - 0
app/model/Migrations.php

xqd
@@ -0,0 +1,13 @@
+<?php
+/**
+ * 数据库迁移模型
+ */
+
+namespace app\model;
+
+use laytp\BaseModel;
+
+class Migrations extends BaseModel
+{
+    protected $name = 'migrations';
+}

+ 39 - 0
app/model/Mode.php

xqd
@@ -0,0 +1,39 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+use app\service\EncryptServiceFacade;
+
+class Mode extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'mode';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function imgFile(){
+        return $this->belongsTo('app\model\Files','img','id');
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+    // public function getGuideAttr($value, $data)
+    // {
+    //     return isset($data['guide'])?EncryptServiceFacade::encrypt($data['guide'],WIKE):0;
+    // }
+}

+ 39 - 0
app/model/Models.php

xqd
@@ -0,0 +1,39 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+use laytp\library\UploadDomain;
+
+class Models extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'models';
+
+    //附加属性
+    protected $append = ['imgs_file'];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function imgFile(){
+        return $this->belongsTo('app\model\Files','img','id');
+    }
+
+    public function getImgsFileAttr($value, $data)
+	{
+		return (isset($data['imgs']) && $data['imgs']) ? UploadDomain::multi($data['imgs']) : '';
+	}
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 38 - 0
app/model/Order.php

xqd
@@ -0,0 +1,38 @@
+<?php
+/**
+ * 订单模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+
+class Order extends BaseModel
+{
+
+    //模型名
+    protected $name = 'order';
+
+    //附加属性
+    protected $append = ['create_time_int','update_time_int'];
+
+    //时间戳字段转换
+
+    //关联模型
+    public function memberInfo(){
+        return $this->belongsTo('app\model\Member','link_id','id')->bind(['title','type']);
+    }
+    public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname']);
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+}

+ 33 - 0
app/model/Question.php

xqd
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Question extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'question';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+    public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id');
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 30 - 0
app/model/Sk.php

xqd
@@ -0,0 +1,30 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Sk extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'sk';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 36 - 0
app/model/Template.php

xqd
@@ -0,0 +1,36 @@
+<?php
+/**
+ * 收藏模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+use app\service\EncryptServiceFacade;
+
+class Template extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'template';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+
+
+    //关联模型
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+    // public function getGuideAttr($value, $data)
+    // {
+    //     return isset($data['guide'])?EncryptServiceFacade::encrypt($data['guide'],WIKE):0;
+    // }
+}

+ 82 - 0
app/model/User.php

xqd
@@ -0,0 +1,82 @@
+<?php
+/**
+ * 会员管理模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class User extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'user';
+
+    //附加属性
+    protected $append = ['is_vip_time_validity','vip_time_str','login_time_int','create_time_int','update_time_int','delete_time_int','vip_time'];
+
+    //时间戳字段转换
+    // protected $type = [
+	// 	'vip_time'  =>  'timestamp:Y-m-d H:i:s',
+	// ];
+
+    //表名
+
+
+    //关联模型
+    public function avatarPicFile(){
+        return $this->belongsTo('app\model\Files','avatar_pic','id');
+    }
+
+	public function question(){
+        return  $this->hasMany('app\model\Question','uid','id');
+    }
+
+	public function commission1(){
+        return  $this->hasMany('app\model\commission\Team','pid','id');
+    }
+
+	public function commission2(){
+        return  $this->hasMany('app\model\commission\Team','gid','id');
+    }
+
+	public function commission3(){
+        return  $this->hasMany('app\model\commission\Team','gfid','id');
+    }
+
+    //新增属性的方法
+	public function getIsVipTimeValidityAttr($value, $data)
+	{
+		$return = 0;
+		if(isset($data['vip_time'])){
+			$return = $data['vip_time']<time() ? 0:1;
+		}
+		return $return;
+	}
+    public function getVipTimeStrAttr($value, $data)
+	{
+		return isset($data['vip_time']) ? date("Y-m-d H:i:s",$data['vip_time']) : 0;
+	}
+
+	public function getLoginTimeIntAttr($value, $data)
+	{
+		return isset($data['login_time']) ? strtotime($data['login_time']) : 0;
+	}
+
+	public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+
+	public function getDeleteTimeIntAttr($value, $data)
+	{
+		return isset($data['delete_time']) ? strtotime($data['delete_time']) : 0;
+	}
+}

+ 38 - 0
app/model/Vipinfo.php

xqd
@@ -0,0 +1,38 @@
+<?php
+/**
+ * 订单模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+
+class Vipinfo extends BaseModel
+{
+
+    //模型名
+    protected $name = 'vipinfo';
+
+    //附加属性
+    protected $append = ['create_time_int','update_time_int'];
+
+    //时间戳字段转换
+
+    //关联模型
+    public function memberInfo(){
+        return $this->belongsTo('app\model\Member','member_id','id')->bind(['title','type']);
+    }
+    public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname']);
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+}

+ 30 - 0
app/model/Words.php

xqd
@@ -0,0 +1,30 @@
+<?php
+/**
+ * 首页菜单管理模型
+ */
+namespace app\model;
+
+use laytp\BaseModel;
+use laytp\library\UploadDomain;
+use think\model\concern\SoftDelete;
+
+class Words extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名,导出功能需要读取此值,所以需要设置成public
+    protected $name = 'words';
+
+    //时间戳字段转换
+    protected $type = [];
+
+    protected $append = [];
+
+    //表名
+
+
+    //关联模型
+
+
+    //新增属性的方法
+}

+ 16 - 0
app/model/admin/Menu.php

xqd
@@ -0,0 +1,16 @@
+<?php
+/**
+ * 后台菜单模型
+ */
+
+namespace app\model\admin;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Menu extends BaseModel
+{
+    use SoftDelete;
+
+    protected $name = 'admin_menu';
+}

+ 16 - 0
app/model/admin/Role.php

xqd
@@ -0,0 +1,16 @@
+<?php
+/**
+ * 角色模型
+ */
+
+namespace app\model\admin;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Role extends BaseModel
+{
+    use SoftDelete;
+
+    protected $name = 'admin_role';
+}

+ 52 - 0
app/model/admin/User.php

xqd
@@ -0,0 +1,52 @@
+<?php
+/**
+ * 后台管理员表模型
+ */
+
+namespace app\model\admin;
+
+use laytp\BaseModel;
+use laytp\library\UploadDomain;
+use think\model\concern\SoftDelete;
+
+class User extends BaseModel
+{
+    use SoftDelete;
+
+    //模型名
+    protected $name = 'admin_user';
+
+    //数组常量
+    public $const = [
+        'is_super_manager' => [
+            '2'   => '否'
+            , '1' => '是',
+        ],
+        'status'           => [
+            '2'   => '禁用'
+            , '1' => '正常',
+        ],
+    ];
+
+    public function avatarFile(){
+        return $this->belongsTo('app\model\Files','avatar','id');
+    }
+
+    // 定义默认头像
+    public function getAvatarFileAttr($value){
+        if(!$value){
+            return [
+                'id' => "",
+                'filename' => '默认头像',
+                'path' => UploadDomain::getDefaultAvatar(),
+            ];
+        }else{
+            return $value;
+        }
+    }
+
+    public function roleIds()
+    {
+        return $this->hasMany(\app\model\admin\role\User::class, 'admin_user_id');
+    }
+}

+ 34 - 0
app/model/admin/action/Log.php

xqd
@@ -0,0 +1,34 @@
+<?php
+/**
+ * 后台操作日志模型
+ */
+namespace app\model\admin\action;
+
+use laytp\BaseModel;
+
+class Log extends BaseModel
+{
+
+    //模型名
+    protected $name = 'admin_action_log';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    public function adminUser(){
+        return $this->belongsTo('app\model\admin\User','admin_id','id');
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 34 - 0
app/model/admin/login/Log.php

xqd
@@ -0,0 +1,34 @@
+<?php
+/**
+ * 后台登录日志模型
+ */
+namespace app\model\admin\login;
+
+use laytp\BaseModel;
+
+class Log extends BaseModel
+{
+
+    //模型名
+    protected $name = 'admin_login_log';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    public function adminUser(){
+        return $this->belongsTo('app\model\admin\User','admin_id','id');
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 13 - 0
app/model/admin/menu/Role.php

xqd
@@ -0,0 +1,13 @@
+<?php
+/**
+ * 菜单与角色关系模型
+ */
+
+namespace app\model\admin\menu;
+
+use laytp\BaseModel;
+
+class Role extends BaseModel
+{
+    protected $name = 'admin_menu_role';
+}

+ 14 - 0
app/model/admin/role/User.php

xqd
@@ -0,0 +1,14 @@
+<?php
+/**
+ * 角色与菜单关联模型
+ */
+
+namespace app\model\admin\role;
+
+use laytp\BaseModel;
+
+class User extends BaseModel
+{
+    protected $name = 'admin_role_user';
+
+}

+ 32 - 0
app/model/api/Log.php

xqd
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Api请求日志模型
+ */
+namespace app\model\api;
+
+use laytp\BaseModel;
+
+class Log extends BaseModel
+{
+
+    //模型名
+    protected $name = 'api_log';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 36 - 0
app/model/commission/Cashout.php

xqd
@@ -0,0 +1,36 @@
+<?php
+/**
+ * 首页菜单管理模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+use laytp\library\UploadDomain;
+use think\model\concern\SoftDelete;
+
+class Cashout extends BaseModel
+{
+    // use SoftDelete;
+
+    //模型名,导出功能需要读取此值,所以需要设置成public
+    protected $name = 'commission_cashout';
+
+    //时间戳字段转换
+    protected $type = [];
+
+    protected $append = [];
+
+    //表名
+
+
+    //关联模型
+    public function userinfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname','avatar'])->field(['id','nickname','avatar']);
+    }
+    public function commissionUserinfo(){
+        return $this->belongsTo('app\model\commission\User','uid','uid');
+    }
+
+
+    //新增属性的方法
+}

+ 36 - 0
app/model/commission/Income.php

xqd
@@ -0,0 +1,36 @@
+<?php
+/**
+ * 首页菜单管理模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+// use think\model\concern\SoftDelete;
+
+class Income extends BaseModel
+{
+    // use SoftDelete;
+
+    //模型名,导出功能需要读取此值,所以需要设置成public
+    protected $name = 'commission_income';
+
+    //时间戳字段转换
+    protected $type = [];
+
+    protected $append = [];
+
+    //表名
+
+
+    //关联模型
+    public function userinfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname','avatar'])->field(['id','nickname','avatar']);
+    }
+
+    public function buyUserinfo(){
+        return $this->belongsTo('app\model\User','buy_uid','id');
+    }
+
+
+    //新增属性的方法
+}

+ 33 - 0
app/model/commission/Log.php

xqd
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 订单模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+
+class Log extends BaseModel
+{
+
+    //模型名
+    protected $name = 'order';
+
+    //附加属性
+    protected $append = ['create_time_int','update_time_int'];
+
+    //时间戳字段转换
+
+    //关联模型
+
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+}

+ 33 - 0
app/model/commission/Order.php

xqd
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 订单模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+
+class Order extends BaseModel
+{
+
+    //模型名
+    protected $name = 'order';
+
+    //附加属性
+    protected $append = ['create_time_int','update_time_int'];
+
+    //时间戳字段转换
+
+    //关联模型
+
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+}

+ 35 - 0
app/model/commission/Settle.php

xqd
@@ -0,0 +1,35 @@
+<?php
+/**
+ * 订单模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+
+class Settle extends BaseModel
+{
+
+    //模型名
+    protected $name = 'commission_settle';
+
+    //附加属性
+    protected $append = ['create_time_int','update_time_int'];
+
+    //时间戳字段转换
+
+    //关联模型
+    public function userInfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname']);
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+}

+ 42 - 0
app/model/commission/Team.php

xqd
@@ -0,0 +1,42 @@
+<?php
+/**
+ * 首页菜单管理模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+use laytp\library\UploadDomain;
+use think\model\concern\SoftDelete;
+
+class Team extends BaseModel
+{
+    // use SoftDelete;
+
+    //模型名,导出功能需要读取此值,所以需要设置成public
+    protected $name = 'commission_team';
+
+    //时间戳字段转换
+    protected $type = [];
+
+    protected $append = ['create_time_int'];
+
+    //表名
+
+
+    //关联模型
+    public function userinfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname','avatar','id_number'])->field(['id','nickname','avatar','id_number']);
+    }
+
+    public function pidUserinfo(){
+        return $this->belongsTo('app\model\User','pid','id')->bind(['nickname','avatar','id_number'])->field(['id','nickname','avatar','id_number']);
+    }
+
+
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+}

+ 58 - 0
app/model/commission/User.php

xqd
@@ -0,0 +1,58 @@
+<?php
+/**
+ * 首页菜单管理模型
+ */
+namespace app\model\commission;
+
+use laytp\BaseModel;
+use laytp\library\UploadDomain;
+use think\model\concern\SoftDelete;
+
+class User extends BaseModel
+{
+    // use SoftDelete;
+
+    //模型名,导出功能需要读取此值,所以需要设置成public
+    protected $name = 'commission_user';
+
+    //时间戳字段转换
+    protected $type = [];
+
+    protected $append = [];
+
+    //表名
+
+
+    //关联模型
+    public function income(){
+        return  $this->hasMany('app\model\commission\Income','uid','uid');
+    }
+
+    public function imgFile(){
+        return $this->belongsTo('app\model\Files','qrcode_wechat','id')->bind(['path']);
+    }
+
+    public function userinfo(){
+        return $this->belongsTo('app\model\User','uid','id')->bind(['nickname','avatar','id_number'])->field(['id','nickname','avatar','id_number']);
+    }
+
+    public function pidUserinfo(){
+        return $this->belongsTo('app\model\commission\Team','uid','uid');
+    }
+
+
+    public function commission1(){
+        return  $this->hasMany('app\model\commission\Team','pid','uid');
+    }
+
+	public function commission2(){
+        return  $this->hasMany('app\model\commission\Team','gid','uid');
+    }
+
+	public function commission3(){
+        return  $this->hasMany('app\model\commission\Team','gfid','uid');
+    }
+
+
+    //新增属性的方法
+}

+ 43 - 0
app/model/files/Category.php

xqd
@@ -0,0 +1,43 @@
+<?php
+/**
+ * 附件分类管理模型
+ */
+namespace app\model\files;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Category extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'files_category';
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    public function parent(){
+        return $this->belongsTo('app\model\files\Category','pid','id');
+    }
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+
+	public function getDeleteTimeIntAttr($value, $data)
+	{
+		return isset($data['delete_time']) ? strtotime($data['delete_time']) : 0;
+	}
+}

+ 44 - 0
app/model/plugin/ali/Sms.php

xqd
@@ -0,0 +1,44 @@
+<?php
+/**
+ * 阿里云手机短信管理模型
+ */
+namespace app\model\plugin\ali;
+
+use laytp\BaseModel;
+use think\model\concern\SoftDelete;
+
+class Sms extends BaseModel
+{
+	use SoftDelete;
+
+    //模型名
+    protected $name = 'plugin\ali_sms';
+
+    //附加属性
+    protected $append = [];
+
+    //时间戳字段转换
+    
+
+    //表名
+    
+
+    //关联模型
+    
+
+    //新增属性的方法
+    public function getCreateTimeIntAttr($value, $data)
+	{
+		return isset($data['create_time']) ? strtotime($data['create_time']) : 0;
+	}
+
+	public function getUpdateTimeIntAttr($value, $data)
+	{
+		return isset($data['update_time']) ? strtotime($data['update_time']) : 0;
+	}
+
+	public function getDeleteTimeIntAttr($value, $data)
+	{
+		return isset($data['delete_time']) ? strtotime($data['delete_time']) : 0;
+	}
+}

+ 7 - 0
app/provider.php

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

+ 28 - 0
app/resource/admin/User.php

xqd
@@ -0,0 +1,28 @@
+<?php
+
+namespace app\resource\admin;
+
+use laytp\Resource;
+
+/**
+ * 用户资源
+ */
+class User extends Resource
+{
+    /**
+     * 用户首页列表需要将关联模型取到的role_ids转换成以逗号分隔的字符串
+     * @param $data
+     * @return mixed
+     */
+    static public function info($data)
+    {
+        $roleIdsArr = [];
+        if($data){
+            foreach ($data['role_ids'] as $k => $v) {
+                $roleIdsArr[] = $v['admin_role_id'];
+            }
+            $data['role_ids'] = implode(',', $roleIdsArr);
+        }
+        return $data;
+    }
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 0
app/service/Bill.php


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů