wupengfei %!s(int64=2) %!d(string=hai) anos
pai
achega
1d5943a7b8
Modificáronse 100 ficheiros con 15038 adicións e 1417 borrados
  1. 26 28
      application/admin/controller/Index.php
  2. 65 0
      application/admin/controller/Official.php
  3. 122 0
      application/admin/controller/Versions.php
  4. 0 3
      application/admin/view/index/index.html
  5. 86 55
      application/admin/view/index/main.html
  6. 18 0
      application/admin/view/official/index-about-us.html
  7. 18 0
      application/admin/view/official/index-agent-notice.html
  8. 18 0
      application/admin/view/official/index-agreement.html
  9. 18 0
      application/admin/view/official/index-customer-service.html
  10. 18 0
      application/admin/view/official/index-integral-channel.html
  11. 18 0
      application/admin/view/official/index-original-pact.html
  12. 18 0
      application/admin/view/official/index-partner-item.html
  13. 18 0
      application/admin/view/official/index-privacy.html
  14. 18 0
      application/admin/view/official/index-refund-desc.html
  15. 18 0
      application/admin/view/official/index-sign-rule.html
  16. 18 0
      application/admin/view/official/index-user-equity.html
  17. 18 0
      application/admin/view/official/index-write-off.html
  18. 38 0
      application/admin/view/official/index.html
  19. 70 0
      application/admin/view/official/platform-set.html
  20. 2 0
      application/admin/view/user/index.html
  21. 33 0
      application/admin/view/versions/form.html
  22. 45 0
      application/admin/view/versions/index.html
  23. 118 0
      application/api/common.php
  24. 703 0
      application/api/controller/Activity.php
  25. 157 243
      application/api/controller/Address.php
  26. 114 66
      application/api/controller/Alipay.php
  27. 865 0
      application/api/controller/ApiRedis.php
  28. 90 42
      application/api/controller/Area.php
  29. 1063 0
      application/api/controller/Article.php
  30. 110 35
      application/api/controller/Base.php
  31. 38 0
      application/api/controller/Bucket.php
  32. 140 0
      application/api/controller/Collect.php
  33. 605 0
      application/api/controller/Datum.php
  34. 663 0
      application/api/controller/Demand.php
  35. 696 0
      application/api/controller/Expedite.php
  36. 94 0
      application/api/controller/Feedback.php
  37. 831 0
      application/api/controller/Forum.php
  38. 68 0
      application/api/controller/General.php
  39. 276 0
      application/api/controller/LevelOrder.php
  40. 97 434
      application/api/controller/Login.php
  41. 331 0
      application/api/controller/Mall.php
  42. 155 0
      application/api/controller/Message.php
  43. 675 410
      application/api/controller/Order.php
  44. 155 0
      application/api/controller/OssManage.php
  45. 374 45
      application/api/controller/Pay.php
  46. 715 0
      application/api/controller/Press.php
  47. 314 0
      application/api/controller/Qc.php
  48. 503 0
      application/api/controller/Recruit.php
  49. 100 0
      application/api/controller/Report.php
  50. 99 0
      application/api/controller/Sample.php
  51. 235 0
      application/api/controller/Sign.php
  52. 618 0
      application/api/controller/Supplier.php
  53. 57 0
      application/api/controller/Task.php
  54. 305 0
      application/api/controller/Trolley.php
  55. 35 5
      application/api/controller/Upload.php
  56. 227 0
      application/api/controller/UserCenter.php
  57. 1199 0
      application/api/controller/Video.php
  58. 286 0
      application/api/controller/VideoDemand.php
  59. 279 0
      application/api/controller/WalletManage.php
  60. 172 0
      application/api/controller/WeChatPay.php
  61. 26 0
      application/api/controller/WeChatPort.php
  62. 251 51
      application/common.php
  63. 9 0
      application/common/model/Activity.php
  64. 22 0
      application/common/model/ActivityApply.php
  65. 9 0
      application/common/model/ArticleCate.php
  66. 8 0
      application/common/model/ArticleComment.php
  67. 8 0
      application/common/model/ArticleCommentLike.php
  68. 15 0
      application/common/model/ArticleIntro.php
  69. 9 0
      application/common/model/ArticleItem.php
  70. 9 0
      application/common/model/ArticleLike.php
  71. 16 0
      application/common/model/ChinaArea.php
  72. 12 0
      application/common/model/DatumCate.php
  73. 12 0
      application/common/model/DatumIntro.php
  74. 9 0
      application/common/model/DatumLike.php
  75. 12 0
      application/common/model/DatumUrl.php
  76. 9 0
      application/common/model/DeliveryAddress.php
  77. 8 0
      application/common/model/DemandComment.php
  78. 10 0
      application/common/model/ForumReply.php
  79. 10 0
      application/common/model/ForumReplyComment.php
  80. 14 0
      application/common/model/GoodsCate.php
  81. 22 0
      application/common/model/GoodsOrder.php
  82. 20 0
      application/common/model/GoodsOrderItem.php
  83. 9 0
      application/common/model/GoodsOrderRefund.php
  84. 8 0
      application/common/model/GoodsParam.php
  85. 14 0
      application/common/model/GoodsSeason.php
  86. 8 0
      application/common/model/GoodsSellInfo.php
  87. 12 0
      application/common/model/GoodsServe.php
  88. 9 0
      application/common/model/InviteInfo.php
  89. 9 0
      application/common/model/LabelMessage.php
  90. 9 0
      application/common/model/LevelOrder.php
  91. 20 0
      application/common/model/NewsCate.php
  92. 12 0
      application/common/model/OrderComment.php
  93. 8 0
      application/common/model/PlatformDemand.php
  94. 56 0
      application/common/model/PlatformLike.php
  95. 38 0
      application/common/model/PlatformSwitch.php
  96. 9 0
      application/common/model/Press.php
  97. 8 0
      application/common/model/PressComment.php
  98. 8 0
      application/common/model/Recruit.php
  99. 8 0
      application/common/model/RecruitCate.php
  100. 8 0
      application/common/model/ReportCase.php

+ 26 - 28
application/admin/controller/Index.php

@@ -57,39 +57,38 @@ class Index extends Controller
     {
         $this->think_ver = \think\App::VERSION;
         $this->mysql_ver = Db::query('select version() as ver')[0]['ver'];
-        //活动总量
-        $goods_count = Db::name('store_goods')->count('id');
-        //用户总量
-        $member_count = Db::name('store_member')->count('id');
-        //报名总量
-        $apply_count = Db::name('store_apply_list')->count('id');
-        //建议总量
-        $complain_count = Db::name('store_complain')->count('id');
-
         $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
         $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
         $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
         $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
-        //昨天报名优惠金额
-        $yesterday_amount = Db::name('store_apply_list')->where('is_deleted',0)->whereBetweenTime('create_at',date('Y-m-d H:i:s',$beginYesterday),date('Y-m-d H:i:s',$endYesterday))->sum('amount');
-        //今天报名优惠金额
-        $today_amount = Db::name('store_apply_list')->where('is_deleted',0)->whereBetweenTime('create_at',date('Y-m-d H:i:s',$beginToday),date('Y-m-d H:i:s',$endToday))->sum('amount');
 
-        //昨天新增用户数
-        $yesterday_member = Db::name('store_member')->whereBetweenTime('create_at',date('Y-m-d H:i:s',$beginYesterday),date('Y-m-d H:i:s',$endYesterday))->count('id');
-        //今天新增用户数
-        $today_member = Db::name('store_member')->whereBetweenTime('create_at',date('Y-m-d H:i:s',$beginToday),date('Y-m-d H:i:s',$endToday))->count('id');
-        $data = array(
-            'goods_count' => $goods_count,
-            'member_count' => $member_count,
-            'apply_count' => $apply_count,
-            'complain_count' => $complain_count,
+        $user_num = \app\common\model\User::where('status',1)->where('is_deleted',0)->count();
+        $agency_num =  \app\common\model\User::where('is_agency',1)->where('is_deleted',0)->count();
+        $partner_num =  \app\common\model\User::where('is_partner',1)->where('is_deleted',0)->count();
+        $goods_num =  \app\common\model\StoreGoods::where('is_deleted',0)->count();
+        $order_num =  \app\common\model\GoodsOrder::where('status','>=',1)->count();
+        $order_money =  \app\common\model\GoodsOrder::where('status','>=',1)->sum('price_total');
+        $gift_order_num =  \app\common\model\GiftOrder::count();
+        $gift_order_money =  \app\common\model\GiftOrder::where('status',1)->sum('price_total');
+        $news_num =  \app\common\model\InformationArticle::where('is_deleted',0)->count();
+        $video_num =  \app\common\model\VideoIntro::where('is_deleted',0)->count();
+
+        $new_user =  \app\common\model\User::where('status',1)->whereBetweenTime('create_at',$beginToday,$endToday)->count();
 
-            'yesterday_amount' => $yesterday_amount,
-            'today_amount' => $today_amount,
-            'yesterday_member' => $yesterday_member,
-            'today_member' => $today_member,
-        );
+
+        $data = [
+            'user_num' => $user_num,
+            'agency_num' => $agency_num,
+            'partner_num' => $partner_num,
+            'goods_num' => $goods_num,
+            'order_num' => $order_num,
+            'order_money' => $order_money,
+            'news_num' => $news_num,
+            'video_num' => $video_num,
+            'new_user' => $new_user,
+            'gift_order_num' => $gift_order_num,
+            'gift_order_money' => $gift_order_money,
+        ];
         $this->assign('data',$data);
         $this->fetch();
     }
@@ -186,7 +185,6 @@ class Index extends Controller
 
     /**
      * 压缩发布系统
-     * @auth true
      */
     public function buildOptimize()
     {

+ 65 - 0
application/admin/controller/Official.php

@@ -0,0 +1,65 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkAdmin
+// +----------------------------------------------------------------------
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// +----------------------------------------------------------------------
+// | 官方网站: http://demo.thinkadmin.top
+// +----------------------------------------------------------------------
+// | 开源协议 ( https://mit-license.org )
+// +----------------------------------------------------------------------
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller;
+
+use app\common\model\UserLevel;
+use app\common\service\ExtendService;
+use library\Controller;
+
+/**
+ * 参数配置
+ * Class Official
+ * @package app\admin\controller
+ */
+class Official extends Controller
+{
+
+    /**
+     * 参数配置
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function index()
+    {
+        $this->title = '参数配置';
+        $this->applyCsrfToken('save');
+        $this->query = ExtendService::queryChinaSmsBalance();
+       // $this->query2 = ExtendService::queryGlobeSmsBalance();
+        $this->crystal_switch = sysconf('crystal_switch');
+        $this->sign_money_switch = sysconf('sign_money_switch');
+        $this->vip_experience = sysconf('vip_experience');
+        $this->user_level = UserLevel::column('name','id');
+        $this->fetch();
+    }
+
+    /**
+     * 保存商城参数
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function save()
+    {
+        if ($this->request->isPost()) {
+            $this->applyCsrfToken('save');
+            foreach ($this->request->post() as $k => $v) sysconf($k, $v);
+            $this->success('参数设置保存成功!');
+        }
+    }
+
+}

+ 122 - 0
application/admin/controller/Versions.php

@@ -0,0 +1,122 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkAdmin
+// +----------------------------------------------------------------------
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// +----------------------------------------------------------------------
+// | 官方网站: http://demo.thinkadmin.top
+// +----------------------------------------------------------------------
+// | 开源协议 ( https://mit-license.org )
+// +----------------------------------------------------------------------
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
+// +----------------------------------------------------------------------
+
+namespace app\admin\controller;
+
+use library\Controller;
+
+/**
+ * 版本管理
+ * Class Versions
+ * @package app\admin\controller
+ */
+class Versions extends Controller
+{
+    /**
+     * 绑定数据表
+     * @var string
+     */
+    protected $table = 'store_versions';
+
+    /**
+     * 版本管理
+     * @auth true
+     * @menu true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function index()
+    {
+        $this->title = '版本管理';
+        $query = $this->_query($this->table)->like('title')->equal('status');
+        $query->where(['is_deleted' => '0'])->order('sort desc,id desc')->page();
+    }
+    /**
+     * 数据列表处理
+     * @param array $data
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    protected function _index_page_filter(&$data){
+
+    }
+    /**
+     * 添加版本
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function add()
+    {
+        $this->title = '添加版本';
+        $this->_form($this->table, 'form');
+    }
+
+    /**
+     * 编辑版本
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function edit()
+    {
+        $this->title = '编辑版本';
+        $this->_form($this->table, 'form');
+    }
+
+    /**
+     * 禁用版本
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function forbid()
+    {
+        $this->_save($this->table, ['status' => '0']);
+    }
+
+    /**
+     * 启用版本
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function resume()
+    {
+        $this->_save($this->table, ['status' => '1']);
+    }
+
+    /**
+     * 删除版本
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function remove()
+    {
+        $this->_delete($this->table);
+    }
+
+}

+ 0 - 3
application/admin/view/index/index.html

@@ -59,9 +59,6 @@
                 <dl class="layui-nav-child">
                     <dd lay-unselect><a data-modal="{:url('admin/index/info',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-set-fill margin-right-5"></i>基本资料</a></dd>
                     <dd lay-unselect><a data-modal="{:url('admin/index/pass',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-component margin-right-5"></i>安全设置</a></dd>
-                    {if auth('admin/index/buildoptimize')}
-                    <dd lay-unselect><a data-modal="{:url('admin/index/buildOptimize')}"><i class="layui-icon layui-icon-template-1 margin-right-5"></i>压缩发布</a></dd>
-                    {/if}
                     {if auth('admin/index/clearruntime')}
                     <dd lay-unselect><a data-modal="{:url('admin/index/clearRuntime')}"><i class="layui-icon layui-icon-fonts-clear margin-right-5"></i>清理缓存</a></dd>
                     {/if}

+ 86 - 55
application/admin/view/index/main.html

@@ -33,74 +33,113 @@
 </style>
 
 <div class="think-box-shadow store-total-container notselect">
-    <div class="margin-bottom-15">商城统计</div>
+    <div class="margin-bottom-15">会员统计</div>
     <div class="layui-row layui-col-space15">
+
         <div class="layui-col-sm6 layui-col-md3">
             <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#57bdbf,#2f9de2)">
-                <div>活动总量</div>
-                <div>{$data.goods_count}</div>
-                <div>当前活动的总数量</div>
+                <div>会员数量</div>
+                <div>{$data.user_num}</div>
+                <div>当前会员数量</div>
             </div>
-            <i class="store-total-icon layui-icon layui-icon-template-1"></i>
+            <i class="store-total-icon layui-icon layui-icon-username"></i>
         </div>
+
         <div class="layui-col-sm6 layui-col-md3">
-            <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#ff7d7d,#fb2c95)">
-                <div>用户总量</div>
-                <div>{$data.member_count}</div>
-                <div>当前用户的总数量</div>
+            <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#57bdbf,#2f9de2)">
+                <div>新增会员数量</div>
+                <div>{$data.new_user}</div>
+                <div>当日注册会员数量</div>
             </div>
             <i class="store-total-icon layui-icon layui-icon-user"></i>
         </div>
+
         <div class="layui-col-sm6 layui-col-md3">
-            <div class="store-total-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
-                <div>报名总量</div>
-                <div>{$data.apply_count}</div>
-                <div>用户已报名的总数量</div>
+            <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#57bdbf,#2f9de2)">
+                <div>区域代理数量</div>
+                <div>{$data.agency_num}</div>
+                <div>区域代理数量</div>
             </div>
-            <i class="store-total-icon layui-icon layui-icon-read"></i>
+            <i class="store-total-icon layui-icon layui-icon-group"></i>
         </div>
+
         <div class="layui-col-sm6 layui-col-md3">
-            <div class="store-total-item nowrap" style="background:linear-gradient(-141deg,#ecca1b,#f39526)">
-                <div>建议总量</div>
-                <div>{$data.complain_count}</div>
-                <div>会员提交建议的总数量</div>
+            <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#57bdbf,#2f9de2)">
+                <div>分销商数量</div>
+                <div>{$data.partner_num}</div>
+                <div>分销商数量</div>
             </div>
-            <i class="store-total-icon layui-icon layui-icon-survey"></i>
+            <i class="store-total-icon layui-icon layui-icon-friends"></i>
         </div>
     </div>
 </div>
 
-<div class="think-box-shadow store-total-container">
-    <div class="margin-bottom-15">实时概况</div>
+<div class="think-box-shadow store-total-container notselect">
+    <div class="margin-bottom-15">商城统计</div>
     <div class="layui-row layui-col-space15">
-        <div class="layui-col-md6 margin-bottom-15">
-            <div class="layui-row">
-                <div class="layui-col-xs3 text-center">
-                    <i class="layui-icon color-blue" style="font-size:60px;line-height:72px">&#xe65e;</i>
-                </div>
-                <div class="layui-col-xs4">
-                    <div class="font-s14">报名优惠金额(元)</div>
-                    <div class="font-s16">{$data.today_amount}</div>
-                    <div class="font-s12 color-desc">昨日:{$data.yesterday_amount}</div>
-                </div>
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-125deg,#ff7d7d,#fb2c95)">
+                <div>商品数量</div>
+                <div>{$data.goods_num}</div>
+                <div>当前商品总数量</div>
             </div>
+            <i class="store-total-icon layui-icon layui-icon-vercode"></i>
         </div>
-        <div class="layui-col-md6 margin-bottom-15">
-            <div class="layui-row">
-                <div class="layui-col-xs3 text-center">
-                    <i class="layui-icon color-blue" style="font-size:60px;line-height:72px">&#xe663;</i>
-                </div>
-                <div class="layui-col-xs4">
-                    <div class="font-s14">新增用户数</div>
-                    <div class="font-s16">{$data.today_member}</div>
-                    <div class="font-s12 color-desc">昨日:{$data.yesterday_member}</div>
-                </div>
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
+                <div>商城订单总量</div>
+                <div>{$data.order_num}</div>
+                <div>当前支付订单总数量</div>
             </div>
+            <i class="store-total-icon layui-icon layui-icon-vercode"></i>
+        </div>
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
+                <div>商城订单交易金额</div>
+                <div>{$data.order_money}</div>
+                <div>当前商城订单交易金额</div>
+            </div>
+            <i class="store-total-icon layui-icon layui-icon-dollar"></i>
+        </div>
+
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
+                <div>定制订单量</div>
+                <div>{$data.gift_order_num}</div>
+                <div>定制订单量数量(所有的)</div>
+            </div>
+            <i class="store-total-icon layui-icon layui-icon-list"></i>
+        </div>
+
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
+                <div>定制订单量交易额</div>
+                <div>{$data.gift_order_money}</div>
+                <div>定制订单量交易金额</div>
+            </div>
+            <i class="store-total-icon layui-icon layui-icon-dollar"></i>
+        </div>
+
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-141deg,#ecca1b,#f39526)">
+                <div>资讯数量</div>
+                <div>{$data.news_num}</div>
+                <div>资讯数量</div>
+            </div>
+            <i class="store-total-icon layui-icon layui-icon-survey"></i>
+        </div>
+        <div class="layui-col-sm6 layui-col-md3">
+            <div class="store-total-item nowrap" style="background:linear-gradient(-141deg,#ecca1b,#f39526)">
+                <div>视频数量</div>
+                <div>{$data.video_num}</div>
+                <div>视频专栏视频数量</div>
+            </div>
+            <i class="store-total-icon layui-icon layui-icon-video"></i>
         </div>
     </div>
 </div>
 
-<!--<div class="layui-row layui-col-space15">
+<div class="layui-row layui-col-space15">
     <div class="layui-col-md6">
         <div class="think-box-shadow">
             <table class="layui-table" lay-skin="line" lay-even>
@@ -155,27 +194,19 @@
                 <tbody>
                 <tr>
                     <td>产品名称</td>
-                    <td>觅食</td>
+                    <td>多端商城</td>
                 </tr>
                 <tr>
                     <td>在线体验</td>
-                    <td><a target="_blank" href="http://mishi.hdlkeji.com">http://mishi.hdlkeji.com</a></td>
-                </tr>
-                <tr>
-                    <td>官方QQ群</td>
-                    <td>
-                        <a href="">
-                            <img src="//pub.idqqimg.com/wpa/images/group.png" style="height:18px;width:auto" target="_blank">
-                        </a>
-                    </td>
+                    <td><a target="_blank" href="http://ddsc.hdlkeji.com">http://ddsc.hdlkeji.com</a></td>
                 </tr>
                 <tr>
                     <td>项目地址</td>
-                    <td><a target="_blank" href="http://mishi.hdlkeji.com">http://mishi.hdlkeji.com</a></td>
+                    <td><a target="_blank" href="http://ddsc.hdlkeji.com">http://ddsc.hdlkeji.com</a></td>
                 </tr>
                 <tr>
                     <td>BUG反馈</td>
-                    <td><a target="_blank" href="http://mishi.hdlkeji.com">http://mishi.hdlkeji.com</a></td>
+                    <td><a target="_blank" href="http://ddsc.hdlkeji.com">http://ddsc.hdlkeji.com</a></td>
                 </tr>
                 <tr>
                     <td>开发团队</td>
@@ -193,5 +224,5 @@
             </table>
         </div>
     </div>
-</div>-->
+</div>
 {/block}

+ 18 - 0
application/admin/view/official/index-about-us.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">关于我们</span><span class="nowrap color-desc">AboutUs</span>
+            <textarea name="about_us">{:sysconf('about_us')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="about_us"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-agent-notice.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">代理商须知</span><span class="nowrap color-desc">AgentNotice</span>
+            <textarea name="agent_notice">{:sysconf('agent_notice')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="agent_notice"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-agreement.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">用户协议</span><span class="nowrap color-desc">Agreement</span>
+            <textarea name="agreement">{:sysconf('agreement')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="agreement"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-customer-service.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">客服设置</span><span class="nowrap color-desc">CustomerService</span>
+            <textarea name="customer_service">{:sysconf('customer_service')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="customer_service"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-integral-channel.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">会员权益</span><span class="nowrap color-desc">IntegralChannel</span>
+            <textarea name="integral_channel">{:sysconf('integral_channel')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="integral_channel"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-original-pact.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">原创公约</span><span class="nowrap color-desc">OriginalPact</span>
+            <textarea name="original_pact">{:sysconf('original_pact')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="original_pact"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-partner-item.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">分销条款</span><span class="nowrap color-desc">PartnerItem</span>
+            <textarea name="partner_item">{:sysconf('partner_item')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="partner_item"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-privacy.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">隐私政策</span><span class="nowrap color-desc">Privacy</span>
+            <textarea name="privacy">{:sysconf('privacy')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="privacy"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-refund-desc.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">退款退货说明</span><span class="nowrap color-desc">RefundDesc</span>
+            <textarea name="refund_desc">{:sysconf('refund_desc')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="refund_desc"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-sign-rule.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">签到规则</span><span class="nowrap color-desc">SignRule</span>
+            <textarea name="sign_rule">{:sysconf('sign_rule')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="sign_rule"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-user-equity.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">会员权益</span><span class="nowrap color-desc">UserEquity</span>
+            <textarea name="user_equity">{:sysconf('user_equity')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="user_equity"]', {height: 500});
+        })
+    </script>
+</form>

+ 18 - 0
application/admin/view/official/index-write-off.html

@@ -0,0 +1,18 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+        <label class="layui-form-item margin-top-20 block relative">
+            <span class="color-green margin-right-10">注销须知</span><span class="nowrap color-desc">WriteOff</span>
+            <textarea name="write_off">{:sysconf('write_off')}</textarea>
+        </label>
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="write_off"]', {height: 500});
+        })
+    </script>
+</form>

+ 38 - 0
application/admin/view/official/index.html

@@ -0,0 +1,38 @@
+{extend name="admin@main"}
+
+{block name="content"}
+
+<div class="layui-tab layui-tab-card think-bg-white">
+    <ul class="layui-tab-title notselect">
+        <li data-type="store-config-type-sms1">配置信息</li>
+        <li data-type="store-config-type-sms2">用户协议</li>
+        <li data-type="store-config-type-sms2">关于我们</li>
+        <li data-type="store-config-type-sms2">隐私政策</li>
+        <li data-type="store-config-type-sms2">会员权益</li>
+        <li data-type="store-config-type-sms2">客服设置</li>
+        <li data-type="store-config-type-sms2">原创公约</li>
+    </ul>
+    <div class="layui-tab-content">
+        <div class="layui-tab-item">{include file='official/platform-set'}</div>
+        <div class="layui-tab-item">{include file='official/index-agreement'}</div>
+        <div class="layui-tab-item">{include file='official/index-about-us'}</div>
+        <div class="layui-tab-item">{include file='official/index-privacy'}</div>
+        <div class="layui-tab-item">{include file='official/index-user-equity'}</div>
+        <div class="layui-tab-item">{include file='official/index-customer-service'}</div>
+        <div class="layui-tab-item">{include file='official/index-original-pact'}</div>
+    </div>
+</div>
+
+<script>
+    (function (storage) {
+        (function (type, $default, $checked) {
+            $default = $('.layui-tab ul.layui-tab-title li:first');
+            $checked = $('.layui-tab ul.layui-tab-title li[data-type="' + type + '"]');
+            ($checked.length > 0 ? $checked : $default).trigger('click');
+        })(layui.data(storage)['type'] || '');
+        $('.layui-tab ul.layui-tab-title li[data-type]').on('click', function () {
+            layui.data(storage, {key: 'type', value: this.getAttribute('data-type')});
+        });
+    })('store-config-type');
+</script>
+{/block}

+ 70 - 0
application/admin/view/official/platform-set.html

@@ -0,0 +1,70 @@
+<form onsubmit="return false;" data-auto="true" action="{:url('save')}" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body padding-40">
+
+        <label class="layui-form-item block relative">
+            <span class="color-green margin-right-10">首页公告</span><span class="nowrap color-desc">IndexNotice</span>
+            <input name="index_notice"   required placeholder="请输首页公告内容" value="{:sysconf('index_notice')}" class="layui-input">
+        </label>
+
+
+        <label class="layui-form-item block relative">
+            <span class="color-green margin-right-10">会员体验</span><span class="nowrap color-desc">VipExperience</span>
+            <select name="vip_experience" class="layui-select">
+                <option value="0">请选择</option>
+                {foreach $user_level as $k=>$v}
+                    <option {if $vip_experience ==  $k}selected{/if} value="{$k}">{$v}</option>
+                {/foreach}
+            </select>
+        </label>
+
+        <label class="layui-form-item block relative">
+            <span class="color-green margin-right-10">平台名称</span><span class="nowrap color-desc">AppName</span>
+            <input name="app_name"   required placeholder="请输平台名称" value="{:sysconf('app_name')}" class="layui-input">
+        </label>
+
+        <div class="layui-form-item">
+            <span class="color-green margin-right-10">平台LOGO</span><span class="nowrap color-desc">AppLogo</span>
+            <div class="layui-input-line">
+                <input name="app_logo" type="hidden"    value="{:sysconf('app_logo')}">
+            </div>
+        </div>
+
+        <div class="layui-form-item">
+            <span class="color-green margin-right-10">客服二维码</span><span class="nowrap color-desc">ServiceQrCode</span>
+            <div class="layui-input-line">
+                <input name="service_qr_code" type="hidden"    value="{:sysconf('service_qr_code')}">
+            </div>
+        </div>
+
+        <label class="layui-form-item block relative">
+            <span class="color-green margin-right-10">客服电话</span><span class="nowrap color-desc">ServicePhone</span>
+            <input name="service_phone"   required placeholder="请输首页公告内容" value="{:sysconf('service_phone')}" class="layui-input">
+        </label>
+
+        <label class="layui-form-item block relative">
+            <span class="color-green margin-right-10">客服邮件</span><span class="nowrap color-desc">ServiceEmail</span>
+            <input name="service_email"   required placeholder="请输首页公告内容" value="{:sysconf('service_email')}" class="layui-input">
+        </label>
+
+        <div class="layui-form-item text-center margin-top-20">
+            <button class="layui-btn" type="submit">保存配置</button>
+        </div>
+    </div>
+</form>
+<script>
+    layui.use('laydate', function(){
+        var laydate = layui.laydate;
+        //时间选择器
+        laydate.render({
+            elem: '#start_time_cost'
+            ,type: 'time'
+        });
+        laydate.render({
+            elem: '#end_time_cost'
+            ,type: 'time'
+        });
+    })
+    $('[name="service_qr_code"]').uploadOneImage();
+    $('[name="app_logo"]').uploadOneImage();
+</script>

+ 2 - 0
application/admin/view/user/index.html

@@ -23,6 +23,7 @@
                 <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
             </th>
             <th class='text-left nowrap'>用户账号</th>
+            <th class='text-left nowrap'>联系手机</th>
             <th class='text-center nowrap'>登录次数</th>
             <th class='text-center nowrap'>使用状态</th>
             <th class='text-left nowrap'>创建时间</th>
@@ -38,6 +39,7 @@
                 <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
             </td>
             <td class='text-left nowrap'>{$vo.username|default=''}</td>
+            <td class='text-left nowrap'>{$vo.phone|default='-'}</td>
             <td class='text-center nowrap'>{$vo.login_num|default=0}</td>
             <td class='text-center nowrap'>{eq name='vo.status' value='0'}<span class="color-red">已禁用</span>{else}<span class="color-green">使用中</span>{/eq}</td>
             <td class='text-left nowrap'>{$vo.create_at|format_datetime}</td>

+ 33 - 0
application/admin/view/versions/form.html

@@ -0,0 +1,33 @@
+<form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">
+
+    <div class="layui-card-body">
+
+
+        <div class="layui-row margin-bottom-15">
+            <label class="layui-form-label label-required">版本號</label>
+            <div class="layui-input-block">
+                <input name="title" required value='{$vo.title|default=""}' placeholder="請輸入版本號" class="layui-input">
+            </div>
+        </div>
+
+        <div class="layui-row margin-bottom-15">
+            <label class="layui-form-label label-required">修改內容</label>
+            <div class="layui-input-block">
+                <textarea name="content">{$vo.content|default=''|raw}</textarea>
+            </div>
+        </div>
+    </div>
+
+    <div class="hr-line-dashed"></div>
+    <div class="layui-form-item text-center">
+        {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
+        <button class="layui-btn" type='submit'>保存數據</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-confirm="確定要取消編輯嗎?" data-close>取消編輯</button>
+    </div>
+    <script>
+        window.form.render();
+        require(['ckeditor', 'angular'], function () {
+            window.createEditor('[name="content"]', {height: 260});
+        })
+    </script>
+</form>

+ 45 - 0
application/admin/view/versions/index.html

@@ -0,0 +1,45 @@
+{extend name='admin@main'}
+
+
+{block name="content"}
+<div class="think-box-shadow">
+
+    <table class="layui-table margin-top-10" lay-skin="line">
+        {notempty name='list'}
+        <thead>
+        <tr>
+
+            <th class='text-left nowrap'>系統類型</th>
+            <th class='text-left nowrap'>版本號</th>
+            <th class="text-center">狀態</th>
+            <th class="text-center">時間</th>
+            <th class="text-center">操作</th>
+        </tr>
+        </thead>
+        {/notempty}
+        <tbody>
+        {foreach $list as $key=>$vo}
+        <tr>
+            <td class='text-left nowrap'>
+                {if $vo.type == 1} 安卓 {else} IOS {/if}
+            </td>
+            <td class='text-left nowrap'>
+
+                {$vo.title|default=''}
+            </td>
+            <td class='text-center nowrap'>
+                {eq name='vo.status' value='0'}<span class="layui-badge">已禁用</span>{else}<span class="layui-badge layui-bg-green">使用中</span>{/eq}<br>
+            </td>
+            <td class='text-center nowrap'>{$vo.create_at|format_datetime}</td>
+            <td class='text-center nowrap'>
+                {if auth("store/versions/edit")}
+                <a data-title="編輯版本" class="layui-btn layui-btn-sm" data-modal='{:url("edit")}?id={$vo.id}'>編 輯</a>
+                {/if}
+            </td>
+        </tr>
+        {/foreach}
+        </tbody>
+    </table>
+    {empty name='list'}<span class="notdata">沒有記錄哦</span>{else}{$pagehtml|raw|default=''}{/empty}
+</div>
+{/block}

+ 118 - 0
application/api/common.php

@@ -0,0 +1,118 @@
+<?php
+// 接口公共方法
+use app\common\model\UserMessage;
+use think\Db;
+use JPush\Client;
+require_once env('root_path').'vendor/jpush/jpush/autoload.php';
+
+function Jpush($user_id = 0,$alert = ''){
+    $appKey = '02a7faefd91c8a6a446a6a14';
+    $masterSecret = 'ba2e100db997024d9b6e5d35';
+    $client = new Client($appKey, $masterSecret,null);
+    $push_payload = $client->push()
+        ->setPlatform(array('ios', 'android'))
+        ->addAlias(strval($user_id))
+        ->iosNotification($alert, array(
+            'badge' => '+1',
+            'content-available' => true,
+            'mutable-content' => true,
+            'category' => 'jiguang',
+            'extras' => array(
+                'key' => 'value',
+                'jiguang'
+            ),
+        ))->androidNotification($alert, array(
+            'title' => '消息通知',
+            // 'builder_id' => 2,
+            'extras' => array(
+                'key' => 'value',
+            ),
+        ))->options(array(
+            'apns_production' => true,// false 开发环境 ,true 生产环境
+        ));
+    try {
+        $response = $push_payload->send();
+        return $response;
+    } catch  (\JPush\Exceptions\APIConnectionException $e) {
+        return $e;
+    } catch (\JPush\Exceptions\APIRequestException $e) {
+        return $e;
+    }
+}
+
+function get_order_sn(){
+    $order_id_main = date('YmdHis') . rand(10000000,99999999);
+    $order_id_len = strlen($order_id_main);
+    $order_id_sum = 0;
+    for($i=0; $i<$order_id_len; $i++){
+        $order_id_sum += (int)(substr($order_id_main,$i,1));
+    }
+    $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
+    return $osn;
+}
+
+function encrypt_password($password){
+    return password_hash($password,PASSWORD_DEFAULT);
+}
+
+function check_password($password,$hash)
+{
+    return password_verify($password,$hash);
+}
+// 获取日历 默认最近7天
+function get_calendar($day = 7,$type='asc'){
+    $data = [];
+    $week_arr = ['日','一','二','三','四','五','六'];
+    for($i=0;$i<$day;$i++) {
+        $day_time = date('Y-m-d',strtotime("-$i days"));
+        $day_title= trim(date('m月d日',strtotime("-$i days")),'0');
+        $time_int = strtotime($day_time);
+        $week_day =$week_arr[date('w',strtotime($day_time))];
+        $data[] = ['day_time' => $day_time,'week_day'=>$week_day,'time_int'=>$time_int,'day_title'=>$day_title];
+    }
+   if($type == 'asc') array_multisort(array_column($data,'time_int'),SORT_ASC,$data);
+   return $data;
+}
+function jg_push()
+{
+    $user_id = 65 ;
+    $alert ='aaa';
+    if(empty($user_id)) return false;
+    $appKey = '02a7faefd91c8a6a446a6a14';
+    $masterSecret = 'ba2e100db997024d9b6e5d35';
+    $client = new Client($appKey, $masterSecret,null);
+    $push_payload = $client->push()
+        ->setPlatform(array('ios', 'android'))
+        ->addAlias(strval($user_id))
+        ->iosNotification($alert, array(
+            'badge' => '+1',
+            'content-available' => true,
+            'mutable-content' => true,
+            'category' => 'jiguang',
+            'extras' => array(
+                'key' => 'value',
+                'jiguang'
+            ),
+        ))->androidNotification($alert, array(
+            'title' => '消息通知',
+            // 'builder_id' => 2,
+            'extras' => array(
+                'key' => 'value',
+                'jiguang'
+            ),
+        ))->options(array(
+            'apns_production' => True,
+        ));
+    try {
+        $response = $push_payload->send();
+        return $response;
+    } catch  (\JPush\Exceptions\APIConnectionException $e) {
+        return $e;
+    } catch (\JPush\Exceptions\APIRequestException $e) {
+        return $e;
+    }
+
+}
+
+
+

+ 703 - 0
application/api/controller/Activity.php

@@ -0,0 +1,703 @@
+<?php
+
+namespace app\api\controller;
+use app\common\model\ActivityApply;
+use app\common\model\PlatformLike;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use app\common\service\OrderCallback;
+use think\Db;
+/**
+ * @title 活动
+ * @controller Activity
+ * @group base
+ */
+class Activity extends Base
+{
+
+    // 需要登录的
+    protected $need_login = ['activityTags','activityCollect','activityTransmit','activityApply','payApplyOrder'];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 活动推荐
+     * @desc 活动推荐
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:string default:-- desc:资料item_id
+     * @return name:id type:int default:-- desc:id
+     * @return name:address type:string default:-- desc:地址
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时候
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:price type:string default:-- desc:价格
+     * @return name:status type:int default:-- desc:活动状态1正常2取消
+     * @return name:is_apply type:int default:-- desc:是否报名(0否1是)
+     */
+    public function getRecommendList()
+    {
+        $search_log =  UserSearch::getSearchTitle($this->user_id,11);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = 'a.id,cover,a.user_id,title,a.status,address,label,start_time,end_time,ladder,price,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_activity';
+        $order_by_two = 'read_num';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id  WHERE a.is_deleted = 0 AND a.status = 1  ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k){
+            $v['is_apply'] = ActivityApply::checkApply($this->user_id,$v['id']);
+            $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+        });
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+    /**
+     * @title 获取活动列表
+     * @desc 获取活动列表
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getActivityList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:status type:int default:-- desc:活动状态1正常2取消
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     * @return name:is_apply type:int default:0 desc:是否报名【0否1是】
+     */
+    public function getActivityList(){
+        $title = input('get.title');
+        $sort_type = input('get.sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,11);
+        $list = \app\common\model\Activity::where(['is_deleted'=>0,'status'=>1])
+            ->when($title,function ($query)use($title){
+                if($title) $query->where('title|label','like','%'.$title.'%');
+            })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+            $v['is_apply'] = ActivityApply::checkApply($this->user_id,$v['id']);
+            $v['ladder_arr'] = json_decode($v['ladder'],true);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取活动详情
+     * @desc 获取活动详情
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getActivityDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:活动id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:status type:int default:-- desc:活动状态1正常2取消
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     * @return name:is_apply type:int default:0 desc:是否报名【0否1是】
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞【0否1是】
+     * @return name:is_collect type:int default:-- desc:是否收藏【0否1是】
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     * @return name:ladder_arr type:array default:-- desc:价格阶梯设置
+     * @return name:ladder_arr.ladder_num type:int default:-- desc:人数
+     * @return name:ladder_arr.ladder_num type:float default:-- desc:价格
+     */
+    public function getActivityDetail()
+    {
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = \app\common\model\Activity::where($sel_where)->find()->toArray();
+        $detail['cover_arr'] = $detail['cover'] ? explode('|',$detail['cover']) : null;
+        $detail['label_name'] = $detail['label'] ?  explode(',',trim($detail['label'],',')): null;
+        $detail['is_apply'] = ActivityApply::checkApply($this->user_id,$detail['id']);
+        $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],4);
+        $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],4);
+        $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,7,$detail['id']);
+        $detail['collect_num'] = UserCollect::getCollectNum(7,$detail['id']);
+        $detail['ladder_arr'] = $detail['ladder'] ? json_decode($detail['ladder']): null;
+        if(!$detail['user_id']){
+            $detail['app_name']  = sysconf('app_name');
+            $detail['app_logo']  = sysconf('app_logo');
+        }else{
+            $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
+            $detail['app_name']  = $user_info ? $user_info->name : '';
+            $detail['app_logo']  = $user_info ? $user_info->headimg : '';
+        }
+        UserTrack::crateTrack($this->user_id,7,input('get.id'),0);
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc 以下接口调用验证登录
+     * @author qc
+     * @method
+     * @url /api/Activity/needLogin()
+     */
+    public function needLogin(){}
+
+
+    /**
+     * @title 点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Activity/activityTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:活动id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function activityTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),4);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+    /**
+     * @title 收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Activity/activityCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:活动id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function activityCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,7,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+
+    /**
+     * @title 活动转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Activity/activityTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:活动id
+     */
+    public function activityTransmit()
+    {
+        $activity_id = input('post.id',0);
+        \app\common\model\Activity::where('id',$activity_id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 活动报名
+     * @desc 活动报名[生成订单(报名记录),返回支付信息]
+     * @author qc
+     * @method POST
+     * @url /api/Activity/activityApply
+     * @header name:Authorization require:1 desc:Token
+     * @param name:act_id type:int default:-- desc:活动id
+     * @param name:name type:string default:-- desc:联系人
+     * @param name:phone type:string default:-- desc:联系人电话
+     * @param name:email type:string default:-- desc:email
+     * @param name:num type:int default:-- desc:报名人数
+     * @param name:phone_code type:int default:-- desc:短信验证码
+     * @param name:pay_type type:int require:1  default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付)
+     * @param name:port type:int default:1 desc:来源【1:h5,2:安卓,3:ios】
+     *
+     * @return name:pay_status type:int default:0 desc:该值为1:订单金额是0不需要支付!!!
+     * @return name:config type:array default:0 desc:支付配置
+     * @return name:config.appId type:string default:-- desc:公众账号ID
+     * @return name:config.signType type:string default:-- desc:签名类型
+     * @return name:config.paySign type:string default:-- desc:签名
+     * @return name:config.nonceStr type:string default:-- desc:随机字符串
+     * @return name:config.timestamp type:string default:-- desc:时间戳
+     * @return name:config.partnerid type:string default:-- desc:商户号
+     * @return name:config.prepayid type:string default:-- desc:唯一支付号
+     * @return name:config.package type:string default:-- desc:package
+     * @return name:config.mch_id type:string default:-- desc:商户号(H5)
+     * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
+     * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
+     * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
+     * @return name:code_url type:string default:-- desc:付款码url
+     * @return name:openid type:string default:-- desc:openid
+     */
+    public function activityApply()
+    {
+        $act_id = input('post.act_id');
+        $name = input('post.name');
+        $phone = input('post.phone');
+        $email = input('post.email');
+        $num = input('post.num',1);
+        $port = input('post.port',1);
+        $phone_code = input('post.phone_code');
+        $pay_type = input('post.pay_type',1);
+        if(!$name || !$phone || !$email) $this->error('请完善报名信息');
+        if(!in_array($pay_type,[1,2,3,4,5])) $this->error('支付方式错误');
+        if($num <= 0) $this->error('请输入报名人数');
+        $check_apply = ActivityApply::checkApply($this->user_id,$act_id);
+        //if($check_apply) $this->error('已报名!');
+        $act_info  = \app\common\model\Activity::where('id',$act_id)->where('is_deleted',0)->find();
+        if(!$act_info) $this->error('活动不存在');
+        if(strtotime($act_info->end_time)   < time() ) $this->error('活动已经结束');
+        if(strtotime($act_info->start_time)  < time() ) $this->error('活动已经开始');
+        if($act_info->status == 2) $this->error('活动已经取消');
+        $check_code = $this->checkPhoneCode($phone,$phone_code);
+       // if(!$check_code) $this->error('验证码错误');
+        $this->updatePhoneCode($check_code);
+        $ladder = $act_info->ladder ? json_decode($act_info->ladder,true) : [];
+        $order_money = bcmul($act_info->price,$num,2);
+        if(!empty($ladder)) {
+            $ladder_set  = array_column($ladder,null,'ladder_num');
+            krsort($ladder_set);
+            $max_num = array_column($ladder_set,'ladder_num');
+            $min_num = array_column($ladder_set,'ladder_num');
+            if($max_num < $num) {
+                $order_money =  bcmul($ladder_set[$max_num]['ladder_price'],$num,2);
+            }else if ($min_num > $num){
+                foreach ($ladder_set as $lk=>$lv) {
+                    if($lk <= $num){
+                        $order_money =  bcmul($lv['ladder_price'],$num,2);
+                        break;
+                    }
+                }
+            }
+        }
+        if($order_money < 0 )$this->error('报名费不能小于0');
+        $apply_info = [
+            'user_id' => $this->user_id,
+            'order_no' => get_order_sn(),
+            'pay_no' => get_order_sn(),
+            'num' => $num,
+            'name' => $name,
+            'phone' => $phone,
+            'email' => $email,
+            'pay_type' => $pay_type,
+            'money' => $order_money,
+            'port' => $port,
+            'act_id' => $act_id,
+        ];
+        $user_info = User::where('id',$this->user_id)->find();
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
+
+        Db::startTrans();
+
+        try {
+            $order_info = ActivityApply::create($apply_info)->toArray();
+            if($order_money == 0) {
+                $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
+                if(!$back_res['ret_val']) $this->exception('报名失败');
+                $ret_data['pay_status'] = 1;
+            }else{
+                $ret_data['order_id'] = $order_info['id'];
+                switch ($pay_type){
+                    case 1:
+                        $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                        $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
+                        if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                        $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                        $pay_config['config']['pay_no'] = $order_info['pay_no'];
+                        $pay_config['config']['notify_url'] = $notify_url;
+                        $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                        $pay_config['config']['total_fee'] = $order_info['money'] * 100;
+                        $ret_data['config'] = $pay_config['config'];
+                        break;
+                    case 2:
+                        $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
+                        $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
+                        $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
+                        $ret_data['config']['ali_url'] = $config;
+                        $ret_data['ali_url'] = $config;
+                        break;
+                    case 3:
+                        $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                        $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
+                        if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                        $ret_data['config'] = $pay_config['config'];
+                        break;
+                    case 4:
+                        $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                        $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
+                        $ret_data['config']['ali_url'] = $config;
+                        $ret_data['ali_url'] = $config;
+                        $ret_data['money'] = $order_info['money'];
+                        break;
+                    case 5 :
+                        if(!$user_info['openid']) $this->exception('请绑定openid');
+                        $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                        $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
+                        if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                        $ret_data['config'] = $pay_config['config'];
+                        break;
+
+                }
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('报名成功',$ret_data);
+
+    }
+
+    /**
+     * @title 活动报名订单支付
+     * @desc 活动报名订单支付
+     * @author qc
+     * @method POST
+     * @url /api/Activity/payApplyOrder
+     * @header name:Authorization require:1 desc:Token
+     * @param name:order_id type:int default:-- desc:订单id【报名记录id】
+     *
+     * @return name:pay_status type:array default:0 desc:该值为1:订单金额是0不需要支付!!!
+     * @return name:config type:array default:0 desc:支付配置
+     * @return name:config.appId type:string default:-- desc:公众账号ID
+     * @return name:config.signType type:string default:-- desc:签名类型
+     * @return name:config.paySign type:string default:-- desc:签名
+     * @return name:config.nonceStr type:string default:-- desc:随机字符串
+     * @return name:config.timestamp type:string default:-- desc:时间戳
+     * @return name:config.partnerid type:string default:-- desc:商户号
+     * @return name:config.prepayid type:string default:-- desc:唯一支付号
+     * @return name:config.package type:string default:-- desc:package
+     * @return name:config.mch_id type:string default:-- desc:商户号(H5)
+     * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
+     * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
+     * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
+     * @return name:code_url type:string default:-- desc:付款码url
+     * @return name:openid type:string default:-- desc:openid
+     */
+    public function payApplyOrder()
+    {
+        $order_id = input('post.order_id');
+        $order_info = ActivityApply::where('id',$order_id)->find()->toArray();
+        if($order_info['status'] != 0) $this->error('订单状态错误');
+        if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
+        if($order_info['money'] <= 0) $this->error('订单金额错误');
+        $pay_type = $order_info['pay_type'];
+        $user_info = User::where('id',$this->user_id)->find();
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
+        Db::startTrans();
+        try {
+            switch ($pay_type){
+                case 1:
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                    $pay_config['config']['pay_no'] = $order_info['pay_no'];
+                    $pay_config['config']['notify_url'] = $notify_url;
+                    $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                    $pay_config['config']['total_fee'] = $order_info['money'] * 100;
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 2:
+                    $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
+                    $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
+                    $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 3:
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 4:
+                    $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                    $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    $ret_data['money'] = $order_info['money'];
+                    break;
+                case 5 :
+                    if(!$user_info['openid']) $this->exception('请绑定openid');
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('ok',$ret_data);
+    }
+
+
+
+
+    /**
+     * @title 我的发布列表
+     * @desc 我的发布列表
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getMyActivityList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+
+     */
+    public function getMyActivityList(){
+        $title = input('get.title');
+        $list = \app\common\model\Activity::where(['is_deleted'=>0,'user_id'=>$this->user_id])
+            ->when($title,function ($query)use($title){
+                if($title) $query->where('title|label','like','%'.$title.'%');
+            })->order( ['sort'=>'desc','id'=>'desc'])->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的收藏【活动】
+     * @desc 我的收藏
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getCollectActivity
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+
+     * @return name:title type:string default:-- desc:标题
+     * @return name:activity_id type:string default:-- desc:活动id
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     */
+    public function getCollectActivity()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',7];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
+            ->leftJoin('Activity i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 浏览记录【活动】
+     * @desc 浏览记录
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getActivityTrack
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+
+     * @return name:title type:string default:-- desc:标题
+     * @return name:activity_id type:string default:-- desc:活动id
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     * @return name:time type:string default:-- desc:时间
+     */
+    public function getActivityTrack()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',4];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
+            ->leftJoin('Activity i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的点赞【活动】
+     * @desc 我的点赞
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getTagsActivity
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+
+     * @return name:title type:string default:-- desc:标题
+     * @return name:activity_id type:string default:-- desc:活动id
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     */
+    public function getTagsActivity()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',4];
+        $list = PlatformLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.like_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
+            ->leftJoin('Activity i','t.like_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的报名【活动】
+     * @desc 我的报名
+     * @author qc
+     * @method GET
+     * @url /api/Activity/getApplyList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+
+     * @return name:title type:string default:-- desc:标题
+     * @return name:activity_id type:string default:-- desc:活动id
+     * @return name:status type:int default:-- desc:活动状态1正常2取消
+     * @return name:cover type:string default:-- desc:图片多张|隔开
+     * @return name:cover_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:start_time type:string default:-- desc:开始时间
+     * @return name:end_time type:string default:-- desc:结束时间
+     * @return name:address type:string default:-- desc:地址
+     * @return name:price type:float default:-- desc:价格
+     * @return name:label type:string default:-- desc:标签[多个','隔开]
+     * @return name:label_name type:array default:-- desc:标签[数组]
+     */
+    public function getApplyList()
+    {
+        $sel_where = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.status','=',1];
+        $list = ActivityApply::where($sel_where)
+            ->field('t.id,t.order_no,t.act_id activity_id,i.title,i.status,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
+            ->alias('t')
+            ->leftJoin('Activity i','t.act_id = i.id')
+            ->order(['t.id'=>'desc'])
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+}

+ 157 - 243
application/api/controller/Address.php

@@ -1,286 +1,200 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | ThinkAdmin
-// +----------------------------------------------------------------------
-// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
-// +----------------------------------------------------------------------
-// | 官方网站: http://demo.thinkadmin.top
-// +----------------------------------------------------------------------
-// | 开源协议 ( https://mit-license.org )
-// +----------------------------------------------------------------------
-// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
-// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
-// +----------------------------------------------------------------------
-
 namespace app\api\controller;
-
-use app\api\controller\Base;
-use app\api\model\Member as MemberModel;
+use app\common\model\DeliveryAddress;
 use think\Db;
-use think\Model;
-use app\api\controller\Area;
-
-
 /**
- * @title 收货地址管理
+ * @title 地址管理
  * @controller Address
- * @group member
+ * @group base
  */
 class Address extends Base
 {
-    function initialize()
+    public function initialize()
     {
-        $this->check_login();
+        parent::initialize();
+        parent::checkLogin();
     }
+
+
     /**
-     * @title 添加收货地址
-     * @desc 添加收货地址
-     * @author QGF
-     * @url /api/Address/add_address
+     * @title 设置收货地址(新增或修改)
+     * @desc  设置收货地址(新增或修改)
+     * @author  qc
+     * @url /api/Address/setDeliveryAddress
      * @method POST
-     * @tag 添加地址
      * @header name:Authorization require:1 desc:Token
-     * @param name:name type:string require:1 default:-- desc:收货人
-     * @param name:phone type:int require:1 default:-- desc:手机号
-     * @param name:province type:int require:1 default:-- desc:省的ID
-     * @param name:city type:int require:1 default:-- desc:市的ID
-     * @param name:county type:int require:1 default:-- desc:区县的ID
-     * @param name:address type:string require:1 default:-- desc:详细地址
-     * @param name:is_default type:tinyint require:0 default:-- desc:是否设置成默认地址(0:不设置默认1:设置默认)
+     * @param  name:id type:int  : default:0 desc:收货地址记录id(不传值是添加)
+     * @param  name:pro_name type:string  require:1  default:-- desc:省名
+     * @param  name:city_name type:string  require:1  default:-- desc:市名
+     * @param  name:county_name type:string  require:1  default:-- desc:县区名
+     * @param  name:detail type:string  require:1  default:-- desc:详细地址
+     * @param  name:phone type:string  require:1  default:-- desc:联系电话
+     * @param  name:name type:string  require:1  default:-- desc:联系人
+     * @param  name:is_mr type:int  require:0  default:0 desc:是否是默认(0不默认,1默认)
      */
-    public function add_address(){
-        $uid = $this->uid;
-        $name = input('name');
-        $phone = input('phone');
-        $province = input('province');
-        $city = input('city');
-        $county = input('county');
-        $address = input('address');
-        $is_default = input('is_default',0);
-        if(empty($name) || empty($phone) ||  empty($province) || empty($city) || empty($county) || empty($address)) {
-            $this ->error('参数错误');
-        }
-        if($is_default){
-            $this->cancel_default();
-        }
-        $data = array(
-            'user_id' => $uid,
-            'name' => $name,
-            'phone' => $phone,
-            'province' => $province,
-            'city' => $city,
-            'county' => $county,
-            'address' => $address,
-            'is_default' => $is_default
-        );
-        $res = Db::name('store_member_address')->insert($data);
-        if($res !==false){
-            $this->success('添加成功');
+    public function  setDeliveryAddress()
+    {
+        $pro_name     = input('post.pro_name');// 省
+        $city_name    = input('post.city_name');// 市
+        $county_name  = input('post.county_name');// 县区
+        $street_name  = input('post.street_name','' );
+        $pro_id     = Db::name('store_area')->where('name',$pro_name)->value('id');
+        $city_id    = Db::name('store_area')->where('name',$city_name)->value('id');
+        $county_id  = Db::name('store_area')->where('name',$county_name)->value('id');
+        $detail     = input('post.detail');// 详细地址
+        $phone      = input('post.phone');
+        $name       = input('post.name');
+        $id         = input('post.id');
+        $is_mr      = input('post.is_mr',0);
+        $set_data =  compact(['pro_id','city_id','county_id','detail','phone','name','is_mr']);
+        $set_data['user_id']    = $this->user_id;
+        $set_data['pro_name']   = $pro_name;
+        $set_data['city_name']  = $city_name;
+        $set_data['county_name']= $county_name;
+        $set_data['street_name']= $street_name;
+        $set_data['mer_name']=$pro_name . $city_name. $county_name;
+        if($id) {
+            Db::name('delivery_address')->where(['id'=>$id])->update($set_data);
         }else{
-            $this->error('添加失败');
+            Db::name('delivery_address')->insert($set_data);
+            $id = Db::getLastInsID();
         }
+        if($is_mr) Db::name('delivery_address')->where('user_id','=',$this->user_id)->where('id','<>',$id)->where('is_mr','=',1)->update(['is_mr'=>0]);
+        $this->success('编辑成功');
     }
+
     /**
-     * @title 收货地址列表
-     * @desc 收货地址列表
-     * @author QGF
-     * @url /api/Address/address_list
-     * @method GET
-     * @tag 地址列表
+     * @title 修改默认收货地址
+     * @desc  修改默认收货地址
+     * @author  qc
+     * @url /api/Address/changeApproveDelivery
+     * @method POST
      * @header name:Authorization require:1 desc:Token
-     * @return name:name type:string default:-- desc:收货人
-     * @return name:phone type:int default:-- desc:手机号
-     * @return name:province type:string default:-- desc:省名称
-     * @return name:city type:string default:-- desc:市名称
-     * @return name:county type:string default:-- desc:区县名称
-     * @return name:address type:string default:-- desc:详细地址
-     * @return name:is_default type:tinyint default:-- desc:(0:不是默认地址1:是默认地址)
-     * @return name:area type:string default:-- desc:省市区
-     * @return name:ID type:int default:1 desc:地址ID
+     * @param name:id type:int default:0 desc:收货地址记录id
+     * @param name:is_mr type:int  default:1 desc:是否是默认(0不默认,1默认)
      */
-    public function address_list(){
-        $uid = $this->uid;
-        $res = Db::name('store_member_address')->where('user_id',$uid)->where('is_deleted',0)->order('is_default desc,id desc')->select();
-        if(empty($res)){
-            $this->success('暂无地址',array());
-        }
-        $area_obj = new area();
-        foreach ($res as &$value){
-            $value['area'] = $area_obj->get_area($value['province'],$value['city'],$value['county']);
-            $value['province'] = $area_obj->get_area($value['province'],'','');
-            $value['city'] = $area_obj->get_area('',$value['city'],'');
-            $value['county'] = $area_obj->get_area('','',$value['county']);
-            $value['ID'] = $value['id'];
-            unset($value['id']);
-            unset($value['user_id']);
-            unset($value['create_at']);
-            unset($value['is_deleted']);
+    public function changeApproveDelivery()
+    {
+        $id         = input('post.id');
+        $is_mr      = input('post.is_mr',1);
+        if($is_mr) {
+            Db::name('delivery_address')
+                ->where('user_id','=',$this->user_id)
+                ->where('is_mr','=',1)
+                ->update(['is_mr'=>0]);
+            Db::name('delivery_address')
+                ->where('user_id','=',$this->user_id)
+                ->where('id','=',$id)
+                ->update(['is_mr'=>1]);
+        }else{
+            Db::name('delivery_address')
+                ->where('user_id','=',$this->user_id)
+                ->where('id','=',$id)
+                ->update(['is_mr'=>0]);
         }
-        $this->success('获取成功',$res);
+        $this->success('修改成功');
     }
+
     /**
-     * @title 编辑收货地址
-     * @desc 编辑收货地址
-     * @author QGF
-     * @url /api/Address/edit_address
+     * @title 删除收货地址
+     * @desc  删除收货地址
+     * @author  qc
+     * @url /api/Address/delDeliveryAddress
      * @method POST
-     * @tag 编辑地址
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:string require:1 default:1 desc:地址ID
-     * @param name:name type:string require:1 default:屈国锋 desc:收件人
-     * @param name:phone type:int require:1 default:18263693516 desc:手机号
-     * @param name:province type:int require:1 default:1375 desc:省的ID
-     * @param name:city type:int require:1 default:1479 desc:市的ID
-     * @param name:county type:int require:1 default:1480 desc:区县的ID
-     * @param name:address type:string require:1 default:环球中心A座1707 desc:详细地址
-     * @param name:is_default type:tinyint require:0 default:0 desc:是否设置成默认地址(0:不设置默认1:设置默认)
+     * @param  name:id type:int  require:1 default:1 desc:收货地址记录id
      */
-    public function edit_address(){
-        $uid = $this->uid;
-        $id = input('id');
-        $name = input('name');
-        $phone = input('phone');
-        $province = input('province');
-        $city = input('city');
-        $county = input('county');
-        $address = input('address');
-        $is_default = input('is_default',0);
-        if(empty($id) || empty($name) || empty($phone) ||  empty($province) || empty($city) || empty($county) || empty($address)) {
-            $this ->error('参数错误');
-        }
-        $member_address = Db::name('store_member_address')->field('id')->where('id',$id)->where('is_deleted',0)->where('user_id',$uid)->find();
-        if(empty($member_address['id'])){
-            $this->error('该地址不存在');
-        }
-        if($is_default){
-            $this->cancel_default();
-        }
-        $data = array(
-            'name' => $name,
-            'phone' => $phone,
-            'province' => $province,
-            'city' => $city,
-            'county' => $county,
-            'address' => $address,
-            'is_default' => $is_default
-        );
-        $res = Db::name('store_member_address')->where('id',$id)->update($data);
-        if($res !==false){
-            $this->success('编辑成功');
-        }else{
-            $this->error('编辑失败');
-        }
+    public function delDeliveryAddress()
+    {
+        $id = input('post.id');
+        if(!$id)$this->error('请选择要删除的收货地址');
+        Db::name('delivery_address')->where(['user_id'=>$this->user_id,'id'=>$id])->update(['is_deleted'=>1,'is_mr'=>0]);
+        $this->success('删除成功!');
     }
+
     /**
-     * @title 收货地址详情
-     * @desc 收货地址详情
-     * @author QGF
-     * @url /api/Address/address_detail
+     * @title 获取收货地址列表
+     * @desc  获取收货地址列表
+     * @author  qc
+     * @url /api/Address/getDeliveryAddressList
      * @method GET
-     * @tag 地址详情
      * @header name:Authorization require:1 desc:Token
-     * @param  name:id type:string require:1 default:1 desc:地址ID
-     * @return name:name type:string default:屈国锋 desc:收件人
-     * @return name:phone type:int default:18263693516 desc:手机号
-     * @return name:province type:int default:-- desc:省id
-     * @return name:city type:int default:-- desc:市id
-     * @return name:county type:int default:-- desc:区县id
-     * @return name:province_name type:string default:-- desc:省名称
-     * @return name:city_name type:string default:-- desc:市名称
-     * @return name:county_name type:string default:-- desc:区县名称
-     * @return name:address type:string default:环球中心A座1707 desc:详细地址
-     * @return name:is_default type:tinyint default:0 desc:(0:不是默认地址1:是默认地址)
-     * @return name:area type:string default:山东省临沂市兰山区 desc:省市区
-     * @return name:ID type:int default:1 desc:地址ID
+     * @param  name:page type:int   default:1 desc:页数
+     * @param  name:page_num type:int   default:20 desc:每页数
+     * @return name:pro_id type:int   default:-- desc:省id
+     * @return name:city_id type:int   default:-- desc:市id
+     * @return name:county_id type:int  default:-- desc:县区id
+     * @return name:pro_name type:string  default:-- desc:省名
+     * @return name:city_name type:string  default:-- desc:市名
+     * @return name:county_name type:string  default:-- desc:县区名
+     * @return name:detail type:string  default:-- desc:详细地址
+     * @return name:phone type:string  default:-- desc:联系电话
+     * @return name:name type:string   default:-- desc:联系人
+     * @return name:is_mr type:int   default:0 desc:是否是默认(0不默认,1默认)
      */
-    public function address_detail(){
-        $uid = $this->uid;
-        $id = input('id');
-        $is_default = input('is_default',0);
-        if($is_default){
-            $address_detail = Db::name('store_member_address')->where('user_id',$uid)->where('is_deleted',0)->where('is_default',1)->find();
-        }else{
-            if(empty($id)){
-                $this->error('参数错误');
-            }
-            $address_detail = Db::name('store_member_address')->where('user_id',$uid)->where('id',$id)->where('is_deleted',0)->find();
-        }
-        if(empty($address_detail['id'])){
-            $this->success('该地址不存在',json_encode(array(), JSON_FORCE_OBJECT));
-        }
-        $area_obj = new area();
-        $address_detail['area'] = $area_obj->get_area($address_detail['province'],$address_detail['city'],$address_detail['county']);
-        $address_detail['province_name'] = $area_obj->get_area($address_detail['province'],'','');
-        $address_detail['city_name'] = $area_obj->get_area('',$address_detail['city'],'');
-        $address_detail['county_name'] = $area_obj->get_area('','',$address_detail['county']);
-        $address_detail['ID'] = $address_detail['id'];
-        unset($address_detail['id']);
-        unset($address_detail['user_id']);
-        unset($address_detail['create_at']);
-        unset($address_detail['is_deleted']);
-        $this->success('获取成功',$address_detail);
+    public function getDeliveryAddressList()
+    {
+        $list = DeliveryAddress::where(['user_id'=>$this->user_id,'is_deleted'=>0])
+            ->order('is_mr desc ,id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+
     }
+
     /**
-     * @title 删除收货地址
-     * @desc 删除收货地址
-     * @author QGF
-     * @url /api/Address/address_delete
+     * @title 获取收货地址详情
+     * @desc  获取收货地址详情
+     * @author  qc
+     * @url /api/Address/getDeliveryAddressDetail
      * @method GET
-     * @tag 删除地址
      * @header name:Authorization require:1 desc:Token
-     * @param  name:id type:string require:1 default:1 desc:地址ID
+     * @param  name:id type:int   default:1 desc:收货地址记录id
+     * @return name:pro_id type:int   default:-- desc:省id
+     * @return name:city_id type:int   default:-- desc:市id
+     * @return name:county_id type:int  default:-- desc:县区id
+     * @return name:pro_name type:string  default:-- desc:省名
+     * @return name:city_name type:string  default:-- desc:市名
+     * @return name:county_name type:string  default:-- desc:县区名
+     * @return name:detail type:string  default:-- desc:详细地址
+     * @return name:phone type:string  default:-- desc:联系电话
+     * @return name:name type:string   default:-- desc:联系人
+     * @return name:is_mr type:int   default:0 desc:是否是默认(0不默认,1默认)
      */
-    public function address_delete(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $address = Db::name('store_member_address')->field('id')->where('user_id',$uid)->where('id',$id)->find();
-        if(empty($address['id'])){
-            $this->error('该地址不存在');
-        }
-        $res = Db::name('store_member_address')->where('id',$id)->update(array('is_deleted'=>1));
-        if($res !==false){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
-        }
+    public function getDeliveryAddressDetail()
+    {
+        $detail  = Db::name('delivery_address')->find(input('id'));
+        $this->success('ok',$detail);
     }
+
     /**
-     * @title 设置默认地址
-     * @desc 设置默认地址
-     * @author QGF
-     * @url /api/Address/set_default
+     * @title 获取默认收货地址详情
+     * @desc  获取默认收货地址详情
+     * @author  qc
+     * @url /api/Address/getDefaultAddress
      * @method GET
-     * @tag 设置默认地址
      * @header name:Authorization require:1 desc:Token
-     * @param  name:id type:string require:1 default:1 desc:地址ID
+     * @return name:pro_id type:int   default:-- desc:省id
+     * @return name:city_id type:int   default:-- desc:市id
+     * @return name:county_id type:int  default:-- desc:县区id
+     * @return name:pro_name type:string  default:-- desc:省名
+     * @return name:city_name type:string  default:-- desc:市名
+     * @return name:county_name type:string  default:-- desc:县区名
+     * @return name:detail type:string  default:-- desc:详细地址
+     * @return name:phone type:string  default:-- desc:联系电话
+     * @return name:name type:string   default:-- desc:联系人
+     * @return name:is_mr type:int   default:0 desc:是否是默认(0不默认,1默认)
      */
-    public function set_default(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $address = Db::name('store_member_address')->field('id,is_default')->where('user_id',$uid)->where('id',$id)->find();
-        if(empty($address['id'])){
-            $this->error('该地址不存在');
-        }
-        if($address['is_default']){
-            $this->error('该地址已是默认地址');
-        }
-        $this->cancel_default();
-        $res = Db::name('store_member_address')->where('id',$id)->update(array('is_default'=>1));
-        if($res){
-            $this->success('设置成功');
-        }else{
-            $this->error('设置失败');
-        }
-    }
-    public function cancel_default(){
-        $uid = $this->uid;
-        Db::name('store_member_address')->where('user_id',$uid)->where('is_default',1)->update(array('is_default'=>0));
+    public function getDefaultAddress()
+    {
+        $default  = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
+        $detail = $default ? $default->toArray() : '';
+        $this->success('ok',$detail);
     }
+
+
+
+
+
+
 }

+ 114 - 66
application/api/controller/Alipay.php

@@ -1,21 +1,8 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | ThinkAdmin
-// +----------------------------------------------------------------------
-// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
-// +----------------------------------------------------------------------
-// | 官方网站: http://demo.thinkadmin.top
-// +----------------------------------------------------------------------
-// | 开源协议 ( https://mit-license.org )
-// +----------------------------------------------------------------------
-// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
-// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
-// +----------------------------------------------------------------------
-
 namespace app\api\controller;
-
 use app\api\controller\Base;
+use app\common\model\GoodsOrder;
+use app\common\service\OrderCallback;
 use think\Controller;
 use think\Db;
 use think\Model;
@@ -23,13 +10,36 @@ use think\Model;
 use Alipay\EasySDK\Kernel\Factory;
 use Alipay\EasySDK\Kernel\Util\ResponseChecker;
 use Alipay\EasySDK\Kernel\Config;
-/**
- * 支付宝支付
- * Class Member
- * @package app\api\controller
- */
+
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Factory.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Config.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/EasySDKKernel.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/AlipayConstants.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Util/ResponseChecker.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Util/JsonUtil.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Util/Signer.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Payment/App/Client.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Payment/App/Models/AlipayTradeAppPayResponse.php';
+
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Payment/Page/Client.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Kernel/Util/PageUtil.php';
+require_once env('root_path').'vendor/alipaysdk/easysdk/php/src/Payment/Page/Models/AlipayTradePagePayResponse.php';
 class Alipay extends Base
 {
+
+    protected static $appid = [
+        'H5'=>'2021003155604810',
+        'APP'=>'2021003155604810'
+    ];
+    protected static $merchantPrivateKey = [
+        'H5'=>'MIIEpQIBAAKCAQEAkfh1oGMZSI8t3WbvpgQhAiK5dk1aSUafBl8AEj+hJQaI6phA+J1IZFMWNPm5dvCwM+u3M/vahxHUgAP0EtL9IsGpqt77r11tKOtV5uMUQH356i8r/RQzOA+y42mShBSq682rC3h2Cn18Y9TDZzPjayGGYx7JA/6e2fbht5Pb23HtegtV7DZZuIVduNgV3EUXiBQBzpj+dO+XEP4+/EYCaqOGWWIZc2IlBgu0uf0ozmOSKvmMtozakl1t8B2JCcOAerCxpSH2XLNi8DyIuCEEiYGfhZwLTadom0M2J6UBGWhgPIq1A83BiZW38PlaldajP+OjicDzVNJPNP+2oVCt5QIDAQABAoIBAQCPUe9UIdjiSEqVFwt36pfqO+PzBvH9/kwHemFciYMUEn1+MS2hrPQ2JOop64OxB5NJ90dyz/b5JYWKh9cuYGDQrmuDbNqbjVSvl5lJUG5DAC3QRK6hFyNPCQLwjGiiLJTBX7dwVL85f4oRjwaonubM+iazzbc6p9aaVe+7Sn7Uz11Y7v+hQ9Zro/YwlQd+palXq0MQK2tAlF3xAgYPe50ztf5lsatGWcs7urWnVNgZLwlF1buoCHzzzJZ7fAzJgkydJjiIZVIXPAcn/gC5AgFV6T3G61jFSnYOrNL5D2xuh8M9tOZ5sq0C+29WCYETbO5X5IXJaUdiO3SEXytqDmrBAoGBAOv55a6sJBuAzmypNbsHlNNwXxePjhvJpDtr4NNVASuhcx8SaBjO2h18KMqufq34uWWeTbJwQRgfe9+v1Vvb8myffPePZw/LQsLPB5zAGTylUzYv3lm3tuKhryUbFrp46wTebWXjxOjmMDIfXCG6rGOwp/uGBBDvy7SwM9kjzpTRAoGBAJ5bX4JmqQC9tOOzCAoHuy3JyGP39DsGrCWqBkIBU2/nBMBtWSecgKvHLaS+lcaajHklju96AMUsPvK759Fd1P/zTNDuOIuklGbnZkZ6ZIZMnugigZvUQLULDVerrOpxYmFNNKJGofcYMYsUlGfLPUYoDIyLNwv8sS8IwQ+FqBzVAoGBAJmFag1axt7xzNpat68nPobUy7jbV1vysptKEunKmslU7z2ezwScxsB5/1vlbFsovw1CkU/uwhq8mO2tSoTJso1CsZ2puSZIWfW9lTlArOqMsHdHa0Q5Ro1pHTZpyj6k3lm7j7bDGV9gKqjhSCJVfUQaMR9tUAXozEGQhRrWtdaRAoGAVChBON7wIAmxsXT658G2Ex5yldY3gIsKP7X9P2TO/+BpYQ573BZLN39R3YS/ul12HAf+z3wqHp9mEMAV8emJAkE96KdBe80KZSnC69+tvsXHiZyU/sitXsmx3I7LBYkefJF4UGlzOAsugTh9qi+Tr84m5SYzKfav/0wKtgIVFsUCgYEAhvi3hDZWo78b8gKd57b1VhRaZEzYeb1TqUMfBuEG1sjqm3Lsshkf+fkdgSaWwgzCmci2iGIt4oCzg08QZRYNK7INAuk3kwVyrg7BvsydzVeT0wi5Ga7tktxzw99Z2/SUbCteIpJ5J4BGnL1ZFnP+3/naQhX5XrbGiu/bU42Zxg0=',
+        'APP'=>'MIIEpQIBAAKCAQEAkfh1oGMZSI8t3WbvpgQhAiK5dk1aSUafBl8AEj+hJQaI6phA+J1IZFMWNPm5dvCwM+u3M/vahxHUgAP0EtL9IsGpqt77r11tKOtV5uMUQH356i8r/RQzOA+y42mShBSq682rC3h2Cn18Y9TDZzPjayGGYx7JA/6e2fbht5Pb23HtegtV7DZZuIVduNgV3EUXiBQBzpj+dO+XEP4+/EYCaqOGWWIZc2IlBgu0uf0ozmOSKvmMtozakl1t8B2JCcOAerCxpSH2XLNi8DyIuCEEiYGfhZwLTadom0M2J6UBGWhgPIq1A83BiZW38PlaldajP+OjicDzVNJPNP+2oVCt5QIDAQABAoIBAQCPUe9UIdjiSEqVFwt36pfqO+PzBvH9/kwHemFciYMUEn1+MS2hrPQ2JOop64OxB5NJ90dyz/b5JYWKh9cuYGDQrmuDbNqbjVSvl5lJUG5DAC3QRK6hFyNPCQLwjGiiLJTBX7dwVL85f4oRjwaonubM+iazzbc6p9aaVe+7Sn7Uz11Y7v+hQ9Zro/YwlQd+palXq0MQK2tAlF3xAgYPe50ztf5lsatGWcs7urWnVNgZLwlF1buoCHzzzJZ7fAzJgkydJjiIZVIXPAcn/gC5AgFV6T3G61jFSnYOrNL5D2xuh8M9tOZ5sq0C+29WCYETbO5X5IXJaUdiO3SEXytqDmrBAoGBAOv55a6sJBuAzmypNbsHlNNwXxePjhvJpDtr4NNVASuhcx8SaBjO2h18KMqufq34uWWeTbJwQRgfe9+v1Vvb8myffPePZw/LQsLPB5zAGTylUzYv3lm3tuKhryUbFrp46wTebWXjxOjmMDIfXCG6rGOwp/uGBBDvy7SwM9kjzpTRAoGBAJ5bX4JmqQC9tOOzCAoHuy3JyGP39DsGrCWqBkIBU2/nBMBtWSecgKvHLaS+lcaajHklju96AMUsPvK759Fd1P/zTNDuOIuklGbnZkZ6ZIZMnugigZvUQLULDVerrOpxYmFNNKJGofcYMYsUlGfLPUYoDIyLNwv8sS8IwQ+FqBzVAoGBAJmFag1axt7xzNpat68nPobUy7jbV1vysptKEunKmslU7z2ezwScxsB5/1vlbFsovw1CkU/uwhq8mO2tSoTJso1CsZ2puSZIWfW9lTlArOqMsHdHa0Q5Ro1pHTZpyj6k3lm7j7bDGV9gKqjhSCJVfUQaMR9tUAXozEGQhRrWtdaRAoGAVChBON7wIAmxsXT658G2Ex5yldY3gIsKP7X9P2TO/+BpYQ573BZLN39R3YS/ul12HAf+z3wqHp9mEMAV8emJAkE96KdBe80KZSnC69+tvsXHiZyU/sitXsmx3I7LBYkefJF4UGlzOAsugTh9qi+Tr84m5SYzKfav/0wKtgIVFsUCgYEAhvi3hDZWo78b8gKd57b1VhRaZEzYeb1TqUMfBuEG1sjqm3Lsshkf+fkdgSaWwgzCmci2iGIt4oCzg08QZRYNK7INAuk3kwVyrg7BvsydzVeT0wi5Ga7tktxzw99Z2/SUbCteIpJ5J4BGnL1ZFnP+3/naQhX5XrbGiu/bU42Zxg0=',
+    ];
+    protected static $alipayPublicKey = [
+        'H5'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAidau5/jnsnry1+3VDvTOO7S+Zsi1u+a0uNvacXXHAh78TQIWPBEt7U/XP7yh89+UDOZQPknxJjpfo53ciOAowEeGFH9O8NimtvSFMMF9iCQijmlhXyOCfZstLyrVRojcZTgv4//AjV877DrUBTsonpeGGSi92Ssl8COPWbr461UtYBCWjAK+UiZsh01ZI5LNTvt8bVyOWPhWDEcPvxxrkTqUF6qRO9Bvr169V0tZxiJgDLu891Ofim/TlD+tHgnOI9NfWQafRddylPCTzIHbaxZyQ0JmNJleROSCMNOpVZiWZX8+mQmhEpeodJ3MqYmAqN4Dla7fN54Y2wWHaRNkGwIDAQAB',
+        'APP'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAidau5/jnsnry1+3VDvTOO7S+Zsi1u+a0uNvacXXHAh78TQIWPBEt7U/XP7yh89+UDOZQPknxJjpfo53ciOAowEeGFH9O8NimtvSFMMF9iCQijmlhXyOCfZstLyrVRojcZTgv4//AjV877DrUBTsonpeGGSi92Ssl8COPWbr461UtYBCWjAK+UiZsh01ZI5LNTvt8bVyOWPhWDEcPvxxrkTqUF6qRO9Bvr169V0tZxiJgDLu891Ofim/TlD+tHgnOI9NfWQafRddylPCTzIHbaxZyQ0JmNJleROSCMNOpVZiWZX8+mQmhEpeodJ3MqYmAqN4Dla7fN54Y2wWHaRNkGwIDAQAB',
+    ];
+
     /**
      * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
      * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -37,9 +47,11 @@ class Alipay extends Base
      * 支付宝支付
      */
     public static function ali_pay($subject,$outTradeNo,$totalAmount,$notifyUrl){
-        Factory::setOptions(self::getOptions($notifyUrl));
+        Factory::setOptions(self::getOptions($notifyUrl,"APP"));
+
         try {
             //2. 发起API调用(以支付能力下的统一收单交易创建接口为例)
+            //$result = Factory::payment()->common()->create("iPhone6 16G", "20200326235526001", "88.88", "2088002656718920");
             $result = Factory::payment()->App()->pay($subject,$outTradeNo , $totalAmount);
             $responseChecker = new ResponseChecker();
             //3. 处理响应或异常
@@ -52,32 +64,36 @@ class Alipay extends Base
             return false;
         }
     }
-    /**
-     * 支付宝支付退款
-     */
-    public static function ali_refund($outTradeNo,$totalAmount){
-        Factory::setOptions(self::getOptions(''));
-        $result = Factory::payment()->common()->refund($outTradeNo,$totalAmount);
-        $responseChecker = new ResponseChecker();
-        return $responseChecker->success($result);
+
+    public static function ali_pay_pc($subject,$outTradeNo,$totalAmount,$notifyUrl,$returnUrl){
+        Factory::setOptions(self::getOptions($notifyUrl,'H5'));
+        try {
+            $result = Factory::payment()->Page()->pay($subject,$outTradeNo,$totalAmount,$returnUrl);
+            $responseChecker = new ResponseChecker();
+            //3. 处理响应或异常
+            if ($responseChecker->success($result)) {
+                return $result->body;
+            } else {
+                echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
+            }
+        } catch (Exception $e) {
+            return false;
+        }
     }
-    public static function getOptions($notifyUrl){
+
+    public static function getOptions($notifyUrl,$type = 'H5'){
         $options = new Config();
         $options->protocol = 'https';
         $options->gatewayHost = 'openapi.alipay.com';
         $options->signType = 'RSA2';
-
-        $options->appId = '2021003128649247';
-
+        $options->appId = static::$appid[$type];
         // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
-        $options->merchantPrivateKey = 'MIIEowIBAAKCAQEAnfxs/Uc1aTxmzXsaLZrElLOq9706rPxNmBjvdDq8Rvko+KD0AlrX3sg25MDixawcg7efpEJe9I05Jeyvaq8ZaMsyzDeEsob/XYBoCQiqKj7XQUtQXVN09ri/YGMQO8zHivS1WH9wiD6kdqh4HYlRc2RnFood0+jx1oJIIN1ombOsX5afehH8jN4I2/tpGP0dI/pye6S4BWi3aB8lyQNSrfFdu1erYWzbXy5YRd1SWTgQfIINxDB0q0/Ei1sqZ2TcTUGMGfGWQ0tFglWXv3yBuywWP4Jf7t6q3OBG+IX6M70jaeFsy8LqdEfMhiycJr//Bhj4JE1NmCcSi0GoQM9KlQIDAQABAoIBABhL/PsK24T+vBS37PO8jKUN6KpHGOIHv2s30oO+kLwdj5aFMmG2VOK3SfHuVDHwYUZElDGv32ie234go2211iOOtJZBp4/JQTbBC77v7TOoDHTHP2nK7v8OtKf/NDzuJnYRYl5k4wqhD6wMBsUMHFGxzETkIug3OBI0YSFky7RvdnUAyhQQVzbZR8THFqOiUySD8IRNy8fIhxWIGB9F5/q4OEoFusnpOA/+EhRLROQmkq56IuN8Q/LyOhwfFpEtkPpkVoBTmu8pdSz4mOJp90p0LVBDMNM4U8y2kk4JDj7Xs6etUWDKysPJkX2hOyvP5PYEHIYwOE3TBS3lWjXNvOECgYEA2Uc4HGb1wRiRZ5KAteq99onQNRe/Jdz2jwUh849XRaKnerF5rAKc+/kKIIEnURY6vNqI/pTQMILPaKIE2/9y1S/LRD4Q5wGC527t+QWIxzxf5pjJFyTG2qO+XD/933hT9nGcngz1AhcofaFshWnLrulv/DZFb5qya4mIo5OHVL0CgYEAuiQl8hLR+571KhYgHYJlR+ehg6n9srsLCi9zAdSH+juRVcLgIslCrallQ4TfoTdRyKVujCJRHgDFuSTEPhfIHWqxg8JSvxYv/P0VonW1M+s9rSNldtp4wx23mEJW35RflmSSgLc7Itf+8T27N5qP3UIlzuOfnaCC4DvMKqubJrkCgYBi780bEb8B6D/9m3ZEX9mUM3i9VEzT3uPeiAXHtBOXP9NnSP0QWDhHfEUiO+09PRQN/qy2z+hkzovHJ09zJcSSUqsKLgDgT43d+GMgK2b24gUBKb0XbsWltT3vH6xoX5BL/bvFND00cHsdia2yqlP3F5DIlaXUheqMkRnI8lqDOQKBgDrQHxksbyJkqCvjD8SjJaMhgbvbIyisxqEyOtFSOKCM36/MQgtbsfCy/CboPcxvcSzHcHVghmbHcbG89zBzTSxWQL5T0NdFiGYUBRjuvhEoe7VP4Mg74TotEoxOMaq087rODigTPOEWhBvvGE9KS7hqJQ4Ih69DPvbgjfLRg9UpAoGBAMjzQq8BI9AepA5js9ajNQQDrnbdB7x3dxjp2MSknIxzz1EccrAmSVF4iVIzevFgL5raqRRaSDEDYbqnPTDOpH/MzehdAt+8UxXq3y7sYhFgckG49PhRKmtM2dmyAuqdRLhd4U8SwbrLtfYhtw6R0iqqhlxU8XCWczbywSMeIho1';
-
+        $options->merchantPrivateKey =  static::$merchantPrivateKey[$type];
         /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
         $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
         $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
-
         //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
-        $options->alipayPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnfxs/Uc1aTxmzXsaLZrElLOq9706rPxNmBjvdDq8Rvko+KD0AlrX3sg25MDixawcg7efpEJe9I05Jeyvaq8ZaMsyzDeEsob/XYBoCQiqKj7XQUtQXVN09ri/YGMQO8zHivS1WH9wiD6kdqh4HYlRc2RnFood0+jx1oJIIN1ombOsX5afehH8jN4I2/tpGP0dI/pye6S4BWi3aB8lyQNSrfFdu1erYWzbXy5YRd1SWTgQfIINxDB0q0/Ei1sqZ2TcTUGMGfGWQ0tFglWXv3yBuywWP4Jf7t6q3OBG+IX6M70jaeFsy8LqdEfMhiycJr//Bhj4JE1NmCcSi0GoQM9KlQIDAQAB';
+        $options->alipayPublicKey =  static::$merchantPrivateKey[$type];
         //可设置异步通知接收服务地址(可选)
         $options->notifyUrl = $notifyUrl;
         //可设置AES密钥,调用AES加解密相关接口时需要(可选)
@@ -85,44 +101,76 @@ class Alipay extends Base
         return $options;
     }
 
-    //订单支付回调
-    public function order_notify()
+
+    // 会员开通回调
+    public function LevelOrderNotify()
     {
         $result = input('post.');
+        $this->payResultLog($result,'dd_level_order');
         if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
             $pay_no = $result['out_trade_no'];
-            // 用户支付成功处理
-            $order_list = Db::table('store_order')->where('status',0)->where('pay_no',$pay_no)->find();
-            if (empty($order_list)) {
-                return true; // 我已经处理完了,订单没找到,别再通知我了
-            }
-            // 用户支付成功处理
-            $status = 1;
-            if($order_list['type'] == 1 && $order_list['is_incidental'] == 0){
-                $status = 2;
-            }
-            Db::table('store_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>$status]);
-            if($order_list['type'] == 1){   //支付成功(如果是付费的课程,增加购买记录)
-                $goods_type = Db::name('store_goods')->where('id',$order_list['goods_id'])->value('type');
-                if($goods_type == 2){
-                    Db::name('store_goods')->where('id',$order_list['goods_id'])->setInc('buy_num',1);
-                }
-            }
-            return true; // 返回处理完成
+            $order_info = \app\common\model\LevelOrder::where('pay_no',$pay_no)->find();
+            if(!$order_info) return false;
+            $order_info = $order_info->toArray();
+            if($order_info['status'] != 0) return true;
+            $back_res = OrderCallback::levelOrderCallBack($order_info,1);// 支付完成后回调
+            return $back_res['ret_val'];
         }
     }
-    //直播订单回调
-    public function live_order_notify(){
+
+    // 活动报名回调
+    public function applyOrderNotify()
+    {
         $result = input('post.');
+        $this->payResultLog($result,'dd_activity_apply');
         if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
             $pay_no = $result['out_trade_no'];
-            // 用户支付成功处理
-            $order_list = Db::table('store_order_live')->where('status',0)->where('pay_no',$pay_no)->find();
-            if (empty($order_list)) {
-                return true; // 我已经处理完了,订单没找到,别再通知我了
-            }
-            Db::table('store_order_live')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>1]);
-            return true; // 返回处理完成
+            $order_info = \app\common\model\ActivityApply::where('pay_no',$pay_no)->find();
+            if(!$order_info) return false;
+            $order_info = $order_info->toArray();
+            if($order_info['status'] != 0) return true;
+            $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
+            return $back_res['ret_val'];
         }
     }
+
+
+    // 商品支付回调
+    public function goodsOrderNotify()
+    {
+        $result = input('post.');
+        $this->payResultLog($result,'dd_goods_order');
+        if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
+            $pay_no = $result['out_trade_no'];
+            $order_info = GoodsOrder::with('orderItem')->where('pay_no',$pay_no)->find();
+            if(!$order_info) return false;
+            $order_info = $order_info->toArray();
+            if($order_info['status'] != 0) return true;
+            $back_res = OrderCallback::goodsOrderCallBack($order_info,1);// 支付完成后回调
+            return $back_res['ret_val'];
+        }
+
+    }
+    /**
+     * 记录支付日志
+     * @param $message
+     * @param $table_name
+     */
+    public function payResultLog($message,$table_name)
+    {
+        // 回调记录
+        $ret_arr = [];
+        $ret_arr['transaction_id'] =    isset($message['trade_no']) ?$message['trade_no']: '';
+        $ret_arr['trade_no'] =          isset($message['out_trade_no']) ?$message['out_trade_no']: '';
+        $ret_arr['return_code'] =       isset($message['trade_status']) ?$message['trade_status']: '';
+        $ret_arr['result_code'] =       isset($message['trade_status']) ?$message['trade_status']: '';
+        $ret_arr['create_at'] =         date('Y-m-d H:i:s');
+        $ret_arr['order_table'] =       $table_name;
+        $ret_arr['result'] =            json_encode($message);
+        $ret_arr['pay_type'] =          'zfb';
+        Db::name('order_pay_result')->insert($ret_arr);
+    }
+
+
+
 }

+ 865 - 0
application/api/controller/ApiRedis.php

@@ -0,0 +1,865 @@
+<?php
+namespace app\api\controller;
+/**
+ * redis操作类
+ * 说明,任何为false的串,存在redis中都是空串。
+ * 只有在key不存在时,才会返回false。
+ * 这点可用于防止缓存穿透
+ *
+ */
+use think\cache\driver\Redis;
+class ApiRedis
+{
+    private $redis;
+    //当前数据库ID号
+    protected $dbId=0;
+    //当前权限认证码
+    protected $auth;
+    /**
+     * 实例化的对象,单例模式.
+     * @var \iphp\db\Redis
+     */
+    static private $_instance=array();
+    private $k;
+    //连接属性数组
+    protected $attr=array(
+        //连接超时时间,redis配置文件中默认为300秒
+        'timeout'=>300,
+        //选择的数据库。
+        'db_id'=>0,
+    );
+    //什么时候重新建立连接
+    protected $expireTime;
+    protected $host;
+    protected $port;
+    private function __construct($config,$attr=array())
+    {
+        $this->attr    =  array_merge($this->attr,$attr);
+        $this->redis  =  new Redis();
+        $this->port    =  $config['port'] ? $config['port'] : 6379;
+        $this->host    =  $config['host'];
+        $this->redis->connect($this->host, $this->port, $this->attr['timeout']);
+        if($config['auth'])
+        {
+            $this->auth($config['auth']);
+            $this->auth  =  $config['auth'];
+        }
+        $this->expireTime  =  time() + $this->attr['timeout'];
+    }
+    /**
+     * 得到实例化的对象.
+     * 为每个数据库建立一个连接
+     * 如果连接超时,将会重新建立一个连接
+     * @param array $config
+     * @param int $dbId
+     * @return \iphp\db\Redis
+     */
+    public static function getInstance($config, $attr = array())
+    {
+        //如果是一个字符串,将其认为是数据库的ID号。以简化写法。
+        if(!is_array($attr))
+        {
+            $dbId  =  $attr;
+            $attr  =  array();
+            $attr['db_id']  =  $dbId;
+        }
+        $attr['db_id']  =  $attr['db_id'] ? $attr['db_id'] : 0;
+        $k  =  md5(implode('', $config).$attr['db_id']);
+        if(! (static::$_instance[$k] instanceof self))
+        {
+            static::$_instance[$k] = new self($config,$attr);
+            static::$_instance[$k]->k    =  $k;
+            static::$_instance[$k]->dbId  =  $attr['db_id'];
+            //如果不是0号库,选择一下数据库。
+            if($attr['db_id'] != 0){
+                static::$_instance[$k]->select($attr['db_id']);
+            }
+        }
+        elseif( time() > static::$_instance[$k]->expireTime)
+        {
+            static::$_instance[$k]->close();
+            static::$_instance[$k]     =   new self($config,$attr);
+            static::$_instance[$k]->k  =  $k;
+            static::$_instance[$k]->dbId=  $attr['db_id'];
+            //如果不是0号库,选择一下数据库。
+            if($attr['db_id']!=0){
+                static::$_instance[$k]->select($attr['db_id']);
+            }
+        }
+        return static::$_instance[$k];
+    }
+    private function __clone(){}
+    /**
+     * 执行原生的redis操作
+     * @return \Redis
+     */
+    public function getRedis()
+    {
+        return $this->redis;
+    }
+    /*****************hash表操作函数*******************/
+    /**
+     * 得到hash表中一个字段的值
+     * @param string $key 缓存key
+     * @param string $field 字段
+     * @return string|false
+     */
+    public function hGet($key,$field)
+    {
+        return $this->redis->hGet($key,$field);
+    }
+    /**
+     * 为hash表设定一个字段的值
+     * @param string $key 缓存key
+     * @param string $field 字段
+     * @param string $value 值。
+     * @return bool
+     */
+    public function hSet($key,$field,$value)
+    {
+        return $this->redis->hSet($key,$field,$value);
+    }
+    /**
+     * 判断hash表中,指定field是不是存在
+     * @param string $key 缓存key
+     * @param string $field 字段
+     * @return bool
+     */
+    public function hExists($key,$field)
+    {
+        return $this->redis->hExists($key,$field);
+    }
+    /**
+     * 删除hash表中指定字段 ,支持批量删除
+     * @param string $key 缓存key
+     * @param string $field 字段
+     * @return int
+     */
+    public function hdel($key,$field)
+    {
+        $fieldArr=explode(',',$field);
+        $delNum=0;
+        foreach($fieldArr as $row)
+        {
+            $row=trim($row);
+            $delNum+=$this->redis->hDel($key,$row);
+        }
+        return $delNum;
+    }
+    /**
+     * 返回hash表元素个数
+     * @param string $key 缓存key
+     * @return int|bool
+     */
+    public function hLen($key)
+    {
+        return $this->redis->hLen($key);
+    }
+    /**
+     * 为hash表设定一个字段的值,如果字段存在,返回false
+     * @param string $key 缓存key
+     * @param string $field 字段
+     * @param string $value 值。
+     * @return bool
+     */
+    public function hSetNx($key,$field,$value)
+    {
+        return $this->redis->hSetNx($key,$field,$value);
+    }
+    /**
+     * 为hash表多个字段设定值。
+     * @param string $key
+     * @param array $value
+     * @return array|bool
+     */
+    public function hMset($key,$value)
+    {
+        if(!is_array($value))
+            return false;
+        return $this->redis->hMset($key,$value);
+    }
+    /**
+     * 为hash表多个字段设定值。
+     * @param string $key
+     * @param array|string $value string以','号分隔字段
+     * @return array|bool
+     */
+    public function hMget($key,$field)
+    {
+        if(!is_array($field))
+            $field=explode(',', $field);
+        return $this->redis->hMget($key,$field);
+    }
+    /**
+     * 为hash表设这累加,可以负数
+     * @param string $key
+     * @param int $field
+     * @param string $value
+     * @return bool
+     */
+    public function hIncrBy($key,$field,$value)
+    {
+        $value=intval($value);
+        return $this->redis->hIncrBy($key,$field,$value);
+    }
+    /**
+     * 返回所有hash表的所有字段
+     * @param string $key
+     * @return array|bool
+     */
+    public function hKeys($key)
+    {
+        return $this->redis->hKeys($key);
+    }
+    /**
+     * 返回所有hash表的字段值,为一个索引数组
+     * @param string $key
+     * @return array|bool
+     */
+    public function hVals($key)
+    {
+        return $this->redis->hVals($key);
+    }
+    /**
+     * 返回所有hash表的字段值,为一个关联数组
+     * @param string $key
+     * @return array|bool
+     */
+    public function hGetAll($key)
+    {
+        return $this->redis->hGetAll($key);
+    }
+    /*********************有序集合操作*********************/
+    /**
+     * 给当前集合添加一个元素
+     * 如果value已经存在,会更新order的值。
+     * @param string $key
+     * @param string $order 序号
+     * @param string $value 值
+     * @return bool
+     */
+    public function zAdd($key,$order,$value)
+    {
+        return $this->redis->zAdd($key,$order,$value);
+    }
+    /**
+     * 给$value成员的order值,增加$num,可以为负数
+     * @param string $key
+     * @param string $num 序号
+     * @param string $value 值
+     * @return 返回新的order
+     */
+    public function zinCry($key,$num,$value)
+    {
+        return $this->redis->zinCry($key,$num,$value);
+    }
+    /**
+     * 删除值为value的元素
+     * @param string $key
+     * @param stirng $value
+     * @return bool
+     */
+    public function zRem($key,$value)
+    {
+        return $this->redis->zRem($key,$value);
+    }
+    /**
+     * 集合以order递增排列后,0表示第一个元素,-1表示最后一个元素
+     * @param string $key
+     * @param int $start
+     * @param int $end
+     * @return array|bool
+     */
+    public function zRange($key,$start,$end)
+    {
+        return $this->redis->zRange($key,$start,$end);
+    }
+    /**
+     * 集合以order递减排列后,0表示第一个元素,-1表示最后一个元素
+     * @param string $key
+     * @param int $start
+     * @param int $end
+     * @return array|bool
+     */
+    public function zRevRange($key,$start,$end)
+    {
+        return $this->redis->zRevRange($key,$start,$end);
+    }
+    /**
+     * 集合以order递增排列后,返回指定order之间的元素。
+     * min和max可以是-inf和+inf 表示最大值,最小值
+     * @param string $key
+     * @param int $start
+     * @param int $end
+     * @package array $option 参数
+     *   withscores=>true,表示数组下标为Order值,默认返回索引数组
+     *   limit=>array(0,1) 表示从0开始,取一条记录。
+     * @return array|bool
+     */
+    public function zRangeByScore($key,$start='-inf',$end="+inf",$option=array())
+    {
+        return $this->redis->zRangeByScore($key,$start,$end,$option);
+    }
+    /**
+     * 集合以order递减排列后,返回指定order之间的元素。
+     * min和max可以是-inf和+inf 表示最大值,最小值
+     * @param string $key
+     * @param int $start
+     * @param int $end
+     * @package array $option 参数
+     *   withscores=>true,表示数组下标为Order值,默认返回索引数组
+     *   limit=>array(0,1) 表示从0开始,取一条记录。
+     * @return array|bool
+     */
+    public function zRevRangeByScore($key,$start='-inf',$end="+inf",$option=array())
+    {
+        return $this->redis->zRevRangeByScore($key,$start,$end,$option);
+    }
+    /**
+     * 返回order值在start end之间的数量
+     * @param unknown $key
+     * @param unknown $start
+     * @param unknown $end
+     */
+    public function zCount($key,$start,$end)
+    {
+        return $this->redis->zCount($key,$start,$end);
+    }
+    /**
+     * 返回值为value的order值
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function zScore($key,$value)
+    {
+        return $this->redis->zScore($key,$value);
+    }
+    /**
+     * 返回集合以score递增加排序后,指定成员的排序号,从0开始。
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function zRank($key,$value)
+    {
+        return $this->redis->zRank($key,$value);
+    }
+    /**
+     * 返回集合以score递增加排序后,指定成员的排序号,从0开始。
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function zRevRank($key,$value)
+    {
+        return $this->redis->zRevRank($key,$value);
+    }
+    /**
+     * 删除集合中,score值在start end之间的元素 包括start end
+     * min和max可以是-inf和+inf 表示最大值,最小值
+     * @param unknown $key
+     * @param unknown $start
+     * @param unknown $end
+     * @return 删除成员的数量。
+     */
+    public function zRemRangeByScore($key,$start,$end)
+    {
+        return $this->redis->zRemRangeByScore($key,$start,$end);
+    }
+    /**
+     * 返回集合元素个数。
+     * @param unknown $key
+     */
+    public function zCard($key)
+    {
+        return $this->redis->zCard($key);
+    }
+    /*********************队列操作命令************************/
+    /**
+     * 在队列尾部插入一个元素
+     * @param unknown $key
+     * @param unknown $value
+     * 返回队列长度
+     */
+    public function rPush($key,$value)
+    {
+        return $this->redis->rPush($key,$value);
+    }
+    /**
+     * 在队列尾部插入一个元素 如果key不存在,什么也不做
+     * @param unknown $key
+     * @param unknown $value
+     * 返回队列长度
+     */
+    public function rPushx($key,$value)
+    {
+        return $this->redis->rPushx($key,$value);
+    }
+    /**
+     * 在队列头部插入一个元素
+     * @param unknown $key
+     * @param unknown $value
+     * 返回队列长度
+     */
+    public function lPush($key,$value)
+    {
+        return $this->redis->lPush($key,$value);
+    }
+    /**
+     * 在队列头插入一个元素 如果key不存在,什么也不做
+     * @param unknown $key
+     * @param unknown $value
+     * 返回队列长度
+     */
+    public function lPushx($key,$value)
+    {
+        return $this->redis->lPushx($key,$value);
+    }
+    /**
+     * 返回队列长度
+     * @param unknown $key
+     */
+    public function lLen($key)
+    {
+        return $this->redis->lLen($key);
+    }
+    /**
+     * 返回队列指定区间的元素
+     * @param unknown $key
+     * @param unknown $start
+     * @param unknown $end
+     */
+    public function lRange($key,$start,$end)
+    {
+        return $this->redis->lrange($key,$start,$end);
+    }
+    /**
+     * 返回队列中指定索引的元素
+     * @param unknown $key
+     * @param unknown $index
+     */
+    public function lIndex($key,$index)
+    {
+        return $this->redis->lIndex($key,$index);
+    }
+    /**
+     * 设定队列中指定index的值。
+     * @param unknown $key
+     * @param unknown $index
+     * @param unknown $value
+     */
+    public function lSet($key,$index,$value)
+    {
+        return $this->redis->lSet($key,$index,$value);
+    }
+    /**
+     * 删除值为vaule的count个元素
+     * PHP-REDIS扩展的数据顺序与命令的顺序不太一样,不知道是不是bug
+     * count>0 从尾部开始
+     * >0 从头部开始
+     * =0 删除全部
+     * @param unknown $key
+     * @param unknown $count
+     * @param unknown $value
+     */
+    public function lRem($key,$count,$value)
+    {
+        return $this->redis->lRem($key,$value,$count);
+    }
+    /**
+     * 删除并返回队列中的头元素。
+     * @param unknown $key
+     */
+    public function lPop($key)
+    {
+        return $this->redis->lPop($key);
+    }
+    /**
+     * 删除并返回队列中的尾元素
+     * @param unknown $key
+     */
+    public function rPop($key)
+    {
+        return $this->redis->rPop($key);
+    }
+    /*************redis字符串操作命令*****************/
+    /**
+     * 设置一个key
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function set($key,$value)
+    {
+        return $this->redis->set($key,$value);
+    }
+    /**
+     * 得到一个key
+     * @param unknown $key
+     */
+    public function get($key)
+    {
+        return $this->redis->get($key);
+    }
+    /**
+     * 设置一个有过期时间的key
+     * @param unknown $key
+     * @param unknown $expire
+     * @param unknown $value
+     */
+    public function setex($key,$expire,$value)
+    {
+        return $this->redis->setex($key,$expire,$value);
+    }
+    /**
+     * 设置一个key,如果key存在,不做任何操作.
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function setnx($key,$value)
+    {
+        return $this->redis->setnx($key,$value);
+    }
+    /**
+     * 批量设置key
+     * @param unknown $arr
+     */
+    public function mset($arr)
+    {
+        return $this->redis->mset($arr);
+    }
+    /*************redis 无序集合操作命令*****************/
+    /**
+     * 返回集合中所有元素
+     * @param unknown $key
+     */
+    public function sMembers($key)
+    {
+        return $this->redis->sMembers($key);
+    }
+    /**
+     * 求2个集合的差集
+     * @param unknown $key1
+     * @param unknown $key2
+     */
+    public function sDiff($key1,$key2)
+    {
+        return $this->redis->sDiff($key1,$key2);
+    }
+    /**
+     * 添加集合。由于版本问题,扩展不支持批量添加。这里做了封装
+     * @param unknown $key
+     * @param string|array $value
+     */
+    public function sAdd($key,$value)
+    {
+        if(!is_array($value))
+            $arr=array($value);
+        else
+            $arr=$value;
+        foreach($arr as $row)
+            $this->redis->sAdd($key,$row);
+    }
+    /**
+     * 返回无序集合的元素个数
+     * @param unknown $key
+     */
+    public function scard($key)
+    {
+        return $this->redis->scard($key);
+    }
+    /**
+     * 从集合中删除一个元素
+     * @param unknown $key
+     * @param unknown $value
+     */
+    public function srem($key,$value)
+    {
+        return $this->redis->srem($key,$value);
+    }
+    /*************redis管理操作命令*****************/
+    /**
+     * 选择数据库
+     * @param int $dbId 数据库ID号
+     * @return bool
+     */
+    public function select($dbId)
+    {
+        $this->dbId=$dbId;
+        return $this->redis->select($dbId);
+    }
+    /**
+     * 清空当前数据库
+     * @return bool
+     */
+    public function flushDB()
+    {
+        return $this->redis->flushDB();
+    }
+    /**
+     * 返回当前库状态
+     * @return array
+     */
+    public function info()
+    {
+        return $this->redis->info();
+    }
+    /**
+     * 同步保存数据到磁盘
+     */
+    public function save()
+    {
+        return $this->redis->save();
+    }
+    /**
+     * 异步保存数据到磁盘
+     */
+    public function bgSave()
+    {
+        return $this->redis->bgSave();
+    }
+    /**
+     * 返回最后保存到磁盘的时间
+     */
+    public function lastSave()
+    {
+        return $this->redis->lastSave();
+    }
+    /**
+     * 返回key,支持*多个字符,?一个字符
+     * 只有* 表示全部
+     * @param string $key
+     * @return array
+     */
+    public function keys($key)
+    {
+        return $this->redis->keys($key);
+    }
+    /**
+     * 删除指定key
+     * @param unknown $key
+     */
+    public function del($key)
+    {
+        return $this->redis->del($key);
+    }
+    /**
+     * 判断一个key值是不是存在
+     * @param unknown $key
+     */
+    public function exists($key)
+    {
+        return $this->redis->exists($key);
+    }
+    /**
+     * 为一个key设定过期时间 单位为秒
+     * @param unknown $key
+     * @param unknown $expire
+     */
+    public function expire($key,$expire)
+    {
+        return $this->redis->expire($key,$expire);
+    }
+    /**
+     * 返回一个key还有多久过期,单位秒
+     * @param unknown $key
+     */
+    public function ttl($key)
+    {
+        return $this->redis->ttl($key);
+    }
+    /**
+     * 设定一个key什么时候过期,time为一个时间戳
+     * @param unknown $key
+     * @param unknown $time
+     */
+    public function exprieAt($key,$time)
+    {
+        return $this->redis->expireAt($key,$time);
+    }
+    /**
+     * 关闭服务器链接
+     */
+    public function close()
+    {
+        return $this->redis->close();
+    }
+    /**
+     * 关闭所有连接
+     */
+    public static function closeAll()
+    {
+        foreach(static::$_instance as $o)
+        {
+            if($o instanceof self)
+                $o->close();
+        }
+    }
+    /** 这里不关闭连接,因为session写入会在所有对象销毁之后。
+    public function __destruct()
+    {
+    return $this->redis->close();
+    }
+     **/
+    /**
+     * 返回当前数据库key数量
+     */
+    public function dbSize()
+    {
+        return $this->redis->dbSize();
+    }
+    /**
+     * 返回一个随机key
+     */
+    public function randomKey()
+    {
+        return $this->redis->randomKey();
+    }
+    /**
+     * 得到当前数据库ID
+     * @return int
+     */
+    public function getDbId()
+    {
+        return $this->dbId;
+    }
+    /**
+     * 返回当前密码
+     */
+    public function getAuth()
+    {
+        return $this->auth;
+    }
+    public function getHost()
+    {
+        return $this->host;
+    }
+    public function getPort()
+    {
+        return $this->port;
+    }
+    public function getConnInfo()
+    {
+        return array(
+            'host'=>$this->host,
+            'port'=>$this->port,
+            'auth'=>$this->auth
+        );
+    }
+    /*********************事务的相关方法************************/
+    /**
+     * 监控key,就是一个或多个key添加一个乐观锁
+     * 在此期间如果key的值如果发生的改变,刚不能为key设定值
+     * 可以重新取得Key的值。
+     * @param unknown $key
+     */
+    public function watch($key)
+    {
+        return $this->redis->watch($key);
+    }
+    /**
+     * 取消当前链接对所有key的watch
+     * EXEC 命令或 DISCARD 命令先被执行了的话,那么就不需要再执行 UNWATCH 了
+     */
+    public function unwatch()
+    {
+        return $this->redis->unwatch();
+    }
+    /**
+     * 开启一个事务
+     * 事务的调用有两种模式Redis::MULTI和Redis::PIPELINE,
+     * 默认是Redis::MULTI模式,
+     * Redis::PIPELINE管道模式速度更快,但没有任何保证原子性有可能造成数据的丢失
+     */
+    public function multi($type=\Redis::MULTI)
+    {
+        return $this->redis->multi($type);
+    }
+    /**
+     * 执行一个事务
+     * 收到 EXEC 命令后进入事务执行,事务中任意命令执行失败,其余的命令依然被执行
+     */
+    public function exec()
+    {
+        return $this->redis->exec();
+    }
+    /**
+     * 回滚一个事务
+     */
+    public function discard()
+    {
+        return $this->redis->discard();
+    }
+    /**
+     * 测试当前链接是不是已经失效
+     * 没有失效返回+PONG
+     * 失效返回false
+     */
+    public function ping()
+    {
+        return $this->redis->ping();
+    }
+    public function auth($auth)
+    {
+        return $this->redis->auth($auth);
+    }
+    /*********************自定义的方法,用于简化操作************************/
+    /**
+     * 得到一组的ID号
+     * @param unknown $prefix
+     * @param unknown $ids
+     */
+    public function hashAll($prefix,$ids)
+    {
+        if($ids==false)
+            return false;
+        if(is_string($ids))
+            $ids=explode(',', $ids);
+        $arr=array();
+        foreach($ids as $id)
+        {
+            $key=$prefix.'.'.$id;
+            $res=$this->hGetAll($key);
+            if($res!=false)
+                $arr[]=$res;
+        }
+        return $arr;
+    }
+    /**
+     * 生成一条消息,放在redis数据库中。使用0号库。
+     * @param string|array $msg
+     */
+    public function pushMessage($lkey,$msg)
+    {
+        if(is_array($msg)){
+            $msg  =  json_encode($msg);
+        }
+        $key  =  md5($msg);
+        //如果消息已经存在,删除旧消息,已当前消息为准
+        //echo $n=$this->lRem($lkey, 0, $key)."\n";
+        //重新设置新消息
+        $this->lPush($lkey, $key);
+        $this->setex($key, 3600, $msg);
+        return $key;
+    }
+    /**
+     * 得到条批量删除key的命令
+     * @param unknown $keys
+     * @param unknown $dbId
+     */
+    public function delKeys($keys,$dbId)
+    {
+        $redisInfo=$this->getConnInfo();
+        $cmdArr=array(
+            'redis-cli',
+            '-a',
+            $redisInfo['auth'],
+            '-h',
+            $redisInfo['host'],
+            '-p',
+            $redisInfo['port'],
+            '-n',
+            $dbId,
+        );
+        $redisStr=implode(' ', $cmdArr);
+        $cmd="{$redisStr} KEYS \"{$keys}\" | xargs {$redisStr} del";
+        return $cmd;
+    }
+}

+ 90 - 42
application/api/controller/Area.php

@@ -14,59 +14,107 @@
 // +----------------------------------------------------------------------
 
 namespace app\api\controller;
-
-use app\common\controller\Api;
-use library\File;
+use app\common\model\ChinaArea;
 use think\Db;
-
 /**
- * @title 省市区
+ * @title 地址库
  * @controller Area
- * @group member
+ * @group common
  */
 class Area extends Base
 {
+
     /**
-     * @title 获取省市区
-     * @desc 获取省市区
-     * @author QGF
-     * @url /api/Area/get_all_area
+     * @title 获取地址库数据
+     * @desc 获取地址库数据
+     * @author qc
      * @method GET
-     * @tag 省市区
+     * @url /api/area/getAreaTree
+     * @header name:Authorization require:1 desc:Token
+     * @param name:level type:int require:0 default:3 desc:查询等级(0全部,1精确到省,2精确到市,3精确到县区,4精确到街道)
+     * @return name:name type:string default:-- desc:名称
+     * @return name:short_name type:string default:-- desc:简称
+     * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
+     * @return name:code type:int default:-- desc:编码
+     * @return name:lng type:string default:-- desc:经度
+     * @return name:lat type:string default:-- desc:纬度
+     * @return name:children type:array default:-- desc:下级(数据字段同上)
      */
-    public function get_all_area(){
-        $field=['id','pid','shortname','name'];
-        if($this->request->get('id')){
-            $list=Db::table('store_area')->where('pid',$this->request->get('id'))->field($field)->select();
+    public function getAreaTree()
+    {
+        $level = input('level',3);
+        if($level){
+            $all_area = ChinaArea::where('level','<=',$level)->select();
         }else{
-           $list=Db::table('store_area')->where('pid',0)->field($field)->select();
-           foreach ($list as $k=>&$v){
-               $v['children']=Db::table('store_area')->where('pid',$v['id'])->field($field)->select();
-               if(!empty($v['children'])){
-                   foreach ($v['children'] as $kk=>&$vv){
-                       $vv['children']=Db::table('store_area')->where('pid',$vv['id'])->field($field)->select();
-                   }
-               }
-           }
+            $all_area = ChinaArea::where('level','>',0)->order('level asc,sort desc,id asc')->select();
         }
-        $this->success('获取成功',$list);
+        $this->success('ok',['list'=>make_tree($all_area)]);
     }
-    public function get_area($province_id,$city_id,$county_id){
-        $province = '';
-        if(!empty($province_id)){
-            $quarters = Db::name('store_area')->field('name')->where('id',$province_id)->find();
-            $province = $quarters['name'];
-        }
-        $city = '';
-        if(!empty($city_id)){
-            $quarters = Db::name('store_area')->field('name')->where('id',$city_id)->find();
-            $city = $quarters['name'];
-        }
-        $county = '';
-        if(!empty($county_id)){
-            $quarters = Db::name('store_area')->field('name')->where('id',$county_id)->find();
-            $county = $quarters['name'];
-        }
-        return $province.$city.$county;
+
+    /**
+     * @title 获取地址库ID获取下一级
+     * @desc 获取地址库ID获取下一级
+     * @author qc
+     * @method GET
+     * @url /api/area/getAreaChildrenByID
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:0 default:0 desc:数据表地址记录id
+     * @return name:name type:string default:-- desc:名称
+     * @return name:short_name type:string default:-- desc:简称
+     * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
+     * @return name:code type:int default:-- desc:编码
+     * @return name:lng type:string default:-- desc:经度
+     * @return name:lat type:string default:-- desc:纬度
+     * @return name:children type:array default:-- desc:下级(数据字段同上)
+     */
+    public function getAreaChildrenByID()
+    {
+        $id = input('id');
+        $list = ChinaArea::where('pid',$id)->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取市级地址
+     * @desc 获取市级地址
+     * @author qc
+     * @method GET
+     * @url /api/area/getCityByName
+     * @header name:Authorization require:1 desc:Token
+     * @param name:name type:string require:0 default:0 desc:市名(或拼音)模糊查询(不传查全部)
+     * @return name:name type:string default:-- desc:名称
+     * @return name:short_name type:string default:-- desc:简称
+     */
+    public function getCityByName()
+    {
+        $where = [];
+        $where[] = ['level','=',2];
+        if(input('name'))   $where[] = ['name|pinyin','like','%'.input('name').'%'];
+        $all_city = ChinaArea::field('id,name,short_name,first')->where($where)->order('sort desc,id asc')->select();
+        $this->success('ok',['list'=>$all_city]);
     }
+
+
+    /**
+     * @title 首字母分组获取地级市
+     * @desc 首字母分组获取地级市
+     * @author qc
+     * @method GET
+     * @url /api/area/getAllCity
+     * @header name:Authorization require:1 desc:Token
+     * @return name:first type:string default:-- desc:首字母
+     * @return name:city_list type:array default:-- desc:城市列表
+     * @return name:city_list.name type:string default:-- desc:名称
+     * @return name:city_list.short_name type:string default:-- desc:简称
+     */
+    public function getAllCity()
+    {
+       $list =  ChinaArea::getAllCity();
+       $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+
 }

+ 1063 - 0
application/api/controller/Article.php

@@ -0,0 +1,1063 @@
+<?php
+namespace app\api\controller;
+use app\common\model\ArticleCate;
+use app\common\model\ArticleComment;
+use app\common\model\ArticleCommentLike;
+use app\common\model\ArticleIntro;
+use app\common\model\ArticleItem;
+use app\common\model\ArticleLike;
+use app\common\model\SeriesArticleCate;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserArticle;
+use app\common\model\UserLearn;
+use app\common\model\UserMessage;
+use app\common\model\UserSearch;
+use app\common\model\UserTag;
+use app\common\model\UserTrack;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 图文
+ * @controller Article
+ * @group base
+ */
+class Article extends Base
+{
+    // 需要登录的
+    protected $need_login = [
+        'articleTransmit',
+        'articleRead',
+        'articleTags',
+        'articleComment',
+        'articleCollect',
+        'userReferArticle',
+        'getMyArticleList',
+        'getUserArticleDetail',
+        'delUserArticle',
+        'delComment',
+        'getLearnHistory',
+        'getArticleCollect',
+        'getCommentArticle',
+        'getPurchaseArticle',
+        'getPurchaseArticle',
+        'getReplyArticle',
+        'getReplyComment',
+        'getTagsArticle',
+    ];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 图文接口说明
+     * @desc  图文接口说明
+     * @author  qc
+     * @url /api/Article/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:图片(images字段)多图片都用竖线(|)隔开,会员上传多张也用(|)隔开
+     * @return name:2 type:string default:-- desc:cover字段值是images的第一个路径【非多张】
+     * @return name:3 type:string default:-- desc:单一图文与系列图文区别,type值(1是单一,2是系列),数据:item_list二维数组数据数量不一样(单一的只有一个,系列的可以是多个)【可以将单一图文看做只有一条记录的系列图文!!!!】
+     * @return name:4 type:string default:-- desc:单一图文详情的字段(cover,images,is_vip,title)与item_list数组的第一个同字段名的值相同
+     * @return name:5 type:string default:-- desc:系列图文详情的字段(cover,images)与item_list的其中一个相同
+     * @return name:6 type:string default:-- desc:关于是否的字段(0否,1是)
+     * @return name:7 type:string default:-- desc:item_id是数组item_list下的id
+     */
+     public function classIntro(){}
+
+
+    /**
+     * @title 获取图文分类
+     * @desc  获取图文分类
+     * @author  qc
+     * @url /api/Article/getArticleCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:type type:int default:1 desc:类型1单个2系列
+     * @return name:id type:int default:-- desc:分类id
+     * @return name:logo type:string default:-- desc:图标
+     * @return name:title type:string default:0 desc:分类名称
+     * @return name:children type:array default:0 desc:下级分类
+     */
+    public function getArticleCate()
+    {
+        $type = input('type',1);
+        if($type == 1) {
+            $list = ArticleCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
+        }else{
+            $list = SeriesArticleCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
+        }
+        $list =  make_tree($list);
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 图文推荐
+     * @desc 图文推荐
+     * @author qc
+     * @method GET
+     * @url /api/Article/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:string default:-- desc:图文item_id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:系列id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images_arr type:string default:-- desc:图片
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台头像
+     */
+    public function getRecommendList()
+    {
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $search_log =  UserSearch::getSearchTitle($this->user_id,2);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = ' a.id,a.title,a.cover,a.images,a.user_id,a.is_vip,a.read_num,a.article_id ,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_article_item';
+        $order_by_two = 'a.read_num';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_article_intro as k ON k.id = a.article_id  WHERE a.is_deleted = 0 AND a.status =1 AND k.status = 1 AND k.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']):null;
+        });
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取图文列表(平台发布)
+     * @desc 获取图文列表
+     * @author qc
+     * @method GET
+     * @url /api/Article/getArticleList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:type type:int default:0 desc:类型1单个2系列
+     * @param  name:is_tj type:int default:0 desc:是否推荐0否1是
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:first_classify type:int default:0 desc:一级分类
+     * @param  name:second_classify type:int default:0 desc:二级分类
+     * @return name:id type:string default:-- desc:ID[请求/api/Article/getArticleDetail用]
+     * @return name:title type:string default:-- desc:标题
+     * @return name:type type:int default:0 desc:类型1单个2系列
+     * @return name:cover type:string default:-- desc:封面()
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:label type:string default:-- desc:标签
+     * @return name:item_list type:array default:-- desc:图文
+     * @return name:item_list.title type:string default:-- desc:图文标题
+     * @return name:item_list.is_vip type:int default:-- desc:是否是vip
+     * @return name:item_list.cover type:string default:-- desc:图文封面
+     * @return name:item_list.images type:string default:-- desc:图片(多张用|隔开)
+     * @return name:item_list.content type:string default:-- desc:内容
+     */
+    public function getArticleList()
+    {
+        $sel_where = [];
+        $title = input('get.title');
+        $type = input('get.type',0);
+        $is_tj = input('get.is_tj',0);
+        $sort_type = input('get.sort_type',1);
+        $first_classify = input('get.first_classify');
+        $second_classify = input('get.second_classify');
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $sel_where[] = ['item_num','>',0];
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        if($type)  $sel_where[]  = ['type','=',$type];
+        if($first_classify)  $sel_where[]  = ['first_classify','=',$first_classify];
+        if($second_classify)  $sel_where[]  = ['second_classify','=',$second_classify];
+
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+
+        if($title && $this->user_id)UserSearch::saveSearchTitle($this->user_id,$title,2);
+        $where_str = 'id > 0';
+        if($is_tj) {
+            $search_log =    UserSearch::getSearchTitle($this->user_id,2);
+            $search_arr = [];
+            foreach ($search_log as $t){
+                $search_arr[] =  " title like '".'%'.$t."%'" .' ';
+            }
+            if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        }
+        $list = ArticleIntro::where($sel_where)->with('itemList')
+            ->limit($this->off_set,$this->page_num)
+            ->where($where_str)
+            ->order($order)
+            ->select()->toArray();
+        array_walk($list,function (&$v,$k){
+
+        });
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取图文详情(平台)
+     * @desc 获取图文详情
+     * @author qc
+     * @method GET
+     * @url /api/Article/getArticleDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:图文id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images type:string default:-- desc:图片
+     * @return name:is_vip type:string default:-- desc:是否VIP
+     * @return name:item_list type:array default:-- desc:图文
+     * @return name:item_list.id type:string default:-- desc:[请求/api/Article/getArticleItemInfo用,请求图文模块其他接口参数:item_id]
+     * @return name:item_list.title type:string default:-- desc:图文标题
+     * @return name:item_list.is_vip type:int default:-- desc:是否是vip
+     * @return name:item_list.cover type:string default:-- desc:封面
+     * @return name:item_list.images type:int default:-- desc:图片
+     * @return name:item_list.content type:int default:-- desc:内容
+     * @return name:item_list.transmit_num type:int default:-- desc:转发量
+     * @return name:item_list.read_num type:int default:-- desc:阅读量
+     * @return name:item_list.comment_num type:int default:-- desc:评论量
+     * @return name:item_list.collect_num type:int default:-- desc:收藏量
+     * @return name:item_list.is_collect type:int default:-- desc:是否收藏
+     * @return name:item_list.video_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:item_list.video_item type:int default:-- desc:关联视频详情id【video_arr.id】
+     * @return name:item_list.datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:item_list.datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     */
+    public function getArticleDetail()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = ArticleIntro::where($sel_where)->with('itemList')->find()->toArray();
+        if($detail['is_deleted'] == 1 || $detail['status'] == 0)$this->error('该图文已下线');
+        foreach ($detail['item_list'] as &$dv) {
+            $dv['comment_num']  = ArticleComment::where(['article_id'=>$detail['id'],'item_id'=>$dv['id']])->count();
+            $dv['collect_num']  = UserCollect::where(['coll_type'=>3,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
+            $dv['is_collect']  = UserCollect::checkCollectByType($this->user_id,3,$detail['id'],$dv['id']);
+        }
+        $detail['read_num']  = array_sum(array_column($detail['item_list'],'read_num'));
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 获取图文ITEM详情(平台)
+     * @desc 获取图文ITEM详情
+     * @author qc
+     * @method GET
+     * @url /api/Article/getArticleItemInfo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:item_id type:int default:0 desc:item_list
+     * @return name:title type:string default:-- desc:图文标题
+     * @return name:is_vip type:int default:-- desc:是否是vip
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images type:int default:-- desc:图片
+     * @return name:content type:int default:-- desc:内容
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:comment_num type:int default:-- desc:评论量
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:like_num type:int default:-- desc:点赞量
+     * @return name:is_like type:int default:-- desc:是否点赞
+     * @return name:video_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
+     * @return name:datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     */
+    public function getArticleItemInfo()
+    {
+        $item_id = input('get.item_id');
+        $detail = ArticleItem::where('id',$item_id)->find()->toArray();
+        $detail['comment_num']  = ArticleComment::where(['article_id'=>$detail['article_id'],'item_id'=>$detail['id']])->count();
+        $detail['collect_num']  = UserCollect::where(['coll_type'=>3,'coll_id'=>$detail['article_id'],'children_id'=>$detail['id']])->count();
+        $detail['is_collect']  = UserCollect::checkCollectByType($this->user_id,3,$detail['article_id'],$detail['id']);
+        $detail['is_like'] = ArticleLike::where(['user_id'=>$this->user_id,'article_id'=>$detail['article_id'],'item_id'=>$detail['id']])->count();
+        $detail['like_num'] = ArticleLike::where(['article_id'=>$detail['article_id'],'item_id'=>$detail['id']])->count();
+        UserTrack::crateTrack($this->user_id,3,$detail['article_id'],$item_id);
+        //var_dump($this->user_id,3,$detail['article_id'],$item_id);
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 获取图文评论列表
+     * @desc 获取图文评论列表
+     * @author qc
+     * @method GET
+     * @url /api/Article/getArticleCommentList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:article_id type:int default:-- desc:图文id
+     * @param name:item_id type:int default:-- desc:item_id
+     * @param name:sort_type type:int default:1 desc:排序1默认2时间升序3时间降序
+     * @param name:page type:int default:-- desc:页数
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
+     * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
+     * @return name:total_num type:int default:-- desc:总评论数(仅一级)
+     */
+    public function getArticleCommentList()
+    {
+        $where = [];
+        $where[] = ['c.article_id','=',input('get.article_id')];
+        $where[] = ['c.is_deleted','=',0];
+        $user_id = $this->user_id;
+        $sort_type= input('sort_type',1);
+        if(input('get.item_id')) $where[] = ['c.item_id','=',input('get.item_id')];
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+
+        $list  =ArticleComment::where($where)
+            ->alias('c')
+            ->field('c.*,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+
+        array_walk($list,function (&$val,$k)use($user_id){
+            $children = ArticleComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->order('c.id asc')
+                ->select()->toArray();
+            $val['children'] =  $children;
+            $val['like_num'] = ArticleCommentLike::where('like_id',$val['id'])->count();
+            $val['is_like'] =  ArticleCommentLike::where(['like_id'=>$val['id'],'user_id'=>$user_id])->count();
+            $parent  = ArticleComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->find();
+            $val['parent']  = $parent ? $parent->toArray() : null;
+            $val['can_delete']  = $val['user_id'] == $this->user_id ? 1 :0;
+        });
+        $total_num  = ArticleComment::where($where)->alias('c')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+    
+    
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc 转发成功后调用
+     * @author qc
+     * @method
+     * @url /api/Article/needLogin()
+     */
+    public function needLogin(){}
+
+
+    /**
+     * @title 图文转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Article/articleTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:item_id type:int default:-- desc:item_list的id
+     */
+    public function articleTransmit()
+    {
+        $item_id = input('post.item_id',0);
+        ArticleItem::where('id',$item_id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 图文阅读(阅读数量统计)
+     * @desc 图文阅读
+     * @author qc
+     * @method POST
+     * @url /api/Article/articleRead
+     * @header name:Authorization require:1 desc:Token
+     * @param name:item_id type:int default:-- desc:item_list的id
+     */
+    public function articleRead()
+    {
+        $item_id = input('post.item_id',0);
+        ArticleItem::where('id',$item_id)->setInc('read_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 图文点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Article/articleTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:article_id type:int default:1 desc:图文id
+     * @param name:item_id type:int default:1 desc:item_id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function articleTags()
+    {
+        $article_id = input('post.article_id');
+        $item_id = input('post.item_id');
+        $ret_val = 0;
+        $check_tags =  ArticleLike::where(['user_id'=>$this->user_id,'article_id'=>$article_id,'item_id'=>$item_id])->value('id');
+        if($check_tags) {
+            ArticleLike::where(['user_id'=>$this->user_id,'article_id'=>$article_id,'item_id'=>$item_id])->delete();
+        }else{
+            Data::save('ArticleLike',
+                ['user_id'=>$this->user_id,'article_id'=>$article_id,'item_id'=>$item_id],'user_id',
+                ['user_id'=>$this->user_id,'article_id'=>$article_id,'item_id'=>$item_id]);
+            $ret_val = 1;
+        }
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+    /**
+     * @title 图文评论
+     * @desc 图文评论
+     * @author qc
+     * @method POST
+     * @url /api/Article/articleComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:article_id type:int default:1 desc:图文id
+     * @param name:item_id type:int default:1 desc:item_id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function articleComment()
+    {
+        $article_id = input('post.article_id');
+        $item_id = input('post.item_id');
+        $content = input('post.content',0);
+        if(!$content) $this->error('请输入评论内容');
+        $res = ArticleComment::create(['user_id'=>$this->user_id,'content'=>$content,'article_id'=>$article_id,'item_id'=>$item_id]);
+        $detail  =ArticleComment::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $send_user = ArticleItem::where('id',$item_id)->value('user_id');
+        $user_info = $this->userInfo('name');
+        if($send_user) UserMessage:: sendUserMessage($send_user,'article',4,0,$this->user_id,$item_id,$user_info['name'].'评论了您的图文');
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 删除评论
+     * @desc 删除评论
+     * @author qc
+     * @method POST
+     * @url /api/Article/delComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     */
+    public function delComment(){
+        ArticleComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
+        $this->success('删除成功');
+    }
+    /**
+     * @title 图文二级评论
+     * @desc 图文二级评论
+     * @author qc
+     * @method POST
+     * @url /api/Article/secondCommend
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function secondCommend()
+    {
+        $comment = ArticleComment::where('id',input('post.id'))->find()->toArray();
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($comment['user_id'],'article',3,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
+        $send_user = ArticleItem::where('id',$comment['item_id'])->value('user_id');
+        if($send_user) UserMessage:: sendUserMessage($send_user,'article',4,0,$this->user_id,$comment['item_id'],$user_info['name'].'评论了您的图文');
+
+        unset($comment['id']);
+        unset($comment['create_at']);
+        $comment['pid'] = input('post.id');
+        $comment['user_id'] = $this->user_id;
+        $comment['content'] = input('post.content');
+        $comment['lev']++;
+        if(!$comment['source_id']) $comment['source_id'] = input('post.id');
+        $res = ArticleComment::create($comment);
+        $detail  = ArticleComment::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 评论点赞||取消点赞
+     * @desc 评论
+     * @author qc
+     * @method POST
+     * @url /api/Article/commentTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:comment_id type:int default:1 desc:评论记录id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function commentTags()
+    {
+        $comment_id = input('post.comment_id');
+        $ret_val = 0;
+        $check_tags =  ArticleCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->value('id');
+        if($check_tags) {
+            ArticleCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->delete();
+        }else{
+            Data::save('ArticleCommentLike',
+                ['user_id'=>$this->user_id,'like_id'=>$comment_id,],'user_id',
+                ['user_id'=>$this->user_id,'like_id'=>$comment_id]);
+            $ret_val = 1;
+        }
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+
+    /**
+     * @title 图文收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Article/articleCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:article_id type:int require:1 default:-- desc:记录id[图文id]
+     * @param name:item_id type:int default:1 desc:item_id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function articleCollect()
+    {
+        $coll_type  = input('post.coll_type',3);
+        $coll_id    = input('post.article_id',0);
+        $item_id    = input('post.item_id',0);
+        $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$item_id);
+        if($collect_check) {
+            UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$item_id])->delete();
+            $this->success('取消收藏成功',['status'=>0]);
+        }else{
+            Data::save('UserCollect', [
+                'user_id'=>$this->user_id,
+                'coll_type'=>$coll_type,
+                'coll_id'=>$coll_id,
+                'children_id'=>$item_id,
+                'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$item_id]);
+            $this->success('收藏成功',['status'=>1]);
+        }
+    }
+
+    
+
+
+
+
+
+    /**
+     * @title 用户提交或修改图文【个人】
+     * @desc 用户提交或修改图文【个人】
+     * @author qc
+     * @method POST
+     * @url /api/Article/userReferArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id(修改时必传)
+     * @param name:title type:string default:-- desc:标题
+     * @param name:images type:string default:-- desc:图片(多张用|隔开)
+     * @param name:desc type:string default:-- desc:简介
+     * @param name:label type:string default:-- desc:图文标签
+     * @param name:document type:string default:-- desc:文件路径【单文件】
+     */
+    public function userReferArticle()
+    {
+        $id = input('post.id',0);
+        $title = input('post.title');
+        $desc = input('post.desc');
+        $images = input('post.images');
+        $label = input('post.label');
+        $document = input('post.document');
+        //if(!$images) $this->error('请上传图文');
+        if($id){
+            $check_status = UserArticle::where('id',$id)->value('status');
+            if($check_status == 1) $this->error('已审核通过,不允许修改');
+        }
+        $data = [
+            'title' => $title,
+            'user_id' => $this->user_id,
+            'desc' => $desc,
+            'images' => $images,
+            'label' => $label,
+            'document' => $document,
+            'cover' => $images ? explode('|',$images)[0] : '',
+            'status' => 0,
+            'remark' => '',
+        ];
+        if($id) $data['id'] =  $id;
+        if($id){
+            UserArticle::where('id',$id)->update($data);
+        }else{
+            $res= UserArticle::create($data) ;
+        }
+        UserMessage::sendUserMessage($this->user_id,'article',1,0,0,$id ? $id:$res->id);
+        $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
+    }
+
+    /**
+     * @title 获取我的图文列表【个人--我的发布列表】
+     * @desc 获取我的图文列表【个人】
+     * @author qc
+     * @method GET
+     * @url /api/Article/getMyArticleList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:desc type:string default:-- desc:简介
+     * @return name:images type:string default:-- desc:图文【多张|隔开】
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     */
+    public function getMyArticleList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['user_id','=',$this->user_id];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        $list = UserArticle::where($sel_where)
+            ->field('id,title,desc,images,status,remark')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取我的图文详情【个人】
+     * @desc 获取我的图文列表【个人】
+     * @author qc
+     * @method GET
+     * @url /api/Article/getUserArticleDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:string default:-- desc:记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:desc type:string default:-- desc:简介
+     * @return name:images type:string default:-- desc:图文[多张|隔开]
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     * @return name:label type:string default:-- desc:标签
+     * @return name:document type:string default:-- desc:文件路径
+     */
+    public function getUserArticleDetail()
+    {
+        $detail =UserArticle::where('id',input('get.id'))->field('id,title,desc,images,status,remark,label,document')->find();
+        if(!$detail) $this->error('图文有误');
+        $this->success('ok',['detail'=>$detail->toArray()]);
+    }
+
+    /**
+     * @title 用户删除图文记录【个人】
+     * @desc 用户删除图文记录【个人】
+     * @author qc
+     * @method POST
+     * @url /api/Article/delUserArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id
+     */
+    public function delUserArticle()
+    {
+        UserArticle::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
+        $this->success('删除成功');
+    }
+
+
+    /**
+     * @title 以下接口学习服务模块的
+     * @desc
+     * @author qc
+     * @method
+     * @url /api/Article/learn()
+     */
+    public function learn(){}
+
+    /**
+     * @title 图文学习历史
+     * @desc 图文学习历史
+     * @author qc
+     * @method GET
+     * @url /api/Article/getLearnHistory
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:time type:string default:-- desc:时间
+     */
+    public function getLearnHistory()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',3];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id article_id,t.second_id item_id,i.title,i.cover')
+            ->leftJoin('ArticleItem i','t.second_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 图文收藏记录
+     * @desc 图文收藏记录
+     * @author qc
+     * @method GET
+     * @url /api/Article/getArticleCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getArticleCollect()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',3];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id article_id,t.children_id item_id,i.title,i.cover')
+            ->leftJoin('ArticleItem i','t.children_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的评论【学习服务--我评论过的图文】
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Article/getCommentArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     */
+    public function getCommentArticle()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','=',1];
+        $list = ArticleComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.article_id,t.item_id,t.lev,t.content,i.title,i.cover')
+            ->leftJoin('ArticleItem i','t.item_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v)
+        {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+        }
+        $this->success('ok',['list'=>$list]);
+
+    }
+
+    /**
+     * @title 评论我的【学习服务--评论我的】
+     * @desc 评论我的
+     * @author qc
+     * @method GET
+     * @url /api/Article/commentMyArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名
+     * @return name:headimg type:string default:-- desc:用户头像
+     */
+    public function commentMyArticle()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['i.user_id','=',$this->user_id];
+        $list = ArticleComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.article_id,t.item_id,t.lev,t.content,i.title,i.cover,u.name user_name,u.headimg')
+            ->leftJoin('ArticleItem i','t.item_id = i.id')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 已购图文列表
+     * @desc 已购图文列表
+     * @author qc
+     * @method GET
+     * @url /api/Article/getPurchaseArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getPurchaseArticle()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',3];
+        $sel_where[]  = ['t.end_int','>',time()];
+        $list = UserLearn::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id article_id,t.second_id item_id,i.title,i.cover')
+            ->leftJoin('ArticleItem i','t.second_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的回复【我的回复--我回复过的评论】
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Article/getReplyArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:图文标题
+     * @return name:parent_comment.article_id type:string default:-- desc:文章id
+     * @return name:parent_comment.item_id type:string default:-- desc:item_id
+     */
+    public function getReplyArticle()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','=',2];
+        $list = ArticleComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.lev,t.content,i.title,t.pid')
+            ->leftJoin('ArticleItem i','t.item_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+            $parent_comment = ArticleComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.article_id,t.item_id,t.content,i.title,i.cover,t.pid,u.name')
+                ->alias('t')
+                ->leftJoin('ArticleItem i','t.item_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 回复我的【回复我的--回复过我的评论】
+     * @desc 回复我的
+     * @author qc
+     * @method GET
+     * @url /api/Article/getReplyComment
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【其他会员】
+     * @return name:headimg type:string default:-- desc:用户头【其他会员】
+     * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:图文标题
+     * @return name:parent_comment.article_id type:string default:-- desc:文章id
+     * @return name:parent_comment.item_id type:string default:-- desc:item_id
+     */
+    public function getReplyComment()
+    {
+        $all_comment = ArticleComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
+        if(empty($all_comment)) $this->success('ok',['list'=>null]);
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','=',2];
+        $sel_where[]  = ['t.user_id','<>',$this->user_id];
+        $sel_where[]  = ['t.pid','in',implode(',',$all_comment)];
+        $list = ArticleComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.lev,t.content,t.pid,u.name user_name,u.headimg')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->leftJoin('ArticleItem i','t.item_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $parent_comment = ArticleComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.article_id,t.item_id,t.content,i.title,i.cover,t.pid,u.name')
+                ->alias('t')
+                ->leftJoin('ArticleItem i','t.item_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 图文点赞列表【我的点赞】
+     * @desc 图文点赞列表
+     * @author qc
+     * @method GET
+     * @url /api/Article/getTagsArticle
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:article_id type:string default:-- desc:文章id
+     * @return name:item_id type:string default:-- desc:item_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:images_arr type:array default:-- desc:图片
+     */
+    public function getTagsArticle()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $list = ArticleLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.article_id,t.item_id,i.title,i.cover,i.is_vip,images,i.read_num')
+            ->leftJoin('ArticleItem i','t.item_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']):null;
+        }
+
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+}

+ 110 - 35
application/api/controller/Base.php

@@ -14,8 +14,6 @@
 // +----------------------------------------------------------------------
 
 namespace app\api\controller;
-
-use app\common\controller\Api;
 use Firebase\JWT\JWT;
 use think\Controller;
 use think\Db;
@@ -23,6 +21,7 @@ use think\Exception;
 use think\exception\HttpResponseException;
 use think\Request;
 use think\Response;
+use function AlibabaCloud\Client\value;
 
 /**
  * 会员管理基类
@@ -31,41 +30,101 @@ use think\Response;
  */
 class Base extends Controller
 {
-    protected $uid;
-    public function initialize()
-    {
+    protected $user_id;
+    protected $page; // 页数
+    protected $page_num;// 每页多少
+    protected $off_set;
+    protected $is_commit = true; // 事务是否提交
+    protected $ret_msg = ''; // 返回提示信息
+    protected $is_test = false;
+    protected $need_login = [];
+    public function initialize(){
+        $this->page = input('page',1);
+        $this->page_num = input('page_num',20);
+        $this->off_set   =   $this->page * $this->page_num - $this->page_num;
+        $this->is_test = input('test',0);// 测试用的
+        $path = explode('/',$this->request->path());
+        if( input('user_id')) $this->user_id = input('user_id');
+        if(!empty($this->need_login) && in_array(end($path),$this->need_login)) $this->checkLogin();
     }
     //校验jwt权限API
-    protected function check_login()
+    protected function checkLogin()
     {
         $authorization = app()->request->header('Authorization');
-        //var_dump($authorization.'111');exit();
         if(empty($authorization) || $authorization == null){
-            $this->error('Token不存在,拒绝访问','',0);
+            if($this->is_test == 1) {
+                $this->user_id = input('user_id')  ? input('user_id') : 22;
+                return true;
+            }
+            $this->error('Token不存在,拒绝访问--','',0,-1);
         }
         $key = md5(config('app.jwt'));
         try {
-            $jwtAuth = json_encode(JWT::decode($authorization, $key, array('HS256')));
-            $authInfo = json_decode($jwtAuth, true);
+            $check_authorization = JWT::decode($authorization, $key, array('HS256'));
+            if($check_authorization['code'] !=200) $this->exception($check_authorization['msg']);
+            $authInfo = json_decode(json_encode($check_authorization['data']), true);
             if (!empty($authInfo['uid'])) {
-                $member = Db::name('store_member')->field('status')->where('id',$authInfo['uid'])->find();
+                $member = Db::name('store_member')->where('id',$authInfo['uid'])->find();
+                if(empty($member) || $member['is_deleted'])  $this->error('会员不存在','',0);
+                //if(!empty($authInfo['facility_code']) && !in_array($authInfo['facility_code'],[$member['facility_1'],$member['facility_2'],$member['facility_3'],$member['facility_4'],$member['facility_5']]))    $this->error('该设备已被禁用','',0,-1);
                 if($member['status']){
-                    $this->uid = $authInfo['uid'];
-                    return $this->uid;
+                    $this->user_id = $authInfo['uid'];
+                    return $this->user_id;
                 }else{
-                    $this->error('该会员已被禁用','',0);
+                    $this->error('该会员已被禁用','',0,-1);
                 }
             } else {
-                $this->error('Token验证不通过,用户不存在','',0);
+                $this->error('Token验证不通过,用户不存在','',0,-1);
             }
-        } catch (\Firebase\JWT\SignatureInvalidException $e) {
-            $this->error('Token无效','',0);
-        } catch (\Firebase\JWT\ExpiredException $e) {
-            $this->error('Token过期','',0);
-        } catch (Exception $e) {
-            return $e;
+        } catch (\Exception $e) {
+            $this->error($e->getMessage(),'',0,-1);
         }
     }
+
+
+    protected function setUid(){
+        $authorization = app()->request->header('Authorization');
+        $key = md5(config('app.jwt'));
+        if(empty($authorization) || $authorization == null) return false;
+        try {
+            $check_authorization = JWT::decode($authorization, $key, array('HS256'));
+            if($check_authorization['code'] !=200) $this->exception($check_authorization['msg']);
+            $authInfo = json_decode(json_encode($check_authorization['data']), true);
+            if (!empty($authInfo['uid'])) {
+                $member = Db::name('store_member')->field('status')->where('id',$authInfo['uid'])->find();
+                if($member['status']){
+                    $this->user_id = $authInfo['uid'];
+                    $this->user_id;
+                    return  true;
+                }
+            }
+        } catch (\Exception $e) {
+            return false;
+            //$this->error($e->getMessage(),'',0,-1);
+        }
+    }
+
+    // 获取用户信息
+    function userInfo($field =''){
+        if(!$this->user_id)  return [];
+        return $field ?  Db::name('store_member')->field($field)->find($this->user_id) : Db::name('store_member')->find($this->user_id);
+    }
+
+    // 验证短信验证码
+    protected function checkPhoneCode($phone,$code){
+        //return true;
+        $sel_time =date('Y-m-d H:i:s',time()-600);
+        $store_member_sms = Db::name('store_member_sms')
+            ->field('id,code')->where('phone',$phone)
+            ->where('create_at','> time',$sel_time)
+            ->where('used',0)->order('id desc')->find();
+        return !empty($store_member_sms) && $store_member_sms['code'] == $code ? $store_member_sms['id'] :0;
+    }
+
+    // 更新验证码状态
+    protected function updatePhoneCode($code_id){
+        Db::name('store_member_sms')->where('id',$code_id)->update(['used'=>1]);
+    }
     /**
      * 操作成功返回的数据
      * @param string $msg   提示信息
@@ -74,7 +133,7 @@ class Base extends Controller
      * @param string $type  输出类型
      * @param array $header 发送的 Header 信息
      */
-    protected function success($msg = '', $data = null , $is_login = 1, $code = 1, $type = null, array $header = [])
+    protected function success($msg = 'ok', $data = null , $is_login = 1, $code = 1, $type = null, array $header = [])
     {
         $this->results($msg, $data, $is_login, $code, $type, $header);
     }
@@ -89,7 +148,7 @@ class Base extends Controller
      */
     protected function error($msg = '', $data = null, $is_login = 1, $code = 0, $type = null, array $header = [])
     {
-        if(empty($this->uid)){
+        if(empty($this->user_id)){
             $is_login = 0;
         }
         $this->results($msg, $data, $is_login, $code, $type, $header);
@@ -130,18 +189,34 @@ class Base extends Controller
         $response = Response::create($result, $type, $code)->header($header);
         throw new HttpResponseException($response);
     }
-    protected function get_uid(){
-        $uid = 0;
-        $authorization = app()->request->header('Authorization');
-        if(!empty($authorization)){
-            $key = md5(config('app.jwt'));
-            $jwtAuth = json_encode(JWT::decode($authorization, $key, array('HS256')));
-            $authInfo = json_decode($jwtAuth, true);
-            if (!empty($authInfo['uid'])) {
-                $uid = $authInfo['uid'];
-            }
-        }
-        return $uid;
+
+
+    //token加密
+    public function createJwt($uid,$facility_code='')
+    {
+        $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到
+        $time = time(); //签发时间
+        $expire = $time + config('app.jwt_time'); //过期时间
+        $token = array(
+            "uid" => $uid,
+            "iss" => "https://zain.com",//签发组织
+            "aud" => "https://zain.com", //签发作者
+            "iat" => $time,
+            "nbf" => $time,
+            "exp" => $expire,
+            "facility_code" => $facility_code,
+        );
+        $jwt = JWT::encode($token, $key);
+        return $jwt;
+    }
+
+    protected function exception($msg){
+        throw new Exception($msg);
+    }
+
+    // 事务返回
+    protected function transReturn($data = []){
+        $this->is_commit ? $this->success($this->ret_msg,$data):$this->error($this->ret_msg);
     }
 
 

+ 38 - 0
application/api/controller/Bucket.php

@@ -0,0 +1,38 @@
+<?php
+namespace app\api\controller;
+use OSS\OssClient;
+use OSS\Core\OssException;
+if (is_file(__DIR__ . '/../autoload.php')) {
+    require_once __DIR__ . '/../autoload.php';
+}
+if (is_file(__DIR__ . '/../vendor/autoload.php')) {
+    require_once __DIR__ . '/../vendor/autoload.php';
+}
+class Bucket extends Base{
+
+    public function index()
+    {
+        // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
+        $accessKeyId = "LTAI5t9YDETAQARbpp2bqktU";
+        $accessKeySecret = "bu05KyY0tkvF3wsw5UGxFD4unT7yz6";
+        // Endpoint以杭州为例,其它Region请按实际情况填写。
+        $endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
+        // 填写存储空间名称。
+        $bucket= "gaoyixia";
+        // 设置存储空间的读写权限为私有。
+        $acl = OssClient::OSS_ACL_TYPE_PRIVATE;
+        try {
+            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
+            $ossClient->putBucketAcl($bucket, $acl);
+        } catch (OssException $e) {
+            printf(__FUNCTION__ . ": FAILED\n");
+            printf($e->getMessage() . "\n");
+            return;
+        }
+        print(__FUNCTION__ . ": OK" . "\n");
+    }
+
+}
+
+
+

+ 140 - 0
application/api/controller/Collect.php

@@ -0,0 +1,140 @@
+<?php
+namespace app\api\controller;
+use app\common\model\UserCollect;
+use app\common\model\VideoUrl;
+use think\Db;
+use library\tools\Data;
+
+/**
+ * @title 收藏
+ * @controller Collect
+ * @group base
+ */
+class Collect extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+
+    /**
+     * @title 用户视频收藏(单个收藏)
+     * @desc 用户视频收藏(单个收藏)
+     * @author qc
+     * @method POST
+     * @url /api/Collect/userCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:coll_type type:int require:1 default:-- desc:类型(1平台视频2用户视频)
+     * @param name:coll_id type:int require:1 default:-- desc:收藏id(平台视频点赞用video_arr的iD)
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function userCollect()
+    {
+        $coll_type  = input('post.coll_type',1);
+        $url_id    = input('post.coll_id',0);
+        $video_id = VideoUrl::where('id',$url_id)->value('video_id');
+        $collect_check = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->find();
+        if($collect_check) {
+            UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->delete();
+            $this->success('取消收藏成功',['status'=>0]);
+        }else{
+            Data::save('UserCollect', [
+                'user_id'=>$this->user_id,
+                'coll_type'=>$coll_type,
+                'coll_id'=>$video_id,
+                'children_id'=>$url_id,
+                'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$video_id,'children_id'=>$url_id]);
+            $this->success('收藏成功',['status'=>1]);
+        }
+    }
+
+
+    /**
+     * @title 获取用户收藏列表
+     * @desc 获取用户收藏列表
+     * @author qc
+     * @method GET
+     * @url /api/Collect/getUserCollectList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:page type:int  default:1 desc:页数
+     * @param name:page_num type:int  : default:20 desc:每页数
+     * @param name:coll_type type:int require:1 default:-- desc:类型(1平台视频,2资料,3图文)
+     * @return name:id type:int default:-- desc:记录id
+     * @return name:create_at type:string default:-- desc:收藏时间
+     * @return name:coll_type type:int default:-- desc:收藏类型(1平台视频)
+     * @return name:video_item type:array default:-- desc:收藏详情(coll_type=1平台视频)
+     * @return name:video_item.video_id type:int default:-- desc:视频记录id
+     * @return name:video_item.id type:int default:-- desc:视频详情【url_arr】id
+     * @return name:video_item.cover type:string default:-- desc:视频详情封面
+     * @return name:video_item.url type:string default:-- desc:视频详情链接
+     * @return name:video_item.title type:string default:-- desc:视频详标题
+     * @return name:datum_item type:array default:-- desc:收藏详情(coll_type=2资料)
+     * @return name:datum_item.datum_id type:int default:-- desc:资料记录id
+     * @return name:datum_item.id type:int default:-- desc:资料详情id
+     * @return name:datum_item.url type:string default:-- desc:资料地址
+     * @return name:datum_item.title type:string default:-- desc:资料标题
+     * @return name:article_item type:array default:-- desc:收藏详情(coll_type=3图文)
+     * @return name:article_item.article_id type:int default:-- desc:图文记录id
+     * @return name:article_item.id type:int default:-- desc:图文详情id
+     * @return name:article_item.cover type:string default:-- desc:封面
+     * @return name:article_item.images type:string default:-- desc:图片(多张用|隔开)
+     * @return name:article_item.content type:string default:-- desc:图文内容
+     */
+    public function getUserCollectList()
+    {
+        $coll_type = input('get.coll_type',1);
+        $sel_where = [];
+        $sel_where[] = ['coll_type','=',$coll_type];
+        $sel_where[] = ['user_id','=',$this->user_id];
+        if(!in_array($coll_type,[1,2,3])) $this->error('收藏类型有误');
+        $with = ['','videoItem','datumItem','articleItem'];
+        $list = UserCollect::with($with[$coll_type])
+            ->field('id,create_at,coll_type')
+            ->where($sel_where)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+
+    }
+
+    /**
+     * @title 取消收藏
+     * @desc 取消收藏
+     * @author qc
+     * @method POST
+     * @url /api/Collect/cancelCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:ids type:string  : default:'' desc:需要删除的id记录(用逗号隔开)
+     */
+    public function cancelCollect()
+    {
+        $ids = input('post.ids','');
+        if(!$ids) $this->error('请选择要取消收藏的记录');
+        UserCollect::where('id','in',$ids)->where('user_id','=',$this->user_id)->delete();
+        $this->success('取消成功');
+    }
+
+    /**
+     * @title 取消收藏
+     * @desc 根据类型(平台视频id||用户视频id)取消
+     * @author qc
+     * @method POST
+     * @url /api/Collect/cancelCollectByType
+     * @header name:Authorization require:1 desc:Token
+     * @param name:coll_type type:int require:1 default:1s desc:类型(1平台视频id,2用户视频id)
+     * @param name:coll_id type:int default:1 desc:取消收藏的id(平台视频id||用户视频id)
+     */
+    public function cancelCollectByType()
+    {
+        $coll_type = input('post.coll_type',1);
+        $coll_id = input('get.coll_id',0);
+        UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id])->delete();
+        $this->success('取消成功');
+    }
+
+
+
+
+}

+ 605 - 0
application/api/controller/Datum.php

@@ -0,0 +1,605 @@
+<?php
+namespace app\api\controller;
+use app\common\model\DatumCate;
+use app\common\model\DatumIntro;
+use app\common\model\DatumLike;
+use app\common\model\DatumUrl;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserDatum;
+use app\common\model\UserDownload;
+use app\common\model\UserLevelRank;
+use app\common\model\UserMessage;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 资料
+ * @controller Datum
+ * @group base
+ */
+class Datum extends Base
+{
+    // 需要登录的
+    protected $need_login = [
+        'datumTransmit',
+        'datumRead',
+        'datumCollect',
+        'datumTags',
+        'userReferDatum',
+        'getMyDatumList',
+        'getUserDatumDetail',
+        'delUserDatum',
+        'getDownloadDatum',
+        'getLearnHistory',
+        'getDatumCollect',
+    ];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+
+    /**
+     * @title 资料接口说明
+     * @desc  资料接口说明
+     * @author  qc
+     * @url /api/Datum/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:单一资料与系列资料区别,type值(1是单一,2是系列),数据:url_arr二维数组数据数量不一样(单一的只有一个,系列的可以是多个)【可以将单一资料看做只有一条记录的系列资料!!!!】
+     * @return name:2 type:string default:-- desc:单一资料详情的字段(除id)与url_arr数组的第一个同字段名的值相同
+     * @return name:3 type:string default:-- desc:系列资料详情的字段(除id)与url_arr数组的其中一个同字段名的值相同
+     * @return name:4 type:string default:-- desc:关于是否的字段(0否,1是)
+     * @return name:5 type:string default:-- desc:url_id是详情或列表url_arr下的id
+     */
+    public function classIntro(){ }
+
+    /**
+     * @title 获取资料目录
+     * @desc  获取资料目录
+     * @author  qc
+     * @url /api/Datum/getDatumCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:id
+     * @return name:title type:string default:0 desc:名称
+     * @return name:datum_list type:array default:0 desc:目录下的资料
+     * @return name:datum_list.id type:int default:0 desc:资料记录
+     * @return name:datum_list.title type:int default:0 desc:资料标题
+     */
+    public function getDatumCate()
+    {
+        $list = DatumCate::field('id,title')->where('is_deleted',0)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['datum_list'] = DatumIntro::field('id,title')->where(['datum_cate'=>$v['id']])->select()->toArray();
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 资料推荐
+     * @desc 资料推荐
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:string default:-- desc:资料item_id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:datum_id type:string default:-- desc:系列id
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:down_num type:int default:-- desc:下载量
+     * @return name:url type:int default:-- desc:资料路径
+     */
+    public function getRecommendList()
+    {
+        $search_log =  UserSearch::getSearchTitle($this->user_id,3);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = ' a.id,a.title,a.user_id,a.down_num,a.read_num,a.is_vip,a.datum_id,a.url ,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_datum_url';
+        $order_by_two = 'a.read_num';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_datum_intro as k ON k.id = a.datum_id WHERE a.status = 1 AND a.is_deleted = 0 AND k.status = 1 AND k.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k){
+
+        });
+        $this->success('ok',['list'=>$list,'sql'=>$sql]);
+    }
+
+
+
+    /**
+     * @title 获取资料列表(平台发布)
+     * @desc 获取资料列表
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getDatumList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:type type:int default:0 desc:类型1单个2系列
+     * @param  name:is_tj type:int default:0 desc:是否推荐0否1是
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @return name:id type:int default:-- desc:[请求/api/Datum/getDatumDetail用,请求资料模块其他接口参数:url_id]
+     * @return name:title type:string default:-- desc:标题
+     * @return name:type type:int default:0 desc:类型1单个2系列
+     * @return name:datum_url type:string default:-- desc:资料地址
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
+     * @return name:label type:string default:-- desc:标签
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:url_arr type:array default:-- desc:资料
+     * @return name:url_arr.title type:string default:-- desc:资料标题
+     * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
+     * @return name:url_arr.url type:string default:-- desc:资料地址
+     */
+    public function getDatumList()
+    {
+        $sel_where = [];
+        $title = input('get.title');
+        $type = input('get.type',0);
+        $is_tj = input('get.is_tj',0);
+        $sort_type = input('get.sort_type',1);
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $sel_where[] = ['url_num','>',0];
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        if($type)  $sel_where[]  = ['type','=',$type];
+
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,3);
+        $where_str = 'id > 0';
+        if($is_tj) {
+            $search_log =    UserSearch::getSearchTitle($this->user_id,3);
+            $search_arr = [];
+            foreach ($search_log as $t){
+                $search_arr[] =  " title like '".'%'.$t."%'" .' ';
+            }
+            if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        }
+        $list = DatumIntro::where($sel_where)->with('urlArr')
+            ->limit($this->off_set,$this->page_num)
+            ->where($where_str)
+            ->order($order)
+            ->select()->toArray();
+        array_walk($list,function (&$v,$k){
+            $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
+            $v['down_num']  = array_sum(array_column($v['url_arr'],'down_num'));
+        });
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取资料详情(平台)
+     * @desc 获取资料详情
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getDatumDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:资料id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:datum_url type:string default:-- desc:资料地址
+     * @return name:down_num type:string default:-- desc:下载量
+     * @return name:url_arr type:array default:-- desc:资料
+     * @return name:url_arr.id type:int default:-- desc:[请求/api/Datum/getDatumItemInfo用,请求资料模块其他接口参数:url_id]
+     * @return name:url_arr.title type:string default:-- desc:资料标题
+     * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
+     * @return name:url_arr.url type:string default:-- desc:资料地址
+     * @return name:url_arr.is_collect type:int default:-- desc:是否收藏
+     * @return name:url_arr.collect_num type:int default:-- desc:收藏量
+     * @return name:url_arr.down_num type:int default:-- desc:下载量
+     */
+    public function getDatumDetail()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = DatumIntro::where($sel_where)->with('urlArr')->find()->toArray();
+        if($detail['is_deleted'] == 1 || $detail['status'] == 0)$this->error('该资料已下线');
+        $level_id = UserLevelRank::getUserVip($this->user_id);
+        foreach ($detail['url_arr'] as &$dv) {
+            if($dv['is_vip'] && !$level_id) $dv['url'] = '';
+            $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['id'],$dv['id']);
+            $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>1,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
+        }
+
+        $detail['read_num']  = array_sum(array_column($detail['url_arr'],'read_num'));
+        $detail['down_num']  = array_sum(array_column($detail['url_arr'],'down_num'));
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 获取资料ITEM详情(平台)
+     * @desc 获取资料ITEM详情
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getDatumItemInfo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:url_id type:int default:0 desc:url_id
+     * @return name:title type:string default:-- desc:资料标题
+     * @return name:is_vip type:int default:-- desc:是否是vip
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images type:int default:-- desc:图片
+     * @return name:content type:int default:-- desc:内容
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:read_num type:int default:-- desc:阅读量
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:down_num type:int default:-- desc:下载量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     */
+    public function getDatumItemInfo()
+    {
+        $url_id = input('get.url_id');
+        $detail = DatumUrl::where('id',$url_id)->find()->toArray();
+        $detail['collect_num']  = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail['datum_id'],'children_id'=>$detail['id']])->count();
+        $detail['is_collect']  = UserCollect::checkCollectByType($this->user_id,2,$detail['datum_id'],$detail['id']);
+        UserTrack::crateTrack($this->user_id,2,$detail['datum_id'],$url_id);
+        $this->success('ok',['detail'=>$detail]);
+    }
+    
+
+    /**
+     * @title 资料转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Datum/datumTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:datum_id type:int default:-- desc:资料id
+     * @param name:url_id type:int default:-- desc:url_id
+     */
+    public function datumTransmit()
+    {
+        $datum_id= input('post.datum_id');
+        $url_id = input('post.url_id',0);
+        DatumUrl::where('id',$url_id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+
+
+    /**
+     * @title 资料下载(资料下载数量统计)
+     * @desc 资料下载
+     * @author qc
+     * @method POST
+     * @url /api/Datum/datumDownload
+     * @header name:Authorization require:1 desc:Token
+     * @param name:datum_id type:int default:-- desc:资料id
+     * @param name:url_id type:int default:-- desc:url_id
+     */
+    public function datumDownload()
+    {
+        $datum_id= input('post.datum_id');
+        $url_id = input('post.url_id',0);
+        Data::save('UserDownload',['user_id'=>$this->user_id,'first_id'=>$datum_id,'second_id'=>$url_id]);
+        DatumUrl::where('id',$url_id)->setInc('down_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 资料阅读(阅读数量统计)
+     * @desc 资料阅读
+     * @author qc
+     * @method POST
+     * @url /api/Datum/datumRead
+     * @header name:Authorization require:1 desc:Token
+     * @param name:url_id type:int default:-- desc:url_arr的id
+     */
+    public function datumRead()
+    {
+        $url_id = input('post.url_id',0);
+        DatumUrl::where('id',$url_id)->setInc('read_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 资料收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Datum/datumCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:datum_id type:int require:1 default:-- desc:记录id[资料id]
+     * @param name:url_id type:int default:1 desc:url_id
+     * @return  name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function datumCollect()
+    {
+        $coll_type  = input('post.coll_type',2);
+        $coll_id    = input('post.datum_id',0);
+        $url_id   = input('post.url_id',0);
+        if(!$coll_id || !$url_id) $this->error('参数错误');
+        $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$url_id);
+        if($collect_check) {
+            UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$url_id])->delete();
+            $this->success('取消收藏成功',['status'=>0]);
+        }else{
+            Data::save('UserCollect', [
+                'user_id'=>$this->user_id,
+                'coll_type'=>$coll_type,
+                'coll_id'=>$coll_id,
+                'children_id'=>$url_id,
+                'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$url_id]);
+            $this->success('收藏成功',['status'=>1]);
+        }
+    }
+
+
+    /**
+     * @title 资料点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Datum/datumTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:datum_id type:int default:1 desc:资料id
+     * @param name:url_id type:int default:1 desc:url_id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function datumTags()
+    {
+        $datum_id = input('post.datum_id');
+        $url_id = input('post.url_id');
+        $ret_val = 0;
+        $check_tags =  DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->value('id');
+        if($check_tags) {
+            DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->delete();
+        }else{
+            Data::save('DatumLike',
+                ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id],'user_id',
+                ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id]);
+            $ret_val = 1;
+        }
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+    
+    /**
+     * @title 用户提交或修改资料【个人】
+     * @desc 用户提交或修改资料【个人】
+     * @author qc
+     * @method POST
+     * @url /api/Datum/userReferDatum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id(修改时必传)
+     * @param name:title type:string default:-- desc:标题
+     * @param name:datum_url type:string default:-- desc:资料地址
+     * @param name:desc type:string default:-- desc:简介
+     * @param name:label type:string default:-- desc:资料标签id(多个用逗号隔开)
+     */
+    public function userReferDatum()
+    {
+        $id = input('post.id',0);
+        $title = input('post.title');
+        $desc = input('post.desc');
+        $datum_url = input('post.datum_url');
+        $label = input('post.label');
+        if(!$datum_url) $this->error('请上传资料');
+        if($id){
+            $check_status = UserDatum::where('id',$id)->value('status');
+            if($check_status == 1) $this->error('已审核通过,不允许修改');
+        }
+        $data = [
+            'title' => $title,
+            'user_id' => $this->user_id,
+            'desc' => $desc,
+            'datum_url' => $datum_url,
+            'label' => $label,
+            'status' => 0,
+            'remark' => '',
+        ];
+        if($id) $data['id'] =  $id;
+        if($id){
+            UserDatum::where('id',$id)->update($data);
+        }else{
+            $res= UserDatum::create($data) ;
+        }
+        UserMessage::sendUserMessage($this->user_id,'datum',1,0,0,$id ? $id:$res->id);
+        $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
+    }
+
+    /**
+     * @title 获取我的资料列表【个人】
+     * @desc 获取我的资料列表【个人】
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getMyDatumList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:desc type:string default:-- desc:简介
+     * @return name:datum_url type:string default:-- desc:资料地址
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     * @return name:label type:string default:-- desc:标签
+     */
+    public function getMyDatumList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['user_id','=',$this->user_id];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        $list = UserDatum::where($sel_where)
+            ->field('id,title,desc,datum_url,status,remark,label')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取我的资料详情【个人】
+     * @desc 获取我的资料列表【个人】
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getUserDatumDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:string default:-- desc:记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:desc type:string default:-- desc:简介
+     * @return name:datum_url type:string default:-- desc:资料地址
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     * @return name:label type:string default:-- desc:标签
+     * @return name:label_name type:array default:-- desc:标签数组
+     */
+    public function getUserDatumDetail()
+    {
+        $detail =UserDatum::where('id',input('get.id'))->field('id,title,desc,datum_url,status,remark,label')->find();
+        if(!$detail) $this->error('资料有误');
+        $detail['label_name'] =$detail['label'] ? $detail['label_name'] = explode(',',trim($detail['label'],',')) : null;
+        $this->success('ok',['detail'=>$detail->toArray()]);
+    }
+
+    /**
+     * @title 用户删除资料记录【个人】
+     * @desc 用户删除资料记录【个人】
+     * @author qc
+     * @method POST
+     * @url /api/Datum/delUserDatum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id
+     */
+    public function delUserDatum()
+    {
+        UserDatum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
+        $this->success('删除成功');
+    }
+
+
+    /**
+     * @title 获取下载资料列表
+     * @desc 获取下载资料列表
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getDownloadDatum
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:datum_id type:int default:-- desc:资料id
+     * @return name:url_id type:int default:-- desc:item_id
+     * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
+     * @return name:url type:string default:-- desc:资料路径
+     */
+    public function getDownloadDatum()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',1];
+        $list = UserDownload::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id datum_id,t.second_id url_id,i.title,i.is_vip,i.url')
+            ->leftJoin('DatumUrl i','t.second_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+    /**
+     * @title 资料学习历史
+     * @desc 资料学习历史
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getLearnHistory
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:datum_id type:int default:-- desc:资料id
+     * @return name:url_id type:int default:-- desc:item_id
+     * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
+     * @return name:url type:string default:-- desc:资料路径
+     */
+    public function getLearnHistory()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',2];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id datum_id,t.second_id url_id,i.title,i.url,i.is_vip')
+            ->leftJoin('DatumUrl i','t.second_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+    /**
+     * @title 资料收藏记录
+     * @desc 图文收藏记录
+     * @author qc
+     * @method GET
+     * @url /api/Datum/getDatumCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:datum_id type:string default:-- desc:资料id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:url type:string default:-- desc:资料路径
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getDatumCollect()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',2];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id datum_id,t.children_id url_id,i.title,i.url,i.is_vip')
+            ->leftJoin('DatumUrl i','t.children_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+}

+ 663 - 0
application/api/controller/Demand.php

@@ -0,0 +1,663 @@
+<?php
+namespace app\api\controller;
+use app\common\model\ArticleCommentLike;
+use app\common\model\PlatformDemand;
+use app\common\model\DemandComment;
+use app\common\model\PlatformLike;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserDemand;
+use app\common\model\UserMessage;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 需求【也叫项目。。。】
+ * @controller Demand
+ * @group base
+ */
+class Demand extends Base
+{
+    // 需要登录的
+    protected $need_login = [
+        'demandComment',
+        'demandSecondComment',
+        'commentTags',
+        'commitDemand',
+        'getMyDemandList',
+        'getMyDemandDetail',
+        'delMyDemand',
+    ];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 需求接口说明
+     * @desc  需求接口说明
+     * @author  qc
+     * @url /api/Demand/classIntro
+     * @method GET
+     */
+     public function classIntro(){}
+
+    /**
+     * @title 需求推荐
+     * @desc 需求推荐
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:is_over type:int default:20 desc:是否解决或开源【0否,1是,2开源】
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:内容
+     * @return name:cover type:array default:-- desc:封面
+     * @return name:money type:float default:-- desc:价格
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
+     *
+     */
+    public function getRecommendList()
+    {
+        $search_log =  UserSearch::getSearchTitle($this->user_id,5);
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $search_arr = [];
+        $is_over = input('is_over',0);
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = 'a.id,cover,money,user_id,label,title,cover,is_over,content,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_platform_demand';
+        $order_by_two = 'id';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND  a.is_over = ".$is_over ." ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
+        });
+
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+
+    /**
+     * @title 需求列表【平台】
+     * @desc 需求列表【平台】
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getDemandList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:需求
+     * @return name:images type:string default:-- desc:图片【多张|隔开】
+     * @return name:user_name type:string default:-- desc:名称
+     * @return name:headimg type:string default:-- desc:头像
+     * @return name:money type:float default:-- desc:金额
+     * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
+     * @param  name:company type:string default:0 desc:公司名
+     * @param  name:company_logo type:string default:0 desc:公司logo
+     */
+     public function getDemandList()
+     {
+        $title = input('get.title');
+        $is_tj = input('get.is_tj',0);
+        $is_over = input('get.is_over',-1);
+         $sort_type = input('get.sort_type',1);
+        $sel_where =[];
+        $sel_where[] = ['d.is_deleted','=',0];
+        $sel_where[] = ['d.status','=',1];
+        if($title)  $sel_where[]  = ['d.title|d.label','like','%'.$title.'%'];
+        if($is_over > -1)  $sel_where[]  = ['d.is_over','=',$is_over];
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,5);
+        $where_str = '';
+        if($is_tj) {
+             $search_log =  UserSearch::getSearchTitle($this->user_id,5);
+             $search_arr = [];
+             foreach ($search_log as $t){
+                 $search_arr[] =  " d.title like '".'%'.$t."%'" .' ';
+             }
+             if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+         }
+         $app_name = sysconf('app_name');
+         $app_log = sysconf('app_log');
+         switch ($sort_type) {
+             case 1:
+                 $order =  ['sort'=>'desc','id'=>'desc'];
+                 break;
+             case 2:
+                 $order =  ['id'=>'asc','sort'=>'desc'];
+                 break;
+             case 3:
+                 $order =  ['id'=>'desc','sort'=>'desc'];
+                 break;
+         }
+
+         $list = PlatformDemand::where($sel_where)
+             ->field('d.*,u.name user_name,u.headimg')
+             ->alias('d')
+             ->leftJoin('store_member u','u.id = d.user_id')
+             ->when($where_str,function ($query)use ($where_str){if($where_str) $query->where($where_str);})
+             ->order($order)
+             ->limit($this->off_set,$this->page_num)->select()->toArray();
+         array_walk($list,function (&$v)use ($app_name,$app_log){
+             if(!$v['user_name']) $v['user_name'] = $app_name;
+             if(!$v['headimg']) $v['headimg'] = $app_log;
+         });
+         $this->success('ok',['list'=>$list]);
+
+     }
+
+
+    /**
+     * @title 需求详情【平台】
+     * @desc 需求详情【平台】
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getDemandInfo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:平台发布需求id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:需求
+     * @return name:images type:string default:-- desc:图片【多张|隔开】
+     * @return name:user_name type:string default:-- desc:名称
+     * @return name:headimg type:string default:-- desc:头像
+     * @return name:money type:float default:-- desc:金额
+     * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
+     * @param  name:company type:string default:0 desc:公司名
+     * @param  name:company_logo type:string default:0 desc:公司logo
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:is_collect type:int default:-- desc:是否收藏(0否1是)
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     */
+     public function getDemandInfo()
+     {
+         $detail = PlatformDemand::where('id',input('get.id'))->find();
+         $app_name = sysconf('app_name');
+         $app_logo = sysconf('app_logo');
+         if(!$detail || $detail->is_deleted == 1) $this->error('该需求已删除');
+         $detail = $detail->toArray();
+         $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')) : null;
+
+         $detail['like_num'] = PlatformLike::getPraiseNum($detail['id'],9);
+         $detail['is_like'] = PlatformLike::checkTags($this->user_id, $detail['id'], 9);
+
+         $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,10,$detail['id']);
+         $detail['collect_num'] = UserCollect::getCollectNum(10,$detail['id']);
+         UserTrack::crateTrack($this->user_id,11,input('get.id'),0);
+         if(!$detail['user_id']){
+             $detail['app_name']  = $app_name;
+             $detail['app_logo']  = $app_logo;
+         }else{
+             $user_info = $this->userInfo('name,headimg');
+             $detail['app_name']  = $user_info['name'];
+             $detail['app_logo']  = $user_info['headimg'];
+         }
+
+         $this->success('ok',['detail'=>$detail]);
+     }
+
+    /**
+     * @title 获取需求评论列表
+     * @desc 获取需求评论列表
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getDemandCommentList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:需求id
+     * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
+     * @param name:page type:int default:-- desc:页数
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
+     * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:total_num type:int default:-- desc:总评论数(仅一级)
+     */
+    public function getDemandCommentList()
+    {
+        $where = [];
+        $where[] = ['c.first_id','=',input('get.id')];
+        $where[] = ['c.is_deleted','=',0];
+        $where[] = ['c.type','=',1];
+        $user_id = $this->user_id;
+        $sort_type= input('sort_type',1);
+        $order = $sort_type == 1 ? 'c.id desc' : 'c.like_times desc';
+        $list  =DemandComment::where($where)
+            ->alias('c')
+            ->field('c.*,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+
+        array_walk($list,function (&$val,$k)use($user_id){
+            $children = DemandComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->order('c.id asc')
+                ->select()->toArray();
+            $val['children'] =  $children ? $children : null;
+            $val['like_num'] = PlatformLike::getPraiseNum($val['id'],6);
+            $val['is_like'] =  PlatformLike::where(['like_id'=>$val['id'],'user_id'=>$user_id,'type'=>6])->count();
+            $parent  = DemandComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->find();
+            $val['parent']  = $parent ? $parent->toArray() : null;
+        });
+        $total_num  = DemandComment::where($where)->alias('c')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc
+     * @author qc
+     * @method
+     * @url /api/Demand/needLogin
+     */
+    public function needLogin(){}
+
+
+    /**
+     * @title 需求评论
+     * @desc 需求评论
+     * @author qc
+     * @method POST
+     * @url /api/Demand/demandComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:需求id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function demandComment()
+    {
+        $id = input('post.id');
+        $content = input('post.content',0);
+        if(!$content) $this->error('请输入评论内容');
+        $send_user = PlatformDemand::where('id',$id)->value('user_id');
+        $user_info = $this->userInfo('name');
+        if($send_user) UserMessage:: sendUserMessage($send_user,'demand',4,0,$this->user_id,$id,$user_info['name'].'评论了您的需求');
+        $res = DemandComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
+        $detail  =DemandComment::where('p.id',$res->id)
+            ->alias('p')
+            ->field('p.id,p.content,p.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = p.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 需求二级评论
+     * @desc 需求二级评论
+     * @author qc
+     * @method POST
+     * @url /api/Demand/demandSecondComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function demandSecondComment()
+    {
+        $comment = DemandComment::where('id',input('post.id'))->find()->toArray();
+
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($comment['user_id'],'demand',3,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
+        $send_user = PlatformDemand::where('id',$comment['first_id'])->value('user_id');
+        if($send_user) UserMessage::sendUserMessage($send_user,'demand',4,0,$this->user_id,$comment['first_id'],$user_info['name'].'评论了您的需求');
+        unset($comment['id']);
+        unset($comment['create_at']);
+        $comment['pid'] = input('post.id');
+        $comment['user_id'] = $this->user_id;
+        $comment['content'] = input('post.content');
+        $comment['lev']++;
+        if(!$comment['source_id']) $comment['source_id'] = input('post.id');
+        $res = DemandComment::create($comment);
+        $detail  = DemandComment::where('p.id',$res->id)
+            ->alias('p')
+            ->field('p.id,p.content,p.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = p.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 需求点赞||取消点赞[需求]
+     * @desc 评论
+     * @author qc
+     * @method POST
+     * @url /api/Demand/demandTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:demand_id type:int default:1 desc:需求id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function demandTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.demand_id'),9);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 评论点赞||取消点赞[评论]
+     * @desc 评论
+     * @author qc
+     * @method POST
+     * @url /api/Demand/commentTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:comment_id type:int default:1 desc:评论记录id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function commentTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.comment_id'),6);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+
+    /**
+     * @title 收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Demand/demandCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:需求id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function demandCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,10,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+    /**
+     * @title 用户提交||修改需求【用户】
+     * @desc 用户提交||修改需求
+     * @author qc
+     * @method POST
+     * @url /api/Demand/commitDemand
+     * @param  name:id type:int default:-- desc:修改必传[添加不传,或是null或是空]
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:content type:string default:1 desc:内容
+     * @param  name:money type:float default:0 desc:价格【设计图没有,可以不传】
+     * @param  name:label type:string default:0 desc:标签【多个逗号隔开】
+     * @param  name:cover type:string default:0 desc:封面【一张】
+     * @param  name:images type:string default:0 desc:图片【多张|隔开】
+     * @param  name:company type:string default:0 desc:公司名
+     * @param  name:company_logo type:string default:0 desc:公司logo
+     */
+    public function commitDemand()
+    {
+        $title = input('post.title');
+        $content = input('post.content');
+        $money = input('post.money');
+        $cover = input('post.cover');
+        $images = input('post.images');
+        $label = input('post.label');
+        $id = input('post.id');
+        $company = input('post.company');
+        $company_logo = input('post.company_logo');
+        if(!$title || !$content) $this->error('标题和需求内容必填');
+        if($id) {
+            $demand_status = UserDemand::where('id',$id)->value('status');
+            if($demand_status == 1) $this->error('已审核通过,不允许修改');
+        }
+        $res = Data::save('UserDemand',[
+            'title'=>$title,
+            'content'=>$content,
+            'user_id'=>$this->user_id,
+            'money'=>$money,
+            'id'=>$id ? $id : null,
+            'cover'=>$cover,
+            'images'=>$images,
+            'label'=>$label,
+            'company'=>$company,
+            'company_logo'=>$company_logo,
+        ],'user_id',['user_id'=>$this->user_id,'id'=>$id]);
+        UserMessage::sendUserMessage($this->user_id,'demand',1,0,0,$id ? $id: intval($res));
+        $this->success('提交成功,请等待审核');
+    }
+
+    /**
+     * @title 获取我的需求列表【我的发布】
+     * @desc 获取我的图文列表【我的发布】
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getMyDemandList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:需求
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     * @return name:money type:float default:0 desc:价格【设计图没有,可以不传】
+     * @return name:cover type:string default:0 desc:封面【一张】
+     * @return name:images type:string default:0 desc:图片【多张|隔开】
+     * @return name:images_arr type:array default:null desc:图片【多张】
+     * @return name:company type:string default:0 desc:公司名
+     * @return name:company_logo type:string default:0 desc:公司logo
+     */
+    public function getMyDemandList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['user_id','=',$this->user_id];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        $list = UserDemand::where($sel_where)
+            ->field('id,title,content,status,remark,cover,images,money,company,company_logo')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$lv){
+            $lv['images_arr'] = $lv['images'] ? explode('|',$lv['images']) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取我的需求详情【用户】
+     * @desc 获取我的需求详情【用户】
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getMyDemandDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:需求记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:需求
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     * @return name:remark type:string default:-- desc:审核备注
+     * @return name:money type:float default:-- desc:金额
+     * @return name:cover type:string default:0 desc:封面【一张】
+     * @return name:images type:string default:0 desc:图片【多张|隔开】
+     * @return name:images_arr type:array default:null desc:图片【多张】
+     * @return  name:company type:string default:0 desc:公司名
+     * @return  name:company_logo type:string default:0 desc:公司logo
+     */
+    public function getMyDemandDetail()
+    {
+        $detail = UserDemand::where(['user_id'=>$this->user_id,'id'=>input('get.id')])->find();
+        if(!$detail || $detail->is_deleted == 1) $this->error('该需求已删除');
+        $detail = $detail->toArray();
+        $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')) : null;
+        $detail['images_arr'] = $detail['images'] ? explode('|',$detail['images']) : null;
+        $this->success('ok',['detail'=>$detail]);
+    }
+    
+    /**
+     * @title 删除我的需求【用户】
+     * @desc 删除我的需求【用户】
+     * @author qc
+     * @method POST
+     * @url /api/Demand/delMyDemand
+     * @param  name:id type:int default:-- desc:需求记录id
+     */
+    public function delMyDemand()
+    {
+        UserDemand::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->delete();
+        $this->success('删除成功');
+    }
+
+    /**
+     * @title 我的点赞列表【需求】
+     * @desc 我的点赞
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getTagsDemand
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:demand_id type:string default:-- desc:需求id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:content type:string default:-- desc:内容
+     * @return name:company type:string default:-- desc:公司
+     * @return name:company_logo type:string default:-- desc:公司logo
+     * @return name:money type:string default:-- desc:价格
+     * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
+     */
+    public function getTagsDemand()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',9];
+        $list = PlatformLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.like_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
+            ->leftJoin('PlatformDemand i','t.like_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的浏览历史【需求】
+     * @desc 我的浏览历史
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getDemandTrack
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:demand_id type:string default:-- desc:需求id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:content type:string default:-- desc:内容
+     * @return name:company type:string default:-- desc:公司
+     * @return name:company_logo type:string default:-- desc:公司logo
+     * @return name:money type:string default:-- desc:价格
+     * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
+     * @return name:time type:string default:-- desc:时间
+     */
+    public function getDemandTrack()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',11];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
+            ->leftJoin('PlatformDemand i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 我的收藏列表【需求】
+     * @desc 我的收藏列表
+     * @author qc
+     * @method GET
+     * @url /api/Demand/getCollectDemand
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:demand_id type:string default:-- desc:需求id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:content type:string default:-- desc:内容
+     * @return name:company type:string default:-- desc:公司
+     * @return name:company_logo type:string default:-- desc:公司logo
+     * @return name:money type:string default:-- desc:价格
+     * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
+     */
+    public function getCollectDemand()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',10];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
+            ->leftJoin('PlatformDemand i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+
+    }
+
+
+}

+ 696 - 0
application/api/controller/Expedite.php

@@ -0,0 +1,696 @@
+<?php
+
+
+namespace app\api\controller;
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+use app\common\model\ArticleIntro;
+use app\common\model\ArticleItem;
+use app\common\model\DatumUrl;
+use app\common\model\PlatformDemand;
+use app\common\model\StoreBanner;
+use app\common\model\StoreGoods;
+use app\common\model\SupplierGoods;
+use app\common\model\TopSearch;
+use app\common\model\User;
+use app\common\model\UserForum;
+use app\common\model\UserLevel;
+use app\common\model\VideoUrl;
+use Dm\Request\V20151123 as Dm;
+use think\cache\driver\Redis;
+use think\Db;
+/**
+ * @title 不需要验证token接口
+ * @controller Expedite
+ * @package app\api\controller
+ */
+class Expedite extends Base
+{
+
+    public function initialize(){
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 获取首页轮播图
+     * @desc  获取首页轮播图
+     * @author  qc
+     * @url /api/Expedite/getBanner
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:place type:int  default:1 desc:展示位置1视频首页
+     * @param  name:num type:int  default:5 desc:查询数量
+     * @return name:cover type:srting default:-- desc:图片路径
+     * @return name:link type:srting default:-- desc:链接
+     */
+    public function getBanner()
+    {
+        $num = input('get.num',5);
+        $place = input('get.place',1);
+        $list = StoreBanner::field('id,cover,link')
+            ->where(['is_deleted'=>0,'place'=>$place])->limit(0,$num)
+            ->order('sort desc ,id desc')->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取会员等级设置
+     * @desc  获取会员等级设置
+     * @author  qc
+     * @url /api/Expedite/getUserLevelSet
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:等级id
+     * @return name:name type:string default:-- desc:等级名称
+     * @return name:logo type:string default:-- desc:图片
+     * @return name:price type:array default:-- desc:价格设置【为空,,不能购买】
+     * @return name:price.title type:string default:-- desc:标题
+     * @return name:price.time type:string default:-- desc:时间(单位月)
+     * @return name:price.price type:float default:-- desc:价格
+     */
+    public function getUserLevelSet()
+    {
+        $list = UserLevel::field('id,logo,name,price')->where("price is not null and price != ''")->where('id',1)->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取热搜设置标题
+     * @desc  获取热搜设置
+     * @author  qc
+     * @url /api/Expedite/getTopSearch
+     * @method GET
+     * @param name:sort_type type:int default:1 desc:排序规则1默认2搜索量
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'图文',3=>'资料',4=>'新闻',5=>'需求',6=>'论坛',7=>'商品',8=>'招聘',9=>'供应商',10=>'供应商产品',
+     * @return name:title type:string default:-- desc:标题
+     * @return name:num type:int default:-- desc:搜索量
+     * @return name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'图文',3=>'资料',4=>'新闻',5=>'需求',6=>'论坛',7=>'商品',8=>'招聘',9=>'供应商',10=>'供应商产品',
+     */
+    public function getTopSearch()
+    {
+        $type = input('type');
+        $sort_type= input('sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['num'=>'desc','id'=>'desc'];
+                break;
+            default:
+                $order =  ['num'=>'desc','id'=>'desc'];
+                break;
+        }
+        $sel = [];
+        $sel['is_deleted'] = 0;
+        $sel['status'] = 1;
+        if($type)   $sel['type'] =$type;
+        $list = TopSearch::field('id,title,type,num')
+            ->where($sel)
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 全局搜索
+     * @desc  全局搜索
+     * @author  qc
+     * @url /api/Expedite/globalSearch
+     * @method GET
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @param name:type type:string default:-- desc:搜索类型(不传查全部)[video=>视频,article=>图文,datum=>资料,goods=>商城商品,press=>新闻,supplier_goods=>供应商商品,demand=>需求,recruit=>招聘,forum=>论坛,activity=>活动]
+     * @param name:search_name type:string default:-- desc:搜索名称
+     * @param name:search_time type:int default:-- desc:0不限,182半年,365一年
+     * @return name:video_list type:array default:-- desc:视频列表【单个】
+     * @return name:video_list.url_id type:int default:-- desc:url_id
+     * @return name:video_list.video_id type:int default:-- desc:video_id
+     * @return name:video_list.cover type:string default:-- desc:封面
+     * @return name:video_list.title type:string default:-- desc:标题
+     * @return name:video_list.is_vip type:int default:-- desc:是否是vip【0否1是】
+     * @return name:video_list.ali_vid type:string default:-- desc:云点播视频id
+     * @return name:video_list.read_num type:int default:-- desc:播放量
+     * @return name:video_list.app_name type:string default:-- desc:平台名称
+     * @return name:video_list.app_logo type:string default:-- desc:平台头像
+
+     * @return name:article_list type:array default:-- desc:图文列表【单个】
+     * @return name:article_list.title type:string default:-- desc:图文标题
+     * @return name:article_list.is_vip type:int default:-- desc:是否是vip
+     * @return name:article_list.cover type:string default:-- desc:封面
+     * @return name:article_list.images type:int default:-- desc:图片【多张|隔开】
+     * @return name:article_list.images_arr type:array default:-- desc:图片
+     * @return name:article_list.read_num type:int default:-- desc:阅读量
+     * @return name:article_list.app_name type:string default:-- desc:平台名称
+     * @return name:article_list.app_logo type:string default:-- desc:平台头像
+     *
+     * @return name:datum_list type:array default:-- desc:资料列表【单个】
+     * @return name:datum_list.id type:int default:-- desc:资料的url_id
+     * @return name:datum_list.title type:string default:-- desc:标题
+     * @return name:datum_list.is_vip type:int default:-- desc:是否是vip
+     *
+     * @return name:press_list type:array default:-- desc:新闻列表
+     * @return name:press_list.id type:int default:-- desc:新闻id
+     * @return name:press_list.title type:string default:-- desc:标题
+     * @return name:press_list.cover type:string default:-- desc:封面
+     * @return name:press_list.images_arr type:array default:-- desc:图片
+     * @return name:press_list.read_num type:int default:-- desc:阅读量
+     *
+     * @return name:recruit_list type:array default:-- desc:招聘列表
+     * @return name:recruit_list.title type:string default:-- desc:标题
+     * @return name:recruit_list.company type:string default:-- desc:公司名
+     * @return name:recruit_list.cover type:string default:-- desc:公司logo
+     * @return name:recruit_list.label_name type:array default:-- desc:标签
+     * @return name:recruit_list.welfare_arr type:array default:-- desc:岗位福利
+     * @return name:recruit_list.education type:string default:-- desc:学历
+     * @return name:recruit_list.experience_min type:int default:0 desc:最低工作年限
+     * @return name:recruit_list.experience_max type:int default:0 desc:最高工作年限
+     * @return name:recruit_list.price_min type:int default:-- desc:最低薪资
+     * @return name:recruit_list.price_max type:int default:-- desc:最高薪资
+     * @return name:recruit_list.province type:string default:-- desc:省名
+     * @return name:recruit_list.city type:string default:-- desc:市名
+     * @return name:recruit_list.address type:string default:-- desc:地址
+     *
+     * @return name:goods_list type:array default:-- desc:商城商品
+     * @return name:goods_list.id type:int default:-- desc:d
+     * @return name:goods_list.name type:string default:-- desc:商品名称
+     * @return name:goods_list.cover type:string default:-- desc:封面
+     * @return name:goods_list.low_price type:float default:-- desc:价格
+     *
+     * @return name:supplier_goods_list type:array default:-- desc:供应商商品
+     * @return name:supplier_goods_list.id type:int default:-- desc:供应商商品d
+     * @return name:supplier_goods_list.name type:string default:-- desc:商品名称
+     * @return name:supplier_goods_list.cover_arr type:array default:-- desc:封面
+     * @return name:supplier_goods_list.label_name type:array default:-- desc:标签
+     * @return name:supplier_goods_list.label type:string default:-- desc:标签
+     * @return name:supplier_goods_list.supplier_name type:float default:-- desc:供应商名称
+     *
+     * @return name:demand_list type:array default:-- desc:需求
+     * @return name:demand_list.title type:string default:-- desc:标题
+     * @return name:demand_list.content type:string default:-- desc:内容
+     * @return name:demand_list.cover type:array default:-- desc:封面
+     * @return name:demand_list.money type:float default:-- desc:价格
+     * @return name:demand_list.app_name type:string default:-- desc:发布方名称
+     * @return name:demand_list.app_logo type:string default:-- desc:发布方头像
+     * @return name:demand_list.is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
+     * @return name:demand_list.company type:string default:-- desc:公司名
+     * @return name:demand_list.company_logo type:string default:-- desc:公司logo
+     *
+     *
+     * @return name:forum_list type:array default:-- desc:论坛
+     * @return name:forum_list.id type:int default:-- desc:id
+     * @return name:forum_list.title type:string default:-- desc:标题
+     * @return name:forum_list.content type:string default:0 desc:内容
+     * @return name:forum_list.level type:int default:-- desc:vip等级id
+     * @return name:forum_list.label type:string default:-- desc:标签
+     * @return name:forum_list.name type:string default:-- desc:发布用户
+     * @return name:forum_list.headimg type:string default:-- desc:发布用户头像
+     * @return name:forum_list.browse_num type:int default:-- desc:浏览量
+     * @return name:forum_list.reply_num type:int default:-- desc:回答量
+     *
+     * @return name:activity_list type:array default:-- desc:活动
+     * @return name:activity_list.id type:int default:-- desc:id
+     * @return name:activity_list.address type:string default:-- desc:地址
+     * @return name:activity_list.cover type:string default:-- desc:封面
+     * @return name:activity_list.label_name type:array default:-- desc:标签
+     * @return name:activity_list.start_time type:string default:-- desc:开始时间
+     * @return name:activity_list.end_time type:string default:-- desc:结束时候
+     * @return name:activity_list.end_time type:string default:-- desc:结束时间
+     * @return name:activity_list.price type:string default:-- desc:价格
+     */
+    public function globalSearch()
+    {
+        $type = input('get.type');
+        $search_name = input('get.search_name');
+        $search_time = input('get.search_time');
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        // 视频
+        $video_list = VideoUrl::field('a.id url_id,a.video_id,a.cover,a.title,a.is_vip,a.ali_vid,a.label,a.read_num,a.transmit_num,a.user_id')->alias('a')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('a.title|a.label','like','%'.$search_name.'%');
+                if($search_time) $query->where('a.create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })->leftJoin('video_intro b','b.id = a.video_id')
+            ->where('a.status',1)
+            ->where('a.is_deleted',0)
+            ->where('b.status',1)
+            ->where('b.is_deleted',0)->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($video_list,function (&$v,$k)use ($app_name,$app_logo){
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+        });
+        // 图文
+        $article_list = ArticleItem::field('a.id item_id,a.user_id,a.article_id,a.cover,a.title,a.is_vip,a.images,a.read_num')->alias('a')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('a.title|a.label','like','%'.$search_name.'%');
+                if($search_time) $query->where('a.create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })->leftJoin('article_intro b','a.article_id = b.id')
+            ->where('a.status',1)
+            ->where('a.is_deleted',0)
+            ->where('b.status',1)
+            ->where('b.is_deleted',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($article_list,function (&$v,$k)use ($app_name,$app_logo){
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+        });
+
+        // 资料
+        $datum_list = DatumUrl::field('a.id,a.url,a.datum_id,a.title,a.is_vip')->alias('a')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+            if($search_name) $query->where('a.title|a.label','like','%'.$search_name.'%');
+            if($search_time) $query->where('a.create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+        })->leftJoin('datum_intro b','b.id = a.datum_id')
+            ->where('a.status',1)
+            ->where('a.is_deleted',0)
+            ->where('b.status',1)
+            ->where('b.is_deleted',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+
+        //新闻
+        $press_list = \app\common\model\Press::field('id,title,cover,images,read_num')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('title|label','like','%'.$search_name.'%');
+                if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($press_list,function (&$v,$k){
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+        });
+
+        //招聘
+        $recruit_list = \app\common\model\Recruit::field('id,title,label,address,price_min,price_max,company,education,experience_min,experience_max,welfare,province,city')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('title|label','like','%'.$search_name.'%');
+                if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($recruit_list,function (&$v,$k){
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+        });
+
+
+        // 商品
+        $goods_list = StoreGoods::field('id,name,cover,low_price')->when($search_name,function ($query)use ($search_name,$search_time){
+            if($search_name) $query->where('name','like','%'.$search_name.'%');
+            if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+        })->where('is_deleted',0)->where('status',1)->limit($this->off_set,$this->page_num)->select()->toArray();
+
+        // 供应商
+        $supplier_goods_list =SupplierGoods::field('g.id,g.supplier_id,g.name,g.label,g.cover,s.title supplier_name')
+            ->alias('g')
+            ->when($search_name,function ($query)use($search_name,$search_time){
+                if($search_name) $query->where('g.name','like','%'.$search_name.'%');
+                if($search_time) $query->where('g.create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })->leftJoin('Supplier s','g.supplier_id = s.id')
+            ->where('g.status','=',1)
+            ->where('g.is_deleted','=',0)
+            ->where('s.status','=',1)
+            ->where('s.is_deleted','=',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($supplier_goods_list,function (&$v,$k){
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
+        });
+
+        // 需求
+        $demand_list = PlatformDemand::field('id,cover,money,user_id,label,title,cover,is_over,content,company,company_logo')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                    if($search_name) $query->where('title|label','like','%'.$search_name.'%');
+                    if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+                })
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($demand_list,function (&$v,$k){
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
+        });
+
+
+        // 论坛
+        $forum_list = UserForum::alias('f')
+            ->field('f.id,f.title,f.content,f.label,f.level,f.browse_num,f.sort,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id),0 ) as reply_num')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('f.title|f.label','like','%'.$search_name.'%');
+                if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+
+            })->leftJoin('store_member u','u.id = f.user_id')
+            ->where('f.status',1)
+            ->where('f.is_deleted',0)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        // 活动
+        $activity_list = \app\common\model\Activity::field('id,cover,title,address,label,start_time,end_time,ladder,price')
+            ->when($search_name,function ($query)use ($search_name,$search_time){
+                if($search_name) $query->where('title|label','like','%'.$search_name.'%');
+                if($search_time) $query->where('create_at','> time',date('Y-m-d H:i:s',strtotime('-'.$search_time.' days')));
+            })
+            ->where('status',1)
+            ->where('is_deleted',0)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        array_walk($activity_list,function (&$v,$k){
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['ladder'] = $v['ladder'] ? json_decode($v['ladder'],true):null;
+        });
+        $this->success('ok',$type ? compact($type.'_list'): compact(['video_list','article_list','datum_list','goods_list','press_list','supplier_goods_list','demand_list','recruit_list','forum_list','activity_list']));
+    }
+
+
+
+    /**
+     * @title 发送短信验证码
+     * @desc 发送短信验证码
+     * @author qc
+     * @url /api/Expedite/sendSms
+     * @method POST
+     * @tag 短信验证码
+     * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
+     * @return name:code type:string default:-- desc:验证码
+     */
+    public function sendSms(){
+        $phone = input('post.phone');
+        $user_info  = User::where('phone',$phone)->where('is_deleted',0)->field('id,status')->find();
+        if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
+        if(empty($phone)) $this ->error('参数错误');
+        $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
+        AlibabaCloud::accessKeyClient('LTAI5tJ5p12drZegeWVG33xZ', '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB')
+            ->regionId('cn-hangzhou')->asDefaultClient();
+        try {
+            $result = AlibabaCloud::rpc()
+                ->product('Dysmsapi')
+                ->version('2017-05-25')
+                ->action('SendSms')
+                ->method('POST')
+                ->host('dysmsapi.aliyuncs.com')
+                ->options([
+                    'query' => [
+                        'RegionId' => "cn-hangzhou",
+                        'PhoneNumbers' => $phone,
+                        'SignName' => "搞一下汽车电子",
+                        'TemplateCode' => "SMS_234397351",
+                        'TemplateParam' => json_encode(array("code"=>$code)),
+                    ],
+                ])->request();
+            $result = $result->toArray();
+            if($result['Code'] == "OK") {
+                $sms_data = array(
+                    'phone'=>$phone,
+                    'code'=>$code,
+                    'result'=>$result['Message']
+                );
+                Db::name('store_member_sms')->insert($sms_data);
+                $this->success('发送成功',['code'=>$code]);
+            }else{
+                $this->error('发送失败');
+            }
+        } catch (ClientException $e) {
+            echo $e->getErrorMessage() . PHP_EOL;
+        } catch (ServerException $e) {
+            echo $e->getErrorMessage() . PHP_EOL;
+        }
+
+    }
+
+    /**
+     * @title 发送邮箱验证码
+     * @desc 发送邮箱验证码
+     * @author qc
+     * @url /api/Expedite/emailSms
+     * @method POST
+     * @tag 邮箱验证码
+     * @param name:email type:int require:1 default:-- desc:邮箱
+     * @return name:code type:string default:-- desc:验证码
+     */
+    function emailSms(){
+        $email = input('post.email');
+        $user_info  = User::where('email',$email)->where('is_deleted',0)->field('id,status')->find();
+        if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
+        $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
+        require_once env('root_path').'/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
+        $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
+        $client = new \DefaultAcsClient($iClientProfile);
+        $request = new Dm\SingleSendMailRequest();
+        $request->setAccountName("gyx@yzm.gyxqcdz.com");
+        $request->setFromAlias("[验证码]");
+        $request->setAddressType(1);
+        $request->setTagName("zonghuzhuche");
+        $request->setReplyToAddress("true");
+        $request->setToAddress($email);
+        $request->setSubject("验证码");
+        $html_body = '验证码:'.$code;
+        $request->setHtmlBody($html_body);
+        try {
+            $send_res = $client->getAcsResponse($request);
+            $sms_data = array(
+                'phone'=>$email,
+                'code'=>$code,
+                'result'=>'OK'
+            );
+            Db::name('store_member_sms')->insert($sms_data);
+            $this->success('发送成功',['code'=>$code]);
+        } catch (ClientException  $e) {
+            $this->error($e->getErrorMessage());
+           // print_r($e->getErrorCode());
+           // print_r($e->getErrorMessage());
+        } catch (ServerException  $e) {
+            $this->error($e->getErrorMessage());
+           // print_r($e->getErrorCode());
+           // print_r($e->getErrorMessage());
+
+        }
+    }
+
+    /**
+     * @title 获取签名
+     * @desc 获取签名
+     * @url /api/Expedite/getWeChatSign
+     * @method POST
+     * @param  name:url type:string default:-- desc:页面地址
+     * @return name:appid type:string default:-- desc:appid
+     * @return name:noncestr type:string default:-- desc:随机字符
+     * @return name:timestamp type:string default:-- desc:时间戳
+     * @return name:sign type:string default:-- desc:签名
+     * @return name:ticket type:string default:-- desc:ticket
+     **/
+    public function getWeChatSign(){
+        $urls = input('post.url');
+        $appid = config('app.official_account')['appid'];
+        $secret =  config('app.official_account')['secret'];
+        $redis = new Redis();
+        $access_token = $redis->get('access_token');
+        if (!$access_token){
+            $access_token = '';
+            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
+            $res= http_curl($url);
+            if (isset($res['access_token'])){
+                $redis->set('access_token',$res['access_token'],'7000');
+                $access_token = $res['access_token'];
+            }
+        }
+
+        $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
+        $res2=http_curl($url2);
+        if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
+        $timestamp = time();
+        $noncestr = get32Str(15);
+        $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
+        $sign = sha1($string);
+        $return = [
+            'appid'=>$appid,
+            'noncestr'=>$noncestr,
+            'timestamp'=>$timestamp,
+            'url'=>$urls,
+            'sign'=>$sign,
+            'ticket'=>$res2['ticket']
+        ];
+        $this->success('成功',$return);
+    }
+
+
+
+    /**
+     * @title 获取平台文案设置
+     * @desc  获取平台文案设置
+     * @author  qc
+     * @url /api/Expedite/getSysConfig
+     * @method GET
+     * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
+     * @return name:agreement type:string default:-- desc:用户协议
+     * @return name:about_us type:string default:-- desc:关于我们
+     * @return name:privacy type:string default:-- desc:隐私政策
+     * @return name:user_equity type:string default:-- desc:会员权益
+     * @return name:customer_service type:string default:-- desc:客服设置
+     * @return name:original_pact type:string default:-- desc:原创公约
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台logo
+     * @return name:app_version type:string default:-- desc:版本号
+     */
+    public function getSysConfig(){
+        $search_name = input('get.search_name');
+        $con_name = $search_name? [$search_name] : ['agreement','about_us','privacy','user_equity','customer_service','original_pact','app_version'];
+        $set = Db::name('system_config')->where('name','in',$con_name)->select();
+        $ret = [];
+        foreach ($set as $value) {
+            $ret[$value['name']]=$value['value'];
+        }
+        $this->success('获取成功',$ret);
+    }
+
+
+    /**
+     * @title 修改版本号
+     * @desc 修改版本号
+     * @author qc
+     * @method POST
+     * @url /api/Expedite/changeVersion
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:app_version type:string default:1 desc:版本号
+     */
+    public function changeVersion()
+    {
+        Db::name('system_config')->where('name','app_version')->update(['value'=>input('app_version')]);
+        $this->success('修改成功');
+    }
+    /**
+     * @title 获取客服设置【平台的】
+     * @desc  获取客服设置【平台的】
+     * @author  qc
+     * @url /api/Expedite/getServiceSet
+     * @method GET
+     * @return name:service_qr_code type:string default:-- desc:客服二维码
+     * @return name:service_phone type:string default:-- desc:客服电话
+     * @return name:service_email type:string default:-- desc:客服邮箱
+     */
+    public function getServiceSet(){
+        $con_name =  ['service_qr_code','service_phone','service_email'];
+        $set = Db::name('system_config')->where('name','in',$con_name)->select();
+        $ret = [];
+        foreach ($set as $value) {
+            $ret[$value['name']]=$value['value'];
+        }
+        $this->success('获取成功',$ret);
+    }
+
+
+    /**
+     * @title 获取联系客服设置【模块的】[所有模块的联系我们都用这个接口]
+     * @desc  获取联系客服设置
+     * @author  qc
+     * @url /api/Expedite/getContact
+     * @method GET
+     * @param name:tag type:string default:-- desc:标识【video=>视频,article=>图文,datum=>资料,activity=>活动,demand=>需求,forum=>论坛,press=>新闻,supplier=>供应商,recruit=>招聘,mall=>商城】
+     * @return name:qrcode type:string default:-- desc:客服二维码
+     * @return name:phone type:string default:-- desc:客服电话
+     * @return name:email type:string default:-- desc:客服邮箱
+     * @return name:place type:string default:-- desc:归属模块
+     * @return name:tag type:string default:-- desc:归属标识【可以按照这个值查询或是区分所属模块】
+     */
+    public function getContact()
+    {
+        $tag = input('get.tag');
+        $sel_tag = $tag ? [$tag] : ['video','article','datum','activity','demand','forum','press','supplier','recruit','mall'];
+        $list = Db::name('contact')->where('tag','in',$sel_tag)->column('tag,qrcode,phone,email,tag,place','tag');
+        $this->success('ok',$list);
+    }
+
+
+    /**
+     * @title 获取模块封面
+     * @desc  获取模块封面
+     * @author  qc
+     * @url /api/Expedite/getModulesCover
+     * @method GET
+     * @param name:tag type:string default:-- desc:标识【video=>视频,article=>图文,datum=>资料,activity=>活动,demand=>需求,forum=>论坛,press=>新闻,supplier=>供应商,recruit=>招聘,mall=>商城】
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:place type:string default:-- desc:归属模块
+     * @return name:tag type:string default:-- desc:归属标识【可以按照这个值查询或是区分所属模块】
+     */
+    public function getModulesCover()
+    {
+        $tag = input('get.tag');
+        $sel_tag = $tag ? [$tag] : ['video','article','datum','activity','demand','forum','press','supplier','recruit','mall'];
+        $list = Db::name('cover')->where('tag','in',$sel_tag)->column('tag,cover,tag,place','tag');
+        $this->success('ok',$list);
+    }
+
+
+    /**
+     * @title 推送测试
+     * @desc  推送测试
+     * @author  qc
+     * @url /api/Expedite/messagePush
+     * @method GET
+     * @param name:user_id type:int default:-- desc:会员id
+     * @param name:content type:string default:-- desc:推送内容
+     */
+    public function messagePush()
+    {
+        $user_id= input('user_id');
+        $content= input('content');
+        $res  = Jpush($user_id,$content);
+        $this->success('',['result'=>$res]);
+
+    }
+
+
+    /**
+     * @title 获取分享地址
+     * @desc  获取分享地址
+     * @author  qc
+     * @url /api/Expedite/getShareUrl
+     * @method GET
+     * @param name:tag type:string default:-- desc:标识【video=>视频,article=>图文,datum=>资料,activity=>活动,demand=>需求,forum=>论坛,press=>新闻,supplier=>供应商商品,recruit=>招聘,mall=>商城商品】
+     * @param name:first_id type:int default:-- desc:【视频系列id,图文系列id,资料系列id,活动id,需求id,论坛id,新闻id,供应商商品id,招聘记录id,商城商品id】
+     * @param name:second_id type:string default:-- desc:【视频url_id,图文item_id,资料item_id,其他类型的不传】
+     * @return name:url type:string default:-- desc:跳转地址
+     */
+    public function getShareUrl()
+    {
+        $tag = input('get.tag');
+        if(!in_array($tag, ['video','article','datum','activity','demand','forum','press','supplier','recruit','mall'])) $this->error('类型标识错误');
+        $first_id = input('get.first_id');
+        $second_id = input('get.second_id');
+        $url_arr= [
+            'video'     =>$this->request->root(true) ."/dist/#/video-details?id=$first_id&videoArrId=$second_id",
+            'article'   =>$this->request->root(true) ."/dist/#/image-text-details?id=$first_id&item_id=$second_id",
+            'datum'     =>$this->request->root(true) ."/dist/#/information-details?id=$first_id&url_id=$second_id",
+            'activity'  =>$this->request->root(true) ."/dist/#/activity-sign-up?activity_id=$first_id",
+            'demand'    =>$this->request->root(true) ."/dist/#/demand-details?demand_id=$first_id",
+            'forum'     =>$this->request->root(true) ."/dist/#/product-details?product_id=$first_id",
+            'press'     =>$this->request->root(true) ."/dist/#/news-details?press_id=$first_id",
+            'supplier'  =>$this->request->root(true) ."/dist/#/supplier-details?goods_id=$first_id",
+            'recruit'   =>$this->request->root(true) ."/dist/#/recruit-details?recruit_id=$first_id",
+            'mall'      =>$this->request->root(true) ."/dist/#/product-details?product_id=$first_id",
+        ];
+       $this->success('ok',['url'=>$url_arr[$tag]]);
+    }
+
+
+}

+ 94 - 0
application/api/controller/Feedback.php

@@ -0,0 +1,94 @@
+<?php
+namespace app\api\controller;
+use app\common\model\UserFeedback;
+use app\common\model\UserMessage;
+
+
+/**
+ * @title 反馈
+ * @controller Feedback
+ * @group base
+ */
+class Feedback extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 用户反馈
+     * @desc  用户反馈
+     * @author  qc
+     * @url /api/Feedback/leaveFeedback
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:content type:string require:1 default:-- desc:反馈内容
+     * @param name:desc type:string require:1 default:-- desc:反馈说明
+     */
+    public function leaveFeedback()
+    {
+        $insert_data = [
+            'user_id'=>$this->user_id,
+            'content'=>input('content'),
+            'desc'=>input('desc'),
+            'create_at'=>date('Y-m-d H:i:s')
+        ];
+        $res =  UserFeedback::create($insert_data);
+        $this->success('反馈成功',$res->id);
+    }
+
+    /**
+     * @title 用户反馈列表
+     * @desc  用户反馈列表
+     * @author  qc
+     * @url /api/Feedback/getFeedbackList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param name:page type:int default:0 desc:页数
+     * @param name:page_num type:int default:20 desc:每页数
+     * @return name:content type:string default:-- desc:反馈内容
+     * @return name:desc type:string default:-- desc:反馈说明
+     * @return name:status type:int default:-- desc:处理进度【0待处理,1处理中,2已完成】
+     * @return name:create_at type:string default:-- desc:反馈时间
+     * @return name:dispose_time type:string default:-- desc:开始处理时间
+     * @return name:over_time type:string default:-- desc:处理完成时间
+     * @return name:reply type:string default:-- desc:后台回复
+     */
+    public function getFeedbackList()
+    {
+        $list  = UserFeedback::where(['user_id'=>$this->user_id])
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 用户反馈详情
+     * @desc  用户反馈详情
+     * @author  qc
+     * @url /api/Feedback/getFeedbackInfo
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:0 desc:反馈记录id
+     * @return name:content type:string default:-- desc:反馈内容
+     * @return name:desc type:string default:-- desc:反馈说明
+     * @return name:status type:int default:-- desc:处理进度【0待处理,1处理中,2已完成】
+     * @return name:create_at type:string default:-- desc:反馈时间
+     * @return name:dispose_time type:string default:-- desc:开始处理时间
+     * @return name:over_time type:string default:-- desc:处理完成时间
+     * @return name:reply type:string default:-- desc:后台回复
+     */
+    public function getFeedbackInfo()
+    {
+        $id = input('get.id');
+        $detail  = UserFeedback::where(['user_id'=>$this->user_id,'id'=>$id])->find()->toArray();
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+
+
+
+}

+ 831 - 0
application/api/controller/Forum.php

@@ -0,0 +1,831 @@
+<?php
+namespace app\api\controller;
+use app\common\model\ForumReply;
+use app\common\model\ForumReplyComment;
+use app\common\model\PlatformLike;
+use app\common\model\PlatformSwitch;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserForum;
+use app\common\model\UserLevelRank;
+use app\common\model\UserMessage;
+use app\common\model\UserReport;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use think\Db;
+use library\tools\Data;
+use vod\Request\V20170321\GetMediaAuditResultTimelineRequest;
+
+/**
+ * @title 论坛
+ * @controller Forum
+ * @group base
+ */
+class Forum extends Base
+{
+    // 需要登录的
+    protected $need_login = [];
+    public function initialize(){
+        parent::initialize();
+        parent::checkLogin();
+        if(!$this->user_id) parent::setUid();
+    }
+
+    /**
+     * @title 获取论坛列表
+     * @desc 获取论坛列表
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getForumList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:is_tj type:int default:0 desc:是否推荐0否1是
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:排序1默认2时间升序3时间降序
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:0 desc:内容
+     * @return name:level type:int default:-- desc:vip等级id
+     * @return name:label type:string default:-- desc:标签
+     * @return name:name type:string default:-- desc:发布用户
+     * @return name:headimg type:string default:-- desc:发布用户头像
+     * @return name:browse_num type:int default:-- desc:浏览量
+     * @return name:reply_num type:int default:-- desc:回答量
+     * @return name:unread_num type:int default:-- desc:未读量
+     */
+    public function getForumList()
+    {
+        $sel_where = [];
+        $title = input('get.title');
+        $label = input('get.label');
+        $is_tj = input('get.is_tj');
+        $sort_type = input('get.sort_type',1);
+        $sel_where[]  = ['f.is_deleted','=',0];
+        if($title)  $sel_where[]  = ['f.title|f.label','like','%'.$title.'%'];
+        if($label)  $sel_where[]  = ['f.label','like','%'.$label.'%'];
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,6);
+        $user_level = UserLevelRank::getUserVip($this->user_id);
+        $max_level = 0;
+        if($user_level == 0){
+            $where_str = ' f.level <= 1';
+            $max_level = 1;
+        }else{
+            $where_str = ' f.level <= '.$user_level;
+            $max_level = $user_level;
+        }
+
+        if($is_tj) {
+            $search_log =    UserSearch::getSearchTitle($this->user_id,6);
+            $search_arr = [];
+            foreach ($search_log as $t){
+                $search_arr[] =  " f.title like '".'%'.$t."%'" .' ';
+                $search_arr[] =  " f.label like '".'%'.$t."%'" .' ';
+            }
+            if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        }
+
+        if($is_tj){
+            $search_log =  UserSearch::getSearchTitle($this->user_id,6);
+            $search_arr = [];
+            $where_str = 'b.id > 0';
+            foreach ($search_log as $t){
+                $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+                $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+            }
+            if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+            $field = ' a.id,a.title,a.content,a.label,a.level,a.browse_num,a.sort,a.create_at,IFNULL(is_recommend,0) is_recommend, u.name,u.headimg';
+            $table = 'dd_user_forum';
+            $order_by_two = 'id';
+            $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_store_member as u ON a.user_id =u.id   WHERE a.is_deleted = 0 AND a.status =1 AND a.level <= $max_level ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+            $list = Db::query($sql);
+            array_walk($list,function (&$v,$k) {
+                $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+                $reply_num =  ForumReply::field('count(DISTINCT user_id) reply_num' )->where(['forum_id'=>$v['id']])->select()->toArray();
+                $v['reply_num'] = array_sum(array_column($reply_num,'reply_num'));
+            });
+        }else{
+            $list = UserForum::where($sel_where)
+                ->alias('f')
+                ->field('f.id,f.title,f.content,f.label,f.level,f.browse_num,f.sort,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id),0 ) as reply_num')
+                ->leftJoin('store_member u','u.id = f.user_id')
+                ->where($where_str)
+                ->limit($this->off_set,$this->page_num)
+                ->order($order)
+                ->select()->toArray();
+            array_walk($list,function (&$v,$k) use ($app_name,$app_logo){
+                $v['label_name'] = $v['label'] ?  explode(',',trim($v['label'],',')): null;
+                if(!$v['name']) $v['name'] = $app_name;
+                if(!$v['headimg']) $v['headimg'] = $app_logo;
+            });
+        }
+        $num = UserForum::where('is_read',0)->count();
+        if(!empty($list)) {
+            $ids_arr = array_column($list,'id');
+            UserForum::where('id','in',implode(',',$ids_arr))->where('is_read',0)->update(['is_read'=>1]);
+            UserForum::where('id','in',implode(',',$ids_arr))->setInc('browse_num');
+        }
+        $this->success('ok',['list'=>$list,'unread_num'=>$num]);
+    }
+
+
+
+    /**
+     * @title 获取论坛未读数量
+     * @desc 获取论坛未读数量
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getUnreadNum
+     * @header name:Authorization require:1 desc:Token
+     * @return name:unread_num type:int default:-- desc:未读量
+     */
+    public function getUnreadNum()
+    {
+        $num = UserForum::where('is_read',0)->where('is_deleted',0)->count();
+        $this->success('ok',['unread_num'=>$num]);
+
+    }
+
+
+    /**
+     * @title 获取论坛详情
+     * @desc 获取论坛详情
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getForumInfo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:string default:-- desc:论坛记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:0 desc:内容
+     * @return name:level type:int default:-- desc:vip等级id
+     * @return name:label type:string default:-- desc:标签
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:name type:string default:-- desc:发布用户
+     * @return name:headimg type:string default:-- desc:发布用户头像
+     * @return name:browse_num type:int default:-- desc:浏览量
+     * @return name:is_collect type:int default:-- desc:是否关注【0否1是】
+     * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
+     * @return name:comment_num type:int default:-- desc:评论数量
+     * @return name:replay_num type:int default:-- desc:回复数量
+     */
+    public function getForumInfo(){
+        $id = input('get.id');
+        $user_level = UserLevelRank::getUserVip($this->user_id);
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $detail = UserForum::where('f.id',$id)
+            ->alias('f')
+            ->field('f.id,f.title,f.is_deleted,f.content,f.label,f.level,f.browse_num,is_read,f.create_at,u.name,u.headimg,IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id  ),0 ) as reply_num')
+            ->leftJoin('store_member u','u.id = f.user_id')
+            ->find()->toArray();
+        if($detail['is_deleted']) $this->error('改论坛已删除');
+        if($user_level > 0 && $detail['level'] > $user_level) $this->error('用户等级不足');
+        if($user_level == 0 && $detail['level'] > 1) $this->error('用户等级不足');
+        $detail['is_collect']  = UserCollect::checkCollectByType($this->user_id,5,$detail['id']);
+        $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,5,$detail['id']);
+        $detail['label_name'] = $detail['label'] ?  explode(',',trim($detail['label'],',')): null;
+        if(!$detail['name']) $detail['name'] = $app_name;
+        if(!$detail['headimg']) $detail['headimg'] = $app_logo;
+        $detail['comment_num'] =  ForumReplyComment::where(['is_deleted'=>0,'forum_id'=>$detail['id']])->count();
+        $detail['replay_num'] =  ForumReply::where(['is_deleted'=>0,'forum_id'=>$detail['id']])->count();
+        UserForum::where('id',$id)->setInc('browse_num');// 增加浏览量
+        if(!$detail['is_read'])UserForum::where('id',$detail['id'])->update(['is_read'=>1]);
+        UserTrack::crateTrack($this->user_id,5,input('get.id'),0);
+        $this->success('ok',['detail'=>$detail]);
+
+    }
+
+    /**
+     * @title 关注||取消关注
+     * @desc 关注||取消关注
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:论坛id
+     * @param name:status type:int default:0 desc:收藏状态(0取消关注【未关注】,1关注)
+     */
+    public function forumCollect()
+    {
+        $coll_status = UserCollect::plateCollect($this->user_id,5,input('post.id',0),0);
+        $coll_status ?  $this->success('关注成功',['status'=>1]) :    $this->success('取消关注成功',['status'=>0]);
+    }
+
+    /**
+     * @title 开启||关闭通知开关
+     * @desc 开启||关闭通知开关
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumSwitch
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:论坛id
+     */
+    public function forumSwitch()
+    {
+        $switch_status = PlatformSwitch::userSwitch($this->user_id,5,input('post.id',0));
+        $switch_status ?  $this->success('开启成功',['status'=>1]) :    $this->success('关闭成功',['status'=>0]);
+    }
+
+    /**
+     * @title 论坛回复
+     * @desc 论坛回复
+     * @author qc
+     * @method POST
+     * @url /api/Forum/replyForum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:论坛id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function replyForum()
+    {
+        $id = input('post.id');
+        $content = input('post.content');
+        if(!$content) $this->error('请上传内容');
+        $issue_user  = UserForum::where('id',$id)->value('user_id');
+        $res = ForumReply::create(['user_id'=>$this->user_id,'content'=>$content,'issue_user'=>$issue_user,'forum_id'=>$id]);
+        $detail  = ForumReply::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($issue_user,'forum',5,0,$this->user_id,$id,$user_info['name'].'回复了您的提问');
+        $this->success('回复成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 论坛回复列表
+     * @desc 论坛回复列表
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getReplyList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:forum_id type:int default:0 desc:论坛记录id
+     * @param name:page type:int default:0 desc:页数
+     * @param name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:论坛回复id
+     * @return name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:children type:array default:-- desc:评论列表【所有的都查了】
+     * @return name:children.content type:string default:-- desc:评论内容
+     * @return name:children.create_at type:string default:-- desc:评论时间
+     * @return name:children.name type:string default:-- desc:会员
+     * @return name:children.headimg type:string default:-- desc:会员头像
+     * @return name:children.like_num type:int default:-- desc:点赞数量
+     * @return name:children.is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:children.children_num type:int default:-- desc:评论数量
+     * @return name:total_num type:int default: desc:总数
+     */
+    public function getReplyList()
+    {
+        $where = [];
+        $where[] = ['r.forum_id','=',input('get.forum_id')];
+        $where[] = ['r.is_deleted','=',0];
+        $list = ForumReply::where($where)
+            ->alias('r')
+            ->field('r.id,r.content,r.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','r.user_id = u.id')
+            ->limit($this->off_set,$this->page_num)
+            ->order('r.id desc')
+            ->select()->toArray();
+        $total_num = ForumReply::where($where)->alias('r')->count();
+        array_walk($list,function (&$val,$k){
+            $val['like_num'] = PlatformLike::getPraiseNum($val['id'],3);
+            $val['is_like'] =  PlatformLike::checkTags($this->user_id,$val['id'],3);
+            $children = ForumReplyComment::where(['c.reply_id'=>$val['id'],'c.is_deleted'=>0])
+                ->alias('c')
+                ->field('c.id,c.create_at,c.content,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->order('c.id desc')
+                ->select()->toArray();
+            foreach ($children as &$c) {
+                $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
+                $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
+            }
+            $val['children'] = $children ? $children : null;
+            $val['children_num'] = count($children);
+        });
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+
+    /**
+     * @title 论坛回复的评论列表
+     * @desc 论坛回复的评论列表
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getReplyCommentList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:reply_id type:int default:0 desc:论坛回复记录id
+     * @param name:page type:int default:0 desc:页数
+     * @param name:page_num type:int default:20 desc:每页数
+     * @return name:content type:string default:-- desc:评论内容
+     * @return name:create_at type:string default:-- desc:评论时间
+     * @return name:name type:string default:-- desc:会员
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:total_num type:int default: desc:总数
+     */
+    public function getReplyCommentList()
+    {
+        $reply_id = input('reply_id');
+        $list =  ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])
+            ->alias('c')
+            ->field('c.id,c.create_at,c.content,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->order('c.id desc')
+            ->select()->toArray();
+       foreach ($list as &$c){
+           $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
+           $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
+       }
+       $total_num = ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])->alias('c')->count();
+       $this->success('ok',compact(['list','total_num']));
+
+    }
+    /**
+     * @title 论坛二级评论
+     * @desc 论坛二级评论
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumSecondComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function forumSecondComment()
+    {
+        $comment = ForumReplyComment::where('id',input('post.id'))->find()->toArray();
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($comment['user_id'],'forum',4,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
+        unset($comment['id']);
+        unset($comment['create_at']);
+        $comment['pid'] = input('post.id');
+        $comment['user_id'] = $this->user_id;
+        $comment['content'] = input('post.content');
+        $comment['lev']++;
+        if(!$comment['source_id']) $comment['source_id'] = input('post.id');
+        $res = ForumReplyComment::create($comment);
+        $detail  = ForumReplyComment::where('p.id',$res->id)
+            ->alias('p')
+            ->field('p.id,p.content,p.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = p.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 论坛回复点赞||取消点赞
+     * @desc 论坛回复点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:like_id type:int default:1 desc:论坛回复的id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function forumTags()
+    {
+        $ret_val=  PlatformLike::userTags($this->user_id,input('post.like_id'),3);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 对论坛回复的评论进行点赞||取消点赞
+     * @desc 论坛回复的评论点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumCommentTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:like_id type:int default:1 desc:论坛回复的评论id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function forumCommentTags()
+    {
+        $ret_val=  PlatformLike::userTags($this->user_id,input('post.like_id'),8);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 对论坛回复进行评论
+     * @desc 对论坛回复进行评论
+     * @author qc
+     * @method POST
+     * @url /api/Forum/commentReply
+     * @header name:Authorization require:1 desc:Token
+     * @param name:reply_id type:int default:-- desc:回复的id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function commentReply()
+    {
+        $reply_id = input('post.reply_id');
+        $content = input('post.content');
+        if(!$content) $this->error('请输入评论内容');
+        $reply_info = ForumReply::where('id',$reply_id)->find()->toArray();
+        //if($reply_info['user_id'] == $this->user_id) $this->error('无法评论自己的回答');
+        $user_info = $this->userInfo('name,headimg');
+        UserMessage:: sendUserMessage($reply_info['user_id'],'forum',3,0,$this->user_id,$reply_id,$user_info['name'].'评论了您的回复');
+        $res = ForumReplyComment::create(['user_id'=>$this->user_id,'content'=>$content,'forum_id'=>$reply_info['forum_id'],'reply_id'=>$reply_id]);
+        $detail  = ForumReplyComment::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 用户发布论坛
+     * @desc 用户发布论坛
+     * @author qc
+     * @method POST
+     * @url /api/Forum/userReferForum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:标题
+     * @param name:content type:string default:-- desc:内容
+     * @param name:label type:string default:-- desc:论坛标签(多个用逗号隔开)
+     * @param name:images type:string default:-- desc:(多个用|隔开)
+     */
+    public function userReferForum()
+    {
+        $title = input('post.title');
+        $content = input('post.content');
+        $label = input('post.label');
+        $images = input('post.images');
+        if(!$title || !$content || !$label) $this->error('参数错误');
+        $data = [
+            'title' => $title,
+            'user_id' => $this->user_id,
+            'content' => $content,
+            'label' => $label,
+            'images' => $images,
+            'level' =>  UserLevelRank::getUserVip($this->user_id),
+        ];
+        $res = UserForum::create($data);
+        UserMessage::sendUserMessage($this->user_id,'forum',1,0,0,$res->id);
+        $this->success('发布成功');
+    }
+
+    /**
+     * @title 用户删除论坛记录
+     * @desc 用户删除论坛记录
+     * @author qc
+     * @method POST
+     * @url /api/Forum/delForum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id
+     */
+    public function delForum(){
+        UserForum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
+        $this->success('删除成功');
+    }
+
+    /**
+     * @title  我的提问
+     * @desc 我的提问
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getUserForumList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:0 desc:内容
+     * @return name:level type:int default:-- desc:vip等级id
+     * @return name:label type:string default:-- desc:标签
+     * @return name:name type:string default:-- desc:发布用户
+     * @return name:headimg type:string default:-- desc:发布用户头像
+     * @return name:browse_num type:int default:-- desc:浏览量
+     * @return name:reply_num type:int default:-- desc:回答量
+     */
+    public function getUserForumList()
+    {
+        $sel_where = [];
+        $sel_where[] = ['f.is_deleted','=',0];
+        $sel_where[] = ['f.user_id','=',$this->user_id];
+        if($title = input('get.title')) $sel_where[] = ['f.title|f.label','like','%'.$title.'%'];
+        $list = UserForum::where($sel_where)
+            ->alias('f')
+            ->field('f.id,f.title,f.content,f.level,f.browse_num,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id  ),0 ) as reply_num')
+            ->leftJoin('store_member u','u.id = f.user_id')
+            ->limit($this->off_set,$this->page_num)
+            ->order( 'id desc' )
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list,'user_info'=>$this->userInfo(['name','headimg'])]);
+    }
+
+    /**
+     * @title 我的回答【列表】--论坛问题
+     * @desc 我的回答【列表】
+     * @author qc
+     * @method GET
+     * @url /api/Forum/myReplyList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:关键字
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:title type:string default:-- desc:标题[论坛]
+     * @return name:content type:string default:0 desc:内容
+     * @return name:name type:string default:-- desc:用户
+     * @return name:headimg type:string default:-- desc:用户头像
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function myReplyList()
+    {
+        $where = [];
+        $where[] = ['r.user_id','=',$this->user_id];
+        $where[] = ['r.is_deleted','=',0];
+        if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
+        $list = ForumReply::where($where)
+            ->alias('r')
+            ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
+            ->leftJoin('user_forum f','r.forum_id = f.id')
+            ->leftJoin('store_member u','r.user_id = u.id')
+            ->limit($this->off_set,$this->page_num)
+            ->order('r.id desc')
+            ->select()->toArray();
+        $total_num = ForumReply::where($where)->alias('r')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 我的评论
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Forum/myDiscuss
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:关键字
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:title type:string default:-- desc:论坛标题
+     * @return name:content type:string default:0 desc:评论内容
+     * @return name:reply_content type:string default:0 desc:回复内容
+     * @return name:name type:string default:-- desc:回复的用户
+     * @return name:headimg type:string default:-- desc:回复的头像
+     */
+    public function myDiscuss()
+    {
+        $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
+            ->where(['c.user_id'=>$this->user_id,'c.is_deleted'=>0])
+            ->leftJoin('forum_reply r','c.reply_id = r.id')
+            ->leftJoin('store_member m','m.id = r.user_id')
+            ->leftJoin('user_forum f','f.id = c.forum_id')
+            ->order('c.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 回答我的
+     * @desc 回答我的
+     * @author qc
+     * @method GET
+     * @url /api/Forum/replyToMyForum
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:关键字
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:title type:string default:-- desc:标题[论坛]
+     * @return name:content type:string default:0 desc:内容
+     * @return name:name type:string default:-- desc:用户
+     * @return name:headimg type:string default:-- desc:用户头像
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function replyToMyForum()
+    {
+        $where = [];
+        $where[] = ['r.issue_user','=',$this->user_id];
+        $where[] = ['r.is_deleted','=',0];
+        if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
+        $list = ForumReply::where($where)
+            ->alias('r')
+            ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
+            ->leftJoin('user_forum f','r.forum_id = f.id')
+            ->leftJoin('store_member u','r.user_id = u.id')
+            ->limit($this->off_set,$this->page_num)
+            ->order('r.id desc')
+            ->select()->toArray();
+        $total_num = ForumReply::where($where)->alias('r')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 评论我的
+     * @desc 评论我的
+     * @author qc
+     * @method GET
+     * @url /api/Forum/commentOnMyReply
+     * @header name:Authorization require:1 desc:Token
+     * @param name:title type:string default:-- desc:关键字
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:title type:string default:-- desc:论坛标题
+     * @return name:content type:string default:0 desc:评论内容
+     * @return name:reply_content type:string default:0 desc:回复内容
+     * @return name:name type:string default:-- desc:评论用户
+     * @return name:headimg type:string default:-- desc:评论用户头像
+     */
+    public function commentOnMyReply()
+    {
+        $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
+            ->where(['r.user_id'=>$this->user_id,'r.is_deleted'=>0])
+            ->leftJoin('forum_reply r','c.reply_id = r.id')
+            ->leftJoin('store_member m','m.id = c.user_id')
+            ->leftJoin('user_forum f','f.id = c.forum_id')
+            ->order('c.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 用户举报
+     * @desc  用户举报
+     * @author  qc
+     * @url /api/Forum/forumReport
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:report_id type:int default:-- desc:举报内容的id
+     * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
+     */
+    public function forumReport()
+    {
+        $report_id= input('post.report_id');
+        $case_ids= input('post.case_ids');
+        if(!$report_id) $this->error('请现在举报内容');
+        if(!$case_ids) $this->error('请选择举报原因');
+        UserReport::report($this->user_id,6,$report_id,$case_ids);
+        $this->success('举报成功');
+    }
+
+
+    /**
+     * @title 转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Forum/forumTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:forum_id type:int default:-- desc:论坛问题id
+     */
+    public function forumTransmit()
+    {
+        $forum_id = input('post.forum_id');
+        UserForum::where('id',$forum_id)->setInc('transmit_num');
+        $this->success('转发成功');
+    }
+
+
+
+
+
+    /**
+     * @title 回复我的【回复我的--回复过我的评论】
+     * @desc 回复我的
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getReplyComment
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     *
+     * @return name:title type:string default:-- desc:论坛标题
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【其他会员】
+     * @return name:headimg type:string default:-- desc:用户头像【其他会员】
+     * @return name:content type:string default:-- desc:回复内容
+     * @return name:parent_comment type:array default:-- desc:你的评论内容
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:你的会员名称
+     * @return name:parent_comment.headimg type:string default:-- desc:你的头像
+     * @return name:parent_comment.title type:string default:-- desc:论坛标题
+     * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
+     */
+    public function getReplyComment()
+    {
+        // 所有我评论的回答
+        $all_comment = ForumReplyComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
+        if(empty($all_comment)) $this->success('ok',['list'=>null]);
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','>=',2];
+        $sel_where[]  = ['t.user_id','<>',$this->user_id];
+        $sel_where[]  = ['t.pid','in',implode(',',$all_comment)];
+        $list = ForumReplyComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name user_name,u.headimg,i.title')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->leftJoin('UserForum i','t.forum_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg')
+                ->alias('t')
+                ->leftJoin('UserForum i','t.forum_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+    /**
+     * @title 我的回复【我的回复--我回复过的评论】
+     * @desc 我的回复
+     * @author qc
+     * @method GET
+     * @url /api/Forum/getReplyForum
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:论坛标题
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     * @return name:content type:string default:-- desc:回复内容
+     * @return name:parent_comment type:array default:-- desc:上级评论内容【你回复的那个】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称【别人的】
+     * @return name:parent_comment.headimg type:string default:-- desc:会员头像【别人的】
+     * @return name:parent_comment.title type:string default:-- desc:论坛标题
+     * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
+     */
+    public function getReplyForum()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','>=',2];
+        $list = ForumReplyComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.content,t.pid,forum_id,i.title')
+            ->leftJoin('UserForum i','t.forum_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+            $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name,u.headimg,i.title')
+                ->alias('t')
+                ->leftJoin('UserForum i','t.forum_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+}

+ 68 - 0
application/api/controller/General.php

@@ -0,0 +1,68 @@
+<?php
+namespace app\api\controller;
+use app\common\model\UserSearch;
+
+/**
+ * @title 其他接口
+ * @controller General
+ * @group base
+ */
+class General extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 用户搜索历史
+     * @desc 用户搜索历史
+     * @author qc
+     * @method GET
+     * @url /api/General/getSearchHistory
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'图文',3=>'资料',4=>'新闻',5=>'需求',6=>'论坛',7=>'商品',8=>'招聘',9=>'供应商',10=>'供应商产品',
+     * @return name:title type:string default:-- desc:标题
+     * @return name:type type:int default:-- desc:类型0全局,1视频,2图文,3资料,4新闻,5需求
+     */
+    public function getSearchHistory()
+    {
+        $title = input('title');
+        $type= input('type',-1);
+        $where= [];
+        $where [] = ['user_id','=',$this->user_id];
+        if($title)$where [] = ['title','like','%'.$title.'%'];
+        if($type > -1)$where [] = ['type','=',$type];
+        $list = UserSearch::where($where)
+            ->limit($this->off_set,$this->page_num)
+            ->order('create_at desc,id desc')
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 删除||清空搜索历史
+     * @desc 删除||清空搜索历史
+     * @author qc
+     * @method POST
+     * @url /api/General/delSearchHistory
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:搜索记录id【不传值清空所有搜索记录】
+     */
+    public function delSearchHistory()
+    {
+        $id = input('post.id');
+        $where= [];
+        $where [] = ['user_id','=',$this->user_id];
+        if($id)$where [] = ['id','=',$id];
+        UserSearch::where($where)->delete();
+        $this->success('删除成功');
+    }
+
+
+
+
+}

+ 276 - 0
application/api/controller/LevelOrder.php

@@ -0,0 +1,276 @@
+<?php
+namespace app\api\controller;
+use app\common\model\User;
+use app\common\model\UserLevel;
+use app\common\model\LevelOrder as LOM;
+use think\Db;
+
+/**
+ * @title 会员等级订单
+ * @controller LevelOrder
+ * @group base
+ */
+class LevelOrder extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+
+    /**
+     * @title 开通会员(续费)订单
+     * @desc  开通会员(续费)订单
+     * @author qc
+     * @url /api/Level_order/createOrder
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:level_id type:int require:1  default:0 desc:会员等级
+     * @param name:level_key type:int require:1  default:0 desc:等级价格的key值
+     * @return name:order_id type:int default:0 desc:订单id
+     */
+
+    public function createOrder(){
+        $level_id = input('post.level_id');
+        $level_key = input('post.level_key');
+        $user_info = User::where('id',$this->user_id)->field('id,group_id,is_first,account_type')->find();
+        if($user_info['account_type'] == 1 && $user_info['is_first'] == 0) $this->error('请联系公司管理员进行会员开通');
+        $level_set = UserLevel::where('id', $level_id)->find()->toArray();
+        if (!$level_set['price']) $this->error('会员价格设置有误');
+        $level_price = json_decode($level_set['price'], true);
+        if (!isset($level_price[$level_key])) $this->error('会员价格设置有误.');
+        $order_insert = [
+            'user_id' => $this->user_id,
+            'order_no' => get_order_sn(),
+            'level_id' => $level_id,
+            'level_key' => $level_key,
+            'month' => $level_price[$level_key]['time'],
+            'price_total' =>$level_price[$level_key]['price'],
+        ];
+        $order_info = LOM::create($order_insert);
+        $this->success('ok', ['order_id' => $order_info->id]);
+    }
+
+    /**
+     * @title 获取订单详情
+     * @desc 获取订单详情
+     * @author qc
+     * @method GET
+     * @url /api/Level_order/getOrderDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param name:order_id type:int default:--  desc:订单id
+     * @return name:id type:int default:--  desc:订单id
+     * @return name:order_no type:string default:--  desc:订单号
+     * @return name:price_total type:float default:--  desc:待支付金额
+     * @return name:level_id type:float default:--  desc:等级id
+     * @return name:level_name type:float default:--  desc:等级名称
+     * @return name:month type:float default:--  desc:时长(月)
+     * @return name:pay_state type:int default:--  desc:支付状态(0未支付1已支付)
+     * @return name:pay_type type:int default:--  desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付)
+     * @return name:pay_no type:string default:--  desc:支付号
+     * @return name:pay_at type:string default:--  desc:支付时间
+     * @return name:cancel_state type:int default:--  desc:取消状态(0未取消1已取消)
+     * @return name:cancel_at type:string default:--  desc:取消时间
+     * @return name:cancel_desc type:string default:--  desc:取消原因
+     * @return name:cancel_desc type:string default:--  desc:取消原因
+     * @return name:level_set type:array default:--  desc:购买会员设置
+     * @return name:level_set.title type:string default:--  desc:标题
+     * @return name:level_set.price type:float default:--  desc:价格
+     * @return name:level_set.time type:int default:--  desc:时间(月)
+     */
+    public function getOrderDetail()
+    {
+        $order_id = input('get.order_id');
+        $detail = LOM::where('id',$order_id)->find()->toArray();
+        $level_set =  UserLevel::where('id', $detail['level_id'])->find()->toArray();
+        $detail['level_name'] = $level_set['name'];
+        $detail['level_set'] = json_decode($level_set['price'],true)[$detail['level_key']];
+        $this->success('',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 订单支付
+     * @desc  订单支付
+     * @author  qc
+     * @url /api/Level_order/payOrder
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
+     * @param name:pay_type type:int require:1  default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝)
+     * @return name:config type:array default:0 desc:小程序支付配置
+     * @return name:config.appId type:string default:-- desc:公众账号ID
+     * @return name:config.signType type:string default:-- desc:签名类型
+     * @return name:config.paySign type:string default:-- desc:签名
+     * @return name:config.nonceStr type:string default:-- desc:随机字符串
+     * @return name:config.timestamp type:string default:-- desc:时间戳
+     * @return name:config.partnerid type:string default:-- desc:商户号
+     * @return name:config.prepayid type:string default:-- desc:唯一支付号
+     * @return name:config.package type:string default:-- desc:package
+     * @return name:config.mch_id type:string default:-- desc:商户号(H5)
+     * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
+     * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
+     * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
+     * @return name:code_url type:string default:-- desc:付款码url
+     * @return name:openid type:string default:-- desc:openid
+     */
+    public function payOrder()
+    {
+        $order_id = input('post.order_id');
+        $pay_type = input('post.pay_type',1);
+        $order_info = LOM::where('id',$order_id)->find()->toArray();
+        if($order_info['status'] != 0) $this->error('订单状态错误');
+        if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
+        if($order_info['price_total'] <= 0) $this->error('订单金额错误');
+        $pay_no  = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
+        if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
+        $user_info = User::where('id',$this->user_id)->find()->toArray();
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
+        Db::startTrans();
+        LOM::where('id',$order_id)->update(['pay_type'=>$pay_type]);
+        try {
+            switch ($pay_type){
+                case 1://微信
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                    $pay_config['config']['pay_no'] = $pay_no;
+                    $pay_config['config']['notify_url'] = $notify_url;
+                    $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                    $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 2 :
+                    $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                    $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
+                    $config = Alipay::ali_pay_pc('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 3:
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 4:
+                    $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                    $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg =  $e->getMessage();
+            Db::rollback();
+        }
+        $this->transReturn($ret_data);
+    }
+
+    /**
+     * @title 开通会员
+     * @desc  开通会员
+     * @author  qc
+     * @url /api/Level_order/payOrderNew
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:level_id type:int require:1  default:0 desc:会员等级
+     * @param name:level_key type:int require:1  default:0 desc:等级价格的key值
+     * @param name:pay_type type:int require:1  default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付)
+     * @return name:config type:array default:0 desc:支付配置
+     * @return name:config.appId type:string default:-- desc:公众账号ID
+     * @return name:config.signType type:string default:-- desc:签名类型
+     * @return name:config.paySign type:string default:-- desc:签名
+     * @return name:config.nonceStr type:string default:-- desc:随机字符串
+     * @return name:config.timestamp type:string default:-- desc:时间戳
+     * @return name:config.partnerid type:string default:-- desc:商户号
+     * @return name:config.prepayid type:string default:-- desc:唯一支付号
+     * @return name:config.package type:string default:-- desc:package
+     * @return name:config.mch_id type:string default:-- desc:商户号(H5)
+     * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
+     * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
+     * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
+     * @return name:code_url type:string default:-- desc:付款码url
+     * @return name:openid type:string default:-- desc:openid
+     */
+    public function payOrderNew()
+    {
+        $level_id = input('post.level_id');
+        $level_key = input('post.level_key');
+        $pay_type = input('post.pay_type',1);
+        $user_info = User::where('id',$this->user_id)->find();
+        if($user_info['account_type'] == 1 && $user_info['is_first'] == 0) $this->error('请联系公司管理员进行会员开通');
+        $level_set = UserLevel::where('id', $level_id)->find()->toArray();
+        if (!$level_set['price']) $this->error('会员价格设置有误');
+        $level_price = json_decode($level_set['price'], true);
+        if (!isset($level_price[$level_key])) $this->error('会员价格设置有误.');
+        $order_insert = [
+            'user_id' => $this->user_id,
+            'order_no' => get_order_sn(),
+            'level_id' => $level_id,
+            'level_key' => $level_key,
+            'pay_type' => $pay_type,
+            'month' => $level_price[$level_key]['time'],
+            'price_total' =>$level_price[$level_key]['price'],
+            'pay_no' =>get_order_sn()
+        ];
+        $order_info = LOM::create($order_insert);
+        $order_info = $order_info->toArray();
+        $pay_no  = $order_info['pay_no'];
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
+        Db::startTrans();
+        try {
+            switch ($pay_type){
+                case 1://微信
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                    $pay_config['config']['pay_no'] = $pay_no;
+                    $pay_config['config']['notify_url'] = $notify_url;
+                    $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                    $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 2 :
+                    $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                    $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
+                    $config = Alipay::ali_pay_pc('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 3:
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 4:
+                    $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
+                    $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 5 :
+                    if(!$user_info['openid']) $this->exception('请绑定openid');
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg =  $e->getMessage();
+            Db::rollback();
+        }
+        $this->transReturn($ret_data);
+    }
+
+
+
+}

+ 97 - 434
application/api/controller/Login.php

@@ -1,460 +1,123 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | ThinkAdmin
-// +----------------------------------------------------------------------
-// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
-// +----------------------------------------------------------------------
-// | 官方网站: http://demo.thinkadmin.top
-// +----------------------------------------------------------------------
-// | 开源协议 ( https://mit-license.org )
-// +----------------------------------------------------------------------
-// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
-// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
-// +----------------------------------------------------------------------
-
 namespace app\api\controller;
-
-use AlibabaCloud\Client\AlibabaCloud;
-use AlibabaCloud\Client\Exception\ClientException;
-use AlibabaCloud\Client\Exception\ServerException;
-use app\api\controller\Base;
+use app\common\model\UserGroup;
+use app\common\model\UserLevelRank;
+use app\common\validate\UserVali;
+use app\common\model\User;
+use app\common\model\UserWallet;
+use library\service\CaptchaService;
+use library\tools\Data;
 use think\Db;
-use Firebase\JWT\JWT;
 use EasyWeChat\Factory;
-use think\route\RuleItem;
+use app\common\model\InviteInfo;
 use function AlibabaCloud\Client\value;
 
 /**
- * @title 登录
+ * @title 用户登录
  * @controller Login
- * @group worker
  */
 class Login extends Base
 {
-    /**
-     * @title 微信登录(小程序)
-     * @desc 微信登录
-     * @author QGF
-     * @url /api/Login/login
-     * @method POST
-     * @tag 登录 授权
-     * @param name:code type:int require:1 default:oRZeJ55dhq8y6gHI9PVwCrv0gvSM desc:code值
-     * @param name:headimg type:string require:1 default:-- desc:头像地址
-     * @param name:nickname type:string require:1 default:-- desc:昵称
-     * @return name:openid type:string default:-- desc:用户openid(未绑定手机号)
-     * @return name:headimg type:string default:-- desc:用户头像地址(未绑定手机号)
-     * @return name:name type:string default:-- desc:用户昵称(未绑定手机号)
-     * @return name:token type:string default:-- desc:用户登录成功后的token值(已绑定手机号)
-     */
-    public function login(){
-        $code = input('code');
-        $headimg = input('headimg');
-        $name = input('name');
-        if(empty($code)){
-            $this->error('参数错误');
-        }
-        $app = Factory::miniProgram(config('app.mini_program'));
-        $data = $app->auth->session($code);
-        if(empty($data['openid'])){
-            $this->error('微信登录失败');
-        }
-        $member = Db::name('store_member')->field('id,phone')->where('openid',$data['openid'])->find();
-        if(empty($member['phone'])){
-            $member_data = array(
-                'openid' => $data['openid'],
-                'headimg' => $headimg,
-                'name' => $name
-            );
-            $this->success('授权成功',$member_data);
-        }
-        $uid = $member['id'];
-        if(empty($uid)){
-            $this->error('数据有误');
-        }
-        $token = self::create_jwt($uid);
-        $this->success('登录成功',$token);
-    }
-    /**
-     * @title 绑定手机号(小程序授权后没绑定手机号)
-     * @desc 绑定手机号
-     * @author QGF
-     * @url /api/Login/binding_phone
-     * @method POST
-     * @tag 绑定手机号
-     * @param name:phone type:int require:1 default:-- desc:要绑定的手机号
-     * @param name:code type:int require:1 default:-- desc:短信验证码
-     * @param name:openid type:string require:1 default:-- desc:微信授权返回的openid
-     * @param name:name type:string require:1 default:-- desc:微信授权返回的用户昵称
-     * @param name:headimg type:string require:1 default:-- desc:微信授权返回的用户头像地址
-     * @return name:token type:string default:-- desc:绑定成功后的token值
-     */
-    public function binding_phone(){
-        $phone = input('phone');
-        $code = input('code');
-        $openid = input('openid');
-        $name = input('name');
-        $headimg = input('headimg');
-        if(empty($phone) || empty($code) || empty($openid) || empty($name) || empty($headimg)){
-            $this ->error('参数错误');
-        }
-        $sms_id = $this->verify_sms($phone,$code);
-        if(empty($sms_id)){
-            $this->error('验证码不正确');
-        }
-        $member_id = Db::name('store_member')->where('phone',$phone)->value('id');
-        if(!$member_id){
-            $data = array(
-                'phone'=>$phone,
-                'name' => $name,
-                'headimg' => $headimg,
-                'openid' => $openid
-            );
-            Db::name('store_member')->insert($data);
-            $member_id = Db::name('store_member')->where('phone',$phone)->value('id');
-            $this->hx_register($member_id,666666);
-        }else{
-            Db::name('store_member')->where('id',$member_id)->update(array('openid'=>$openid));
-        }
-        Db::name('store_member_sms')->where('id',$sms_id)->update(array('used'=>1));
-        $token = self::create_jwt($member_id);
-        $this->success('绑定成功',$token);
-    }
-    /**
-     * @title 注册(app)
-     * @desc 注册
-     * @author QGF
-     * @url /api/Login/register
-     * @method POST
-     * @tag 注册
-     * @param name:phone type:int require:1 default:-- desc:手机号
-     * @param name:code type:int require:1 default:-- desc:短信验证码
-     * @param name:password type:int require:1 default:-- desc:密码
-     * @param name:password_two type:int require:1 default:-- desc:确认密码
-     * @param name:openid type:string require:0 default:-- desc:微信授权返回的openid
-     * @param name:name type:string require:0 default:-- desc:微信授权返回的用户昵称
-     * @param name:headimg type:string require:0 default:-- desc:微信授权返回的用户头像地址
-     */
-    public function register(){
-        $phone = input('phone');
-        $code = input('code');
-        $password = input('password');
-        $password_two = input('password_two');
-
-        $openid = input('openid','');
-        $name = input('name',substr($phone,-4));
-        $headimg = input('headimg','https://zjth2021.oss-cn-beijing.aliyuncs.com/0909a49add201291/a20687c6493d3eab.jpg');
 
-        if(empty($phone) || empty($code) || empty($password) || empty($password_two)){
-            $this->error('参数错误');
-        }
-        if($password != $password_two){
-            $this->error('两次密码不一致');
-        }
-        $sms_id = $this->verify_sms($phone,$code);
-        if(empty($sms_id)){
-            $this->error('验证码不正确');
-        }
-        $member_id = Db::name('store_member')->where('phone',$phone)->value('id');
-        if(!empty($member_id)){
-            $this->error('该手机号已被注册');
-        }
-        $data = array(
-            'phone'=>$phone,
-            'name' => $name,
-            'openid_app' => $openid,
-            'headimg' => $headimg,
-            'password' => md5($password),
-            'decode_password' => $password
-        );
-        Db::name('store_member')->insert($data);
-        $member_id = Db::name('store_member')->where('phone',$phone)->value('id');
-        Db::name('store_member_sms')->where('id',$sms_id)->update(array('used'=>1));
-        $this->hx_register($member_id,666666);
-        $token = self::create_jwt($member_id);
-        $this->success('注册成功',$token);
-    }
-    /**
-     * @title 微信授权(app)
-     * @desc 微信授权
-     * @author QGF
-     * @url /api/Login/we_chat_app
-     * @method POST
-     * @tag 授权
-     * @param name:code type:int require:1 default:-- desc:code值
-     * @return name:-- type:json default:-- desc:微信注册返回授权后的信息(openid:微信openid,name:微信昵称,headimgurl:微信头像地址,token:token值(这时为空)注:仅微信注册有)
-     * @return name:token type:string default:-- desc:用户微信登录成功后的token值(仅用户登录有)
-     */
-    public function we_chat_app(){
-        $code = input('code');
-        if(empty($code)){
-            $this->error('参数错误');
-        }
-        $res = requestGet('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.config('app_program')['app_id'].'&secret='.config('app_program')['secret'].'&code='.$code.'&grant_type=authorization_code');
-        $res = json_decode($res,true);
-        $user_info = requestGet('https://api.weixin.qq.com/sns/userinfo?access_token='.$res['access_token'].'&openid='.$res['openid']);
-        $user_info = json_decode($user_info,true);
-        $data['openid'] = $user_info['openid'];
-        $data['name'] = $user_info['nickname'];
-        $data['headimg'] = $user_info['headimgurl'];
-        $data['token'] = '';
-        $member_id = Db::name('store_member')->where('openid_app',$data['openid'])->value('id');
-        if(empty($member_id)){
-            $this->success('授权成功',$data);
-        }else{
-            $token = self::create_jwt($member_id);
-            $data['token'] = $token;
-            $this->success('登录成功',$data);
-        }
-    }
     /**
-     * @title 验证码登录
-     * @desc 验证码登录
-     * @author QGF
-     * @url /api/Login/code_login
+     * @title 用户统一登录
+     * @desc 用户登录
+     * @author qc
+     * @url /api/Login/unifiedLogin
      * @method POST
-     * @tag 验证码登录
-     * @param name:phone type:int require:1 default:-- desc:手机号
-     * @param name:code type:string require:1 default:-- desc:短信验证码
+     * @tag 登录 授权
+     * @param name:account_type type:int require:1 default:1 desc:账号类型1企业2个人
+     * @param name:account type:int require:1 default:-- desc:账号
+     * @param name:code type:int require:1 default:-- desc:验证码
+     * @param name:facility_type type:int require:1 default:-- desc:设备类型1安卓手机设备,2ios手机设备,3安卓ipad,4iosipad,5pc电脑设备号
+     * @param name:facility_code type:string require:1 default:-- desc:设备号
      * @return name:token type:string default:-- desc:用户登录成功后的token值
      */
-    public function code_login(){
-        $phone = input('phone');
-        $code = input('code');
-        if(empty($phone) || empty($code)){
-            $this ->error('参数错误');
-        }
-        $sms_id = $this->verify_sms($phone,$code);
-        if(empty($sms_id)){
-            $this->error('验证码不正确');
-        }
-        $member_id = Db::name('store_member')->where('phone',$phone)->value('id');
-        if(empty($member_id)){
-            $this->error('你还没有账号,请先注册');
-        }
-        $token = self::create_jwt($member_id);
-        $this->success('登录成功',$token);
-    }
-    /**
-     * @title 密码登录(app端)
-     * @desc 密码登录
-     * @author QGF
-     * @url /api/Login/password_login
-     * @method POST
-     * @tag 登录
-     * @param name:phone type:int require:1 default:-- desc:手机号
-     * @param name:password type:string require:1 default:-- desc:登录密码
-     * @return name:token type:string default:-- desc:token值
-     */
-    public function password_login(){
-        $phone = input('phone');
-        $password = input('password');
-        if(empty($password) || empty($phone)){
-            $this->error('参数错误');
-        }
-        $member_id = Db::name('store_member')->where('phone',$phone)->where('password',md5($password))->value('id');
-        if(!$member_id){
-            $this->error('账号或密码错误');
-        }
-        $token = self::create_jwt($member_id);
-        $this->success('登录成功',$token);
-    }
-    /**
-     * @title 忘记密码(新增)
-     * @desc 忘记密码
-     * @author QGF
-     * @url /api/login/update_login_password
-     * @method POST
-     * @tag 忘记密码
-     * @header name:Authorization require:1 desc:Token
-     * @param name:phone type:int require:1 default:-- desc:手机号
-     * @param name:code type:string require:1 default:-- desc:短信验证码
-     * @param name:password type:string require:1 default:-- desc:新密码
-     * @param name:password_again type:string require:1 default:-- desc:新密码(重复)
-     */
-    public function update_login_password(){
-        $phone = input('phone');
-        $code = input('code');
-        $password = input('password');
-        $password_again = input('password_again');
-        if(empty($phone) || empty($code) || empty($password) || empty($password_again)){
-            $this ->error('参数错误');
-        }
-        $sms_id = $this->verify_sms($phone,$code);
-        if(empty($sms_id)){
-            $this->error('验证码不正确');
-        }
-        if($password != $password_again){
-            $this ->error('两次密码不一致');
-        }
+    public function unifiedLogin()
+    {
+        $code = input('post.code','');
+        $account = input('post.account','');
+        $account_type = input('post.account_type', 1);
+        $facility_type = input('post.facility_type', 1);
+        $facility_code = input('post.facility_code');
+        $ret_data = ['code' => 200, 'token' => ''];
+        $msg = '登录成功';
+        Db::startTrans();
+        try {
+            $check_code = $this->checkPhoneCode($account,$code);
+           // if(!$check_code) $this->exception('验证码错误');
+           // $this->updatePhoneCode($check_code);
+            $where = [];
+            $where[] = $account_type == 1 ? ['email','=',$account] : ['phone','=',$account];
+            $where[] = ['is_deleted','=',0];
+            $user_info = User::where($where)->find();
+            if(!$user_info) {
+                $reg_data = [];
+                $reg_data['account_type'] = $account_type;
+                $reg_data['facility_'.$facility_type] = $facility_code;// 注册设备号
+                if($account_type == 1){
+                    $group_title  = explode('@',$account)[1];
+                    $group_info = UserGroup::where(['title'=>'@'.$group_title])->find();
+                    $reg_data['email'] = $account;
+                    $validate = new UserVali();
+                    if (!$validate->scene('email_login')->check(['email'=>$account])) $this->exception($validate->getError());
+                    if($group_info){
+                        $reg_data['name'] = 'G企业用户_'.$group_info->name.'_'.$group_title;
+                        $check_group = User::where(['group_id'=>$group_info->id,'is_first'=>1])->value('id');//该公司是否有第一个注册的
+                        $reg_data['group_id']  = $group_info->id;
+                        if(!$check_group) $reg_data['is_first']  =1;
+                        if($check_group)$reg_data['group_first']  = $check_group;
+                    }else{
+                        $this->exception('该企业邮箱ID无效');
+                       // $reg_data['name'] = 'G企业用户_'.$group_title;
+                    }
+                }else{
+                    $validate = new UserVali();
+                    if (!$validate->scene('phone_login')->check(['phone'=>$account])) {
+                        $this->exception($validate->getError());
+                    }
+                    $reg_data['phone'] = $account;
+                    $reg_data['name'] = 'G'. substr_replace($account,'****',3,4);
+                }
+                $user_info = User::create($reg_data);
+                if($account_type == 1 && isset_full_check($reg_data,'is_first',1)) User::where('id',$user_info->id)->update(['group_first'=>$user_info->id]);
+                $reg_level = sysconf('vip_experience');
+                // 非企业会员注册,是否怎送会员
+                if($reg_level && $account_type == 2) UserLevelRank::create(['user_id'=>$user_info->id,'level_id'=>$reg_level,'start_time'=>time(),'end_time'=>time()+86400*7,'end_date'=>date('Y-m-d H:i:s',time()+86400*7)]);
+            }else{
+                // 已设置登录设备号
+                if($user_info['status'] != 1) $this->error('用户被禁用');
+               // if($user_info['facility_'.$facility_type] != '' && $facility_code != $user_info['facility_'.$facility_type]) $this->exception('设备号错误');
+                if(!$user_info['facility_'.$facility_type]) User::where('id',$user_info->id)->update(['facility_'.$facility_type=>$facility_code] );
 
-        $member = Db::name('store_member')->field('id,decode_password')->where('phone',$phone)->find();
-        if(empty($member)){
-            $this->error('请先注册');
-        }
-        if($password == $member['decode_password']){
-            $this ->error('要修改的密码和原密码一致,无需修改');
-        }
-        $update_data = array(
-            'password'=>md5($password),
-            'decode_password'=>$password
-        );
-        Db::name('store_member')->where('id',$member['id'])->update($update_data);
-        $this->success('设置成功');
-    }
-    //注册单个用户(环信)
-    public function hx_register($username,$password='666666'){
-        $data = array(
-            'grant_type' => 'client_credentials',
-            'client_id' => 'YXA66NVbVYW7S5SNSM6o7neIPA',
-            'client_secret' => 'YXA6yybYeTS4oAgVEX5PZ8_xGhFd_kU'
-        );
-        $token_res = requestPost('https://a1.easemob.com/1132191221113786/xiognwenwang/token',json_encode($data));
-        $token_res = json_decode($token_res,true);
-        $param = array(
-            'username' => $username*$password,
-            'password' => $password
-        );
-        $hx_account = $this->http_post_json('https://a1.easemob.com/1132191221113786/xiognwenwang/users',json_encode($param),$token_res['access_token']);
-        if(!isset($hx_account['entities'][0]['uuid'])){
-            return false;
+            }
+            $ret_data['token'] =  $this->createJwt($user_info->id,$facility_code);
+            Db::commit();
+        }catch (\Exception $e){
+            $ret_data['code'] = 201;
+            $msg =$e->getMessage();
+            Db::rollback();
         }
-        Db::name('store_member')->where('id',$username)->update(array('hx_username'=>$username*$password,'hx_password'=>$password,'hx_uid'=>$hx_account['entities'][0]['uuid']));
-        return true;
+        $ret_data['code'] == 200 ? $this->success($msg,$ret_data):$this->error($msg,$ret_data);
     }
-    public function http_post_json($url, $jsonStr,$token_res)
-    {
-        $headers = ['Authorization:Bearer '.$token_res,'Content-Type: application/json; charset=utf-8',
-            'Content-Length: ' . strlen($jsonStr)];
-        $ch = curl_init();
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
 
-        $response = curl_exec($ch);
-        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-        curl_close($ch);
 
-        return  json_decode($response,true);
-    }
-
-    /**
-     * @title 发送短信验证码
-     * @desc 发送短信验证码
-     * @author QGF
-     * @url /api/Login/send_sms
-     * @method POST
-     * @tag 短信验证码
-     * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
-     * @return name:code type:string default:-- desc:验证码
-     */
-    public function send_sms(){
-        $phone = input('phone');
-        if(empty($phone)){
-            $this ->error('参数错误');
-        }
-        $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
-        AlibabaCloud::accessKeyClient('LTAI5t7bxx6UhJsFYbQcbaaB', '9qkYH3x0KSiUfkH6FDe8XPu5CfvO9m')->regionId('cn-beijing')->asDefaultClient();
-        try {
-            $result = AlibabaCloud::rpc()
-                ->product('Dysmsapi')
-                ->version('2017-05-25')
-                ->action('SendSms')
-                ->method('POST')
-                ->host('dysmsapi.aliyuncs.com')
-                ->options([
-                    'query' => [
-                        'RegionId' => "cn-hangzhou",
-                        'PhoneNumbers' => $phone,
-                        'SignName' => "雄文网",
-                        'TemplateCode' => "SMS_234275235",
-                        'TemplateParam' => json_encode(array("code"=>$code)),
-                    ],
-                ])->request();
-            $result = $result->toArray();
-            $sms_data = array(
-                'phone'=>$phone,
-                'code'=>$code,
-                'result'=>$result['Message']
-            );
-            Db::name('store_member_sms')->insert($sms_data);
-        } catch (ClientException $e) {
-            echo $e->getErrorMessage() . PHP_EOL;
-        } catch (ServerException $e) {
-            echo $e->getErrorMessage() . PHP_EOL;
-        }
-        $this->success('发送成功',$code);
-    }
-    //校验短信验证码
-    public function verify_sms($phone = '',$code = ''){
-        $store_member_sms = Db::name('store_member_sms')->field('id,code')->where('phone',$phone)->where('used',0)->order('id desc')->find();
-        if($store_member_sms['code'] == $code){
-            return $store_member_sms['id'];
-        }else{
-            return 0;
-        }
-    }
-    //token加密
-    public function create_jwt($uid)
-    {
-        $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到
-        $time = time(); //签发时间
-        $expire = $time + config('app.jwt_time'); //过期时间
-        $token = array(
-            "uid" => $uid,
-            "iss" => "https://zain.com",//签发组织
-            "aud" => "https://zain.com", //签发作者
-            "iat" => $time,
-            "nbf" => $time,
-            "exp" => $expire
-        );
-        $jwt = JWT::encode($token, $key);
-        return $jwt;
-    }
     /**
-     * @title 注册协议
-     * @desc 注册协议
-     * @author QGF
-     * @url /api/Login/agreement
+     * @title 获取验证码
+     * @desc 获取验证码
+     * @author qc
+     * @url /api/Login/getCaptcha
      * @method GET
-     * @tag 注册协议
-     * @return name:-- type:string default:-- desc:注册协议内容(富文本)
+     * @return name:image type:string default:-- desc:图片
+     * @return name:uniqid type:string default:-- desc:uniqid
      */
-    public function agreement(){
-        $this->success('获取成功',htmlspecialchars_decode(sysconf('agreement')));
-    }
-    /**
-     * @title 隐私政策
-     * @desc 隐私政策
-     * @author QGF
-     * @url /api/Login/privacy_policy
-     * @method GET
-     * @tag 隐私政策
-     * @return name:-- type:string default:-- desc:隐私政策(富文本)
-     */
-    public function privacy_policy(){
-        $this->success('获取成功',htmlspecialchars_decode(sysconf('privacy_policy')));
-    }
-    public function  get_token(){
-        $token = self::create_jwt(22);
-        echo $token;exit();
-    }
-    public function chatrooms(){
-        $data = array(
-            'grant_type' => 'client_credentials',
-            'client_id' => 'YXA66NVbVYW7S5SNSM6o7neIPA',
-            'client_secret' => 'YXA6yybYeTS4oAgVEX5PZ8_xGhFd_kU'
-        );
-        $token_res = requestPost('https://a1.easemob.com/1132191221113786/xiognwenwang/token',json_encode($data));
-        $token_res = json_decode($token_res,true);
-        $param = array(
-            'name' => '直播聊天室',
-            'description' => '直播时供大家交流使用',
-            'owner' => '11333322',
-        );
-        $chatrooms_id = $this->http_post_json('https://a1.easemob.com/1132191221113786/xiognwenwang/chatrooms',json_encode($param),$token_res['access_token']);
-        var_dump($chatrooms_id);exit();
+    public function getCaptcha()
+    {
+        $image = CaptchaService::instance();
+        $captcha = ['image' => $image->getData(), 'uniqid' => $image->getUniqid()];
+        $this->success('生成验证码成功', $captcha);
     }
+
+
+
 }

+ 331 - 0
application/api/controller/Mall.php

@@ -0,0 +1,331 @@
+<?php
+namespace app\api\controller;
+use app\common\model\GoodsCate;
+use app\common\model\GoodsSeason;
+use app\common\model\GoodsServe;
+use app\common\model\StoreGoods;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use app\common\service\Activity;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 商城
+ * @controller Mall
+ * @group base
+ */
+class Mall extends Base
+{
+    // 需要登录的
+    protected $need_login = ['goodsCollect'];
+    public function initialize(){
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 获取商品分类
+     * @desc  获取商品分类
+     * @author  qc
+     * @url /api/Mall/getGoodsCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:分类id
+     * @return name:title type:srting default:-- desc:标题
+     * @return name:lev type:srting default:-- desc:分类等级(1,2,3,4)
+     * @return name:children type:array default:-- desc:下级分类(数据同上)
+     */
+    public function getGoodsCate()
+    {
+        $list = GoodsCate::getCateTree();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取商品二级分类
+     * @desc  获取商品二级分类
+     * @author  qc
+     * @url /api/Mall/getSecondCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:一级分类id
+     * @return name:title type:srting default:-- desc:标题
+     * @return name:lev type:srting default:-- desc:分类等级(1,2,3,4)
+     */
+    public function getSecondCate()
+    {
+        $list = GoodsCate::field('id,title,pid,lev')->where(['status'=>1,'is_deleted'=>0,'pid'=>input('get.id')])->order('sort desc ,id desc')->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+    /**
+     * @title 商城商品推荐
+     * @desc 商城商品推荐
+     * @author qc
+     * @method GET
+     * @url /api/Mall/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:id
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:low_price type:float default:-- desc:价格
+     */
+    public function getRecommendList()
+    {
+        $search_log =  UserSearch::getSearchTitle($this->user_id,7);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.name like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = 'a.id,name,cover,low_price,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_store_goods';
+        $order_by_two = 'id';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.status =1 AND a.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取商品列表
+     * @desc  获取商品列表
+     * @author  qc
+     * @url /api/Mall/getGoodsList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:goods_name type:string require:0  default:-- desc:商品名称
+     * @param  name:first_classify type:int require:0  default:-- desc:一级分类id
+     * @param  name:second_classify type:int require:0  default:-- desc:二级分类id
+     * @param  name:sort_type type:int default:1 desc:排序--1默认2时间升序3时间降序
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:image type:string default:-- desc:商品展示图[多张|隔开]
+     * @return name:content type:string default:-- desc:商品详情图[多张|隔开]
+     * @return name:low_price type:float default:-- desc:最低售价
+     * @return name:max_price type:float default:-- desc:最高售价
+     * @return name:low_original type:float default:-- desc:最低原价格
+     * @return name:total_num type:int default:-- desc:商品总数量
+     * @return name:detail type:int default:-- desc:商品详情
+     * @return name:first_classify type:int require:0  default:-- desc:一级分类id
+     * @return name:second_classify type:int require:0  default:-- desc:二级分类id
+     * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板
+     * @return name:freight_id type:int default:-- desc:模板id(freight_type=1)
+     * @return name:postage type:float default:-- desc:运费(freight_type=0)
+     * @return name:item_list type:array default:-- desc:商品多规格列表
+     * @return name:item_list.spec_info type:array default:-- desc:规格型号设置['规格组id'=>'规格id','规格组id'=>'规格id'];
+     * @return name:item_list.goods_no type:string default:-- desc:规格货号
+     * @return name:item_list.goods_title:string default:-- desc:规格标题
+     * @return name:item_list.cover type:string default:-- desc:规格封面
+     * @return name:item_list.stock type:int default:-- desc:剩余库存
+     * @return name:item_list.original_price type:float default:-- desc:原价
+     * @return name:item_list.sell_price type:float default:-- desc:售价
+     * @return name:item_list.virtual type:int default:-- desc:虚拟销量
+     * @return name:item_list.weight type:float default:-- desc:重量【kg】
+     * @return name:total_num type:int default:-- desc:总数
+     */
+    public function getGoodsList(){
+        $all_cate = GoodsCate::field('id,title')->select()->toArray();
+        $all_cate = array_column($all_cate,null,'id');
+        $input = input('get.');
+        $sel_where = [];
+        $sel_where[] = ['status','=',1];
+        $sel_where[] = ['is_deleted','=',0];
+        $sort_type = input('get.sort_type',1);
+        if(isset_full($input,'goods_name')) {
+            $sel_where[] = ['name','like',"%".$input['goods_name']."%"];
+            if($this->user_id) UserSearch::saveSearchTitle($this->user_id,$input['goods_name'],7);
+        }
+        if(isset_full($input,'first_classify'))$sel_where[] = ['first_classify','=',$input['first_classify']];
+        if(isset_full($input,'second_classify'))$sel_where[] = ['second_classify','=',$input['second_classify']];
+
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        $list = StoreGoods::with(['itemList'])
+            ->field('specs,lists',true)
+            ->where($sel_where)->limit($this->off_set,$this->page_num)
+            ->order($order)
+            ->select()->toArray();
+        foreach ($list as &$v){
+            $v['first_classify_name'] = isset($all_cate[$v['first_classify']]['title']) ? $all_cate[$v['first_classify']]['title']:'';
+            $v['second_classify_name'] = isset($all_cate[$v['second_classify']]['title']) ? $all_cate[$v['second_classify']]['title']:'';
+            $v['low_original'] = empty($v['item_list']) ? 0 :  min(array_column($v['item_list'],'original_price'));
+            $v['low_price'] = empty($v['item_list']) ? 0 : min(array_column($v['item_list'],'sell_price'));
+            $v['max_price'] = empty($v['item_list']) ? 0 : max(array_column($v['item_list'],'sell_price'));
+            $v['total_num'] =  empty($v['item_list']) ? 0 :array_sum(array_column($v['item_list'],'base_stock'));
+        }
+        $total_num =  StoreGoods::where($sel_where)->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+
+    }
+
+    /**
+     * @title 获取商品详情
+     * @desc  获取商品详情
+     * @author  qc
+     * @url /api/Mall/getGoodsDetail
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:goods_id  type:int require:1  default:0 desc:商品id
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:low_price type:float default:-- desc:最低价格
+     * @return name:max_price type:float default:-- desc:最高价格(下划线公用)
+     * @return name:low_seckill type:float default:-- desc:最低秒杀价格(有秒杀活动)
+     * @return name:low_group type:float default:-- desc:最低拼团价格(有拼团活动)
+     * @return name:low_discount type:float default:-- desc:最低折扣价格(有折扣活动)
+     * @return name:discount type:float default:-- desc:商品折扣(没有折扣为10,有折扣活动,例如75折,值为7.5)
+     * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板
+     * @return name:freight_id type:int default:-- desc:模板id(freight_type=1)
+     * @return name:postage type:float default:-- desc:运费(freight_type=0)
+     * @return name:is_collect type:int default:-- desc:是否收藏(1是0否)
+     * @return name:item_list type:array default:-- desc:商品多规格列表
+     * @return name:item_list.spec_info type:array default:-- desc:规格型号设置;
+     * @return name:item_list.goods_no type:string default:-- desc:规格货号
+     * @return name:item_list.stock type:int default:-- desc:剩余库存
+     * @return name:item_list.original_price type:float default:-- desc:原价
+     * @return name:item_list.sell_price type:float default:-- desc:售价
+     */
+    public function getGoodsDetail()
+    {
+        $goods_id = input('goods_id');
+        $detail = StoreGoods::with(['itemList'])->field('specs,lists',true)->where('id',$goods_id)->find()->toArray();
+        $detail['max_price'] = max(array_column($detail['item_list'],'original_price'));
+        $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,6,$detail['id']);
+        UserTrack::crateTrack($this->user_id,6,$goods_id,0);
+        $this->success('oK',['goods_info'=>$detail]);
+    }
+
+    /**
+     * @title 收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Mall/goodsCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:商品id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function goodsCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,6,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+    /**
+     * @title 商品浏览记录
+     * @desc  商品浏览记录
+     * @author  qc
+     * @url /api/Mall/getGoodsHistory
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:name type:string require:0  default:-- desc:商品名称
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:low_price type:float default:-- desc:最低售价
+     */
+    public function getGoodsHistory()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',6];
+        $title = input('get.name');
+        if($title)  $sel_where[]  = ['i.name','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.date,t.first_id goods_id,i.name,i.cover,i.low_price')
+            ->leftJoin('StoreGoods i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 商品收藏列表
+     * @desc  商品收藏列表
+     * @author  qc
+     * @url /api/Mall/getGoodsCollectList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:name type:string require:0  default:-- desc:商品名称
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:low_price type:float default:-- desc:最低售价
+     */
+    public function getGoodsCollectList()
+    {
+        $sel_where  = [];
+        $title = input('get.name');
+        if($title)  $sel_where[]  = ['i.name','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',6];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id goods_id,i.name,i.cover,i.low_price')
+            ->leftJoin('StoreGoods i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取我发布的商品列表
+     * @desc  获取我发布的商品列表
+     * @author  qc
+     * @url /api/Mall/getOwnGoodsList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:name type:string require:0  default:-- desc:商品名称
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:low_price type:float default:-- desc:最低售价
+     */
+    public function getOwnGoodsList()
+    {
+        $list = StoreGoods::field('id,name,desc,create_at,low_price')
+            ->where(['user_id'=>$this->user_id])
+            ->order(['sort'=>'desc','id'=>'desc'])
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+}

+ 155 - 0
application/api/controller/Message.php

@@ -0,0 +1,155 @@
+<?php
+namespace app\api\controller;
+use app\common\model\GoodsOrder;
+use app\common\model\StoreGoodsItem;
+use app\common\model\UserMessage;
+use library\tools\Data;
+/**
+ * @title 消息管理
+ * @controller Message
+ * @group base
+ */
+class Message extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+
+    /**
+     * @title 获取视频平台消息
+     * @desc  获取视频平台消息
+     * @author  qc
+     * @url /api/Message/getVideoPlatformNews
+     * @method GET
+     * @return name:content type:string default:-- desc:标题
+     * @return name:is_read type:string default:-- desc:是否已读(0否)
+     */
+    public function getVideoPlatformNews()
+    {
+        $video = PlatformMessage::where(['type'=>1])->order('id desc')->find();
+        if(!$video)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
+        $detail =  $video->toArray();
+        $detail['is_read'] =  PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>1,'relation_id'=>$detail['id']])->count();
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 获取交易物流消息(菜单)
+     * @desc  获取交易物流消息
+     * @author  qc
+     * @url /api/Message/getExpressMessageMenu
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:content type:string default:-- desc:内容
+     * @return name:is_read type:int default:-- desc:是否已读(0否)
+     */
+    public function getExpressMessageMenu()
+    {
+        $where[] =  ['user_id','=',$this->user_id];
+        $where[] =  ['type_id','in','2,3'];
+        $detail = UserMessage::where($where)->order('id desc')->find();
+        $this->success('ok',['detail'=>$detail ? $detail->toArray():['content'=>'','is_read'=>0]]);
+    }
+
+
+    /**
+     * @title 获取交易物流消息(内页列表)
+     * @desc  获取交易物流消息(内页列表)
+     * @author  qc
+     * @url /api/Message/getExpressMessageList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int  default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:content type:string default:-- desc:内容
+     * @return name:type_id type:int default:-- desc:类型[2发货通知,3收货通知]
+     * @return name:order_info type:array default:-- desc:订单信息
+     * @return name:order_info.id type:int default:-- desc:订单id
+     * @return name:order_info.express_send_no type:string default:-- desc:发货单号
+     * @return name:order_info.order_no type:string default:-- desc:订单号
+     * @return name:goods_list type:array default:-- desc:商品列表
+     * @return name:goods_list.goods_name type:string default:-- desc:商品名
+     * @return name:goods_list.cover type:string default:-- desc:商品图
+     * @return name:goods_list.goods_spec type:string default:-- desc:商品规格
+     */
+    public function getExpressMessageList()
+    {
+        $where[] =  ['user_id','=',$this->user_id];
+        $where[] =  ['type_id','in','2,3'];
+        $list = UserMessage::where($where)
+            ->limit($this->off_set,$this->page_num)
+            ->order('id desc')
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['goods_list'] = StoreGoodsItem::field('goods_name,cover,goods_spec')->where(['order_id'=>$v['relation_id']])->select()->toArray();
+            $v['order_info'] = GoodsOrder::field('id,order_no,express_send_no')->where('id',$v['relation_id'])->find()->toArray();
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取活动平台消息(菜单)
+     * @desc  获取活动平台消息(菜单)
+     * @author  qc
+     * @url /api/Message/getActivityNews
+     * @method GET
+     * @return name:content type:string default:-- desc:标题
+     * @return name:is_read type:string default:-- desc:是否已读(0否)
+     */
+    public function getActivityNews()
+    {
+        $detail = PlatformMessage::where(['type'=>2])->order('id desc')->find();
+        if(!$detail)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
+        $detail =  $detail->toArray();
+        $detail['is_read'] =  PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$detail['id']])->count();
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 获取活动平台消息(内页)
+     * @desc  获取活动平台消息(内页)
+     * @author  qc
+     * @url /api/Message/getActivityNewsList
+     * @method GET
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:start_time type:string default:-- desc:活动开始时间
+     * @return name:end_time type:string default:-- desc:活动结束时间
+     * @return name:goods_list type:array default:-- desc:商品列表(最多查3个)
+     * @return name:goods_list.name type:string default:-- desc:商品名
+     * @return name:goods_list.cover type:string default:-- desc:商品图
+     */
+    public function getActivityNewsList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $list = SeckillActivity::where($sel_where)
+            ->field('id,title,cover,start_time,end_time')
+            ->order('id desc')->limit(0,5)->select()->toArray();
+        if(!empty($list)){
+            $relation_id = PlatformMessage::where(['type'=>2])->max('id');// 最新的一条视频推荐
+            Data::save('PlatformReadLog',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id,'create_at'=>date('Y-m-d H:i:s')],'user_id',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id]);
+        }
+        foreach ($list as &$v){
+            $v['goods_list'] = SeckillGoods::field('g.id,g.name,g.cover')
+                ->alias('s')
+                ->leftJoin('StoreGoods g','g.id = s.goods_id')
+                ->order('s.id desc')
+                ->limit(0,3)
+                ->select()->toArray();
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+}

+ 675 - 410
application/api/controller/Order.php

@@ -1,474 +1,739 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | ThinkAdmin
-// +----------------------------------------------------------------------
-// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
-// +----------------------------------------------------------------------
-// | 官方网站: http://demo.thinkadmin.top
-// +----------------------------------------------------------------------
-// | 开源协议 ( https://mit-license.org )
-// +----------------------------------------------------------------------
-// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
-// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
-// +----------------------------------------------------------------------
-
 namespace app\api\controller;
-
-use app\api\controller\Alipay;
-use app\api\controller\Area;
-use app\api\controller\Base;
+use app\common\model\OrderComment;
+use app\common\model\ShoppingTrolley;
+use app\common\model\DeliveryAddress;
+use app\common\model\StoreGoods;
+use app\common\model\StoreGoodsItem;
+use app\common\model\GoodsOrder;
+use app\common\model\GoodsOrderItem;
+use app\common\model\User;
+use app\common\model\UserMessage;
+use app\common\service\ExpressService;
 use think\Db;
-use think\Model;
-use EasyWeChat\Factory;
+use think\Exception;
+
 /**
- * @title 订单管理
+ * @title 订单
  * @controller Order
- * @group member
+ * @group base
  */
 class Order extends Base
 {
-    function initialize(){
-        $this->check_login();
+    public $int_rate = 100;
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
     }
+
     /**
-     * @title 提交订单
-     * @desc 提交订单
-     * @author QGF
-     * @url /api/Order/create_order
-     * @method POST
-     * @tag 提交订单
+     * @title 订单确认页面(立即购买)
+     * @desc  订单确认页面
+     * @author qc
+     * @url /api/Order/confirmOrderImmediately
+     * @method GET
      * @header name:Authorization require:1 desc:Token
-     * @param name:type type:int require:1 default:-- desc:下单的物品类型(1:课程,2:书籍)
-     * @param name:id type:int require:1 default:-- desc:课程或书籍ID
-     * @param name:address_id type:int require:1 default:-- desc:收货地址ID(当type等于2时必传,当type等于1并且有附带品也必传)
-     * @param name:num type:int require:1 default:1 desc:购买数量(默认1)
-     * @param name:platform type:tinyint require:1 default:1 desc:平台(1:小程序(默认),2:app)
-     * @param name:pay_type type:int require:1 default:-- desc:支付类型(1:微信,2:支付宝)
-     * @return name:config type:array default:-- desc:支付配置(微信和支付宝返回值不同)
+     * @param name:goods_id type:int require:1  default:0 desc:商品id
+     * @param name:spec_id type:int require:1  default:0 desc:商品多规格的规格id
+     * @param name:num type:int default:1 desc:数量
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover type:string default:-- desc:商品封面图
+     * @return name:desc type:string default:-- desc:商品简述(副标题)
+     * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板
+     * @return name:freight_id type:int default:-- desc:模板id(freight_type=1)
+     * @return name:postage type:float default:-- desc:运费(freight_type=0)
+     * @return name:total_price type:float default:-- desc:商品金额[不含运费]
+     * @return name:freight type:float default:-- desc:运费
+     * @return name:freight_code type:int default:1 desc:运费提示编号【1所选地址支持发货,0所选地址不支持发货】
+     * @return name:freight_msg type:string default:-- desc:运费提示信息【freight_code=1忽略】
+     * @return name:goods_no type:string default:-- desc:规格货号
+     * @return name:goods_spec type:string default:-- desc:规格
+     * @return name:sell_price type:float default:-- desc:售价
+     * @return name:add_info type:array default:-- desc:默认收货地址(设置才有)
+     * @return name:add_info.pro_id type:int   default:-- desc:省id
+     * @return name:add_info.city_id type:int   default:-- desc:市id
+     * @return name:add_info.county_id type:int  default:-- desc:县区id
+     * @return name:add_info.pro_name type:string  default:-- desc:省名
+     * @return name:add_info.city_name type:string  default:-- desc:市名
+     * @return name:add_info.county_name type:string  default:-- desc:县区名
+     * @return name:add_info.detail type:string  default:-- desc:详细地址
+     * @return name:add_info.phone type:string  default:-- desc:联系电话
+     * @return name:add_info.name type:string   default:-- desc:联系人
+     * @return name:freight type:float default:-- desc:运费
+     * @return name:freight_code type:int default:1 desc:运费提示编号【1所选地址支持发货,0所选地址不支持发货】
+     * @return name:freight_msg type:string default:-- desc:运费提示信息【freight_code=1忽略】
      */
-    public function create_order(){
-        $uid = $this->uid;
-        $type = input('type');
-        $id = input('id');
-        $address_id = input('address_id',0);
-        $num = input('num',1);
-        $platform = input('platform',1);
-        $pay_type = input('pay_type');
-        if(empty($type) || empty($id) || empty($pay_type)){
-            $this->error('参数错误');
-        }
-        if($type == 1){
-            $goods_info = Db::name('store_goods')->field('goods_price,is_incidental')->where('id',$id)->where('type',2)->where('status',1)->where('is_deleted',0)->find();
-            if(empty($goods_info)){
-                $this->error('课程信息有误');
-            }
-            if($goods_info['is_incidental'] == 1){
-                if(empty($address_id)){
-                    $this->error('参数错误');
-                }
-            }
-            $price_total = $goods_info['goods_price'];
-        }else{
-            if(empty($address_id)){
-                $this->error('参数错误');
-            }
-            $book_info = Db::name('store_book')->field('price')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
-            if(empty($book_info)){
-                $this->error('书籍信息有误');
+    public function confirmOrderImmediately(){
+        $goods_id = input('get.goods_id');
+        $spec_id = input('get.spec_id');
+        $num = input('get.num',1);
+        $field = 'id,name,cover,desc,low_price,status,is_deleted,freight_type,postage,freight_id';
+        $goods_info = StoreGoods::field($field)->where('id',$goods_id)->find()->toArray();
+        $spec_info = StoreGoodsItem::where('id',$spec_id)->find()->toArray();
+        $goods_info['total_price']= bcmul($spec_info['sell_price'],$num,2);
+        $goods_info['goods_spec']= $spec_info['goods_spec'];
+        $goods_info['goods_no']= $spec_info['goods_no'];
+        $goods_info['sell_price']= $spec_info['sell_price'];
+        $add_info = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
+        $freight = 0;
+        if($add_info){
+            $goods_freight = ExpressService::getGoodsExpressPrice($goods_info,$add_info->id,$num);
+            if($goods_freight['code'] !=200){
+                $this->is_commit =  false;
+                $this->ret_msg =  $goods_freight['msg'];
             }
-            $price_total = sprintf('%.2f',$book_info['price'] * $num);
-        }
-        $order_no = get_order_sn();
-        $pay_no = get_order_sn();
-        $order_data = array(
-            'user_id' => $uid,
-            'order_no' => $order_no,
-            'goods_id' => $id,
-            'type' => $type,
-            'is_incidental' => isset($goods_info['is_incidental'])?$goods_info['is_incidental']:'',
-            'num' => $num,
-            'address_id' => $address_id,
-            'price_total' => $price_total,
-            'price_amount' => $price_total,
-            'pay_type' => $pay_type,
-            'pay_no' => $pay_no
-        );
-        Db::name('store_order')->insert($order_data);
-        $data = $this->pay_config($pay_no,$pay_type,$platform);
-        if($data['code']){
-            $this->success($data['msg'],$data['data']);
-        }else{
-            $this->error($data['msg']);
+           if($goods_freight['code'] == 200) $freight = $goods_freight['freight'];
         }
+        $this->success('ok',['goods_info'=>$goods_info,
+            'add_info' =>$add_info ? $add_info->toArray():null,
+            'freight' =>$freight,
+            'freight_msg' => $this->ret_msg,
+            'freight_code' => $this->is_commit ? 1 :0
+        ]);
     }
+
     /**
-     * @title 立即支付
-     * @desc 立即支付
-     * @author QGF
-     * @url /api/Order/pay_order
+     * @title 生成订单(立即购买)
+     * @desc  立即购买场景
+     * @author  qc
+     * @url /api/Order/createOrderImmediately
      * @method POST
-     * @tag 支付
      * @header name:Authorization require:1 desc:Token
-     * @param name:order_id type:int require:1 default:-- desc:订单ID
-     * @param name:platform type:tinyint require:1 default:1 desc:平台(1:小程序(默认),2:app)
-     * @param name:pay_type type:int require:0 default:-- desc:支付类型(1:微信,2:支付宝)
-     * @return name:config type:array default:-- desc:支付配置(微信和支付宝返回值不同)
+     * @param name:goods_id type:int require:1  default:0 desc:商品id
+     * @param name:spec_id type:int require:1  default:0 desc:商品多规格的规格id
+     * @param name:num type:int default:1 desc:数量
+     * @param name:add_id type:int default:1 desc:收货地址id
+     * @param name:remark type:string default:1 desc:订单备注
+     * @return name:order_id type:int default:1 desc:订单id
      */
-    public function pay_order(){
-        $uid = $this->uid;
-        $order_id = input('order_id');
-        $pay_type = input('pay_type',0);
-        $platform = input('platform',1);
-        if(empty($order_id)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('id,price_total,pay_type')->where('user_id',$uid)->where('id',$order_id)->where('status',0)->find();
-        if(empty($order_info)){
-            $this->error('订单信息有误');
-        }
-        if(empty($pay_type)){
-            $pay_type = $order_info['pay_type'];
-        }
-        $pay_no = get_order_sn();
-        Db::name('store_order')->where('id',$order_id)->update(array('pay_no'=>$pay_no,'pay_type'=>$pay_type));
-        $data = $this->pay_config($pay_no,$pay_type,$platform);
-        if($data['code']){
-            $this->success($data['msg'],$data['data']);
-        }else{
-            $this->error($data['msg']);
+    public function createOrderImmediately()
+    {
+        $goods_id = input('post.goods_id');
+        $spec_id = input('post.spec_id');
+        $num = input('post.num');
+        $add_id = input('post.add_id');
+        $remark = input('post.remark');
+        if(!$goods_id || !$spec_id)  $this->error('请选择商品');
+        if($num <=0 ) $this->error('数量有误');
+        if(!$add_id ) $this->error('请选择收货地址');
+        Db::startTrans();
+        try {
+            $add_info = DeliveryAddress::find($add_id)->toArray();
+            $order_insert = [
+                'user_id' => $this->user_id,
+                'order_no' => get_order_sn(),
+                'goods_num' => $num,
+                'pro_name' => $add_info['pro_name'],
+                'city_name' => $add_info['city_name'],
+                'county_name' => $add_info['county_name'],
+                'street_name' => $add_info['street_name'],
+                'user_name' => $add_info['name'],
+                'add_detail' => $add_info['detail'],
+                'phone' => $add_info['phone'],
+                'remark' => $remark,
+            ];
+            $goods_info = StoreGoods::with(['itemList'=>function($query)use($spec_id){
+                return $query->where('id',$spec_id)->where('is_deleted',0);
+            }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find();
+            if(!$goods_info) throw new Exception('商品已下架');
+            $goods_info = $goods_info->toArray();
+            if(empty($goods_info['item_list'])) throw new Exception('该规格已下架');
+            if($goods_info['item_list'][0]['stock'] < $num) throw new Exception('库存不足');
+            $order_insert['original_price'] = bcmul($num,$goods_info['item_list'][0]['original_price'],2);// 原价
+            $true_cost = $goods_info['item_list'][0]['sell_price'];//实际售价
+            $spec_info = $goods_info['item_list'][0];
+            $price_goods   =  bcmul($num,$true_cost,2); // 需要支付商品价格
+            // 获取运费信息
+            $exp_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$num);
+            if($exp_data['code'] != 200 ) throw  new Exception($exp_data['msg']);
+            $price_express =  $exp_data['freight']; //  商品运费
+            //订单金额 =  商品金额 + 运费
+            $order_money = bcadd($price_goods,$price_express ,2);
+            if($order_money < 0) $this->exception('订单金额有误');
+            $order_insert['price_total'] = $order_money;
+            $order_insert['price_goods'] = $price_goods;
+            $order_insert['price_express'] = $price_express;
+            $order_info = GoodsOrder::create($order_insert);
+            $order_item = [
+                'user_id' => $this->user_id,
+                'order_id' => $order_info->id,
+                'goods_id' => $goods_id,
+                'goods_no' => $spec_info['goods_no'],
+                'goods_spec' => $spec_info['goods_spec'],
+                'goods_name' => $goods_info['name'],
+                'spec_title' => $spec_info['spec_title'],
+                'spec_id' => $spec_info['id'],
+                'cover' => $goods_info['cover'],
+                'original_price' => $spec_info['original_price'],
+                'sell_price' => $true_cost,
+                'pay_price' => $order_money,
+                'num' => $num,
+            ];
+            GoodsOrderItem::create($order_item);
+            StoreGoods::where('id',$goods_id)->setDec('stock',$num);
+
+            StoreGoodsItem::where('id',$spec_id)->setDec('stock',$num);
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg = $e->getMessage();
+            Db::rollback();
         }
+        $this->is_commit ? $this->success('添加成功',['order_id'=>$order_info->id]):$this->error($this->ret_msg);
     }
-    //获取支付参数
-    function pay_config($pay_no,$pay_type,$platform){
-        $uid = $this->uid;
-        $price_total = Db::name('store_order')->where('pay_no',$pay_no)->value('price_total');
-        if($pay_type == 1){    //微信支付
-            $notify_url = $this->request->root(true) . '/api/Pay/order_notify';
-            $price_total = 0.01;
-            if ($platform == 1) {        //小程序支付
-                $openid = Db::name('store_member')->where('id',$uid)->value('openid');
-                if(empty($openid)){
-                    $this->error('缺少微信ID');
+
+    /**
+     * @title 生成订单(购物车)
+     * @desc  购物车场景
+     * @author  qc
+     * @url /api/Order/createOrderByTrolley
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:ids type:int require:1  default:0 desc:购物车记录id
+     * @param name:add_id type:int default:1 desc:收货地址id
+     * @param name:remark type:string default:1 desc:订单备注
+     * @return name:order_id type:int default:1 desc:订单id
+     */
+    public function createOrderByTrolley()
+    {
+        $ids  = input('post.ids');
+        $add_id = input('post.add_id');
+        if(!$ids) $this->error('请选择商品');
+        if(!$add_id ) $this->error('请选择收货地址');
+        $ret_data = ['order_id'=>0];
+        Db::startTrans();
+        try{
+            $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray();
+            $trolley_list = ShoppingTrolley::with(['goodsSpec','goodsInfo'])->where('id','in',$ids)->select()->toArray();
+            if(empty($trolley_list)) $this->exception('购物车记录有误');
+            // 计算运费
+            $price_express = 0;// 总运费
+            $goods_list = ShoppingTrolley::where('id','in',$ids)->field('goods_id,sum(num) as total_num')->group('goods_id')->select()->toArray();
+            foreach ($goods_list as $v){
+                $goods_info = StoreGoods::field('name,freight_type,freight_id,postage')->where('id',$v['goods_id'])->find()->toArray();
+                $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$v['total_num']);
+                if($freight_data['code'] != 200){
+                    $this->exception($goods_info['name'].$freight_data['msg']);
+                    break;
                 }
-                $config = Pay::wx_pay('订单支付',$pay_no,$price_total,$notify_url,'JSAPI',$openid);
-            }else{
-                $config = Pay::wx_pay('订单支付',$pay_no,$price_total,$notify_url,'APP','');
+                $price_express += $freight_data['freight'];
             }
-            if($config){
-                Db::commit();
-                $data = array(
-                    'msg' => '支付成功',
-                    'code' => 1,
-                    'data' => ['jump'=>1,'config'=>$config]
-                );
-            }else{
-                Db::rollback();
-                $data = array(
-                    'msg' => '支付失败',
-                    'code' => 0,
-                    'data' => []
-                );
+            // 计算运费 end
+            $price_goods =  0; // 商品总金额
+            $original_total = 0; // 商品总原价
+            $total_num = 0;// 商品总数量
+            $order_item = [];// 订单列表
+            foreach ($trolley_list as $trolley)
+            {
+                $price_goods += $trolley['num'] * $trolley['goods_spec']['sell_price'];
+                $original_total += $trolley['num'] * $trolley['goods_spec']['original_price'];
+                $total_num +=$trolley['num'];
+                $order_item[] = [
+                    'user_id' => $this->user_id,
+                    'goods_id' => $trolley['goods_id'],
+                    'goods_no' => $trolley['goods_spec']['goods_no'],
+                    'goods_name' => $trolley['goods_info']['name'],
+                    'goods_spec' => $trolley['goods_spec']['goods_spec'],
+                    'spec_title' => $trolley['goods_spec']['spec_title'],
+                    'spec_id' => $trolley['spec_id'],
+                    'cover' =>  $trolley['goods_info']['cover'],
+                    'original_price' => $trolley['goods_spec']['original_price'],
+                    'sell_price' => $trolley['goods_spec']['sell_price'],
+                    'num' => $trolley['num'],
+                    'trolley_id' => $trolley['id'],
+                ];
             }
-        }else{    //支付宝支付
-            $notify_url = $this->request->root(true) . '/api/Alipay/order_notify';
-            $price_total = 0.01;
-            $ali_obj = new Alipay();
-            $config = $ali_obj::ali_pay('订单支付',$pay_no,$price_total,$notify_url);
-            if($config){
-                Db::commit();
-                $data = array(
-                    'msg' => '支付成功',
-                    'code' => 1,
-                    'data' => ['jump'=>1,'config'=>$config]
-                );
-            }else{
-                Db::rollback();
-                $data = array(
-                    'msg' => '支付失败',
-                    'code' => 0,
-                    'data' => []
-                );
+            $order_insert = [
+                'user_id' => $this->user_id,
+                'order_no' => get_order_sn(),
+                'goods_num' => $total_num,
+                'pro_name' => $add_info['pro_name'],
+                'city_name' => $add_info['city_name'],
+                'county_name' => $add_info['county_name'],
+                'user_name' => $add_info['name'],
+                'add_detail' => $add_info['detail'],
+                'phone' => $add_info['phone'],
+            ];
+            $price_total = bcadd($price_goods ,$price_express,2);
+            $order_insert['price_total'] = $price_total;
+            $order_insert['price_goods'] = $price_goods ;
+            $order_insert['original_total'] = $original_total ;
+            $order_insert['price_express'] = $price_express ;
+            $order_info = GoodsOrder::create($order_insert);// 生成订单
+            array_walk($order_item,function (&$v,$k)use ($order_info){
+                $v['order_id'] = $order_info->id;
+            });
+            (new GoodsOrderItem())->insertAll($order_item);// 生成订单商品详情
+            ShoppingTrolley::where('id','in',$ids)->delete();// 删除购物车
+            $ret_data['order_id'] =  $order_info->id;
+            Db::commit();
+        }catch (\Exception $e){
+            $this->ret_msg = $e->getMessage();
+            $this->is_commit = false;
+            Db::rollback();
+        }
+        $this->transReturn($ret_data);
+    }
+
+    /**
+     * @title 订单支付
+     * @desc  订单支付
+     * @author  qc
+     * @url /api/Order/payOrder
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
+     * @param  name:pay_type type:int require:1  default:0 desc:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付)
+     * @return name:config type:array default:0 desc:小程序支付配置
+     * @return name:config.appId type:string default:-- desc:公众账号ID(小程序支付)
+     * @return name:config.signType type:string default:-- desc:签名类型(小程序支付)
+     * @return name:config.paySign type:string default:-- desc:签名(小程序支付)
+     * @return name:config.nonceStr type:string default:-- desc:随机字符串(小程序支付&&APP支付)
+     * @return name:config.timestamp type:string default:-- desc:时间戳小程序支付&&APP支付)
+     * @return name:config.partnerid type:string default:-- desc:商户号(App支付)
+     * @return name:config.prepayid type:string default:-- desc:唯一支付号(App支付)
+     * @return name:config.package type:string default:-- desc:package(App支付)
+     * @return name:config.sign type:string default:-- desc:签名(App支付)
+     * @return name:code_url type:string default:-- desc:付款码url
+     */
+    public function payOrder()
+    {
+        $order_id = input('post.order_id');
+        $pay_type = input('post.pay_type');
+        $order_info = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
+        if($order_info['status'] != 0) $this->error('订单状态错误');
+        if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
+        if($order_info['price_total'] <= 0) $this->error('订单金额错误');
+        $pay_no  = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
+        if(!$order_info['pay_no']) GoodsOrder::where('id',$order_id)->update(['pay_no'=>$pay_no]);
+        $user_info = User::with('wallet')->where('id',$this->user_id)->find()->toArray();
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>''];
+        Db::startTrans();
+        GoodsOrder::where('id',$order_id)->update(['pay_type'=>$pay_type]);
+        try {
+            switch ($pay_type){
+                case 1://微信
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                    $pay_config['config']['pay_no'] = $pay_no;
+                    $pay_config['config']['notify_url'] = $notify_url;
+                    $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                    $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 2:
+                    $notify_url = $this->request->root(true) . '/api/Alipay/goodsOrderNotify';
+                    $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
+                    $config = Alipay::ali_pay_pc('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 3:  //移动支付(微信)
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 4://移动支付(支付宝)
+                    $notify_url = $this->request->root(true) . '/api/Alipay/goodsOrderNotify';
+                    $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url,);
+                    $ret_data['config']['ali_url'] = $config;
+                    $ret_data['ali_url'] = $config;
+                    break;
+                case 5 :
+                    if(!$user_info['openid']) $this->exception('请绑定openid');
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+
             }
+
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg =  $e->getMessage();
+            Db::rollback();
         }
-        return $data;
+        $this->transReturn($ret_data);
     }
+
     /**
-     * @title 订单列表
-     * @desc 订单列表
-     * @author QGF
-     * @url /api/Order/order_list
+     * @title 获取订单列表
+     * @desc 订单优惠:int_cash + coupon_cash
+     * @author qc
      * @method GET
-     * @tag 订单列表
+     * @url /api/Order/getOrderList
      * @header name:Authorization require:1 desc:Token
-     * @param name:status type:tinyint require:0 default:-1 desc:订单的状态(-1:全部订单(默认),0:待支付,1:已支付,2:已完成)
-     * @param name:keyword type:string require:0 default:-- desc:搜索的服务类目名称
-     * @param name:page type:int require:0 default:1 desc:页数(默认为1)
-     * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
-     * @return name:id type:int default:-- desc:订单ID
-     * @return name:order_no type:string default:-- desc:订单编号
-     * @return name:type type:string default:-- desc:商品类型(1:课程,2:书籍教材)
-     * @return name:price_total type:int default:-- desc:支付金额
-     * @return name:status type:int default:-- desc:订单状态(0:未支付,1:已支付,2:已完成,3:已退款,4:已取消)
-     * @return name:refund_status type:string default:-- desc:退款状态(0:未申请退款,1:退款中,2:退款成功)
-     * @return name:goods_name type:string default:-- desc:商品名称
-     * @return name:goods_cover type:string default:-- desc:商品封面图地址
+     * @param  name:page type:int  default:1 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:status type:int default:-1  desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
+     * @param  name:pay_state type:int default:-1  desc:支付状态(-1全部,0未支付,1已支付)
+     * @param  name:cancel_state type:int default:-1  desc:取消状态(-1全部,0未取消,1已取消)
+     * @param  name:apply_refund type:int default:-1  desc:申请退款状态(-1全部,0未申请||已取消,1已申请)
+     * @return name:id type:int default:--  desc:订单id
+     * @return name:order_no type:string default:--  desc:订单号
+     * @return name:price_total type:float default:--  desc:待支付金额(所以优惠完价格+运费)
+     * @return name:price_goods type:float default:--  desc:商品金额(用售价计算)
+     * @return name:price_express type:float default:--  desc:运费金额
+     * @return name:original_total type:float default:--  desc:总原价(下划线)
+     * @return name:pay_state type:int default:--  desc:支付状态(0未支付1已支付)
+     * @return name:pay_type type:int default:--  desc:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付)
+     * @return name:pay_no type:string default:--  desc:支付号
+     * @return name:pay_at type:string default:--  desc:支付时间
+     * @return name:cancel_state type:int default:--  desc:取消状态(0未取消1已取消)
+     * @return name:cancel_at type:string default:--  desc:取消时间
+     * @return name:cancel_desc type:string default:--  desc:取消原因
+     * @return name:cancel_desc type:string default:--  desc:取消原因
+     * @return name:refund_state type:int default:--  desc:退款状态(0未申请1待审核,2审核通过,3审核拒绝)
+     * @return name:express_state type:int default:--  desc:发货状态(0未发货,1已发货,2已签收)
+     * @return name:express_company_title type:string default:--  desc:发货快递公司名称
+     * @return name:express_send_no type:string default:--  desc:物流单号
+     * @return name:express_send_at type:string default:--  desc:发货时间
+     * @return name:status type:int default:--  desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
+     * @return name:create_at type:string default:--  desc:下单时间
+     * @return name:integral type:string default:--  desc:使用积分数量
+     * @return name:int_cash type:float default:--  desc:使用积分抵扣金额
+     * @return name:cl_ids type:string default:--  desc:使用优惠券id串
+     * @return name:coupon_cash type:string default:--  desc:使用优惠券抵扣金额
+     * @return name:blance type:string default:--  desc:使用余额支付金额
+     * @return name:redu_money type:float default:--  desc:订单满减金额
+     * @return name:remark type:string default:--  desc:订单备注
+     * @return name:goods_num type:int default:--  desc:订单商品总数量
+     * @return name:pro_name type:string default:--  desc:省名称(收货地址)
+     * @return name:city_name type:string default:--  desc:市名称(收货地址)
+     * @return name:county_name type:string default:--  desc:县区名称(收货地址)
+     * @return name:street_name type:string default:--  desc:街道名称(收货地址)
+     * @return name:add_detail type:string default:--  desc:详细地址(收货地址)
+     * @return name:user_name type:string default:--  desc:收货人
+     * @return name:phone type:string default:--  desc:收货人联系电话
+     * @return name:act_type type:int default:--  desc:活动类型0无1秒杀2拼团
+     * @return name:act_id type:int default:--  desc:活动id
+     * @return name:share_user type:int default:--  desc:分享人id
+     * @return name:order_item type:array default:--  desc:订单商品列表
+     * @return name:order_item.name type:float default:--  desc:商品名
+     * @return name:order_item.cover type:float default:--  desc:商品图
+     * @return name:order_item.sell_price type:float default:--  desc:购买价格
+     * @return name:order_item.goods_spec type:float default:--  desc:规格
+     * @return name:order_item.num type:int default:--  desc:数量
      */
-    public function order_list(){
-        $uid = $this->uid;
-        $status = input('status',-1);
-        $page = input('page',1);
-        $pageSize = input('page_size',10);
-        if($status == -1){
-            $where = 'is_deleted = 0 and user_id = '.$uid;
-        }else{
-            $where = 'is_deleted = 0 and user_id = '.$uid.' and status = '.$status;
-        }
-        $field = 'id,goods_id,order_no,type,price_total,status,refund_status';
-        $order_list = Db::name('store_order')->field($field)->where($where)->order('id desc')->page($page,$pageSize)->select();
-        foreach ($order_list as &$value){
-            $table_name = $value['type'] == 1?'store_goods':'store_book';
-            $goods_info = Db::name($table_name)->field('name,cover')->where('id',$value['goods_id'])->find();
-            $value['goods_name'] = $goods_info['name'];
-            $value['goods_cover'] = $goods_info['cover'];
-            unset($value['goods_id']);
-        }
-        $this->success('获取成功',$order_list);
+    public function getOrderList()
+    {
+        $status = input('get.status',-1);
+        $pay_state = input('get.pay_state',-1);
+        $cancel_state = input('get.cancel_state',-1);
+        $refund_state = input('get.apply_refund',-1);
+        $where = [];
+        $where[] = ['user_id','=',$this->user_id];
+        if($status > -1) $where[] = ['status','=',$status];
+        if($pay_state > -1) $where[] = ['pay_state','=',$pay_state];
+        if($cancel_state > -1) $where[] = ['cancel_state','=',$cancel_state];
+        if($refund_state == 0) $where[] = ['refund_state','=',$refund_state];
+        if($refund_state == 1) $where[] = ['refund_state','in','1,2,3,4'];
+        $list = GoodsOrder::with(['orderItem'])->where($where)->order('id desc ')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('',['list'=>$list]);
     }
+
     /**
-     * @title 订单详情
-     * @desc 订单详情
-     * @author QGF
-     * @url /api/Order/order_detail
+     * @title 获取订单详情
+     * @desc 获取订单详情
+     * @author qc
      * @method GET
-     * @tag 订单详情
+     * @url /api/Order/getOrderDetail
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:int require:1 default:1 desc:订单ID
-     * @return name:id type:int default:-- desc:订单ID
-     * @return name:goods_id type:int default:-- desc:商品ID(type为1时代表课程ID,为2时代表书籍教材ID)
-     * @return name:order_no type:int default:-- desc:等等编号
-     * @return name:type type:string default:-- desc:商品类型(1:课程,2:书籍教材)
-     * @return name:num type:int default:-- desc:购买数量
-     * @return name:price_total type:string default:-- desc:支付金额
-     * @return name:express_send_no type:string default:-- desc:快递单号
-     * @return name:status type:string default:-- desc:订单状态(0:未支付,1:已支付,2:已完成,3:已退款,4:已取消)
-     * @return name:refund_status type:string default:-- desc:退款状态(0:未申请退款,1:退款中,2:退款成功)
-     * @return name:create_at type:string default:-- desc:下单时间
-     * @return name:pay_at type:string default:-- desc:支付时间
-     * @return name:teacher_name type:string default:-- desc:讲师名称(type为1时才有该字段)
-     * @return name:chapter_num type:int default:-- desc:课时数量(type为1时才有该字段)
-     * @return name:residue_time type:int default:-- desc:未支付订单剩余支付时长(单位:秒)
-     * @return name:consignee_area type:string default:-- desc:收货人详细地址(type为2时才有该字段)
-     * @return name:consignee_name type:string default:-- desc:收货人姓名(type为2时才有该字段)
-     * @return name:consignee_phone type:string default:-- desc:收货人手机号(type为2时才有该字段)
-     * @return name:goods_name type:string default:-- desc:商品名称
-     * @return name:goods_cover type:string default:-- desc:商品封面图地址
+     * @param name:order_id type:int default:--  desc:订单id
+     * @return name:id type:int default:--  desc:订单id
+     * @return name:order_no type:string default:--  desc:订单号
+     * @return name:price_total type:float default:--  desc:待支付金额(商品价格+运费)
+     * @return name:price_goods type:float default:--  desc:商品金额
+     * @return name:price_express type:float default:--  desc:运费金额
+     * @return name:original_total type:float default:--  desc:总原价(下划线)
+     * @return name:original_total type:float default:--  desc:总原价(下划线)
+     * @return name:pay_state type:int default:--  desc:支付状态(0未支付1已支付)
+     * @return name:pay_type type:int default:--  desc:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付)
+     * @return name:pay_no type:string default:--  desc:支付号
+     * @return name:pay_at type:string default:--  desc:支付时间
+     * @return name:cancel_state type:int default:--  desc:取消状态(0未取消1已取消)
+     * @return name:cancel_at type:string default:--  desc:取消时间
+     * @return name:cancel_desc type:string default:--  desc:取消原因
+     * @return name:refund_state type:int default:--  desc:退款状态(0未申请1待审核,2审核拒绝,3审核通过)
+     * @return name:express_state type:int default:--  desc:发货状态(0未发货,1已发货,2已签收)
+     * @return name:express_company_title type:string default:--  desc:发货快递公司名称
+     * @return name:express_send_no type:string default:--  desc:物流单号
+     * @return name:express_send_at type:string default:--  desc:发货时间
+     * @return name:status type:int default:--  desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
+     * @return name:create_at type:string default:--  desc:下单时间
+     * @return name:blance type:string default:--  desc:使用余额支付金额(余额抵扣)
+     * @return name:remark type:string default:--  desc:订单备注
+     * @return name:goods_num type:int default:--  desc:订单商品总数量
+     * @return name:pro_name type:string default:--  desc:省名称(收货地址)
+     * @return name:city_name type:string default:--  desc:市名称(收货地址)
+     * @return name:county_name type:string default:--  desc:县区名称(收货地址)
+     * @return name:street_name type:string default:--  desc:街道名称(收货地址)
+     * @return name:add_detail type:string default:--  desc:详细地址(收货地址)
+     * @return name:user_name type:string default:--  desc:收货人
+     * @return name:phone type:string default:--  desc:收货人联系电话
+     * @return name:order_item type:array default:--  desc:订单商品列表(按商品id分组)
+     * @return name:order_item.name type:float default:--  desc:商品名
+     * @return name:order_item.cover type:float default:--  desc:商品图
+     * @return name:order_item.sell_price type:float default:--  desc:购买价格
+     * @return name:order_item.goods_spec type:float default:--  desc:规格
+     * @return name:order_item.num type:int default:--  desc:数量
      */
-    public function order_detail(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $field = 'id,goods_id,order_no,type,num,price_total,address_id,express_send_no,status,refund_status,create_at,pay_at,is_incidental';
-        $order_detail = Db::name('store_order')->field($field)->where('user_id',$uid)->where('id',$id)->where('is_deleted',0)->find();
-        if(empty($order_detail)){
-            $this->error('订单信息有误');
-        }
-        if($order_detail['type'] == 2){
-            $goods_info = Db::name('store_book')->field('name,cover')->where('id',$order_detail['goods_id'])->find();
-            $address_info = Db::name('store_member_address')->where('id',$order_detail['address_id'])->find();
-            $area_obj = new Area();
-            $order_detail['consignee_area'] = $area_obj->get_area($address_info['province'],$address_info['city'],$address_info['county']).$address_info['address'];
-            $order_detail['consignee_name'] = $address_info['name'];
-            $order_detail['consignee_phone'] = $address_info['phone'];
-        }else{
-            $goods_info = Db::name('store_goods')->field('name,cover,teacher_name,chapter_num')->where('id',$order_detail['goods_id'])->find();
-            $order_detail['teacher_name'] = $goods_info['teacher_name'];
-            $order_detail['chapter_num'] = $goods_info['chapter_num'];
-            if($order_detail['is_incidental']){
-                $address_info = Db::name('store_member_address')->where('id',$order_detail['address_id'])->find();
-                $area_obj = new Area();
-                $order_detail['consignee_area'] = $area_obj->get_area($address_info['province'],$address_info['city'],$address_info['county']).$address_info['address'];
-                $order_detail['consignee_name'] = $address_info['name'];
-                $order_detail['consignee_phone'] = $address_info['phone'];
-            }
-        }
-        //未支付的计算剩余关闭时间
-        if($order_detail['status'] == 0){
-            $close_order_time = sysconf('close_order_time');
-            $residue_time = time() + $close_order_time * 60 - strtotime($order_detail['create_at']);
-            if($residue_time > 0){
-                $order_detail['residue_time'] = $residue_time;
-            }
-        }
-        $order_detail['goods_name'] = $goods_info['name'];
-        $order_detail['goods_cover'] = $goods_info['cover'];
-        unset($order_detail['address_id']);
-        $this->success('获取成功',$order_detail);
+    public function getOrderDetail()
+    {
+        $order_id = input('get.order_id');
+        $detail = GoodsOrder::where('id',$order_id)->find()->toArray();
+        $detail['order_item']  = (new GoodsOrderItem())->getOrderItem($order_id);
+        $this->success('ok',['detail'=>$detail]);
     }
+
     /**
-     * @title 确认收货
-     * @desc 确认收货
-     * @author QGF
-     * @url /api/Order/confirm_completed
+     * @title 计算商品运费(一个商品id)
+     * @desc  计算商品运费(一个商品id)
+     * @author qc
+     * @url /api/Order/getGoodsFreight
      * @method GET
-     * @tag 确认收货
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:int require:1 default:1 desc:订单ID
+     * @param  name:goods_id type:int require:1  default:0 desc:商品id
+     * @param  name:num type:int require:1  default:0 desc:商品数量
+     * @param  name:add_id type:int require:1  default:0 desc:收货地址id
+     * @return name:freight type:float require:0 default:0 desc运费金额
      */
-    public function confirm_completed(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('id')->where('id',$id)->where('user_id',$uid)->where('status',1)->find();
-        if(empty($order_info)){
-            $this->error('订单信息有误');
-        }
-        $res = Db::name('store_order')->where('id',$id)->update(array('status'=>2));
-        if($res){
-            $this->success('确认成功');
-        }else{
-            $this->error('确认失败');
-        }
+    public function getGoodsFreight()
+    {
+        $goods_id = input('get.goods_id');
+        $num = input('get.num');
+        $add_id = input('get.add_id');
+        $goods_info = StoreGoods::where('id',$goods_id)->find()->toArray();
+        $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray();
+        $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$num);
+        if($freight_data['code'] != 200 ) $this->error($freight_data['msg']);
+        $this->success('ok',['freight'=>$freight_data['freight']]);
     }
+
     /**
-     * @title 取消订单
-     * @desc 取消订单
-     * @author QGF
-     * @url /api/Order/cancel_order
+     * @title 计算购物车商品运费
+     * @desc  计算购物车商品运费
+     * @author qc
+     * @url /api/Order/getTrolleyFreight
      * @method GET
-     * @tag 取消订单
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:int require:1 default:1 desc:订单的ID
+     * @param  name:ids type:int require:1  default:0 desc:购物车商品id串
+     * @param  name:add_id type:int require:1  default:0 desc:收货地址id
+     * @return name:freight type:float require:0 default:0 desc运费金额
      */
-    public function cancel_order(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('id')->where('id',$id)->where('user_id',$uid)->where('status',0)->where('is_deleted',0)->find();
-        if(empty($order_info)){
-            $this->error('订单信息有误');
+    public function getTrolleyFreight()
+    {
+        $trolley_ids = input('get.ids');
+        $add_id = input('get.add_id');
+        $goods_list = ShoppingTrolley::where('id','in',$trolley_ids)
+            ->field('goods_id,sum(num) as total_num')
+            ->group('goods_id')
+            ->select()->toArray();
+        $total_price = 0;
+        $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray();
+        foreach ($goods_list as $v){
+            $goods_info = StoreGoods::field('name,freight_type,freight_id,postage')->where('id',$v['goods_id'])->find()->toArray();
+            $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$v['total_num']);
+            if($freight_data['code'] != 200){
+                $this->error($goods_info['name'].$freight_data['msg']);
+                break;
+            }
+            $total_price += $freight_data['freight'];
         }
-        $res = Db::name('store_order')->where('id',$order_info['id'])->update(array('status'=>4));
-        if($res){
-            $this->success('取消成功');
-        }else{
-            $this->error('取消失败');
+        $this->success('ok',['freight'=>$total_price]);
+    }
+
+    /**
+     * @title 取消订单
+     * @desc  取消订单
+     * @author  qc
+     * @url /api/Order/cancelOrder
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
+     */
+    public function cancelOrder()
+    {
+        $order_id = input('post.order_id');
+        Db::startTrans();
+        try {
+            $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
+            if($detail['status'] != 0) $this->exception('订单状态有误');
+            // 取消订单状态
+            GoodsOrder::update(['status'=>9],['id'=>$order_id]);
+            // 订单处理
+            foreach ($detail['order_item'] as $item_info) {
+                //  更改订单详情状态
+                GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
+                // 商品规格库存返回
+                StoreGoodsItem::where('id',$item_info['spec_id'])->setInc('stock',$item_info['num']);
+                // 商品总库存增加
+                StoreGoods::where('id',$item_info['goods_id'])->setInc('stock',$item_info['num']);
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            $this->ret_msg = $e->getMessage();
+            $this->is_commit = false;
+            Db::rollback();
         }
+        $this->is_commit ? $this->success('取消成功') : $this->error($this->ret_msg);
     }
+
     /**
      * @title 删除订单
-     * @desc 删除订单
-     * @author QGF
-     * @url /api/Order/delete_order
-     * @method GET
-     * @tag 删除订单
+     * @desc  删除订单
+     * @author  qc
+     * @url /api/Order/deleteOrder
+     * @method POST
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:int require:1 default:1 desc:订单的ID
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
      */
-    public function delete_order(){
-        $uid = $this->uid;
-        $id = input('id');
-        if(empty($id)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('id')->where('id',$id)->where('user_id',$uid)->where('status',4)->where('is_deleted',0)->find();
-        if(empty($order_info)){
-            $this->error('订单信息有误');
-        }
-        $res = Db::name('store_order')->where('id',$order_info['id'])->update(array('is_deleted'=>1));
-        if($res){
-            $this->success('删除成功');
-        }else{
-            $this->error('删除失败');
-        }
+    public function deleteOrder()
+    {
+        $order_id = input('post.order_id');
+        $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
+        if($detail['status'] == 0) $this->error('请先取消订单');
+        GoodsOrder::update(['is_deleted'=>1],['id'=>$order_id]);
+        $this->success('删除成功');
     }
+
+
     /**
-     * @title 申请退款
-     * @desc 申请退款
-     * @author QGF
-     * @url /api/Order/apply_refund
-     * @method GET
-     * @tag 申请退款
+     * @title 更换订单收货地址
+     * @desc  更换订单收货地址(仅待支付订单可以修改地址)
+     * @author  qc
+     * @url /api/Order/changeOrderDelivery
+     * @method POST
      * @header name:Authorization require:1 desc:Token
-     * @param name:id type:int require:1 default:-- desc:订单的ID
-     * @param name:reason type:int require:1 default:-- desc:退款原因
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
+     * @param  name:add_id type:int require:1  default:0 desc:收货地址id
      */
-    public function apply_refund(){
-        $uid = $this->uid;
-        $id = input('id');
-        $reason = input('reason');
-        if(empty($id) || empty($reason)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('id,order_no,price_total')->where('id',$id)->where('user_id',$uid)->where('type',2)->where('status',1)->where('refund_status',0)->where('is_deleted',0)->find();
-        if(empty($order_info)){
-            $this->error('订单信息有误');
-        }
-        //写入退款表
-        $data = array(
-            'user_id' => $uid,
-            'order_no' => $order_info['order_no'],
-            'refund_no' => get_order_sn(),
-            'reason' => $reason,
-            'amount' => $order_info['price_total'],
-        );
-        Db::name('store_order_refund')->insert($data);
-        Db::name('store_order')->where('id',$order_info['id'])->update(array('refund_price'=>$order_info['price_total'],'refund_status'=>1,'refund_at'=>date('Y-m-d H:i:s'),'refund_reason'=>$reason));
-        $this->success('申请成功');
+    public function changeOrderDelivery()
+    {
+        $order_id = input('post.order_id');
+        $add_id = input('post.add_id');
+        $detail = GoodsOrder::where('id',$order_id)->find()->toArray();
+        if($detail['status'] != 0) $this->error('操作错误');
+        $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray();
+        $order_update =[
+            'pro_name' => $add_info['pro_name'],
+            'city_name' => $add_info['city_name'],
+            'county_name' => $add_info['county_name'],
+            'street_name' => $add_info['street_name'],
+            'add_detail' => $add_info['detail'],
+            'user_name' => $add_info['name'],
+            'phone' => $add_info['phone'],
+        ];
+        GoodsOrder::update($order_update,['id'=>$order_id]);
+        $this->success('修改成功');
+
+    }
+
+    /**
+     * @title 确认收货
+     * @desc  确认收货
+     * @author  qc
+     * @url /api/Order/confirmReceipt
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:order_id type:int require:1  default:0 desc:订单id
+     */
+    public function confirmReceipt()
+    {
+        $order_id = input('post.order_id');
+        $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
+        if($detail['status'] == 0) $this->error('订单未支付');
+        if($detail['status'] == 1) $this->error('订单未发货');
+        if($detail['status'] == 3) $this->error('订单已收货');
+        GoodsOrder::update(['status'=>3,'express_state'=>2],['id'=>$order_id]);
+        GoodsOrderItem::update(['status'=>3,'express_state'=>2],['order_id'=>$order_id]);
+        UserMessage::create(['user_id'=>$this->user_id,'type_id'=>3,'relation_id'=>$order_id,'content'=>'订单收货成功']);
+        $this->success('已确认收货');
     }
+
     /**
-     * @title 快递查询
-     * @desc 快递查询
-     * @author QGF
-     * @url /api/Order/express_search
+     * @title 订单评价
+     * @desc  订单评价
+     * @author  qc
+     * @url /api/Order/orderComment
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:item_id type:int require:1  default:0 desc:订单item表id
+     * @param  name:content type:string require:1  default:0 desc:评论内容
+     * @param  name:images type:string default:0 desc:图片
+     * @param  name:video type:string default:0 desc:视频
+     * @param  name:goods_core type:int default:0 desc:商品评分
+     * @param  name:wl_core type:int default:0 desc:物流评分
+     * @param  name:serve_core type:int default:0 desc:服务评分
+     */
+    public function orderComment()
+    {
+        $item_id = input('post.item_id','');
+        $content = input('post.content','');
+        $images = input('post.images','');
+        $video = input('post.video','');
+        $goods_core = input('post.goods_core','');
+        $wl_core = input('post.wl_core','');
+        $serve_core = input('post.serve_core','');
+        $item = GoodsOrderItem::get($item_id);
+        if(!$item) $this->error('订单不存在');
+        $order_info = GoodsOrder::where('id',$item->order_id)->find();
+        if($order_info->status < 3) $this->error('请先确认收货');
+        GoodsOrderItem::where('id',$item->id)->update(['status'=>4]);
+        GoodsOrder::where('id',$item->order_id)->update(['status'=>4]);
+        $data = [
+            'user_id' => $this->user_id,
+            'order_id' =>$item->order_id,
+            'goods_id' =>$item->goods_id,
+            'spec_id' =>$item->spec_id,
+            'content' =>$content,
+            'images' =>$images,
+            'video' =>$video,
+            'goods_core' =>$goods_core,
+            'wl_core' =>$wl_core,
+            'serve_core' =>$serve_core,
+        ];
+        OrderComment::create($data);
+        $this->success('评论成功');
+    }
+
+    /**
+     * @title 获取物流详情
+     * @desc 获取物流详情
+     * @author qc
+     * @url /api/Order/deliveryDetails
      * @method GET
-     * @tag 快递查询
      * @header name:Authorization require:1 desc:Token
-     * @param name:order_id type:int require:1 default:-- desc:订单的ID
+     * @param name:order_id type:string require:1 default:-- desc:订单id
+     * @return name:number type:string default:-- desc:单号
+     * @return name:type type:string default:-- desc:快递类型
+     * @return name:list type:array default:-- desc:数据列表
+     * @return name:list.time type:string default:-- desc:时间
+     * @return name:list.status type:string default:-- desc:内容
+     * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收
+     * @return name:issign type:int default:-- desc:是否签收(1.是否签收)
+     * @return name:expName type:string default:-- desc:快递公司名称
+     * @return name:expSite type:string default:-- desc:快递公司官网
+     * @return name:expPhone type:string default:-- desc:快递公司电话
+     * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空)
+     * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空)
+     * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间
+     * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹)
+     * @return name:logo type:string default:-- desc:快递公司LOGO
      */
-    function express_search(){
-        $uid = $this->uid;
-        $order_id = input('order_id');
-        if(empty($order_id)){
-            $this->error('参数错误');
-        }
-        $order_info = Db::name('store_order')->field('express_send_no,express_code,express_title')->where('id',$order_id)->where('user_id',$uid)->find();
-        if(empty($order_info['express_send_no'])){
-            $this->error('订单信息有误');
-        }
-        $host = "https://wuliu.market.alicloudapi.com";//api访问链接
-        $path = "/kdi";//API访问后缀
-        $method = "GET";
-        $appcode = "f87d623992f64fbeaa30d34eb46ac153";//开通服务后 买家中心-查看AppCode
-        $headers = array();
-        array_push($headers, "Authorization:APPCODE " . $appcode);
-        $querys = "no=".$order_info['express_send_no']."&type=".$order_info['express_code'];  //参数写在这里
-        $bodys = "";
-        $url = $host . $path . "?" . $querys;
-        $curl = curl_init();
-        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
-        curl_setopt($curl, CURLOPT_URL, $url);
-        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
-        curl_setopt($curl, CURLOPT_FAILONERROR, false);
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($curl, CURLOPT_HEADER, false);
-        if (1 == strpos("$" . $host, "https://")) {
-            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        $out_put = curl_exec($curl);
-        if($out_put){
-           $res = json_decode($out_put,true);
-           $this->success('获取成功',$res['result']);
-        }else{
-            $this->success('暂无快递信息');
-        }
+    public function deliveryDetails(){
+        $send_no = GoodsOrder::where('id',input('get.order_id'))->value('express_send_no');
+        if(!$send_no) $this->error('订单没有发货');
+        $data = get_delivery($send_no);
+        $this->success('ok',$data);
     }
-}
 
+}

+ 155 - 0
application/api/controller/OssManage.php

@@ -0,0 +1,155 @@
+<?php
+namespace app\api\controller;
+use AlibabaCloud\SDK\Sts\V20150401\Sts;
+use \Exception;
+use AlibabaCloud\Tea\Exception\TeaError;
+use AlibabaCloud\Tea\Utils\Utils;
+use Darabonba\OpenApi\Models\Config;
+use AlibabaCloud\SDK\Sts\V20150401\Models\AssumeRoleRequest;
+use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
+use AlibabaCloud\SDK\Vod\V20170321\Models\GetVideoPlayAuthRequest;
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+require_once '../vendor/aliyunmail/aliyun-php-sdk-core/Config.php';   // 假定您的源码文件和aliyun-php-sdk处于同一目录
+$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
+if (file_exists($path)) require_once $path;
+date_default_timezone_set('PRC');
+
+/**
+ * @title OssManage
+ * @controller OssManage
+ * @group base
+ */
+class OssManage extends Base
+{
+
+    protected $access_key = 'LTAI5tGJE1WU5ytYK2zBxnDx';// key
+    protected $access_secret = 'uNyByodVajsN1lrMSCxpbrJF46Pwx3';//secret
+
+    protected $role_arn= 'acs:ram::1122764885952286:role/ramoss';//role_arn
+    protected $role_session_name= 'RamOss';//role_session_name
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param string $accessKeyId
+     * @param string $accessKeySecret
+     * @return Sts Client
+     */
+    public static function createClient($accessKeyId, $accessKeySecret){
+        $config = new Config([
+            // 您的 AccessKey ID
+            "accessKeyId" => $accessKeyId,
+            // 您的 AccessKey Secret
+            "accessKeySecret" => $accessKeySecret
+        ]);
+        // 访问的域名
+        $config->endpoint = "sts.cn-hangzhou.aliyuncs.com";
+        return new Sts($config);
+    }
+
+    /**
+     * @title 获取STS临时身份凭证
+     * @desc 获取STS临时身份凭证
+     * @author qc
+     * @url /api/Oss_manage/getOssCredentials
+     * @method GET
+     * @tag 视频播放凭证
+     * @header name:Authorization require:1 desc:Token
+     * @return name:RequestId type:string default:-- desc:RequestId
+     * @return name:Arn type:string default:-- desc:RoleArn(Arn)
+     * @return name:AssumedRoleId type:string default:-- desc:AssumedRoleId
+     * @return name:SecurityToken type:string default:-- desc:SecurityToken
+     * @return name:AccessKeyId type:string default:-- desc:AccessKeyId
+     * @return name:AccessKeySecret type:string default:-- desc:AccessKeySecret
+     * @return name:Expiration type:string default:-- desc:Expiration
+     */
+    public function getOssCredentials()
+    {
+        $client = self::createClient($this->access_key,$this->access_secret);
+        $assumeRoleRequest = new AssumeRoleRequest([
+            'roleArn' => $this->role_arn,
+            'roleSessionName' =>$this->role_session_name,
+        ]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+           $res =  $client->assumeRoleWithOptions($assumeRoleRequest, $runtime);
+            $json_res =  json_encode($res,true);
+            $res_arr = json_decode($json_res,true);
+        }
+        catch (Exception $error) {
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            $this->error($error->message);
+        }
+        $this->success('ok',$res_arr['body'] );
+    }
+
+
+    /**
+     * @title 获取STS临时身份凭证
+     * @desc 获取STS临时身份凭证
+     * @author qc
+     * @url /api/Oss_manage/getOssCredential2
+     * @method GET
+     * @tag 视频播放凭证
+     * @header name:Authorization require:1 desc:Token
+     * @return name:RequestId type:string default:-- desc:RequestId
+     * @return name:Arn type:string default:-- desc:RoleArn(Arn)
+     * @return name:AssumedRoleId type:string default:-- desc:AssumedRoleId
+     * @return name:SecurityToken type:string default:-- desc:SecurityToken
+     * @return name:AccessKeyId type:string default:-- desc:AccessKeyId
+     * @return name:AccessKeySecret type:string default:-- desc:AccessKeySecret
+     * @return name:Expiration type:string default:-- desc:Expiration
+     */
+    public function getOssCredential2(){
+        //构建一个阿里云客户端,用于发起请求。
+        //设置调用者(RAM用户或RAM角色)的AccessKey ID和AccessKey Secret。
+        AlibabaCloud::accessKeyClient($this->access_key, $this->access_secret)->regionId('cn-hangzhou')->asDefaultClient();
+        //设置参数,发起请求。
+        try {
+            $result = AlibabaCloud::rpc()
+                ->product('Sts')
+                 ->scheme('https')
+                ->version('2015-04-01')
+                ->action('AssumeRole')
+                ->method('POST')
+                ->host('sts.aliyuncs.com')
+                ->options([
+                    'query' => [
+                        'RegionId' => "cn-hangzhou",
+                        'RoleArn' => $this->role_arn,
+                        'RoleSessionName' => $this->role_session_name
+                    ],
+                ])
+                ->request();
+            $ret = $result->toArray();
+            $this->success('请求成功',$ret);
+        } catch (ClientException $e) {
+            $this->error($e->getErrorMessage() . PHP_EOL);
+        } catch (ServerException $e) {
+            $this->error($e->getErrorMessage() . PHP_EOL);
+        }
+    }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 374 - 45
application/api/controller/Pay.php

@@ -1,30 +1,11 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | ThinkAdmin
-// +----------------------------------------------------------------------
-// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
-// +----------------------------------------------------------------------
-// | 官方网站: http://demo.thinkadmin.top
-// +----------------------------------------------------------------------
-// | 开源协议 ( https://mit-license.org )
-// +----------------------------------------------------------------------
-// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
-// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
-// +----------------------------------------------------------------------
-
 namespace app\api\controller;
-
-use app\admin\controller\Config;
-use app\api\controller\Base;
-use app\api\model\Member as MemberModel;
 use EasyWeChat\Factory;
 use think\Controller;
 use think\Db;
 use think\Exception;
 use think\Model;
 use app\api\controller\Evaluate;
-use app\api\controller\Serve;
 /**
  * 支付管理类
  * Class Refund
@@ -32,16 +13,16 @@ use app\api\controller\Serve;
  */
 class Pay extends Controller
 {
-    //微信支付
-    public static function wx_pay($name,$out_trade_no,$total_fee,$notify_url,$trade_type,$openid){
+    //小程序微信支付(type为1时是货主端微信配置,type为2时是接单端微信配置)
+    public static function wx_pay($name='充值',$out_trade_no,$total_fee,$notify_url,$trade_type = 'JSAPI',$openid,$type = 1){
         try{
             if(empty($out_trade_no) || empty($total_fee) || empty($notify_url)){
                 return false;
             }
-            if($trade_type != 'APP'){   //小程序
+            if($type == 1){
                 $app = Factory::payment(config('app.wx_pay'));
             }else{
-                $app = Factory::payment(config('app.app_wx_pay'));
+                $app = Factory::payment(config('app.worker_wx_pay'));
             }
             $parameter = array(
                 'body' => $name,
@@ -52,42 +33,117 @@ class Pay extends Controller
             );
             if($trade_type != 'APP'){
                 $parameter['openid'] = $openid;
-                $result = $app->order->unify($parameter);
-                $jssdk = $app->jssdk;
-                $config = $jssdk->sdkConfig($result['prepay_id']);
-            }else{
-                $result = $app->order->unify($parameter);
-                $jssdk = $app->jssdk;
-                $config = $jssdk->appConfig($result['prepay_id']);
             }
+            $result = $app->order->unify($parameter);
+            $jssdk = $app->jssdk;
+            $config = $jssdk->sdkConfig($result['prepay_id']);
             return $config;
         }catch (Exception $e){
             return false;
         }
     }
-    //订单回调
+    //app微信支付
+    public static function wx_pay_app($name='保证金',$out_trade_no,$total_fee,$notify_url){
+        try{
+            if(empty($out_trade_no) || empty($total_fee) || empty($notify_url)){
+                return false;
+            }
+            $app = Factory::payment(config('app.worker_app_wx_pay'));
+            $result = $app->order->unify([
+                'body' => $name,
+                'out_trade_no' => $out_trade_no,
+                'total_fee' => $total_fee*100,
+                'notify_url' => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+                'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
+            ]);
+            $jssdk = $app->jssdk;
+            $config = $jssdk->appConfig($result['prepay_id']);
+            return $config;
+        }catch (Exception $e){
+            return false;
+        }
+    }
+    //充值余额回调
+    public function balance_notify(){
+        $app = Factory::payment(config('app.wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            $order_list = Db::name('store_balance_order')->where('status',0)->where('pay_no',$pay_no)->find();
+            if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
+                return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+            }
+            if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户支付成功处理
+                $order_info = Db::name('store_balance_order')->where('pay_no',$pay_no)->find();
+                Db::startTrans();
+                $res = Db::table('store_balance_order')->where('user_id',$order_info['user_id'])->where('pay_no',$order_info['pay_no'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
+                $error = 0;
+                if(!$res){
+                    $error = 1;
+                    Db::rollback();
+                }
+                $balance_data = array(
+                    'amount' => $order_info['price_total'],
+                    'user_id' => $order_info['user_id'],
+                    'order_id' => $order_info['id'],
+                    'status' => 1
+                );
+                $balance_list = Db::name('store_balance_list')->insert($balance_data);
+                if(!$balance_list){
+                    $error = 2;
+                    Db::rollback();
+                }
+                $member_balance = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance',$order_info['price_total']);
+                if(!$member_balance){
+                    $error = 3;
+                    Db::rollback();
+                }
+                $member_balance_all = Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance_all',$order_info['price_total']);
+                if(!$member_balance_all){
+                    $error = 4;
+                    Db::rollback();
+                }
+                if($error == 0){
+                    Db::commit();
+                }
+                return true; // 返回处理完成
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+    //订单支付回调
     public function order_notify(){
         $app = Factory::payment(config('app.wx_pay'));
         $response = $app->handlePaidNotify(function ($message, $fail) {
             // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
             $pay_no = $message['out_trade_no'];
-            $order_list = Db::name('store_order')->where('status',0)->where('pay_no',$pay_no)->find();
+            $order_list = Db::name('store_order')->where('status',1)->where('pay_no',$pay_no)->find();
             if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
                 return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
             }
             if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
                 // 用户支付成功处理
-                $status = 1;
-                if($order_list['type'] == 1 && $order_list['is_incidental'] == 0){
-                    $status = 2;
-                }
-                Db::table('store_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>$status]);
-                if($order_list['type'] == 1){   //支付成功(如果是付费的课程,增加购买记录)
-                    $goods_type = Db::name('store_goods')->where('id',$order_list['goods_id'])->value('type');
-                    if($goods_type == 2){
-                        Db::name('store_goods')->where('id',$order_list['goods_id'])->setInc('buy_num',1);
+                $order_info = Db::name('store_order')->field('id,worker_id')->where('pay_no',$pay_no)->find();
+                Db::startTrans();
+                $res = Db::table('store_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>2]);
+                $error = 0;
+                if(!$res){
+                    $error = 1;
+                    Db::rollback();
+                }
+                if($order_info['worker_id']){
+                    $rebate_res = $this->serve_rebate($order_info['id']);
+                    if(!$rebate_res['code']){
+                        $error = 2;
+                        Db::rollback();
                     }
                 }
+                if($error == 0){
+                    Db::commit();
+                }
                 return true; // 返回处理完成
             } else {
                 return $fail('通信失败,请稍后再通知我');
@@ -95,19 +151,116 @@ class Pay extends Controller
         });
         $response->send();
     }
-    //直播订单回调
-    public function live_order_notify(){
+    //增加费用订单支付回调
+    public function expenses_order_notify(){
         $app = Factory::payment(config('app.wx_pay'));
         $response = $app->handlePaidNotify(function ($message, $fail) {
             // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
             $pay_no = $message['out_trade_no'];
-            $order_list = Db::name('store_order_live')->where('status',0)->where('pay_no',$pay_no)->find();
+            $order_list = Db::name('store_expenses_order')->where('status',0)->where('pay_no',$pay_no)->find();
+            if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
+                return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+            }
+            if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                $order_info = Db::name('store_expenses_order')->field('id,order_id,price_total,reason')->where('pay_no',$pay_no)->find();
+                // 用户支付成功处理
+                Db::startTrans();
+                $expenses_order_res = Db::table('store_expenses_order')->where('id',$order_info['id'])->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
+                $error = 0;
+                if(!$expenses_order_res){
+                    $error = 1;
+                    Db::rollback();
+                }
+                $rebate_res = $this->add_serve_rebate($order_info['id']);
+                if(!$rebate_res){
+                    $error = 2;
+                    Db::rollback();
+                }
+                $store_order_info = Db::name('store_order')->field('price_total,price_amount')->where('id',$order_info['order_id'])->find();
+                $store_order_res = Db::name('store_order')->where('id',$order_info['order_id'])->update(['expenses_time'=>date('Y-m-d H:i:s'),'expenses_pay_type'=>1,'expenses_amount'=>$order_info['price_total'],'expenses_reason'=>$order_info['reason'],'price_total'=>$store_order_info['price_total'] + $order_info['price_total'],'price_amount'=>$store_order_info['price_amount'] + $order_info['price_total']]);
+                if(!$store_order_res){
+                    $error = 3;
+                    Db::rollback();
+                }
+                if($error == 0){
+                    Db::commit();
+                }else{
+                    Db::rollback();
+                }
+                return true; // 返回处理完成
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+    //保证金支付回调
+    public function deposit_notify(){
+        $app = Factory::payment(config('app.worker_wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            $order_list = Db::name('store_deposit_order')->where('status',0)->where('pay_no',$pay_no)->find();
+            if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
+                return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+            }
+            if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户支付成功处理
+                 Db::table('store_deposit_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
+                 $wid = Db::table('store_deposit_order')->where('pay_no',$pay_no)->value('worker_id');
+                //更新是否缴纳保证金
+                Db::name('store_worker')->where('id',$wid)->update(array('deposit'=>1));
+                //添加运输路线
+                $county_arr = explode(',',$order_list['county']);
+                foreach ($county_arr as $area){
+                    $city_id = Db::name('store_area')->where('id',$area)->value('pid');
+                    $province_id = Db::name('store_area')->where('id',$city_id)->value('pid');
+                    $area_data = array(
+                        'worker_id' => $wid,
+                        'start_province_id' => $order_list['start_province'],
+                        'start_city_id' => $order_list['start_city'],
+                        'start_county_id' => $order_list['start_county'],
+                        'end_province_id' => $province_id,
+                        'end_city_id' => $city_id,
+                        'end_county_id' => $area
+                    );
+                    Db::name('store_serve_area')->insert($area_data);
+                }
+                return true; // 返回处理完成
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+    //会员费用回调
+    public function membership_notify(){
+        $app = Factory::payment(config('app.worker_wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            $order_list = Db::name('store_membership_order')->where('status',0)->where('pay_no',$pay_no)->find();
             if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
                 return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
             }
             if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
                 // 用户支付成功处理
-                Db::table('store_order_live')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_status'=>1,'status'=>1]);
+                Db::table('store_membership_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
+                $order_info = Db::table('store_membership_order')->where('pay_no',$pay_no)->find();
+                //添加接单人员会员信息
+                $vip_time = Db::name('store_worker')->where('id',$order_info['worker_id'])->value('vip_time');
+                $vip_timestamp = 0;
+                if($order_info['type'] == 1){
+                    $vip_timestamp = strtotime('next month');
+                }elseif($order_info['type'] == 2){
+                    $vip_timestamp = strtotime('+3 month');
+                }elseif ($order_info['type'] == 3){
+                    $vip_timestamp = strtotime('+1years');
+                }
+                if($vip_time && $vip_time > time()){
+                    $vip_timestamp = $vip_timestamp + ($vip_time - time());
+                }
+                Db::name('store_worker')->where('id',$order_info['worker_id'])->update(array('vip'=>$order_info['type'],'vip_time'=>$vip_timestamp));
                 return true; // 返回处理完成
             } else {
                 return $fail('通信失败,请稍后再通知我');
@@ -115,4 +268,180 @@ class Pay extends Controller
         });
         $response->send();
     }
+    //自动报价回调
+    public function offer_notify(){
+        $app = Factory::payment(config('app.worker_wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            $order_list = Db::name('store_offer_order')->where('status',0)->where('pay_no',$pay_no)->find();
+            if (empty($order_list)) { // 如果订单不存在 或者 订单已经支付过了
+                return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
+            }
+            if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                // 用户支付成功处理
+                Db::table('store_offer_order')->where('pay_no',$pay_no)->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'status'=>1]);
+                $order_info = Db::table('store_offer_order')->where('pay_no',$pay_no)->find();
+                //添加接单人员自动报价信息
+                $offer_time = Db::name('store_worker')->where('id',$order_info['worker_id'])->value('offer_time');
+                $offer_timestamp = 0;
+                if($order_info['type'] == 1){
+                    $offer_timestamp = strtotime('next month');
+                }elseif($order_info['type'] == 2){
+                    $offer_timestamp = strtotime('+3 month');
+                }elseif ($order_info['type'] == 3){
+                    $offer_timestamp = strtotime('+1years');
+                }
+                if($offer_time && $offer_time > time()){
+                    $offer_timestamp = $offer_timestamp + ($offer_time - time());
+                }
+                Db::name('store_worker')->where('id',$order_info['worker_id'])->update(array('offer_time'=>$offer_timestamp));
+                return true; // 返回处理完成
+            } else {
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+    /**
+     * 余额支付(雇主端)
+     * $order_id 订单ID
+     * $table_type 订单类型 1:store_order(订单),5:store_expenses_order(增加费用)
+     */
+    public function balance_pay($order_id,$table_type = 1){
+        $field = 'user_id,price_total';
+        $table_name = $table_type == 1?'store_order':'store_expenses_order';
+        $order_info = Db::name($table_name)->field($field)->where('id',$order_id)->find();
+        if(empty($order_info) || $order_info['price_total'] <= 0){
+            return false;
+        }
+        $amount = $order_info['price_total'];
+        $user_id = $order_info['user_id'];
+        Db::startTrans();
+        $balance_data = array(
+            'amount' => $amount,
+            'user_id' => $user_id,
+            'type' => 2,
+            'order_id' => $order_id,
+            'table_type' => $table_type,
+            'status' => 1
+        );
+        $error = 0;
+        $balance = Db::name('store_balance_list')->insert($balance_data);
+        if(!$balance){
+            $error = 1;
+            Db::rollback();
+        }
+        $member = Db::name('store_member')->where('id',$user_id)->setDec('balance',$amount);
+        if(!$member){
+            $error = 2;
+            Db::rollback();
+        }
+        if($error == 0){
+            Db::commit();
+            return true;
+        }else{
+            return false;
+        }
+    }
+    /**
+     * 余额支付(接单端)
+     * $order_id 订单ID
+     */
+    public function worker_balance_pay($order_id,$table_type){
+        $field = 'price_total,worker_id';
+        $table_type_arr = array(1=>'store_order',2=>'store_deposit_order',3=>'store_offer_order',4=>'store_grab_order',6=>'store_membership_order');
+        $table_name = $table_type_arr[$table_type];
+        $order_info = Db::name($table_name)->field($field)->where('id',$order_id)->find();
+        if(empty($order_info) || $order_info['price_total'] <= 0){
+            return false;
+        }
+        $amount = $order_info['price_total'];
+        $worker_id = $order_info['worker_id'];
+        Db::startTrans();
+        $balance_data = array(
+            'amount' => $amount,
+            'user_id' => $worker_id,
+            'user_type' => 2,
+            'type' => 2,
+            'order_id' => $order_id,
+            'table_type' => $table_type,
+            'status' => 1
+        );
+        $error = 0;
+        $balance = Db::name('store_balance_list')->insert($balance_data);
+        if(!$balance){
+            $error = 1;
+            Db::rollback();
+        }
+        $worker = Db::name('store_worker')->where('id',$worker_id)->setDec('balance',$amount);
+        if(!$worker){
+            $error = 2;
+            Db::rollback();
+        }
+        if($error == 0){
+            Db::commit();
+            return true;
+        }else{
+            return false;
+        }
+    }
+    /**
+     * 订单支付完成进行返利(未到账,等货主点击确认完成才到账)
+     * $order_id 订单ID
+     */
+    public function serve_rebate($order_id){
+        $field = 'worker_id,price_total,worker_ratio';
+        $order_info = Db::name('store_order')->field($field)->where('id',$order_id)->find();
+        if(empty($order_info) || $order_info['price_total'] <= 0 || $order_info['worker_ratio'] <= 0){
+            return false;
+        }
+        //接单人员拿到的服务余额
+        $worker_serve_amount = sprintf("%.2f",$order_info['price_total'] * $order_info['worker_ratio'] / 100);
+        $worker_balance_data = array(
+            'amount' => $worker_serve_amount,
+            'user_id' =>  $order_info['worker_id'],
+            'user_type' => 2,
+            'get_type' => 2,
+            'order_id' => $order_id
+        );
+        $worker_balance = Db::name('store_balance_list')->insert($worker_balance_data);
+        if($worker_balance){
+            $data = array('code'=>1,'返利成功');
+        }else{
+            $data = array('code'=>0,'返利失败');
+        }
+        return $data;
+    }
+    /**
+     * 增加费用支付完成进行追加返利
+     * $order_id 增加费用订单ID
+     */
+    public function add_serve_rebate($order_id){
+        $expenses_order_info = Db::name('store_expenses_order')->field('price_total,order_id')->where('id',$order_id)->find();
+        if(empty($expenses_order_info) || $expenses_order_info['price_total'] <= 0 || $expenses_order_info['order_id'] <= 0){
+            return false;
+        }
+
+        $field = 'worker_id,price_total,worker_ratio';
+        $order_info = Db::name('store_order')->field($field)->where('id',$expenses_order_info['order_id'])->find();
+        if(empty($order_info) || $order_info['worker_ratio'] <= 0){
+            return false;
+        }
+        //增加接单人员拿到的服务余额
+        //获取下单服务拥挤返利的信息
+        $balance_info = Db::name('store_balance_list')->field('id,amount')->where('user_id',$order_info['worker_id'])->where('user_type',2)->where('order_id',$expenses_order_info['order_id'])->where('table_type',1)->find();
+        if(empty($balance_info)){
+            return false;
+        }
+        $worker_serve_amount = sprintf("%.2f",$expenses_order_info['price_total'] * $order_info['worker_ratio'] / 100);
+
+        $worker_balance = Db::name('store_balance_list')->where('id',$balance_info['id'])->update(array('amount'=>$balance_info['amount'] + $worker_serve_amount));
+        if($worker_balance){
+            $data = array('code'=>1,'增加返利成功');
+        }else{
+            $data = array('code'=>0,'增加返利失败');
+        }
+        return $data;
+    }
 }

+ 715 - 0
application/api/controller/Press.php

@@ -0,0 +1,715 @@
+<?php
+namespace app\api\controller;
+use app\common\model\PressComment;
+use app\common\model\PlatformLike;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserMessage;
+use app\common\model\UserReport;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use library\tools\Data;
+/**
+ * @title 新闻
+ * @controller Press
+ * @group base
+ */
+class Press extends Base
+{
+    // 需要登录的
+    protected $need_login = ['pressCollect','pressTransmit','pressRead','PressTags','pressComment','pressCommend','delComment'];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 新闻接口说明
+     * @desc  新闻接口说明
+     * @author  qc
+     * @url /api/Press/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:该模块没有视频!!
+     */
+     public function classIntro(){}
+
+    /**
+     * @title 获取新闻列表
+     * @desc 获取新闻列表
+     * @author qc
+     * @method GET
+     * @url /api/Press/getPressList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:images type:string default:-- desc:图片多张|隔开
+     * @return name:images_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:read_num type:int default:-- desc:阅读
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞
+     * @return name:comment_num type:int default:-- desc:评论量
+     */
+    public function getPressList(){
+        $title = input('get.title');
+
+        $sort_type = input('get.sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =   ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =   ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =   ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,4);
+        $list = \app\common\model\Press::where(['is_deleted'=>0])
+            ->field('id,images,title,content,read_num,create_at,transmit_num')
+            ->when($title,function ($query)use($title){
+            if($title) $query->where('title|label','like','%'.$title.'%');
+        })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['comment_num'] = PressComment::where(['first_id'=>$v['id'],'type'=>1,'is_deleted'=>0])->count();
+            $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
+            $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
+            $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
+            $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取新闻详情
+     * @desc 获取新闻详情
+     * @author qc
+     * @method GET
+     * @url /api/Press/getPressDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:新闻id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:images type:string default:-- desc:图片多张|隔开
+     * @return name:images_arr type:array default:-- desc:图片多张[数组]
+     * @return name:content type:string default:-- desc:详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:read_num type:int default:-- desc:阅读
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞
+     * @return name:comment_num type:int default:-- desc:评论量
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     */
+    public function getPressDetail()
+    {
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = \app\common\model\Press::field('id,images,title,content,read_num,create_at,transmit_num,user_id')->where($sel_where)->find()->toArray();
+        $detail['comment_num'] = PressComment::where(['first_id'=>$detail['id'],'type'=>1,'is_deleted'=>0])->count();
+        $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$detail['id']);
+        $detail['collect_num'] = UserCollect::getCollectNum(4,$detail['id']);
+        $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],1);
+        $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],1);
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        if(!$detail['user_id']){
+            $detail['app_name']  = $app_name;
+            $detail['app_logo']  = $app_logo;
+        }else{
+            $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
+            $detail['app_name']  = $user_info ? $user_info->name : '';
+            $detail['app_logo']  = $user_info ? $user_info->headimg : '';
+        }
+
+
+        UserTrack::crateTrack($this->user_id,4,input('get.id'),0);
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 获取新闻评论列表
+     * @desc 获取新闻评论列表
+     * @author qc
+     * @method GET
+     * @url /api/Press/getPressCommentList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:新闻id
+     * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数量
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
+     * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:total_num type:int default:-- desc:总评论数(仅一级)
+     */
+    public function getPressCommentList()
+    {
+        $where = [];
+        $where[] = ['c.first_id','=',input('get.id')];
+        $where[] = ['c.is_deleted','=',0];
+        $where[] = ['c.type','=',1];
+        $user_id = $this->user_id;
+        $sort_type= input('sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['c.id'=>'desc'];
+                break;
+            default:
+                $order =  ['c.like_times'=>'desc'];
+                break;
+        }
+        $list  =PressComment::where($where)
+            ->alias('c')
+            ->field('c.*,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+
+        array_walk($list,function (&$val,$k)use($user_id){
+            $children = PressComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->order('c.id asc')
+                ->select()->toArray();
+            $val['children'] =  $children ? $children : null;
+            $val['like_num'] = PlatformLike::getPraiseNum($val['id'],2);
+            $val['is_like'] =  PlatformLike::checkTags($user_id,$val['id'],2);
+            $parent  = PressComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->find();
+            $val['parent']  = $parent ? $parent->toArray() : null;
+        });
+        $total_num  = PressComment::where($where)->alias('c')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 删除评论
+     * @desc 删除评论
+     * @author qc
+     * @method POST
+     * @url /api/Press/delComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     */
+    public function delComment(){
+        PressComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
+        $this->success('删除成功');
+    }
+    
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc 以下接口调用验证登录
+     * @author qc
+     * @method
+     * @url /api/Press/needLogin()
+     */
+    public function needLogin(){}
+
+    /**
+     * @title 收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:新闻id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function pressCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,4,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+    /**
+     * @title 新闻转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:新闻id
+     */
+    public function pressTransmit()
+    {
+        $press_id = input('post.id',0);
+        \app\common\model\Press::where('id',$press_id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+
+    /**
+     * @title 新闻举报
+     * @desc  新闻举报
+     * @author  qc
+     * @url /api/Press/pressReport
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:report_id type:int default:-- desc:举报内容的id
+     * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
+     */
+    public function pressReport()
+    {
+        $report_id= input('post.report_id');
+        $case_ids= input('post.case_ids');
+        if(!$report_id) $this->error('请现在举报内容');
+        if(!$case_ids) $this->error('请选择举报原因');
+        UserReport::report($this->user_id,7,$report_id,$case_ids);
+        $this->success('举报成功');
+    }
+
+
+
+    /**
+     * @title 新闻阅读(阅读数量统计)
+     * @desc 新闻阅读
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressRead
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:新闻id
+     */
+    public function pressRead()
+    {
+        $press_id = input('post.id',0);
+        \app\common\model\Press::where('id',$press_id)->setInc('read_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 新闻点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Press/PressTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:新闻id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function pressTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),1);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 新闻评论点赞||取消点赞
+     * @desc 新闻评论点赞
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressCommentTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function pressCommentTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),2);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+
+    /**
+     * @title 新闻评论
+     * @desc 新闻评论
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:新闻id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function pressComment()
+    {
+        $id = input('post.id');
+        $content = input('post.content',0);
+        if(!$content) $this->error('请输入评论内容');
+        $res = PressComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
+        $detail  =PressComment::where('p.id',$res->id)
+            ->alias('p')
+            ->field('p.id,p.content,p.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = p.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 新闻二级评论
+     * @desc 新闻二级评论
+     * @author qc
+     * @method POST
+     * @url /api/Press/pressSecondComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function pressSecondComment()
+    {
+        $comment = PressComment::where('id',input('post.id'))->find()->toArray();
+
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($comment['user_id'],'press',1,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
+
+        unset($comment['id']);
+        unset($comment['create_at']);
+        $comment['pid'] = input('post.id');
+        $comment['user_id'] = $this->user_id;
+        $comment['content'] = input('post.content');
+        $comment['lev']++;
+        if(!$comment['source_id']) $comment['source_id'] = input('post.id');
+        $res = PressComment::create($comment);
+        $detail  = PressComment::where('p.id',$res->id)
+            ->alias('p')
+            ->field('p.id,p.content,p.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = p.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 回复我的【回复我的--回复过我的评论】
+     * @desc 回复我的
+     * @author qc
+     * @method GET
+     * @url /api/Press/getReplyComment
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:iamges_arr type:array default:-- desc:图片【多张】
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【其他会员】
+     * @return name:headimg type:string default:-- desc:用户头【其他会员】
+     * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:标题
+     * @return name:parent_comment.press_id type:string default:-- desc:新闻id
+     */
+    public function getReplyComment()
+    {
+        $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
+        if(empty($all_comment)) $this->success('ok',['list'=>null]);
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','>=',2];
+        $sel_where[]  = ['t.user_id','<>',$this->user_id];
+        $sel_where[]  = ['t.pid','in',implode(',',$all_comment)];
+        $list = PressComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.cover,i.images')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->leftJoin('Press i','t.first_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+            $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.first_id press_id,t.content,i.title,i.cover,t.pid,u.name')
+                ->alias('t')
+                ->leftJoin('Press i','t.first_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 评论我的
+     * @desc 评论我的
+     * @author qc
+     * @method GET
+     * @url /api/Press/commentMyPress
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:string default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名
+     * @return name:headimg type:string default:-- desc:用户头像
+     */
+    public function commentMyPress()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['i.user_id','=',$this->user_id];
+        $list = PressComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id press_id,t.content,i.title,i.cover,u.name user_name,u.headimg')
+            ->leftJoin('Press i','t.first_id = i.id')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的评论
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Press/getMyPressComment
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:string default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images_arr type:array default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     */
+    public function getMyPressComment()
+    {
+        $where = [];
+        $where[] = ['t.is_deleted','=',0];
+        $where[] = ['t.type','=',1];
+        $where[] = ['t.user_id','=',$this->user_id];
+        $list = PressComment::where($where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg')
+            ->leftJoin('Press i','t.first_id = i.id')
+            ->leftJoin('store_member u','u.id = t.user_id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+        }
+        $this->success('ok',['list'=>$list]);
+
+    }
+
+
+    /**
+     * @title 我的回复【我的回复--我回复过的评论】
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Press/getReplyPress
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:int default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:images_arr type:array default:-- desc:图片多张[数组]
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:新闻标题
+     * @return name:parent_comment.press_id type:string default:-- desc:新闻id
+     */
+    public function getReplyPress()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','>=',2];
+        $list = PressComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,i.title,i.cover,images')
+            ->leftJoin('Press i','t.first_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+            $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.first_id press_id,t.content,i.title,i.cover,i.images,t.pid,u.name')
+                ->alias('t')
+                ->leftJoin('Press i','t.first_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $parent_comment['images_arr'] = $parent_comment['images'] ? explode('|',$parent_comment['images']) : null;
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 我的收藏【新闻】
+     * @desc 我的收藏
+     * @author qc
+     * @method GET
+     * @url /api/Press/getPressCollect
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:string default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getPressCollect()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',4];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id press_id,i.title,i.cover,images')
+            ->leftJoin('Press i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的点赞列表【新闻】
+     * @desc 我的点赞
+     * @author qc
+     * @method GET
+     * @url /api/Press/getTagsPress
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:string default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getTagsPress()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',1];
+        $list = PlatformLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.like_id press_id,i.title,i.cover,images')
+            ->leftJoin('Press i','t.like_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的浏览历史【新闻】
+     * @desc 我的浏览历史
+     * @author qc
+     * @method GET
+     * @url /api/Press/getPressTrack
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:press_id type:string default:-- desc:新闻id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getPressTrack()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',4];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id press_id,i.title,i.cover,i.images')
+            ->leftJoin('Press i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
+            $v['cover'] =   $v['images_arr'] ? $v['images_arr'][0] : null;
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+
+
+
+
+
+
+
+}

+ 314 - 0
application/api/controller/Qc.php

@@ -0,0 +1,314 @@
+<?php
+
+namespace app\api\controller;
+use app\common\model\ChinaArea;
+use app\common\model\ForumReply;
+use app\common\model\GoodsOrder;
+use app\common\model\LevelOrder;
+use app\common\model\LevelOrder as LOM;
+use app\common\model\StoreGoods;
+use app\common\model\User;
+use app\common\model\UserLevelRank;
+use app\common\model\UserMessage;
+use app\common\model\UserWallet;
+use app\common\model\VideoIntro;
+use app\common\service\Activity;
+use app\common\service\OrderCallback;
+use app\order\controller\StoreOrder;
+use EasyWeChat\MiniProgram\Application;
+use library\tools\Data;
+use MongoDB\Driver\Server;
+use Qiniu\Auth;
+use Qiniu\Storage\UploadManager;
+use think\Exception;
+use think\Session;
+use think\cache\driver\Redis;
+use EasyWeChat\Factory;
+use Firebase\JWT\JWT;
+use think\Db;
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+use function AlibabaCloud\Client\value;
+use function EasyWeChat\Kernel\data_get;
+use function Stringy\create;
+
+use JPush\Client;
+require_once env('root_path').'vendor/jpush/jpush/autoload.php';
+class Qc extends Base {
+
+    public function index()
+    {
+        $user_id = 3333 ;
+        $alert ='aaa';
+        if(empty($user_id)) return false;
+        $appKey = '02a7faefd91c8a6a446a6a14';
+        $masterSecret = 'ba2e100db997024d9b6e5d35';
+        $client = new Client($appKey, $masterSecret,null);
+        $push_payload = $client->push()
+            ->setPlatform(array('ios', 'android'))
+            ->addAlias(strval($user_id))
+            //->addAllAudience()
+            ->iosNotification($alert, array(
+                'badge' => '+1',
+                'content-available' => true,
+                'mutable-content' => true,
+                'category' => 'jiguang',
+                'extras' => array(
+                    'key' => 'value',
+                    'jiguang'
+                ),
+            ))->androidNotification($alert, array(
+                'title' => '消息通知',
+                // 'builder_id' => 2,
+                'extras' => array(
+                    'key' => 'value',
+                    'jiguang'
+                ),
+            ))->options(array(
+                'apns_production' => True,
+            ));
+        try {
+            $response = $push_payload->send();
+            return $response;
+        } catch  (\JPush\Exceptions\APIConnectionException $e) {
+            return $e;
+        } catch (\JPush\Exceptions\APIRequestException $e) {
+            return $e;
+        }
+
+    }
+
+
+
+
+    public function payOrder()
+    {
+        $this->user_id = 22;
+        $order_id = input('post.order_id');
+        $pay_type = input('post.pay_type',1);
+        $order_info = LOM::where('id',$order_id)->find()->toArray();
+        if($order_info['status'] != 0) $this->error('订单状态错误');
+        if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
+        if($order_info['price_total'] <= 0) $this->error('订单金额错误');
+        $pay_no  = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
+        if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
+        $user_info = User::where('id',$this->user_id)->find()->toArray();
+        $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
+        Db::startTrans();
+        try {
+            switch ($pay_type){
+                case 1://微信小程序
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
+                    $pay_config['config']['pay_no'] = $pay_no;
+                    $pay_config['config']['notify_url'] = $notify_url;
+                    $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
+                    $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+                case 2 :
+                    if(!$user_info['openid']) $this->exception('请绑定公众号');
+                    $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
+                    $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
+                    if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
+                    $ret_data['config'] = $pay_config['config'];
+                    break;
+            }
+
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg =  $e->getMessage();
+            Db::rollback();
+        }
+        $this->transReturn($ret_data);
+    }
+
+
+
+    /**
+     * @title 获取分享的签名
+     * @desc 获取分享的签名
+     * @url /api/qc/getWeChatSign
+     * @method POST
+     * @tag 基础
+     *
+     **/
+    public function getWeChatSign(){
+        $urls = input('url');
+        $appid = config('app.official_account')['appid'];
+        $secret =  config('app.official_account')['secret'];
+        $redis = new Redis();
+        $access_token = $redis->get('access_token');
+        if (!$access_token){
+            $access_token = '';
+            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
+            $res= http_curl($url);
+            if (isset($res['access_token'])){
+                $redis->set('access_token',$res['access_token'],'7000');
+                $access_token = $res['access_token'];
+            }
+        }
+
+        $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
+        $res2=http_curl($url2);
+        if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
+        $timestamp = time();
+        $noncestr = get32Str(15);
+        $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
+        $sign = sha1($string);
+        $return = [
+            'appid'=>$appid,
+            'noncestr'=>$noncestr,
+            'timestamp'=>$timestamp,
+            'url'=>$urls,
+            'sign'=>$sign,
+            'ticket'=>$res2['ticket']
+        ];
+        $this->success('成功',$return);
+    }
+
+    /**
+     * 导入子项目数据
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function import()
+    {
+        $get = $this->request->get();
+        $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
+        $project_id = $get['project_id'];
+        $num = 5;
+        try {
+            $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
+            $objExcel = $objReader->load($import_path);
+
+            $list = $objExcel->getActiveSheet()->toArray();
+            if (!isset($list[2][15]) || !$list[2][15]){
+                $this->error('失败');
+            }
+            if (isset($list[2][16])){
+                $this->error('失败');
+            }
+            Db::name($this->table3)->where('project_id',$project_id)->delete();
+            Db::name($this->table)->where('id',$project_id)->update(['url'=>$get['url']]);
+            $result = 0;
+            foreach ($list as $k=>$v){
+                if($k>=$num-1){
+                    if(array_filter($v)){
+                        $data=[];
+                        foreach ($v as $kk=>$vv){
+                            $data[IntToChr($kk)]=trim($vv);
+                        }
+                        $date['project_id'] = $project_id;
+                        $date['number'] = $data['A'];
+                        $date['cost_project'] = $data['B'];
+                        $date['area_calculating_aperture'] = $data['C'];
+                        $date['single_party_cost'] = $data['D'];
+                        $date['single_party_cost1'] = str_replace(',','',$data['D']);
+                        $date['total_price_included'] = $data['E'];
+                        $date['total_price_included1'] = str_replace(',','',$data['E']);
+                        $date['single_party_cost_excluding'] = $data['F'];
+                        $date['single_party_cost_excluding1'] = str_replace(',','',$data['F']);
+                        $date['total_price_included_excluding'] = $data['G'];
+                        $date['total_price_included_excluding1'] = str_replace(',','',$data['G']);
+
+                        $date['single_party_cost_tax'] = $data['H'];
+                        $date['single_party_cost_tax1'] = str_replace(',','',$data['H']);
+                        $date['single_party_cost_no_tax'] = $data['I'];
+                        $date['single_party_cost_no_tax1'] = str_replace(',','',$data['I']);
+
+                        $date['quantities'] = $data['J'];
+                        $date['quantities1'] = str_replace(',','',$data['J']);
+                        $date['calculating_unit'] = $data['K'];
+                        $date['unilateral_content'] = $data['L'];
+                        $date['unilateral_content1'] = str_replace(',','',$data['L']);
+                        $date['unilateral_content_excluding'] = $data['M'];
+                        $date['unilateral_content_excluding1'] = str_replace(',','',$data['M']);
+
+                        $date['saleable_single_party_tax'] = $data['N'];
+                        $date['saleable_single_party_tax1'] = str_replace(',','',$data['N']);
+
+                        $date['saleable_single_party_no_tax'] = $data['O'];
+                        $date['saleable_single_party_no_tax1'] = str_replace(',','',$data['O']);
+
+                        $date['note'] = $data['P'];
+                        $date['create_at'] = date('Y-m-d H:i:s');
+
+                        $numbers = explode('.',$data['A']);
+                        if (count($numbers)>1){
+                            array_pop($numbers); //去掉数组最后一组元素
+                            $number = implode('.',$numbers);
+                            $date['pid'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('id');
+                            $date['pname'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('cost_project');
+                        }else{
+                            $date['pid'] = 0;
+                            $date['pname'] = '';
+                        }
+                        if (Db::table($this->table3)->insertGetId($date)){
+                            $result = 1;
+                        }else{
+                            $result = 0;
+                            break;
+                        }
+                    }
+                }
+            }
+            if ($result==1){
+                $this->success('成功');
+            }else{
+                $this->error('失败');
+            }
+        } catch (\think\exception\ValidateException $e) {
+            $this->error($e->getMessage());
+
+        }
+    }
+
+    function excelToArray(){
+        //加载excel文件
+        $filename = dirname(__FILE__).'/result.xlsx';
+        $objPHPExcelReader = \PHPExcel_IOFactory::load($filename);
+
+        $sheet = $objPHPExcelReader->getSheet(0);        // 读取第一个工作表(编号从 0 开始)
+        $highestRow = $sheet->getHighestRow();           // 取得总行数
+        $highestColumn = $sheet->getHighestColumn();     // 取得总列数
+
+        $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
+        // 一次读取一列
+        $res_arr = array();
+        for ($row = 2; $row <= $highestRow; $row++) {
+            $row_arr = array();
+            for ($column = 0; $arr[$column] != 'F'; $column++) {
+                $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
+                $row_arr[] = $val;
+            }
+
+            $res_arr[] = $row_arr;
+        }
+
+        return $res_arr;
+    }
+
+
+
+
+
+
+    public function index_match()
+    {
+        $password = "123456879_/";
+        //密码必须包含大小写字母/数字/符号任意两者组合
+        $regStr = "/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,16}$/";
+        var_dump(preg_match($regStr, $password));
+
+    }
+
+
+
+
+}

+ 503 - 0
application/api/controller/Recruit.php

@@ -0,0 +1,503 @@
+<?php
+namespace app\api\controller;
+use app\common\model\PlatformLike;
+use app\common\model\RecruitCate;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 招聘
+ * @controller Recruit
+ * @group base
+ */
+class Recruit extends Base
+{
+    // 需要登录的
+    protected $need_login = [
+        'activityTags',
+        'recruitCollect',
+        'recruitTransmit',
+        'getOwnRecruitList',
+        'getBrowseList',
+        'getRecruitCollect',
+    ];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 招聘接口说明
+     * @desc  招聘接口说明
+     * @author  qc
+     * @url /api/Recruit/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:--
+     */
+     public function classIntro(){}
+
+    /**
+     * @title 获取招聘分类
+     * @desc  两级分类
+     * @author  qc
+     * @url /api/Recruit/getRecruitCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:分类id
+     * @return name:title type:string default:0 desc:分类名称
+     * @return name:children type:array default:0 desc:下级分类
+     */
+     public function getRecruitCate()
+     {
+         $list = RecruitCate::where(['is_deleted'=>0])->field('id,title,pid')->order('sort desc')->select()->toArray();
+         $list =  make_tree($list);
+         $this->success('ok',['list'=>$list]);
+     }
+
+
+    /**
+     * @title 联系我们【两个二维码】(招聘详情内部)
+     * @desc 联系HR
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getRecruitContact
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:招聘记录id
+     * @return name:phone type:string default:-- desc:招聘电话
+     * @return name:email type:string default:-- desc:招聘email
+     * @return name:hr_code type:int default:-- desc:招聘二维码
+     * @return name:principal type:string default:-- desc:招聘联系人
+     * @return name:qrcode type:string default:-- desc:平台二维码
+     * @return name:contact_phone type:string default:-- desc:平台电话
+     * @return name:contact_email type:string default:-- desc:平台邮箱
+     */
+     public function getRecruitContact()
+     {
+         $sel_where[]  = ['id','=',input('get.id')];
+         $detail = \app\common\model\Recruit::field('id,phone,email,hr_code,principal')->where($sel_where)->find()->toArray();
+         $contact = Db::name('contact')->where('tag','recruit')->field('qrcode,phone contact_phone,email contact_email')->find();
+         $contact['phone'] = $detail['phone'];
+         $contact['email'] = $detail['email'];
+         $contact['hr_code'] = $detail['hr_code'];
+         $contact['principal'] = $detail['principal'];
+         $this->success('ok',$contact);
+
+     }
+
+
+    /**
+     * @title 招聘推荐
+     * @desc 招聘推荐
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:记录ID
+     * @return name:title type:string default:-- desc:标题
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:principal type:string default:-- desc:联系人
+     * @return name:hr_headimg type:string default:-- desc:hr头像
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:salary type:int default:-- desc:薪资【文本】
+     * @return name:province type:string default:-- desc:省名
+     * @return name:city type:string default:-- desc:市名
+     * @return name:county type:string default:-- desc:县区
+     * @return name:address type:string default:-- desc:地址
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     */
+    public function getRecommendList()
+    {
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $search_log =  UserSearch::getSearchTitle($this->user_id,8);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = 'a.id,title,a.user_id,label,salary,principal,hr_headimg,address,price_min,price_max,company,education,experience_min,experience_max,welfare,province,city,county,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_recruit';
+        $order_by_two = 'id';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.status = 1 AND a.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+        });
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取招聘列表
+     * @desc 获取招聘列表
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getRecruitList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:first_classify type:int default:0 desc:一级分类id
+     * @param  name:second_classify type:int default:0 desc:二级分类id
+     *
+     * @return name:title type:string default:-- desc:标题
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:phone type:string default:-- desc:电话
+     * @return name:email type:string default:-- desc:email
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:salary type:int default:-- desc:薪资【文本】
+     * @return name:content type:string default:-- desc:招聘详情
+     * @return name:create_at type:string default:-- desc:发布时间
+     * @return name:first_classify type:int default:-- desc:一级分类id
+     * @return name:second_classify type:int default:-- desc:二级分类id
+     * @return name:province type:string default:-- desc:省名
+     * @return name:city type:string default:-- desc:市名
+     * @return name:county type:string default:-- desc:县区
+     * @return name:address type:string default:-- desc:地址
+     * @return name:longitude type:string default:-- desc:经度
+     * @return name:latitude type:string default:-- desc:纬度
+     * @return name:num type:int default:-- desc:招聘人数
+     * @return name:app_name type:string default:-- desc:发布方名称
+     * @return name:app_logo type:string default:-- desc:发布方头像
+     */
+    public function getRecruitList(){
+        $title = input('get.title');
+        $sort_type = input('get.sort_type',1);
+        $first_classify = input('get.first_classify');
+        $second_classify = input('get.second_classify');
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        switch ($sort_type) {
+            case 1:
+                $order =   ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =   ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =   ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        $sel_where = [];
+        $sel_where[] = ['is_deleted','=',0];
+        $sel_where[] = ['status','=',1];
+        if($first_classify)  $sel_where[]  = ['first_classify','=',$first_classify];
+        if($second_classify)  $sel_where[]  = ['second_classify','=',$second_classify];
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,8);
+        $list = \app\common\model\Recruit::where($sel_where)
+            ->when($title,function ($query)use($title){
+                if($title) $query->where('title|label','like','%'.$title.'%');
+            })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取招聘详情
+     * @desc 获取招聘详情
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getRecruitDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:招聘记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:company_label type:array default:-- desc:公司标签
+     * @return name:principal type:string default:-- desc:联系人
+     * @return name:hr_headimg type:string default:-- desc:联系人头像
+     * @return name:phone type:string default:-- desc:电话
+     * @return name:email type:string default:-- desc:email
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:salary type:int default:-- desc:薪资【文本】
+     * @return name:content type:string default:-- desc:招聘详情
+     * @return name:create_at type:string default:-- desc:发布时间
+     * @return name:first_classify type:int default:-- desc:一级分类id
+     * @return name:second_classify type:int default:-- desc:二级分类id
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞【0否1是】
+     * @return name:is_collect type:int default:-- desc:是否收藏【0否1是】
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:province type:string default:-- desc:省名
+     * @return name:city type:string default:-- desc:市名
+     * @return name:county type:string default:-- desc:县区
+     * @return name:address type:string default:-- desc:地址
+     * @return name:longitude type:string default:-- desc:经度
+     * @return name:latitude type:string default:-- desc:纬度
+     * @return name:num type:int default:-- desc:招聘人数
+     * @return name:hr_code type:int default:-- desc:二维码
+     */
+    public function getRecruitDetail()
+    {
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = \app\common\model\Recruit::where($sel_where)->find()->toArray();
+        $detail['label_name'] = explode(',',trim($detail['label'],','));
+        $detail['welfare_arr'] = explode(',',trim($detail['welfare'],','));
+        $detail['company_label'] = explode(',',trim($detail['company_label'],','));
+        $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],5);
+        $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],5);
+        $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,8,$detail['id']);
+        $detail['collect_num'] = UserCollect::getCollectNum(8,$detail['id']);
+        UserTrack::crateTrack($this->user_id,8,input('get.id'),0);
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc 以下接口调用验证登录
+     * @author qc
+     * @method
+     * @url /api/Recruit/needLogin()
+     */
+    public function needLogin(){}
+
+    /**
+     * @title 点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Recruit/recruitTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:招聘记录id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function recruitTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),5);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Recruit/recruitCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:招聘记录id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function recruitCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,8,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+    /**
+     * @title 转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Recruit/recruitTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:招聘记录id
+     */
+    public function recruitTransmit()
+    {
+        $id = input('post.id',0);
+        \app\common\model\Recruit::where('id',$id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+
+
+    /**
+     * @title 我的发布【招聘】
+     * @desc 我的发布【招聘】
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getOwnRecruitList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:salary type:int default:-- desc:薪资【文本】
+     * @return name:create_at type:string default:-- desc:发布时间
+     * @return name:num type:int default:-- desc:招聘人数
+     * @return name:principal type:string default:-- desc:联系人
+     * @return name:hr_headimg type:string default:-- desc:联系人头像
+     */
+    public function getOwnRecruitList()
+    {
+        $title = input('get.title');
+        $sel_where = [];
+        $sel_where[] = ['is_deleted','=',0];
+        $sel_where[] = ['status','=',1];
+        $sel_where[] = ['user_id','=',$this->user_id];
+        $list = \app\common\model\Recruit::where($sel_where)
+            ->field('id,title,company,label,welfare,education,experience_min,salary,experience_max,price_min,price_max,create_at,num,principal,hr_headimg,province,city,county')
+            ->when($title,function ($query)use($title){
+                if($title) $query->where('title|label','like','%'.$title.'%');
+            })->order(['id'=>'desc'])
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+                $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 浏览记录【招聘】
+     * @desc 浏览记录【招聘】
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getBrowseList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:浏览记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:recruit_id type:int default:-- desc:招聘记录id
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:salary type:int default:-- desc:薪资【文本】
+     * @return name:num type:int default:-- desc:招聘人数
+     * @return name:time type:string default:-- desc:浏览时间
+     * @return name:principal type:string default:-- desc:联系人
+     * @return name:hr_headimg type:string default:-- desc:联系人头像
+     */
+    public function getBrowseList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',8];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id recruit_id,i.salary,i.title,i.price_max,i.company,i.label,province,city,county,i.welfare,i.education,i.experience_min,i.experience_max,price_min,price_max,i.num,principal,hr_headimg')
+            ->leftJoin('Recruit i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+                $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 收藏记录【招聘】
+     * @desc 收藏记录【招聘】
+     * @author qc
+     * @method GET
+     * @url /api/Recruit/getRecruitCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:收藏记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:recruit_id type:int default:-- desc:招聘记录id
+     * @return name:company type:string default:-- desc:公司名
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:welfare_arr type:array default:-- desc:岗位福利
+     * @return name:education type:string default:-- desc:学历
+     * @return name:experience_min type:int default:0 desc:最低工作年限
+     * @return name:experience_max type:int default:0 desc:最高工作年限
+     * @return name:price_min type:int default:-- desc:最低薪资[弃用]
+     * @return name:price_max type:int default:-- desc:最高薪资[弃用]
+     * @return name:, type:int default:-- desc:薪资【文本】
+     * @return name:num type:int default:-- desc:招聘人数
+     * @return name:time type:string default:-- desc:浏览时间
+     * @return name:principal type:string default:-- desc:联系人
+     * @return name:hr_headimg type:string default:-- desc:联系人头像
+     */
+    public function getRecruitCollect()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',8];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id recruit_id,i.title,i.company,i.label,i.salary,i.welfare,i.education,i.experience_min,i.experience_max,price_min,price_max,i.num,principal,hr_headimg,province,city,county')
+            ->leftJoin('Recruit i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+                $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['welfare_arr'] = explode(',',trim($v['welfare'],','));
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+}

+ 100 - 0
application/api/controller/Report.php

@@ -0,0 +1,100 @@
+<?php
+namespace app\api\controller;
+use app\common\model\ArticleIntro;
+use app\common\model\DatumIntro;
+use app\common\model\ReportCase;
+use app\common\model\User;
+use app\common\model\UserForum;
+use app\common\model\UserReport;
+use app\common\model\VideoComment;
+use app\common\model\VideoIntro;
+use library\tools\Data;
+
+/**
+ * @title 举报
+ * @controller Report
+ * @group base
+ */
+class Report extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 获取举报类目
+     * @desc  获取举报类目(共两级)
+     * @author  qc
+     * @url /api/Report/getReportCase
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:id
+     * @return name:title type:string default:0 desc:名称
+     * @return name:children type:array default:0 desc:下级分类
+     */
+    public function getReportCase()
+    {
+        $list = ReportCase::where(['is_deleted'=>0])->field('id,title,pid')->order('sort desc')->select()->toArray();
+        $list =  make_tree($list);
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 用户举报
+     * @desc  用户举报
+     * @author  qc
+     * @url /api/Report/userReport
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:type type:int default:1 desc:举报类型(1视频2视频评论3会员,4资料,5图文6论坛问题)
+     * @param name:report_id type:int default:-- desc:举报内容的id
+     * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
+     */
+    public function userReport()
+    {
+        $type= input('post.type',1);
+        $report_id= input('post.report_id');
+        $case_ids= input('post.case_ids');
+        if(!$report_id) $this->error('请现在举报内容');
+        if(!$case_ids) $this->error('请选择举报原因');
+        switch ($type)
+        {
+            case 1:
+                $check_id =  VideoIntro::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('视频不存在');
+                break;
+            case 2:
+                $check_id =  VideoComment::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('视频评论不存在');
+                break;
+            case 3:
+                $check_id =  User::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('会员不存在');
+                break;
+            case 4:
+                $check_id =  DatumIntro::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('资料不存在');
+                break;
+            case 5:
+                $check_id =  ArticleIntro::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('图文不存在');
+                break;
+            case 6:
+                $check_id =  UserForum::where('id',$report_id)->value('id');
+                if(!$check_id) $this->error('论坛问题不存在');
+                break;
+        }
+        UserReport::report($this->user_id,$type,$report_id,$case_ids);
+        $this->success('举报成功');
+    }
+
+
+
+
+
+
+
+
+}

+ 99 - 0
application/api/controller/Sample.php

@@ -0,0 +1,99 @@
+<?php
+
+// This file is auto-generated, don't edit it. Thanks.
+namespace app\api\controller;
+use app\common\controller\Api;
+use AlibabaCloud\SDK\Vod\V20170321\Vod;
+use \Exception;
+use AlibabaCloud\Tea\Exception\TeaError;
+use AlibabaCloud\Tea\Utils\Utils;
+use library\File;
+use Darabonba\OpenApi\Models\Config;
+use AlibabaCloud\SDK\Vod\V20170321\Models\CreateUploadVideoRequest;
+use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
+use AlibabaCloud\SDK\Vod\V20170321\Models\GetPlayInfoRequest;
+$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
+if (file_exists($path))require_once $path;
+class Sample extends Base
+{
+
+    protected $id ;
+    protected $key;
+    protected $host;
+    protected $accessKeyId = 'LTAI5tJ5p12drZegeWVG33xZ';
+    protected $accessKeySecret = '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB';
+    protected $endpoint = 'outin-146bbb17cdb211ec935300163e1c7426.oss-cn-shanghai.aliyuncs.com';
+
+    public function initialize(){
+        $this->id =   config('app.ali_set.Key');
+        $this->key =  config('app.ali_set.secret');
+        $this->host = config('app.ali_set.host');
+    }
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param string $accessKeyId
+     * @param string $accessKeySecret
+     * @return Vod Client
+     */
+    public static function createClient($accessKeyId, $accessKeySecret)
+    {
+        $config = new Config([
+            // 您的 AccessKey ID
+            "accessKeyId" => $accessKeyId,
+            // 您的 AccessKey Secret
+            "accessKeySecret" => $accessKeySecret
+        ]);
+        // 访问的域名
+        $config->endpoint ='vod.cn-shanghai.aliyuncs.com';
+        return new Vod($config);
+    }
+
+    // 文件上传
+    public function upload()
+    {
+        if (!($file = $this->getUploadFile()) || empty($file)) $this->error('文件上传异常,文件可能过大或未上传!');
+        if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) $this->error('文件上传类型受限,请在后台配置!');
+        if ($file->checkExt('php,sh')) $this->error('可执行文件禁止上传到本地服务器!');
+        $size = $file->getSize();
+        $file_name = $file->getInfo('name');
+        $extend = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION);
+        $up_param = [
+            'fileName'=>$file_name,
+            'FileSize'=>$size,
+            'title'=>'视频上传',
+        ];
+        var_dump($up_param);
+        $client = self::createClient($this->accessKeyId, $this->accessKeySecret);
+        $createUploadVideoRequest = new CreateUploadVideoRequest($up_param);
+        $runtime = new RuntimeOptions([]);
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+           $res = $client->createUploadVideoWithOptions($createUploadVideoRequest, $runtime);
+            //$c = json_encode(simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA));
+           var_dump(json_decode(json_encode($res),true));
+        } catch (Exception $error) {
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            // 如有需要,请打印 error
+            Utils::assertAsString($error->message);
+            var_dump($error->message.'22222');
+        }
+    }
+
+    /**
+     * 获取本地文件对象
+     * @return \think\File
+     */
+    private function getUploadFile()
+    {
+        try {
+            return $this->request->file('file');
+        } catch (\Exception $e) {
+            $this->error(lang($e->getMessage()));
+        }
+    }
+
+}
+

+ 235 - 0
application/api/controller/Sign.php

@@ -0,0 +1,235 @@
+<?php
+namespace app\api\controller;
+use app\common\model\UserSignCard;
+use app\common\model\UserWallet;
+use think\Db;
+use app\common\model\UserSign;
+/**
+ * @title 会员签到
+ * @controller Sign
+ * @group base
+ */
+class Sign extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 验证会员当天是否签到
+     * @desc  验证会员当天是否签到
+     * @author qc
+     * @url /api/Sign/checkSign
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return  name:is_sign type:int  default:0  desc:是否签到0未签到,1已签到
+     */
+    public function checkSign()
+    {
+        $year = date('Y');
+        $month = date('m');
+        $day = date('d');
+        $ck_sign = UserSign::where(['user_id'=>$this->user_id,'year'=>$year,'month'=>$month,'day'=>$day])->count();
+        $this->success('ok',['is_sign'=>$ck_sign]);
+    }
+
+    /**
+     * @title 获取会员连续签到天数
+     * @desc  获取会员连续签到天数
+     * @author qc
+     * @url /api/Sign/getContinuousSign
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:is_sign type:int  default:-- desc:当天是否签到(0签到,1已签到)
+     * @return name:sign_num type:int  default:-- desc:连续签到天数
+     * @return name:sign_card type:int  default:-- desc:补签卡数量
+     */
+    public function getContinuousSign()
+    {
+        $today_sign =  UserSign::where(['user_id'=>$this->user_id,'day_time'=>date('Y-m-d')])->find();
+        $is_sign = !empty($today_sign) ? 1:0;
+        $sign_num = 0;
+        $week_sign = UserSign::where('user_id','=',$this->user_id)
+            ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
+            ->where('status','=',0)
+            ->order('create_at desc')
+            ->select()->toArray();
+        $sign_date =  array_column($week_sign,'day_time');
+        for($i=0;$i<=6;$i++) {
+            if(in_array(date('Y-m-d',strtotime("-$i days")),$sign_date)){
+                $sign_num++;
+            }else if($i>0){
+                break;
+            }
+        }
+        $sign_card = UserSignCard::where(['user_id'=>$this->user_id,'status'=>0])->count();
+        $this->success('ok',['sign_num'=>$sign_num,'is_sign'=>$is_sign,'sign_card'=>$sign_card]);
+    }
+
+    /**
+     * @title 会员签到
+     * @desc 会员签到
+     * @author qc
+     * @url /api/Sign/userSign
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @return name:integral type:int  default:--  desc:签到获得积分数
+     * @return name:next_integral type:int  default:--  desc:明日签到积分
+     * @return name:sign_num type:int  default:--  desc:连续签到天数
+     */
+    public function userSign()
+    {
+        $year = date('Y');
+        $month = date('m');
+        $day = date('d');
+        $ck_sign = UserSign::where(['user_id'=>$this->user_id,'year'=>$year,'month'=>$month,'day'=>$day])->count();
+        if($ck_sign) $this->error('已签到');
+        $sign_data=[
+            'user_id' =>$this->user_id,
+            'year' =>$year,
+            'month' =>$month,
+            'day' =>$day,
+            'day_time'=>date('Y-m-d'),
+            'create_at' => date('Y-m-d H:i:s'),
+            'desc' => '每日签到',
+        ];
+        UserSign::create($sign_data);
+
+        $sign_num = 0;
+        // 最近七天签到情况
+        $week_sign = UserSign::where('user_id','=',$this->user_id)
+            ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
+            ->where('status','=',0)
+            ->order('create_at desc')
+            ->select()->toArray();
+        $sign_date =  array_column($week_sign,'day_time');
+        for($i=0;$i<=6;$i++) {
+            if(in_array(date('Y-m-d',strtotime("-$i days")),$sign_date)){
+                $sign_num++;
+            }else if($i>0){
+                break;
+            }
+        }
+        $integral = in_array($sign_num,[2,3]) ? $sign_num:1;
+        UserWallet::userIntegralChange($this->user_id,$integral,'签到奖励',6, 1);
+        UserWallet::userExpChange($this->user_id,$integral,'签到奖励');
+        $next_integral = 1;
+        if(in_array($sign_num,[1,2]))$next_integral += $sign_num;
+        $this->success('签到成功',['integral'=>$integral,'sign_num'=>$sign_num,'next_integral'=>$next_integral]);
+    }
+
+    /**
+     * @title 会员领取签到卡
+     * @desc 会员领取签到卡
+     * @author qc
+     * @url /api/Sign/getSignCard
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     */
+    public function getSignCard()
+    {
+        $sign_num = 0;
+        // 最近七天签到情况
+        $week_sign = UserSign::where('user_id','=',$this->user_id)
+            ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
+            ->where('status','=',0)
+            ->order('create_at desc')
+            ->count();
+        $sign_date =  array_column($week_sign,'day_time');
+        for($i=0;$i<=6;$i++) {
+            if(in_array(date('Y-m-d',strtotime("-$i days")),$sign_date)){
+                $sign_num++;
+            }else if($i>0){
+                break;
+            }
+        }
+        if($sign_num != 7) $this->error('连续签到天数不足7天');
+        UserSign::where('user_id','=',$this->user_id)
+            ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
+            ->where('status','=',0)
+            ->update(['status'=>1]);
+        UserSignCard::create([ 'user_id' => $this->user_id]);
+        $this->success('领取成功');
+    }
+
+
+    /**
+     * @title 会员补签
+     * @desc 会员补签
+     * @author qc
+     * @url /api/Sign/retroactive
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:date_time type:int  default:--  desc:补签日期(2022-04-07)
+     * @return name:integral type:int  default:--  desc:签到获得积分数
+     * @return name:next_integral type:int  default:--  desc:明日签到积分
+     * @return name:sign_num type:int  default:--  desc:连续签到天数
+     */
+    public function retroactive()
+    {
+        $date_time = input('post.date_time',date('Y-m-d'));
+        $year = date('Y',strtotime($date_time));
+        $month = date('m',strtotime($date_time));
+        $day = date('d',strtotime($date_time));
+        $ck_sign = UserSign::where(['user_id'=>$this->user_id,'year'=>$year,'month'=>$month,'day'=>$day])->count();
+        if($ck_sign) $this->error('已签到');
+        $user_card = UserSignCard::where(['user_id'=>$this->user_id,'status'=>0])->min('id');
+        if(!$user_card) $this->error('补签卡不足');
+        $sign_data=[
+            'user_id' =>$this->user_id,
+            'year' =>$year,
+            'month' =>$month,
+            'day' =>$day,
+            'day_time'=>$date_time,
+            'create_at' => $date_time . date('H:i:s'),
+            'desc' => '每日签到(补签)',
+        ];
+        UserSign::create($sign_data);
+
+        $sign_num = 0;
+        // 最近七天签到情况
+        $week_sign = UserSign::where('user_id','=',$this->user_id)
+            ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
+            ->where('status','=',0)
+            ->order('create_at desc')
+            ->select()->toArray();
+        $sign_date =  array_column($week_sign,'day_time');
+        for($i=0;$i<=6;$i++) {
+            if(in_array(date('Y-m-d',strtotime("-$i days")),$sign_date)){
+                $sign_num++;
+            }else if($i>0){
+                break;
+            }
+        }
+        $integral = in_array($sign_num,[2,3]) ? $sign_num:1;
+        $next_integral = 1;
+        if(in_array($sign_num,[1,2]))$next_integral += $sign_num;
+        $this->success('补签成功',['integral'=>$integral,'sign_num'=>$sign_num,'next_integral'=>$next_integral]);
+    }
+
+
+    /**
+     * @title 会员签到列表
+     * @desc  会员签到列表
+     * @author  qc
+     * @url /api/Sign/getSignList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int  default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:desc type:string default:-- desc:描述
+     */
+    public function getSignList()
+    {
+        $list = UserSign::field('id,create_at,desc')
+            ->where('user_id','=',$this->user_id)
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select();
+        $this->success('ok',['list'=>$list ? $list->toAray() :[]]);
+    }
+
+}

+ 618 - 0
application/api/controller/Supplier.php

@@ -0,0 +1,618 @@
+<?php
+namespace app\api\controller;
+use app\common\model\PlatformLike;
+use app\common\model\PressComment;
+use app\common\model\SupplierCate;
+use app\common\model\UserCollect;
+use app\common\model\UserSearch;
+use app\common\model\SupplierGoods;
+use app\common\model\UserTrack;
+use library\tools\Data;
+use think\Db;
+
+/**
+ * @title 供应商
+ * @controller Supplier
+ * @group base
+ */
+class Supplier extends Base
+{
+    // 需要登录的
+    protected $need_login = ['','',''];
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+    /**
+     * @title 供应商接口说明
+     * @desc  供应商接口说明
+     * @author  qc
+     * @url /api/Supplier/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:--
+     */
+     public function classIntro(){}
+
+    /**
+     * @title 获取供应商分类
+     * @desc  两级分类
+     * @author  qc
+     * @url /api/Supplier/getSupplierCate
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:分类id
+     * @return name:title type:string default:0 desc:分类名称
+     * @return name:children type:array default:0 desc:下级分类
+     */
+     public function getSupplierCate()
+     {
+         $list = SupplierCate::where(['is_deleted'=>0])->field('id,title,pid')->order('sort desc')->select()->toArray();
+         $list =  make_tree($list);
+         $this->success('ok',['list'=>$list]);
+     }
+
+
+
+    /**
+     * @title 联系我们(详情内部)【两个二维码】
+     * @desc 联系我们
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierContact
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:supplier_id type:int default:-- desc:供应商id
+     * @return name:phone type:string default:-- desc:供应商电话
+     * @return name:email type:string default:-- desc:供应商email
+     * @return name:qr_code type:int default:-- desc:供应商二维码
+     * @return name:contact_qrcode type:string default:-- desc:平台二维码
+     * @return name:contact_phone type:string default:-- desc:平台电话
+     * @return name:contact_email type:string default:-- desc:平台邮箱
+     */
+    public function getSupplierContact()
+    {
+        $sel_where[]  = ['id','=',input('get.supplier_id')];
+        $detail = \app\common\model\Supplier::field('id,phone,email,qr_code')->where($sel_where)->find()->toArray();
+        $contact = Db::name('contact')->where('tag','supplier')->field('qrcode contact_qrcode,phone contact_phone,email contact_email')->find();
+        $contact['phone'] = $detail['phone'];
+        $contact['email'] = $detail['email'];
+        $contact['qr_code'] = $detail['qr_code'];;
+        $this->success('ok',$contact);
+
+    }
+
+
+
+
+    /**
+     * @title 获取供应商列表
+     * @desc 获取供应商列表
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:first_classify type:int default:0 desc:一级分类id
+     * @param  name:second_classify type:int default:0 desc:二级分类id
+     *
+     * @return name:title type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:phone type:string default:-- desc:电话
+     * @return name:email type:string default:-- desc:email
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:content type:string default:-- desc:供应商详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:build_time type:string default:-- desc:成立时间
+     * @return name:work_place type:string default:-- desc:办公地点
+     * @return name:business type:string default:-- desc:业务范围
+     *
+     */
+    public function getSupplierList(){
+        $title = input('get.title');
+        $sort_type = input('get.sort_type',1);
+        $first_classify = input('get.first_classify');
+        $second_classify = input('get.second_classify');
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+        $sel_where = [];
+        $sel_where[] = ['is_deleted','=',0];
+        $sel_where[] = ['status','=',1];
+        if($first_classify)  $sel_where[]  = ['first_classify','=',$first_classify];
+        if($second_classify)  $sel_where[]  = ['second_classify','=',$second_classify];
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,9);
+        $list = \app\common\model\Supplier::where($sel_where)
+            ->when($title,function ($query)use($title){
+                if($title) $query->where('title|label','like','%'.$title.'%');
+            })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover'] =$v['logo'] ;
+            $v['label_name'] =$v['label'] ?  explode(',',trim($v['label'],',')):null;
+            $v['business_arr'] = $v['business'] ? explode(',',trim($v['business'],',')) : null;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取供应商详情
+     * @desc 获取供应商详情
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:-- desc:供应商记录id
+     * @return name:title type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:公司logo
+     * @return name:phone type:string default:-- desc:电话
+     * @return name:email type:string default:-- desc:email
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:content type:string default:-- desc:供应商详情
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:build_time type:string default:-- desc:成立时间
+     * @return name:work_place type:string default:-- desc:办公地点
+     * @return name:business type:string default:-- desc:业务范围
+
+
+     */
+    public function getSupplierDetail()
+    {
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = \app\common\model\Supplier::where($sel_where)->find()->toArray();
+        $detail['label_name'] =$detail['label'] ?  explode(',',trim($detail['label'],',')):null;
+        $detail['business_arr'] = $detail['business'] ? explode(',',trim($detail['business'],',')) : null;
+        UserTrack::crateTrack($this->user_id,9,input('get.id'),0);
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+    /**
+     * @title 供应商商品推荐
+     * @desc 供应商商品推荐
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:int default:-- desc:供应商商品d
+     * @return name:name type:string default:-- desc:商品名称
+     * @return name:cover_arr type:array default:-- desc:封面
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:label type:string default:-- desc:标签
+     * @return name:supplier_name type:float default:-- desc:供应商名称
+     * @return name:supplier_logo type:string default:-- desc供应商logo
+     * @return name:read_num type:int default:-- desc:阅读量
+     *
+     */
+    public function getRecommendList()
+    {
+        $search_log =  UserSearch::getSearchTitle($this->user_id,10);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.name like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = 'a.id,a.supplier_id,a.name,a.label,a.cover,a.read_num,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_supplier_goods';
+        $order_by_two = 'read_num';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_supplier as k ON a.supplier_id = k.id  WHERE a.is_deleted = 0 AND a.status = 1 AND k.status =1 AND k.is_deleted = 0  ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k){
+            $supplier_info =\app\common\model\Supplier::where('id',$v['supplier_id'])->find()->toArray();
+            $v['supplier_name']=$supplier_info['title'];
+            $v['supplier_logo'] =$supplier_info['logo'];
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['cover_arr'] = $v['cover']? explode('|',trim($v['cover'],'|')):null;
+        });
+
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+    /**
+     * @title 供应商商品列表【产品集合】
+     * @desc 供应商商品列表
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierGoodsList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:supplier_id type:int default:-- desc:供应商记录id
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     *
+     * @return name:name type:string default:-- desc:名称
+     * @return name:supplier_name type:string default:-- desc:供应商名称
+     * @return name:supplier_logo type:string default:-- desc供应商logo
+     * @return name:cover type:string default:-- desc:图片【多张|隔开】
+     * @return name:cover_arr type:array default:-- desc:图片数组
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:content type:string default:-- desc:详情
+     * @return name:article_id type:int default:-- desc:关联图文id【单个id||系列id】
+     * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
+     * @return name:datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     * @return name:video_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
+     * @return name:total_num type:array default:-- desc:总数
+     *
+     */
+    public function getSupplierGoodsList()
+    {
+        $supplier_id = input('get.supplier_id');
+        $sort_type = input('get.sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+        $sel_where = [];
+        $sel_where[] = ['is_deleted','=',0];
+        $sel_where[] = ['status','=',1];
+        $sel_where[] = ['supplier_id','=',$supplier_id];
+        $list = SupplierGoods::where($sel_where)
+            ->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        $supplier_info = \app\common\model\Supplier::where('id',$supplier_id)->find()->toArray();
+        foreach ($list as &$v) {
+            $v['label_name'] =$v['label'] ?  explode(',',trim($v['label'],',')):null;
+            $v['cover_arr'] =$v['cover'] ?  explode('|',trim($v['cover'])):null;
+            $v['supplier_name'] =$supplier_info['title'];
+            $v['supplier_logo'] =$supplier_info['logo'];
+        }
+        $total_num = SupplierGoods::where($sel_where)->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 供应商产品详情
+     * @desc 供应商产品详情
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierGoodsDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:goods_id type:int default:-- desc:供应商产品id
+     * @return name:name type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:图片【多张逗号隔开】
+     * @return name:cover_arr type:array default:-- desc:图片数组
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:content type:string default:-- desc:详情
+     * @return name:article_id type:int default:-- desc:关联图文id【单个id||系列id】
+     * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
+     * @return name:datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     * @return name:video_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞
+     * @return name:transmit_num type:int default:-- desc:转发量
+     *
+     * @return name:supplier_info type:array default:-- desc:供应商详情
+     * @return name:supplier_info.title type:string default:-- desc:名称
+     * @return name:supplier_info.cover type:string default:-- desc:公司logo
+     * @return name:supplier_info.phone type:string default:-- desc:电话
+     * @return name:supplier_info.email type:string default:-- desc:email
+     * @return name:supplier_info.label_name type:array default:-- desc:标签
+     * @return name:supplier_info.content type:string default:-- desc:供应商详情
+     * @return name:supplier_info.create_at type:string default:-- desc:时间
+     * @return name:supplier_info.build_time type:string default:-- desc:成立时间
+     * @return name:supplier_info.work_place type:string default:-- desc:办公地点
+     * @return name:supplier_info.business type:string default:-- desc:业务范围
+     */
+    public function getSupplierGoodsDetail()
+    {
+        $goods_id = input('get.goods_id');
+        $detail = SupplierGoods::where('id',$goods_id)->find()->toArray();
+        $detail['label_name'] =$detail['label'] ?  explode(',',trim($detail['label'],',')):null;
+
+        $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,9,$detail['id']);
+        $detail['collect_num'] = UserCollect::getCollectNum(9,$detail['id']);
+        $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],7);
+        $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],7);
+
+
+        $supplier_info = \app\common\model\Supplier::where('id',$detail['supplier_id'])->find()->toArray();
+        $supplier_info['label_name'] =$supplier_info['label'] ?  explode(',',trim($supplier_info['label'],',')):null;
+        $supplier_info['business_arr'] = $supplier_info['business'] ? explode(',',trim($supplier_info['business'],',')) : null;
+        $supplier_info['cover'] = $supplier_info['logo'] ;
+        UserTrack::crateTrack($this->user_id,10,$goods_id,0);
+        SupplierGoods::where('id',$goods_id)->setInc('read_num');
+        $this->success('ok',['detail'=>$detail,'supplier_info'=>$supplier_info]);
+    }
+
+    /**
+     * @title 供应商搜索列表
+     * @desc 供应商搜索列表
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/searchGoods
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:search_name type:int default:-- desc:搜索名称
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     *
+     * @return name:name type:string default:-- desc:名称
+     * @return name:supplier_name type:string default:-- desc:供应商名称
+     * @return name:cover type:string default:-- desc:图片【多张逗号隔开】
+     * @return name:cover_arr type:array default:-- desc:图片数组
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:content type:string default:-- desc:详情
+     * @return name:article_id type:int default:-- desc:关联图文id【单个id||系列id】
+     * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
+     * @return name:datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     * @return name:video_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
+     * @return name:total_num type:array default:-- desc:总数
+     *
+     */
+    public function searchGoods()
+    {
+        $search_name = input('get.search_name');
+        $sort_type = input('get.sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['g.sort'=>'desc','g.id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['g.id'=>'asc','g.sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['g.id'=>'g.desc','g.sort'=>'desc'];
+                break;
+        }
+        $sel_where = [];
+        $sel_where[] = ['g.is_deleted','=',0];
+        $sel_where[] = ['g.status','=',1];
+        if($search_name && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$search_name,10);
+        $list = SupplierGoods::where($sel_where)
+            ->field('g.id,g.supplier_id,g.name,g.label,g.cover,s.title supplier_name')
+            ->when($search_name,function ($query)use($search_name){
+                if($search_name) $query->where('g.name|g.label','like','%'.$search_name.'%');
+            })->alias('g')
+            ->leftJoin('Supplier s','g.supplier_id = s.id')
+            ->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
+        foreach ($list as &$v) {
+            $v['label_name'] =$v['label'] ?  explode(',',trim($v['label'],',')):null;
+            $v['cover_arr'] =$v['cover'] ?  explode('|',trim($v['cover'])):null;
+        }
+        $total_num = SupplierGoods::where($sel_where)->alias('g')->when($search_name,function ($query)use($search_name){
+            if($search_name) $query->where('g.name|g.label','like','%'.$search_name.'%');
+        })->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+
+    /**
+     * @title 以下接口调用验证登录【需要header传Authorization】
+     * @desc 以下接口调用验证登录
+     * @author qc
+     * @method
+     * @url /api/Supplier/needLogin()
+     */
+    public function needLogin(){}
+
+
+
+
+
+    /**
+     * @title 供应商商品点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Supplier/supplierGoodsTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:供应商商品记录id
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function supplierGoodsTags()
+    {
+        $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),7);
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 供应商商品收藏||取消收藏
+     * @desc 用户收藏
+     * @author qc
+     * @method POST
+     * @url /api/Supplier/supplierGoodsCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int require:1 default:-- desc:供应商商品记录id
+     * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
+     */
+    public function supplierGoodsCollect(){
+        $coll_status = UserCollect::plateCollect($this->user_id,9,input('post.id',0));
+        $coll_status ?  $this->success('收藏成功',['status'=>1]) :    $this->success('取消收藏成功',['status'=>0]);
+    }
+
+    /**
+     * @title 转发(转发数量统计【供应商】)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Supplier/supplierTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:供应商记录id
+     */
+    public function supplierTransmit()
+    {
+        $id = input('post.id',0);
+        \app\common\model\Supplier::where('id',$id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+    /**
+     * @title 转发(转发数量统计【供应商商品】)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Supplier/supplierGoodsTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:供应商商品记录id
+     */
+    public function supplierGoodsTransmit()
+    {
+        $id = input('post.id',0);
+        SupplierGoods::where('id',$id)->setInc('transmit_num');
+        $this->success('ok');
+    }
+
+
+
+
+    /**
+     * @title 我的浏览历史【供应商商品】
+     * @desc 我的浏览历史
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getSupplierGoodsTrack
+     * @header name:Authorization require:1 desc:Token
+     * @param name:name type:string default:-- desc:商品名称
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     * @return name:id type:string default:-- desc:浏览记录id
+     * @return name:goods_id type:string default:-- desc:商品id
+     * @return name:name type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:封面(多张|隔开)
+     * @return name:cover_arr type:array default:-- desc:封面
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:supplier_name type:array default:-- desc:供应商名称
+     * @return name:time type:string default:-- desc:时间
+     */
+    public function getSupplierGoodsTrack()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',10];
+        $name = input('get.name');
+        if($name)  $sel_where[]  = ['i.name|i.label','like','%'.$name.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id goods_id,i.name,i.cover,i.label,supplier_id')
+            ->leftJoin('SupplierGoods i','t.first_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+            $v['cover_arr'] = $v['cover']? explode('|',$v['cover']) : null;
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['supplier_name'] = \app\common\model\Supplier::where('id',$v['supplier_id'])->value('title');
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的点赞【供应商商品点赞列表】
+     * @desc 供应商商品点赞列表
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getTagsSupplierGoods
+     * @header name:Authorization require:1 desc:Token
+     * @param name:name type:string default:-- desc:商品名称
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     * @return name:id type:string default:-- desc:浏览记录id
+     * @return name:goods_id type:string default:-- desc:商品id
+     * @return name:name type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:封面(多张|隔开)
+     * @return name:cover_arr type:array default:-- desc:封面
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:supplier_name type:array default:-- desc:供应商名称
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getTagsSupplierGoods()
+    {
+        $sel_where  = [];
+        $name = input('get.name');
+        if($name)  $sel_where[]  = ['i.name|i.label','like','%'.$name.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',7];
+        $list = PlatformLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.like_id goods_id,i.name,i.cover,i.label,supplier_id')
+            ->leftJoin('SupplierGoods i','t.like_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = explode('|',$v['cover']);
+            $v['label_name'] = explode(',',$v['label']);
+            $v['supplier_name'] = \app\common\model\Supplier::where('id',$v['supplier_id'])->value('title');
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 我的收藏【供应商商品收藏列表】
+     * @desc 供应商商品收藏列表
+     * @author qc
+     * @method GET
+     * @url /api/Supplier/getCollectSupplierGoods
+     * @header name:Authorization require:1 desc:Token
+     * @param name:name type:string default:-- desc:商品名称
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:id type:string default:-- desc:浏览记录id
+     * @return name:goods_id type:string default:-- desc:商品id
+     * @return name:name type:string default:-- desc:名称
+     * @return name:cover type:string default:-- desc:封面(多张|隔开)
+     * @return name:cover_arr type:array default:-- desc:封面
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:supplier_name type:array default:-- desc:供应商名称
+     * @return name:create_at type:string default:-- desc:时间
+     */
+    public function getCollectSupplierGoods()
+    {
+        $sel_where  = [];
+        $name = input('get.name');
+        if($name)  $sel_where[]  = ['i.name|i.label','like','%'.$name.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',9];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id goods_id,i.name,i.cover,i.label,supplier_id')
+            ->leftJoin('SupplierGoods i','t.coll_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['cover_arr'] = explode('|',$v['cover']);
+            $v['label_name'] = explode(',',$v['label']);
+            $v['supplier_name'] = \app\common\model\Supplier::where('id',$v['supplier_id'])->value('title');
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+}

+ 57 - 0
application/api/controller/Task.php

@@ -0,0 +1,57 @@
+<?php
+namespace app\api\controller;
+
+use app\common\model\LabelMessage;
+use app\common\model\User;
+use app\common\model\UserMessage;
+
+/**
+ * @title 定时任务
+ * Class Task
+ * @controller Task
+ * @group base
+ */
+class Task extends Base
+{
+    // 会员消息推送
+    public function taskUserMessage(){
+        $list = UserMessage::field('id,user_id,content')->where('jg_type',1)->where('jg_status',0)->limit(0,50)->order('id')->select();
+        foreach ($list as $v) {
+            UserMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
+            Jpush($v['user_id'],$v['content']);
+        }
+    }
+
+
+    /**
+     * @title 标签推送[根据标签id]
+     * @desc  标签推送
+     * @author  qc
+     * @url /api/Task/taskLabelMessage
+     */
+    //按照标签推送
+    public function taskLabelMessage()
+    {
+        $list = LabelMessage::where('jg_status',0)->where('is_deleted',0)->select()->toArray();
+        foreach ($list as $v) {
+            LabelMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
+            $user_list = User::field('id')
+                ->where('label','like','%|'.$v['label_id'].'|%')
+                ->where('status','=',1)
+                ->where('type','=',1)
+                ->where('is_deleted','=',0)->select()->toArray();;
+            foreach ($user_list as $user_info) {
+              $res =  Jpush($user_info['id'],$v['content']);
+            }
+        }
+    }
+
+
+
+
+
+
+
+
+
+}

+ 305 - 0
application/api/controller/Trolley.php

@@ -0,0 +1,305 @@
+<?php
+namespace app\api\controller;
+use app\common\model\StoreGoods;
+use app\common\model\StoreGoodsItem;
+use app\common\service\ExpressService;
+use think\Db;
+use app\common\model\ShoppingTrolley;
+use app\common\model\DeliveryAddress;
+use think\Exception;
+
+/**
+ * @title 购物车
+ * @controller Trolley
+ * @group base
+ */
+class Trolley extends Base
+{
+
+    protected $no_login = ['delComment'];// 不需要登录的
+
+    public function initialize()
+    {
+        parent::initialize();
+        $path = explode('/',$this->request->path());
+        if(!in_array(end($path),$this->no_login)) parent::checkLogin();
+    }
+
+    /**
+     * @title 获取购物车商品数量
+     * @desc  获取购物车商品数量
+     * @author  qc
+     * @url /api/Trolley/getTrolleyNum
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param name:goods_id type:int default:-- desc:商品id(商品id不传查全部的)
+     * @return name:total_num type:int default:-- desc:购物车商品数量
+     */
+    public function getTrolleyNum()
+    {
+        $where = [];
+        $where['user_id'] = $this->user_id;
+        if($goods_id = input('get.goods_id',0)) $where['goods_id'] = $goods_id;
+        $total_num = ShoppingTrolley::where($where)->sum('num');
+        $this->success('ok',['total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 获取购物车列表
+     * @desc  获取购物车列表
+     * @author  qc
+     * @url /api/Trolley/getTrolleyList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:购物车记录id
+     * @return name:goods_id type:int default:-- desc:商品id
+     * @return name:goods_name type:string default:-- desc:商品名称
+     * @return name:goods_status type:int default:-- desc:商品状态(1上架,0下架)
+     * @return name:cover type:string default:-- desc:商品封面
+     * @return name:deleted_status type:string default:-- desc:商品删除状态(1删除,0未删除)
+     * @return name:num type:int default:-- desc:数量
+     * @return name:goods_id type:int default:-- desc:商品id
+     * @return name:goods_id type:int default:-- desc:商品id
+     * @return name:spec_id type:int default:-- desc:规格id
+     * @return name:goods_spec type:int default:-- desc:规格
+     * @return name:goods_no type:int default:-- desc:货号
+     * @return name:original_price type:float default:-- desc:规格原价(下划线价格)
+     * @return name:sell_price type:float default:-- desc:规格售价
+     */
+    public function getTrolleyList()
+    {
+        $join_field = 't.id,t.num,t.spec_id,t.goods_id,i.goods_spec,g.cover,i.goods_no,i.is_deleted,i.original_price,i.sell_price,i.weight,g.name goods_name,g.status goods_status,g.is_deleted deleted_status';
+        $list = ShoppingTrolley::field($join_field)
+            ->alias('t')
+            ->where(['t.user_id'=>$this->user_id])
+            ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
+            ->leftJoin('StoreGoods g','t.goods_id = g.id')
+            ->order('t.id desc')
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 商品添加购物车(按规格加入)
+     * @desc  商品某个规格加入多少
+     * @author  qc
+     * @url /api/Trolley/addTrolley
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:goods_id type:int require:1  default:0 desc:商品id
+     * @param  name:spec_id type:int  require:1 default:0 desc:规格id
+     * @param  name:num type:int default:1 desc:数量
+     */
+    public function addTrolley()
+    {
+        $goods_id = input('post.goods_id');
+        $spec_id = input('post.spec_id');
+        $num    = input('post.num',1);
+        if(!$goods_id || !$spec_id)  $this->error('请选择商品');
+        if($num <=0 ) $this->error('添加数量有误');
+        Db::startTrans();
+        try {
+            // 商品详情
+            $goods_info = StoreGoods::with(['itemList'=>function($query)use($spec_id){
+                return $query->where('id',$spec_id)->where('is_deleted',0);
+            }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find();
+            if(!$goods_info) throw new Exception('商品已下架');
+            $goods_info = $goods_info->toArray();
+            if(empty($goods_info['item_list'])) throw new Exception('该规格已下架');
+            if($goods_info['item_list'][0]['stock'] < $num) throw new Exception('库存不足');
+            $trolley_id = ShoppingTrolley::checkTrolley($this->user_id,$goods_id,$spec_id);
+            // 添加到购物车
+            if($trolley_id) {
+                ShoppingTrolley::where('id',$trolley_id)->setInc('num',$num);
+            }else{
+                $trolley_info = [
+                    'user_id' => $this->user_id,
+                    'goods_id' => $goods_id,
+                    'spec_id' => $spec_id,
+                    'goods_no' => $goods_info['item_list'][0]['goods_no'],
+                    'num' => $num,
+                ];
+                ShoppingTrolley::create($trolley_info);
+            }
+            // 扣减库存
+            StoreGoods::where('id',$goods_id)->setDec('stock',$num);
+            StoreGoodsItem::where('id',$spec_id)->setDec('stock',$num);
+            Db::commit();
+        }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg = $e->getMessage();
+            Db::rollback();
+        }
+        $this->is_commit ? $this->success('添加成功'):$this->error($this->ret_msg);
+    }
+
+    /**
+     * @title 修改购物车商品数量
+     * @desc  修改购物车商品数量
+     * @author  qc
+     * @url /api/Trolley/changeTrolleyNum
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:trolley_id type:int require:1  default:0 desc:购物车记录id
+     * @param name:num type:int require:1 default:1 desc:变更数量
+     * @param name:type type:int require:1 default:1 desc:变更类型(1增加2扣减)
+     */
+    public function changeTrolleyNum()
+    {
+        $trolley_id = input('post.trolley_id');
+        $num = input('post.num',1);
+        $type = input('post.type',1);
+        if(!in_array($type,[1,2])) $this->error('变更可类型错误');
+        Db::startTrans();
+        try {
+            $trolley_info = ShoppingTrolley::get($trolley_id);
+            if(!$trolley_info) $this->exception('记录不存在!');
+            $goods_info = StoreGoods::getGoodsSpec($trolley_info->goods_id,$trolley_info->spec_id);
+            if($type == 1){
+                if(!$goods_info) $this->exception('商品已下架');
+                if(empty($goods_info['item_list'])) $this->exception('该规格已下架');
+                if($goods_info['item_list'][0]['stock'] < $num)$this->exception('库存不足');
+                ShoppingTrolley::where('id',$trolley_id)->setInc('num',$num);
+                StoreGoods::where('id',$trolley_info->goods_id)->setDec('stock',$num);// 扣减商品库存
+                StoreGoodsItem::where('id',$trolley_info->spec_id)->setDec('stock',$num);// 扣减规格库存
+            }else{
+                if($trolley_info->num < $num) $this->exception('扣减数量有误');
+                if($trolley_info->num > $num){
+                    ShoppingTrolley::where('id',$trolley_id)->setDec('num',$num);//扣减数量
+                }else{
+                    ShoppingTrolley::where('id',$trolley_id)->delete();//删除记录
+                }
+                StoreGoods::where('id',$trolley_info->goods_id)->setInc('stock',$num);//增加商品库存
+                StoreGoodsItem::where('id',$trolley_info->spec_id)->setInc('stock',$num);//增加规格库存
+            }
+            Db::commit();
+        }catch (\Exception $e){
+            $this->ret_msg = $e->getMessage();
+            $this->is_commit = false;
+            Db::rollback();
+        }
+        $this->is_commit ? $this->success('操作成功') : $this->error($this->ret_msg);
+    }
+
+    /**
+     * @title 删除购物车记录
+     * @desc  删除购物车记录
+     * @author  qc
+     * @url /api/Trolley/cancelTrolleyList
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:ids type:string require:1  default:0 desc:购物车记录id(多条用逗号隔开)
+     */
+    public function cancelTrolleyList()
+    {
+        $ids = input('post.ids');
+        if(!$ids) $this->error('请选择要删除的数据');
+        $trolley_list = ShoppingTrolley::where('id','in',$ids)->select();
+        Db::startTrans();
+        foreach ($trolley_list as $trolley_info) {
+            StoreGoods::where('id',$trolley_info->goods_id)->setInc('stock',$trolley_info->num);//增加商品库存
+            StoreGoodsItem::where('id',$trolley_info->spec_id)->setInc('stock',$trolley_info->num);//增加规格库存
+        }
+        ShoppingTrolley::where('id','in',$ids)->delete();
+        Db::commit();
+        $this->success('删除成功');
+
+    }
+
+    /**
+     * @title 某商品是否添加到购物
+     * @desc  获取某商品添加到购物车规格及数量
+     * @author  qc
+     * @url /api/Trolley/getTrolleyByGoodsId
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:goods_id type:int  default:1 desc:商品id
+     * @return name:spec_id type:int default:-- desc:规格id
+     * @return name:num type:int default:-- desc:数量
+     */
+    public function getTrolleyByGoodsId()
+    {
+        $goods_id = input('get.goods_id');
+        $list = ShoppingTrolley::field('id,goods_id,spec_id,goods_no,num')
+            ->where(['user_id'=>$this->user_id,'goods_id'=>$goods_id])
+            ->order('id desc')
+            ->select();
+        $this->success('ok',['list'=>$list?$list->toArray() : null ]);
+    }
+
+
+    /**
+     * @title 购物车订单确认
+     * @desc  购物车订单确认
+     * @author  qc
+     * @url /api/Trolley/confirmTrolleyList
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:ids type:int  default:1 desc:购物车记录id(多条用逗号隔开)
+     * @return name:goods_id type:int default:-- desc:商品id
+     * @return name:goods_name type:string default:-- desc:商品名称
+     * @return name:goods_status type:int default:-- desc:商品状态(1上架,0下架)
+     * @return name:deleted_status type:string default:-- desc:删除状态(1删除,0未删除)
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:item_list type:array default:-- desc:添加该商品的规格列表
+     * @return name:item_list.spec_id type:int default:-- desc:规格id
+     * @return name:item_list.goods_no type:int default:-- desc:货号
+     * @return name:item_list.original_price type:float default:-- desc:规格原价
+     * @return name:item_list.sell_price type:float default:-- desc:规格售价
+     * @return name:item_list.goods_spec type:string default:-- desc:规格
+     * @return name:total_money type:float default:-- desc:商品总金额【不含运费】
+     * @return name:freight type:float default:-- desc:运费
+     * @return name:freight_code type:int default:1 desc:运费提示编号【1所选地址支持发货,0所选地址不支持发货】
+     * @return name:freight_msg type:string default:-- desc:运费提示信息【freight_code=1忽略】
+     */
+    public function confirmTrolleyList()
+    {
+        $ids = input('get.ids');
+        $trolley_goods = ShoppingTrolley::field('goods_id')
+            ->where('user_id',$this->user_id)
+            ->where('id','in',$ids)
+            ->group('goods_id')
+            ->select();
+        if(!$trolley_goods) $this->error('请选择商品');
+        $goods_ids = array_column($trolley_goods->toArray(),'goods_id');
+        $freight = 0;
+        $list = [];
+        $total_money = 0;
+        $goods_list = StoreGoods::where('id','in',$goods_ids)->select()->toArray();
+        $address_info = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
+        foreach ($goods_list as $goods_info){
+            $trolley_data =  ['goods_id'=>$goods_info['id'],'goods_name'=>$goods_info['name'],'goods_status'=>$goods_info['status'],'cover'=>$goods_info['cover'],'deleted_status'=>$goods_info['is_deleted']];
+            $trolley_data['item_list'] = ShoppingTrolley::field('t.*,i.original_price,i.sell_price,i.goods_spec')
+                ->alias('t')
+                ->where('t.id','in',$ids)
+                ->where('t.goods_id',$goods_info['id'])
+                ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
+                ->select()->toArray();
+            foreach ($trolley_data['item_list'] as $iv){
+                $total_money = bcadd(bcmul($iv['num'],$iv['sell_price'],2),$total_money,2);
+            }
+            $list[] = $trolley_data;
+            $fre_num = array_sum(array_column($trolley_data['item_list'],'num'));
+            if($address_info) {
+                $goods_freight = ExpressService::getGoodsExpressPrice($goods_info,$address_info->id,$fre_num);
+                if($goods_freight['code'] !=200){
+                    $this->is_commit =  false;
+                    $this->ret_msg =  $goods_freight['msg'];
+                }
+                $freight +=  $goods_freight['freight']; //  商品运费
+            }
+        }
+        $this->success('ok',[
+            'list'=>$list,
+            'total_money'=>$total_money,
+            'address_info'=>$address_info ? $address_info->toArray():null,
+            'freight' =>$freight,
+            'freight_msg' => $this->ret_msg,
+            'freight_code' => $this->is_commit ? 1 :0
+        ]);
+    }
+
+
+
+
+}

+ 35 - 5
application/api/controller/Upload.php

@@ -25,7 +25,29 @@ use library\File;
  */
 class Upload extends Base
 {
+    protected $id ;
+    protected $key;
+    protected $host;
 
+
+    public function initialize(){
+       $this->id =   config('app.ali_set.Key');
+       $this->key =  config('app.ali_set.secret');
+       $this->host = config('app.ali_set.host');
+    }
+
+
+    /**
+     * @title 文件上传
+     * @desc 个人信息
+     * @author qc
+     * @url /api/upload/upload
+     * @method GET||POST
+     * @tag 个人信息
+     * @header name:Authorization require:1 desc:Token
+     * @param name:file require:1 desc:文件名
+     *
+     */
     public function upload()
     {
         if (!($file = $this->getUploadFile()) || empty($file)) {
@@ -44,7 +66,7 @@ class Upload extends Base
         $info = File::instance($this->uptype)->save($name, file_get_contents($file->getRealPath()), $this->safe);
         if (is_array($info) && isset($info['url'])) {
             $url = $this->safe ? $name : $info['url'];
-            $this->success('成功',$url);
+            $this->success('上传成功',$url);
         } else {
             $this->error('文件处理失败,请稍候再试!');
         }
@@ -83,16 +105,14 @@ class Upload extends Base
      * @url /api/Upload/getSignedUrl
      * @method GET
      * @tag 配置信息
+     * @param name:type type:string require:1 default:-- desc:
      */
     public function getSignedUrl(){
 
-        $type=$this->request->get('type','image');
+        $type=$this->request->get('type');
         $data=$this->getPolicy($type.'/');
         $this->success('操作成功',$data);
     }
-    protected $id= 'LTAI5t7bxx6UhJsFYbQcbaaB';
-    protected $key= '9qkYH3x0KSiUfkH6FDe8XPu5CfvO9m';
-    protected $host = 'https://xiongwenwang.oss-cn-beijing.aliyuncs.com';
 
     public function getPolicy($path,$maxSize=5000000){
         $now = time();
@@ -129,4 +149,14 @@ class Upload extends Base
         $expiration = substr($expiration, 0, $pos);
         return $expiration."Z";
     }
+
+
+    public function getSysDirection()
+    {
+        $data = [
+            'film_notice'=>htmlspecialchars_decode(sysconf('film_notice')),
+            'film_direction'=>htmlspecialchars_decode(sysconf('film_direction'))
+        ];
+        $this->success('获取成功',$data);
+    }
 }

+ 227 - 0
application/api/controller/UserCenter.php

@@ -0,0 +1,227 @@
+<?php
+namespace app\api\controller;
+use app\common\model\UserLevelRank;
+use app\common\model\UserMessage;
+use app\common\validate\UserVali;
+use think\Db;
+use app\common\model\User;
+/**
+ * @title 会员个人中心
+ * @controller UserCenter
+ * @group base
+ */
+class UserCenter extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 获取个人信息
+     * @desc 个人信息
+     * @author qc
+     * @url /api/User_center/getUserInfo
+     * @method GET
+     * @tag 个人信息
+     * @header name:Authorization require:1 desc:Token
+     * @return name:phone type:int default:-- desc:手机号
+     * @return name:name type:string default:-- desc:昵称
+     * @return name:headimg type:string default:-- desc:头像地址
+     * @return name:sex type:int default:1 desc:性别(1男2女)
+     * @return name:true_name type:string default:-- desc:真实姓名
+     * @return name:invite_code type:string default:-- desc:邀请码
+     * @return name:account_type type:int default:-- desc:账号类型1公司,2个人
+     * @return name:is_first type:int default:-- desc:企业组是否是第一个注册(1是0否【第一个注册有会员会员重置权限,公司其他人会员权限读取公司第一个注册的会员权限】)
+     * @return name:user_level type:array default:-- desc:开通会员信息[为空就不是vip]
+     * @return name:user_level.level_id type:int default:-- desc:等级id
+     * @return name:user_level.end_date type:string default:-- desc:过期时间
+     * @return name:user_level.name type:string default:-- desc:会员等级名称
+     * @return name:user_level.logo type:string default:-- desc:会员等级logo
+     *
+     */
+    public function getUserInfo()
+    {
+        $field = 'id,phone,name,level_id,headimg,openid,true_name,sex,invite_code,account_type,group_id,is_first,group_first';
+        $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray();
+        if($user_info['account_type'] == 2 || ($user_info['account_type']== 1 && $user_info['is_first'])){
+            $user_level = UserLevelRank::field('r.id,r.level_id,r.end_time,r.end_date,l.name,l.logo')
+                ->alias('r')
+                ->leftJoin('UserLevel l','l.id = r.level_id')
+                ->where([['r.user_id','=',$this->user_id],['r.end_time','>',time()]])->order('r.level_id desc')->find();
+        }else{
+            $user_level = UserLevelRank::field('r.id,r.level_id,r.end_time,r.end_date,l.name,l.logo')
+                ->alias('r')
+                ->leftJoin('UserLevel l','l.id = r.level_id')
+                ->where([['r.user_id','=',$user_info['group_first']],['r.end_time','>',time()]])->order('r.level_id desc')->find();
+        }
+        $this->success('获取成功',['detail'=>$user_info,'user_level'=>$user_level ? $user_level->toArray() :null]);
+    }
+
+    /**
+     * @title 编辑个人信息
+     * @desc 编辑个人信息
+     * @author qc
+     * @url /api/User_center/updateUserInfo
+     * @method POST
+     * @tag 编辑信息
+     * @header name:Authorization require:1 desc:Token
+     * @param name:name type:string default:-- desc:昵称
+     * @param name:headimg type:string default:-- desc:头像地址
+     */
+    public function updateUserInfo()
+    {
+        $headimg    = input('post.headimg');
+        $name       = trim(input('post.name',''));
+        $update_data= [];
+        $update_data['name']        = $name;
+        $update_data['headimg']     = $headimg;
+        Db::name('store_member')->where('id',$this->user_id)->update($update_data);
+        $field = 'phone,name,headimg';
+        $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
+        $this->success('编辑成功',['detail'=>$user_info]);
+    }
+
+    /**
+     * @title 绑定手机号
+     * @desc  绑定手机号
+     * @author  qc
+     * @url /api/User_center/modifyPhone
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:phone type:int require:1 default:-- desc:手机号
+     * @param name:code type:int require:1 default:-- desc:手机号验证码
+     * @return name:phone type:int default:-- desc:手机号
+     * @return name:name type:string default:-- desc:昵称
+     * @return name:headimg type:string default:-- desc:头像地址
+     */
+    public function modifyPhone()
+    {
+        $uid = $this->user_id;
+        $phone = input('post.phone');
+        $code  = input('post.code');
+        if(empty($phone) || empty($code) ) $this->error('参数错误');
+        $field = 'id,phone,name,headimg';
+        $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
+        if($user_info['phone'] == $phone)$this->error('更换手机号与绑定手机号一致!');
+        $check_code = $this->checkPhoneCode($phone,$code);
+        if(!$check_code) $this->error('验证码错误');
+        //判断手机号是否已注册
+        $member_id = Db::name('store_member')
+            ->where('phone','=',$phone)->where('is_deleted','=',0)->where('id','<>',$this->user_id)->value('id');
+        if($member_id)  $this->error('手机号已注册过');
+        Db::name('store_member')->where('id',$uid)->update(['phone'=>$phone]);
+        $user_info['phone'] = $phone;
+        $this->updatePhoneCode($check_code);
+        $this->success('绑定成功',$user_info);
+    }
+
+    /**
+     * @title 更换或设置登录密码
+     * @desc  更换或设置登录密码
+     * @author  qc
+     * @url /api/User_center/modifyPassword
+     * @method POST
+     * @header name:Authorization require:1 desc:Token
+     * @param name:phone type:int require:1 default:-- desc:手机号
+     * @param name:code type:int require:1 default:-- desc:手机号验证码
+     * @param name:password type:string default:-- desc:密码
+     */
+    public function modifyPassword()
+    {
+        $uid = $this->user_id;
+        $phone = input('post.phone');
+        $code  = input('post.code');
+        $password  = input('post.password');
+        if(empty($phone) || empty($code) || empty($password) ) $this->error('参数错误');
+        $field = 'id,phone';
+        $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray();
+        if(!$user_info['phone']) $this->error('请先绑定手机号');
+        if($user_info['phone'] != $phone) $this->error('与绑定手机号不一致');
+        $check_code = $this->checkPhoneCode($phone,$code);
+        if(!$check_code) $this->error('验证码错误');
+        $validate = new UserVali();
+        if (!$validate->scene('reset_password')->check(['phone'=>$phone,'password'=>$password])) {
+            $this->error($validate->getError());
+        }
+        $encryption_password = encrypt_password($password);
+        User::where('id',$uid)->update(['password'=>$password,'encryption_password'=>$encryption_password]);
+        $this->updatePhoneCode($check_code);
+        $this->success('更换成功');
+    }
+
+
+    /**
+     * @title 完善用户openid
+     * @desc 完善用户openid
+     * @author qc
+     * @method POST
+     * @tag 编辑信息
+     * @url /api/User_center/saveOpenid
+     * @header name:Authorization require:1 desc:Token
+     * @param name:code type:string require:1 default:-- desc:code
+     */
+    public function saveOpenid()
+    {
+        $code = input('post.code');
+        if (empty($code)) $this->error('参数错误');
+        $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.config('app.official_account')['appid'].'&secret='.config('app.official_account')['secret'].'&code='.$code.'&grant_type=authorization_code');
+        $res = json_decode($res,true);
+        if (empty($res['openid'])) $this->error('未获取到openid');
+        $member_data = ['openid' => $res['openid']];
+        Db::name('store_member')->where('id',$this->user_id)->update($member_data);
+        $this->success('已绑定openid');
+    }
+
+
+    /**
+     * @title 消息列表【会员消息】
+     * @desc 我的点赞
+     * @author qc
+     * @method GET
+     * @url /api/User_center/getMessageList
+     * @header name:Authorization require:1 desc:Token
+
+     * @param name:title type:string default:-- desc:标题
+     * @param name:page type:int default:-- desc:页数
+     * @param name:page_num type:int default:-- desc:每页数
+     *
+     * @return name:id type:int default:-- desc:记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:内容
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:is_read type:int default:-- desc:是否已读【0否1是】
+     */
+    public function getMessageList()
+    {
+        $list = UserMessage::where(['user_id'=>$this->user_id])
+            ->limit($this->off_set,$this->page_num)
+            ->order(['id'=>'desc'])
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 消息详情【会员消息】
+     * @desc 消息详情
+     * @author qc
+     * @method GET
+     * @url /api/User_center/getMessageInfo
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:消息记录id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:content type:string default:-- desc:内容
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:is_read type:int default:-- desc:是否已读【0否1是】
+     */
+    public function getMessageInfo()
+    {
+        $detail= UserMessage::where(['user_id'=>$this->user_id,'id'=>input('get.id')])->find()->toArray();
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+
+}
+
+

+ 1199 - 0
application/api/controller/Video.php

@@ -0,0 +1,1199 @@
+<?php
+namespace app\api\controller;
+use app\common\model\SeriesVideoCate;
+use app\common\model\User;
+use app\common\model\UserCollect;
+use app\common\model\UserLearn;
+use app\common\model\UserLevelRank;
+use app\common\model\UserMessage;
+use app\common\model\UserSearch;
+use app\common\model\UserTrack;
+use app\common\model\UserVideo;
+use app\common\model\VideoCate;
+use app\common\model\VideoComment;
+use app\common\model\VideoCommentLike;
+use app\common\model\VideoIntro;
+use app\common\model\VideoLabel;
+use app\common\model\VideoUrl;
+use library\tools\Data;
+use think\Db;
+/**
+ * @title 视频
+ * @controller Video
+ * @group base
+ */
+class Video extends Base
+{
+ // 需要登录的
+    protected $need_login = [
+        'userReferVideo',
+        'userReferVideoDetail',
+        'delUserVideo',
+        'videoComment',
+        'secondCommend',
+        'videoTags',
+        'videoTransmit',
+        'getMyVideoList',
+        'delComment',
+        'getLearnHistory',
+        'getReplayComment',
+        'getReplyVideo',
+        'getPurchaseVideo',
+        'getVideoCollect',
+        'getTagsVideo',
+    ];
+
+    public function initialize()
+    {
+        parent::initialize();
+        parent::setUid();
+    }
+
+
+    /**
+     * @title 视频接口说明
+     * @desc  视频接口说明
+     * @author  qc
+     * @url /api/Video/classIntro
+     * @method GET
+     * @return name:1 type:string default:-- desc:视频播放改DRM加密,请勿用视频地址【url】播放,这个字段弃用!!
+     * @return name:2 type:string default:-- desc:ali_vid视频点播id,阿里云视频点播用
+     */
+    public function classIntro(){}
+
+
+    /**
+     * @title 获取分类
+     * @desc  获取分类(共两级)
+     * @author  qc
+     * @url /api/Video/getCateTree
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:type type:int default:0 desc:类型1单个2系列
+     * @return name:id type:int default:-- desc:分类id
+     * @return name:logo type:string default:-- desc:图标
+     * @return name:title type:string default:0 desc:分类名称
+     * @return name:children type:array default:0 desc:下级分类
+     */
+    public function getCateTree()
+    {
+        $type = input('type',1);
+        if($type == 1) {
+            $list = VideoCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
+        }else{
+            $list = SeriesVideoCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
+        }
+        $list =  make_tree($list);
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 获取视频标签
+     * @desc  获取视频标签
+     * @author  qc
+     * @url /api/Video/getVideoLabel
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:int default:-- desc:id
+     * @return name:title type:string default:0 desc:标题
+     */
+    public function getVideoLabel()
+    {
+        $list = VideoLabel::field('id,title')->where(['is_deleted'=>0,'status'=>1])->select()->toArray();
+        $this->success('',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 视频推荐
+     * @desc 视频推荐
+     * @author qc
+     * @method GET
+     * @url /api/Video/getRecommendList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:id type:string default:-- desc:视频url_id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:系列id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台头像
+     */
+    public function getRecommendList()
+    {
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $search_log =  UserSearch::getSearchTitle($this->user_id,1);
+        $search_arr = [];
+        $where_str = 'b.id > 0';
+        foreach ($search_log as $t){
+            $search_arr[] =  " b.title like '".'%'.$t."%'" .' ';
+            $search_arr[] =  " b.label like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $field = ' a.id,a.title,a.cover,a.user_id,a.is_vip,a.ali_vid,a.video_id ,IFNULL(is_recommend,0) is_recommend ';
+        $table = 'dd_video_url';
+        $order_by_two = 'id';
+        $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id Left JOIN dd_video_intro as k ON a.video_id  = k.id  WHERE a.is_deleted = 0 AND a.status =1 AND k.is_deleted = 0 AND k.status = 1 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
+        $list = Db::query($sql);
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            if(!$v['user_id']){
+                $v['app_name']  = $app_name;
+                $v['app_logo']  = $app_logo;
+            }else{
+                $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
+                $v['app_name']  = $user_info ? $user_info->name : '';
+                $v['app_logo']  = $user_info ? $user_info->headimg : '';
+            }
+        });
+        $this->success('ok',['list'=>$list,'sql'=>$sql]);
+    }
+
+
+
+
+    /**
+     * @title 获取视频列表(平台发布)
+     * @desc 获取视频列表
+     * @author qc
+     * @method GET
+     * @url /api/Video/getVideoList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:type type:int default:0 desc:类型0全部1单个2系列
+     * @param  name:is_tj type:int default:0 desc:是否推荐0否1是
+     * @param  name:is_hot type:int default:-1 desc:是否置顶0否1是(-1全部)
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:first_classify type:int default:0 desc:视频一级分类
+     * @param  name:second_classify type:int default:0 desc:视频二级分类
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @return name:id type:string default:-- desc:ID[请求/api/Video/getVideoDetail用]
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类
+     * @return name:second_classify type:int default:-- desc:视频二级分类
+     * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
+     * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
+     * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
+     * @return name:label_name type:array default:-- desc:标签
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:total_num type:int default:-- desc:总数量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台头像
+     * @return name:video_arr type:array default:-- desc:视频地址
+     * @return name:video_arr.url type:string default:-- desc:视频地址
+     */
+    public function getVideoList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $sel_where[]  = ['url_num','>=',1];
+        $title = input('get.title');
+        $type = input('get.type',0);
+        $is_hot = input('get.is_hot',-1);
+        $first_classify = input('get.first_classify');
+        $second_classify = input('get.second_classify');
+        $sort_type = input('get.sort_type',1);
+        $is_tj = input('get.is_tj',0);
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,1);
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        if($first_classify)  $sel_where[]  = ['first_classify','=',$first_classify];
+        if($second_classify)  $sel_where[]  = ['second_classify','=',$second_classify];
+        if($type)  $sel_where[]  = ['type','=',$type];
+        if($is_hot >= 0)  $sel_where[]  = ['is_hot','=',$is_hot];
+        $where_str = 'id > 0';
+        switch ($sort_type) {
+            case 1:
+                $order =  ['is_top'=>'desc','sort'=>'desc','id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['id'=>'asc','sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['id'=>'desc','sort'=>'desc'];
+                break;
+        }
+
+        $total_num =VideoIntro::where($sel_where)->where($where_str)->count();
+
+        $list = VideoIntro::with(['videoArr'])->where($sel_where)
+            ->where($where_str)
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,1,$v['id']);
+            $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
+            $v['read_num']  = array_sum(array_column($v['video_arr'],'read_num'));
+            $v['app_name']  = $app_name;
+            $v['app_logo']  = $app_logo;
+        });
+
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 获取推荐视频列表【不分页】【弃用】
+     * @desc 获取推荐视频列表【不分页】
+     * @author qc
+     * @method GET
+     * @url /api/Video/getRecommendVideoList
+     * @header name:Authorization require:1 desc:Token
+     * @return name:id type:string default:-- desc:id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:预览图
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:is_vip type:int default:-- desc:是否是需要会员(0否1是)
+     * @return name:ppt type:string default:-- desc:关联ppt链接
+     * @return name:ali_vid type:string default:-- desc:阿里云点播id
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台头像
+     */
+    public function getRecommendVideoList()
+    {
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        $where_str = 'id > 0';
+        $sel_where = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $search_log =  UserSearch::getSearchTitle($this->user_id,1);
+        $search_arr = [];
+        foreach ($search_log as $t){
+            $search_arr[] =  " title like '".'%'.$t."%'" .' ';
+        }
+        if(!empty($search_arr)) $where_str  =  implode(' OR ',$search_arr);
+        $list = VideoUrl::field('id,video_id,title,cover,ali_vid,ppt,is_vip,read_num')
+            ->where($where_str)->where($sel_where)->order('id desc')->limit(0,20)->select()->toArray();
+        $rand_num = 0;
+        if(count($list) < 20)$rand_num =  20 - count($list);
+        if($rand_num > 0) {
+            $rand_list = VideoUrl::field('id,video_id,title,cover,ali_vid,ppt,is_vip,read_num')->where(function ($query)use($rand_num,$list){
+                if(!empty($search_ids)){
+                    $search_ids = array_column($list,'id');
+                    $all_ids = VideoUrl::where(['is_deleted'=>0])->where('id not in '.implode(',',$search_ids))->column('id,title','id');
+                    $rand_ids = array_keys($all_ids);
+                    if(count($all_ids) > $rand_num) $rand_ids = array_rand($all_ids,$rand_num);
+                    return $query->where('id','in',implode(',',$rand_ids));
+                }
+            })->where($sel_where)->limit(0,$rand_num)->select()->toArray();
+           if(!empty($rand_list)) $list = array_merge($list,$rand_list);
+        }
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            $v['app_name']  = $app_name;
+            $v['app_logo']  = $app_logo;
+        });
+
+        $this->success('ok',$list);
+    }
+
+    /**
+     * @title 视频搜索
+     * @desc 视频搜索
+     * @author qc
+     * @method GET
+     * @url /api/Video/videoSearch
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:1 desc:标题
+     * @param  name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:预览图
+     * @return name:transmit_num type:int default:-- desc:转发量
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:is_vip type:int default:-- desc:是否是需要会员(0否1是)
+     * @return name:ali_vid type:string default:-- desc:阿里云点播id
+     * @return name:app_name type:string default:-- desc:平台名称
+     * @return name:app_logo type:string default:-- desc:平台头像
+     */
+    public function videoSearch()
+    {
+        $title = input('get.title');
+        $sort_type = input('get.sort_type',1);
+        if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,1);
+        $sel_where = [];
+        $sel_where[]  = ['a.is_deleted','=',0];
+        $sel_where[]  = ['a.status','=',1];
+        $sel_where[]  = ['b.is_deleted','=',0];
+        $sel_where[]  = ['b.status','=',1];
+        if($title)  $sel_where[]  = ['a.title|a.label','like','%'.$title.'%'];
+        $app_name = sysconf('app_name');
+        $app_logo = sysconf('app_logo');
+        switch ($sort_type) {
+            case 1:
+                $order =  ['a.id'=>'desc'];
+                break;
+            case 2:
+                $order =  ['a.id'=>'asc','a.sort'=>'desc'];
+                break;
+            case 3:
+                $order =  ['a.id'=>'desc','a.sort'=>'desc'];
+                break;
+        }
+        $list = VideoUrl::field('a.id,a.video_id,a.title,a.cover,a.ali_vid,a.ppt,a.is_vip,a.read_num')
+            ->alias('a')
+            ->leftJoin('VideoIntro b','a.video_id = b.id')
+            ->where($sel_where)->order($order)
+            ->limit($this->off_set,$this->page_num)->select()->toArray();
+        array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
+            $v['app_name']  = $app_name;
+            $v['app_logo']  = $app_logo;
+        });
+
+
+        $this->success('ok',$list);
+    }
+
+
+
+
+    /**
+     * @title 获取视频详情(平台)
+     * @desc 获取视频详情
+     * @author qc
+     * @method GET
+     * @url /api/Video/getVideoDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:视频id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类
+     * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:video_arr type:array default:-- desc:视频地址
+     * @return name:video_arr.id type:int default:-- desc:ID[请求视频模块其他接口参数:url_id]
+     * @return name:video_arr.cover type:string default:-- desc:预览图
+     * @return name:video_arr.url type:string default:-- desc:视频地址
+     * @return name:video_arr.transmit_num type:int default:-- desc:转发量
+     * @return name:video_arr.read_num type:int default:-- desc:播放量
+     * @return name:video_arr.is_vip type:int default:-- desc:是否是需要会员(0否1是)
+     * @return name:video_arr.is_collect type:int default:-- desc:是否收藏
+     * @return name:video_arr.collect_num type:int default:-- desc:收藏量
+     * @return name:video_arr.praise_num type:int default:-- desc:点赞量
+     * @return name:video_arr.is_praise type:int default:-- desc:是否点赞
+     * @return name:video_arr.article_id type:int default:-- desc:关联视频id【单个id||系列id】
+     * @return name:video_arr.article_item type:int default:-- desc:关联视频详情id【item_list.id】
+     * @return name:video_arr.datum_id type:int default:-- desc:资料id【单个id||系列id】
+     * @return name:video_arr.datum_item type:int default:-- desc:资料详情id【url_arr.id】
+     * @return name:video_arr.ppt type:string default:-- desc:关联ppt链接
+     * @return name:video_arr.ali_vid type:string default:-- desc:阿里云点播id
+     */
+    public function getVideoDetail()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['id','=',input('get.id')];
+        $detail = VideoIntro::with(['videoArr'])->where($sel_where)->find()->toArray();
+        if($detail['is_deleted'] == 1 || $detail['status'] == 0)$this->error('该视频已下线');
+        $detail['label_name'] = [];
+        if($detail['label']) {
+            $detail['label_name'] = explode(',',trim($detail['label'],','));
+        }
+        $level_id = UserLevelRank::getUserVip($this->user_id);
+        foreach ($detail['video_arr'] as &$dv) {
+            if($dv['is_vip'] && !$level_id) $dv['url'] = '';
+            $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,1,$detail['id'],$dv['id']);
+          //  $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>1,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
+            $dv['collect_num'] =  UserCollect::getCollectNum(1,$detail['id'],$dv['id']);
+            $dv['is_praise'] = VideoCommentLike::where(['user_id'=>$this->user_id,'type'=>2,'like_id'=>$dv['id']])->count();
+            $dv['praise_num'] = VideoCommentLike::where(['type'=>2,'like_id'=>$dv['id']])->count();
+        }
+
+        $detail['read_num']  = array_sum(array_column($detail['video_arr'],'read_num'));
+        $this->success('ok',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 获取视频列表(用户发布【审核通过的】)
+     * @desc 用户发布【审核通过的】
+     * @author qc
+     * @method GET
+     * @url /api/Video/getUserVideoList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:first_classify type:int default:0 desc:视频一级分类
+     * @param  name:second_classify type:int default:0 desc:视频二级分类
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类
+     * @return name:second_classify type:int default:-- desc:视频二级分类
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     */
+    public function getUserVideoList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['status','=',1];
+        $title = input('get.title');
+        $first_classify = input('get.first_classify');
+        $second_classify = input('get.second_classify');
+        if($title)  $sel_where[]  = ['v.title|v.label','like','%'.$title.'%'];
+        if($first_classify)  $sel_where[]  = ['v.first_classify','=',$first_classify];
+        if($second_classify)  $sel_where[]  = ['v.second_classify','=',$second_classify];
+        $list = UserVideo::field('v.*')->where($sel_where)->order('v.id desc')
+            ->alias('v')
+            ->leftJoin('User u','u.id = v.user_id')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取我的视频列表
+     * @desc 获取我的视频列表
+     * @author qc
+     * @method GET
+     * @url /api/Video/getMyVideoList
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类
+     * @return name:second_classify type:int default:-- desc:视频二级分类
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
+     */
+    public function getMyVideoList()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['is_deleted','=',0];
+        $sel_where[]  = ['user_id','=',$this->user_id];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['title|label','like','%'.$title.'%'];
+        $list = UserVideo::where($sel_where)->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 获取视频详情(会员)
+     * @desc 获取视频详情
+     * @author qc
+     * @method GET
+     * @url /api/Video/getUserVideoDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:id type:int default:0 desc:视频id
+     * @param  name:first_classify type:int default:0 desc:视频一级分类
+     * @param  name:second_classify type:int default:0 desc:视频二级分类
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类
+     * @return name:second_classify type:int default:-- desc:视频二级分类
+     * @return name:read_num type:int default:-- desc:播放量
+     * @return name:is_collect type:int default:-- desc:是否收藏
+     * @return name:collect_num type:int default:-- desc:收藏量
+     * @return name:praise_num type:int default:-- desc:点赞量
+     * @return name:is_praise type:int default:-- desc:是否点赞
+     * @return name:transmit_num type:int default:-- desc:转发量
+     */
+    public function getUserVideoDetail()
+    {
+        $detail = UserVideo::where('id',input('get.id'))->find();
+        if(!$detail)$this->error('该视频已下线');
+        if($detail->status != 1)$this->error('该视频未通过审核');
+        $detail->is_collect = 0;
+        $detail->collect_num = 0;
+        $detail->is_praise =0;
+        $detail->praise_num = 0;
+        $this->success('ok',['detail'=>$detail->toArray()]);
+    }
+
+    /**
+     * @title 用户提交或修改视频
+     * @desc 用户提交或修改视频
+     * @author qc
+     * @method POST
+     * @url /api/Video/userReferVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id(修改时必传)
+     * @param name:title type:string default:-- desc:标题
+     * @param name:video_url type:string default:-- desc:视频地址
+     * @param name:desc type:string default:-- desc:简介
+     * @param name:first_classify type:int default:-- desc:视频一级分类id
+     * @param name:second_classify type:int default:-- desc:视频二级分类id
+     * @param name:label type:string default:-- desc:视频标签id(多个用逗号隔开)
+     */
+    public function userReferVideo()
+    {
+        $id = input('post.id',0);
+        $title = input('post.title');
+        $desc = input('post.desc');
+        $video_url = input('post.video_url');
+        $cover = $video_url.'?x-oss-process=video/snapshot,t_2000,m_fast';
+        $first_classify = input('post.first_classify',0);
+        $second_classify = input('post.second_classify',0);
+        $label = input('post.label');
+        if(!$video_url) $this->error('请上传视频');
+        if($id){
+            $check_status = UserVideo::where('id',$id)->value('status');
+            if($check_status == 1) $this->error('视频已审核通过,不允许修改');
+        }
+        $data = [
+            'title' => $title,
+            'cover' => $cover,
+            'user_id' => $this->user_id,
+            'desc' => $desc,
+            'first_classify' => $first_classify,
+            'second_classify' => $second_classify,
+            'video_url' => $video_url,
+            'label' => $label,
+            'status' => 0,
+            'remark' => '',
+        ];
+        if($id) $data['id'] =  $id;
+        if($id){
+            UserVideo::where('id',$id)->update($data);
+        }else{
+            $res= UserVideo::create($data) ;
+
+        }
+        UserMessage::sendUserMessage($this->user_id,'video',1,0,0,$id ? $id:$res->id);
+        $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
+    }
+
+    /**
+     * @title 获取用户提交视频详情
+     * @desc 获取用户提交视频详情
+     * @author qc
+     * @method GET
+     * @url /api/Video/userReferVideoDetail
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id
+     * @return name:title type:string default:-- desc:标题
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:video_url type:string default:-- desc:视频地址
+     * @return name:first_classify type:int default:-- desc:视频一级分类id
+     * @return name:second_classify type:int default:-- desc:视频二级分类id
+     * @return name:label type:string default:-- desc:视频标签id(多个用逗号隔开)
+     */
+    public function userReferVideoDetail()
+    {
+        $detail = UserVideo::where('id',input('get.id'))->find()->toArray();
+        if($detail['is_deleted'] == 1) $this->error('视频已删除');
+        $detail['label_name'] = [];
+        if($detail['label']) {
+            $detail['label_name'] =explode(',',trim($detail['label'],','));
+        }
+        $this->success('获取成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 用户删除视频记录
+     * @desc 用户删除视频记录
+     * @author qc
+     * @method POST
+     * @url /api/Video/delUserVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:-- desc:id
+     */
+    public function delUserVideo()
+    {
+        UserVideo::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
+        $this->success('删除成功');
+    }
+
+    /**
+     * @title 视频评论
+     * @desc 视频评论
+     * @author qc
+     * @method POST
+     * @url /api/Video/videoComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:video_type type:int default:1 desc:视频类型(1平台2会员)
+     * @param name:video_id type:int default:-- desc:视频id
+     * @param name:url_id type:int default:-- desc:平台类型必传
+     * @param name:content type:string default:-- desc:内容
+     */
+    public function videoComment()
+    {
+        $video_type = input('post.video_type',1);
+        $video_id = input('post.video_id');
+        $url_id = input('post.url_id',0);
+        $content = input('post.content',0);
+        if(!$content) $this->error('请输入评论内容');
+        $res =  VideoComment::create(['user_id'=>$this->user_id,'content'=>$content,'video_id'=>$video_id,'url_id'=>$url_id,'video_type'=>$video_type]);;
+        $detail  =VideoComment::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.user_id,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $send_user = VideoUrl::where('id',$url_id)->value('user_id');
+        $user_info = $this->userInfo('name');
+        if($send_user) UserMessage:: sendUserMessage($send_user,'video',4,0,$this->user_id,$url_id,$user_info['name'].'评论了您的视频');
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 视频二级评论
+     * @desc 视频二级评论
+     * @author qc
+     * @method POST
+     * @url /api/Video/secondCommend
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     * @param name:content type:string default:-- desc:内容
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     */
+    public function secondCommend()
+    {
+        $comment = VideoComment::where('id',input('post.id'))->find()->toArray();
+        $user_info = $this->userInfo('name');
+        UserMessage:: sendUserMessage($comment['user_id'],'video',3,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
+        $send_user = VideoUrl::where('id',$comment['url_id'])->value('user_id');
+        if($send_user) UserMessage:: sendUserMessage($send_user,'video',4,0,$this->user_id,$comment['url_id'],$user_info['name'].'评论了您的视频');
+        unset($comment['id']);
+        unset($comment['create_at']);
+        $comment['pid'] = input('post.id');
+        $comment['user_id'] = $this->user_id;
+        $comment['content'] = input('post.content');
+        $comment['lev']++;
+        if(!$comment['source_id']) $comment['source_id'] = input('post.id');
+        $res = VideoComment::create($comment);
+        $detail  = VideoComment::where('c.id',$res->id)
+            ->alias('c')
+            ->field('c.id,c.content,c.create_at,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->find()->toArray();
+        $this->success('评论成功',['detail'=>$detail]);
+    }
+
+    /**
+     * @title 获取视频评论列表
+     * @desc 获取视频评论列表
+     * @author qc
+     * @method GET
+     * @url /api/Video/getVideoCommentList
+     * @header name:Authorization require:1 desc:Token
+     * @param name:video_type type:int default:1 desc:视频类型(1平台2会员)
+     * @param name:video_id type:int default:-- desc:视频id
+     * @param name:url_id type:int default:-- desc:url_id
+     * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
+     * @param name:page type:int default:1 desc:页数
+     * @param name:page_num type:int default:20 desc:每页数
+     * @return name:name type:string default:-- desc:会员名称
+     * @return name:headimg type:string default:-- desc:会员头像
+     * @return name:content type:string default:-- desc:内容
+     * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
+     * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
+     * @return name:like_num type:int default:-- desc:点赞数量
+     * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
+     * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
+     * @return name:total_num type:int default:-- desc:总评论数(仅一级)
+     *
+     */
+    public function getVideoCommentList()
+    {
+        $where = [];
+        $where[] = ['c.video_id','=',input('get.video_id')];
+        $where[] = ['c.url_id','=',input('get.url_id')];
+        $where[] = ['c.video_type','=',input('get.video_type')];
+        $where[] = ['c.is_deleted','=',0];
+        $user_id = $this->user_id;
+        $sort_type= input('sort_type',1);
+        switch ($sort_type) {
+            case 1:
+                $order =  ['c.id'=>'desc','c.like_times'=>'desc'];
+                break;
+            case 2:
+                $order =   ['c.like_times'=>'desc','c.id'=>'desc'];
+                break;
+        }
+
+
+        $list  =VideoComment::where($where)
+            ->alias('c')
+            ->field('c.*,u.name,u.headimg')
+            ->leftJoin('store_member u','u.id = c.user_id')
+            ->order($order)
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+
+        array_walk($list,function (&$val,$k)use($user_id){
+            $children = VideoComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
+                ->alias('c')
+                ->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->order('c.id asc')
+                ->select()->toArray();
+            $val['like_num'] = VideoCommentLike::where('like_id',$val['id'])->where('type',1)->count();
+            $val['children'] =  $children;
+            $val['is_like'] =  VideoCommentLike::where(['like_id'=>$val['id'],'user_id'=>$user_id,'type'=>1])->count();
+
+            $parent  = VideoComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
+                ->alias('c')->field('c.*,u.name,u.headimg')
+                ->leftJoin('store_member u','u.id = c.user_id')
+                ->find();
+            $val['parent']  = $parent ? $parent->toArray() : null;
+            $val['can_delete']  = $val['user_id'] == $this->user_id ? 1 :0;
+        });
+
+        $total_num  = VideoComment::where($where)->alias('c')->count();
+        $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
+    }
+
+    /**
+     * @title 删除评论
+     * @desc 删除评论
+     * @author qc
+     * @method POST
+     * @url /api/Video/delComment
+     * @header name:Authorization require:1 desc:Token
+     * @param name:id type:int default:1 desc:评论id
+     */
+    public function delComment(){
+        VideoComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
+        $this->success('删除成功');
+    }
+
+    /**
+     * @title 点赞||取消点赞
+     * @desc 点赞||取消点赞
+     * @author qc
+     * @method POST
+     * @url /api/Video/videoTags
+     * @header name:Authorization require:1 desc:Token
+     * @param name:type type:int default:1 desc:1评论点赞,评论记录id,2平台视频点赞
+     * @param name:like_id type:int default:1 desc:点赞id【二级评论不要这个功能】(平台视频点赞用video_arr的iD)
+     * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
+     */
+    public function videoTags()
+    {
+        $type = input('post.type',1);
+        $like_id = input('post.like_id');
+        $ret_val = 0;
+        $check_tags =  VideoCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$like_id,'type'=>$type])->value('id');
+        if($check_tags) {
+            VideoCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$like_id,'type'=>$type])->delete();
+            if($type == 1) VideoComment::where('id',$like_id)->setDec('like_times');
+        }else{
+            Data::save('VideoCommentLike',
+                ['user_id'=>$this->user_id,'like_id'=>$like_id,'type'=>$type],'user_id',
+                ['user_id'=>$this->user_id,'like_id'=>$like_id,'type'=>$type]);
+            $ret_val = 1;
+            if($type == 1) VideoComment::where('id',$like_id)->setInc('like_times');
+        }
+        $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
+    }
+
+
+    /**
+     * @title 视频转发(转发数量统计)
+     * @desc 转发成功后调用
+     * @author qc
+     * @method POST
+     * @url /api/Video/videoTransmit
+     * @header name:Authorization require:1 desc:Token
+     * @param name:video_type type:int default:1 desc:视频类型(1平台2会员)
+     * @param name:video_id type:int default:-- desc:视频id
+     * @param name:url_id type:int default:-- desc:平台类型必传
+     */
+    public function videoTransmit()
+    {
+        $video_type = input('post.video_type',1);
+        $video_id = input('post.video_id');
+        $url_id = input('post.url_id',0);
+        if($video_type == 1) {
+            VideoUrl::where('id',$url_id)->setInc('transmit_num');
+        }else{
+            UserVideo::where('id',$video_id)->setInc('transmit_num');
+        }
+        $this->success('ok');
+    }
+
+    /**
+     * @title 视频播放(播放数量统计)
+     * @desc 播放数量统计
+     * @author qc
+     * @method POST
+     * @url /api/Video/videoPlay
+     * @header name:Authorization require:1 desc:Token
+     * @param name:video_id type:int default:-- desc:视频id
+     * @param name:url_id type:int default:-- desc:url_id
+     */
+    public function videoPlay()
+    {
+        $video_id = input('post.video_id');
+        $url_id = input('post.url_id',0);
+        VideoUrl::where('id',$url_id)->setInc('read_num');
+        if(!$video_id) $video_id = VideoUrl::where('id',$url_id)->value('video_id');
+        UserTrack::crateTrack($this->user_id,1,$video_id,$url_id);
+        $this->success('ok');
+    }
+
+
+    /**
+     * @title 以下接口学习服务模块的
+     * @desc
+     * @author qc
+     * @method
+     * @url /api/Video/learn()
+     */
+    public function learn(){}
+
+    /**
+     * @title 视频学习历史
+     * @desc 视频学习历史
+     * @author qc
+     * @method GET
+     * @url /api/Video/getLearnHistory
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:time type:string default:-- desc:时间
+     * @return name:ali_vid type:string default:-- desc:云点播id
+     * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
+     */
+    public function getLearnHistory()
+    {
+        $sel_where  = [];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',1];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $list = UserTrack::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.update_int,t.first_id video_id,t.second_id url_id,i.title,i.cover,i.ali_vid')
+            ->leftJoin('VideoUrl i','t.second_id = i.id')
+            ->order('update_int desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 回复我的【回复我的--回复过我的评论】
+     * @desc 回复我的
+     * @author qc
+     * @method GET
+     * @url /api/Video/getReplayComment
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【其他会员】
+     * @return name:headimg type:string default:-- desc:用户头【其他会员】
+     * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:视频标题
+     * @return name:parent_comment.video_id type:string default:-- desc:视频id
+     * @return name:parent_comment.url_id type:string default:-- desc:url_id
+     * @return name:parent_comment.ali_vid:string default:-- desc:云点播id
+     */
+    public function getReplayComment()
+    {
+        $all_comment = VideoComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
+        if(empty($all_comment)) $this->success('ok',['list'=>null]);
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','=',2];
+        $sel_where[]  = ['t.user_id','<>',$this->user_id];
+        $sel_where[]  = ['t.pid','in',implode(',',$all_comment)];
+        $list = VideoComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.id url_id,i.video_id,i.ali_vid,i.cover')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->leftJoin('VideoUrl i','t.url_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $parent_comment = VideoComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.video_id,t.url_id,t.content,i.title,i.cover,t.pid,u.name,i.ali_vid')
+                ->alias('t')
+                ->leftJoin('VideoUrl i','t.url_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的回复【我的回复--我回复过的评论】
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Video/getReplyVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
+     * @return name:parent_comment.content type:string default:-- desc:内容
+     * @return name:parent_comment.name type:string default:-- desc:会员名称
+     * @return name:parent_comment.title type:string default:-- desc:视频标题
+     * @return name:parent_comment.video_id type:string default:-- desc:视频id
+     * @return name:parent_comment.url_id type:string default:-- desc:url_id
+     * @return name:parent_comment.ali_vid:string default:-- desc:云点播id
+     */
+    public function getReplyVideo()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['t.lev','=',2];
+        $list = VideoComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.lev,t.content,i.title,t.pid,i.id url_id,i.video_id,i.ali_vid,i.cover')
+            ->leftJoin('VideoUrl i','t.url_id = i.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v) {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+            $parent_comment = VideoComment::where([['t.id','=',$v['pid']]])
+                ->field('t.id,t.video_id,t.url_id,t.content,i.title,i.cover,t.pid,u.name,i.ali_vid')
+                ->alias('t')
+                ->leftJoin('VideoUrl i','t.url_id = i.id')
+                ->leftJoin('store_member u','t.user_id = u.id')
+                ->find()->toArray();
+            $v['parent_comment'] = $parent_comment;
+        }
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 我的评论【学习服务--我评论过的视频】
+     * @desc 我的评论
+     * @author qc
+     * @method GET
+     * @url /api/Video/getCommentVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名【用户自己的】
+     * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
+     * @return name:ali_vid:string default:-- desc:云点播id
+     */
+    public function getCommentVideo()
+    {
+        $user_info = $this->userInfo();
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $list = VideoComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.video_id,t.url_id,t.lev,t.content,i.title,i.cover,i.ali_vid,i.cover')
+            ->leftJoin('VideoUrl i','t.url_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        foreach ($list as &$v)
+        {
+            $v['user_name'] = $user_info['name'];
+            $v['headimg'] = $user_info['headimg'];
+        }
+        $this->success('ok',['list'=>$list]);
+
+    }
+
+    /**
+     * @title 评论我的【学习服务--评论我的】
+     * @desc 评论我的
+     * @author qc
+     * @method GET
+     * @url /api/Video/commentMyVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:user_name type:string default:-- desc:用户名
+     * @return name:headimg type:string default:-- desc:用户头像
+     * @return name:ali_vid:string default:-- desc:云点播id
+     */
+    public function commentMyVideo()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.is_deleted','=',0];
+        $sel_where[]  = ['i.user_id','=',$this->user_id];
+        $list = VideoComment::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.video_id,t.video_id,t.lev,t.content,i.title,i.cover,i.ali_vid,u.name user_name,u.headimg')
+            ->leftJoin('VideoUrl i','t.url_id = i.id')
+            ->leftJoin('store_member u','t.user_id = u.id')
+            ->order('t.id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+    /**
+     * @title 已购视频列表
+     * @desc 已购视频列表
+     * @author qc
+     * @method GET
+     * @url /api/Video/getPurchaseVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:ali_vid type:string default:-- desc:云点播id
+     * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
+     */
+    public function getPurchaseVideo()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',1];
+        $sel_where[]  = ['t.end_int','>',time()];
+        $list = UserLearn::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.first_id video_id,t.second_id url_id,i.title,i.cover,i.is_vip,i.ali_vid')
+            ->leftJoin('VideoUrl i','t.second_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 视频收藏记录【我的收藏】
+     * @desc 视频收藏记录
+     * @author qc
+     * @method GET
+     * @url /api/Video/getVideoCollect
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:ali_vid type:string default:-- desc:云点播id
+     * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
+     */
+    public function getVideoCollect()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.coll_type','=',1];
+        $list = UserCollect::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.coll_id video_id,t.children_id url_id,i.title,i.cover,i.is_vip,i.ali_vid')
+            ->leftJoin('VideoUrl i','t.children_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+    /**
+     * @title 视频点赞列表【我的点赞】
+     * @desc 视频点赞列表
+     * @author qc
+     * @method GET
+     * @url /api/Video/getTagsVideo
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:title type:string default:-- desc:标题
+     * @param  name:page type:int default:0 desc:页数
+     * @param  name:page_num type:int default:20 desc:每页数
+     * @return name:title type:string default:-- desc:标题
+     * @return name:video_id type:string default:-- desc:视频id
+     * @return name:url_id type:string default:-- desc:url_id
+     * @return name:cover type:string default:-- desc:封面
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:ali_vid type:string default:-- desc:云点播id
+     * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
+     */
+    public function getTagsVideo()
+    {
+        $sel_where  = [];
+        $title = input('get.title');
+        if($title)  $sel_where[]  = ['i.title|i.label','like','%'.$title.'%'];
+        $sel_where[]  = ['t.user_id','=',$this->user_id];
+        $sel_where[]  = ['t.type','=',2];
+        $list = VideoCommentLike::where($sel_where)
+            ->alias('t')
+            ->field('t.id,t.create_at,t.like_id url_id,i.title,i.cover,i.is_vip,i.cover,i.ali_vid,i.video_id')
+            ->leftJoin('VideoUrl i','t.like_id = i.id')
+            ->order('id desc')
+            ->limit($this->off_set,$this->page_num)
+            ->select()->toArray();
+        $this->success('ok',['list'=>$list]);
+    }
+
+
+
+
+
+
+}

+ 286 - 0
application/api/controller/VideoDemand.php

@@ -0,0 +1,286 @@
+<?php
+namespace app\api\controller;
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+use AlibabaCloud\SDK\Vod\V20170321\Vod;
+use AlibabaCloud\SDK\Vod\V20170321\Models\GetPlayInfoRequest;
+use AlibabaCloud\Tea\Exception\TeaError;
+use Darabonba\OpenApi\Models\Config;
+use AlibabaCloud\SDK\Vod\V20170321\Models\CreateUploadVideoRequest;
+use AlibabaCloud\SDK\Vod\V20170321\Models\RefreshUploadVideoRequest;
+use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
+use AlibabaCloud\Tea\Utils\Utils;
+use \Exception;
+use AlibabaCloud\SDK\Vod\V20170321\Models\GetVideoPlayAuthRequest;
+require_once '../vendor/aliyunmail/aliyun-php-sdk-core/Config.php';   // 假定您的源码文件和aliyun-php-sdk处于同一目录
+$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
+if (file_exists($path)) require_once $path;
+date_default_timezone_set('PRC');
+
+/**
+ * @title 阿里云视频点播【接口数据及格式为视频点播接口返回】
+ * @controller VideoDemand
+ * @group base
+ */
+class VideoDemand extends Base
+{
+
+    protected $account_name = 'vod@1122764885952286.onaliyun.com'; // 账号
+    protected $login_secret = 'NKna#5y1mKBp58k)qqwJHhRcrUE!{ECT';// 密码
+    protected $account_uid = '285664060640337784';// uid
+    protected $access_key = 'LTAI5tN5SwDsN2km6PgZPScp';// key
+    protected $access_secret = 'SqRcmQNYG8d7l2vjDLpVvibwT59bSj';//secret
+    protected $role_arn= 'acs:ram::1122764885952286:role/voderole';//role_arn
+    protected $role_session_name= 'voderole';//role_session_name
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param string $accessKeyId
+     * @param string $accessKeySecret
+     * @return Vod Client
+     */
+    public static function createClient($accessKeyId, $accessKeySecret){
+        $config = new Config([
+            // 您的 AccessKey ID
+            "accessKeyId" => $accessKeyId,
+            // 您的 AccessKey Secret
+            "accessKeySecret" => $accessKeySecret
+        ]);
+        // 访问的域名
+        $config->endpoint = "vod.cn-shanghai.aliyuncs.com";
+        return new Vod($config);
+    }
+
+    /**
+     * 获取本地文件对象
+     * @return \think\File
+     */
+    private function getUploadFile()
+    {
+        try {
+            return $this->request->file('file');
+        } catch (\Exception $e) {
+            $this->error(lang($e->getMessage()));
+        }
+    }
+
+    /**
+     * @title 获取视频播放凭证[STS方式]
+     * @desc 获取视频播放凭证[STS方式]
+     * @author qc
+     * @url /api/Video_demand/getVideoCredentials
+     * @method GET
+     * @tag 视频播放凭证
+     * @header name:Authorization require:1 desc:Token
+     * @return name:RequestId type:string default:-- desc:RequestId
+     * @return name:Arn type:string default:-- desc:RoleArn(Arn)
+     * @return name:AssumedRoleId type:string default:-- desc:AssumedRoleId
+     * @return name:SecurityToken type:string default:-- desc:SecurityToken
+     * @return name:AccessKeyId type:string default:-- desc:AccessKeyId
+     * @return name:AccessKeySecret type:string default:-- desc:AccessKeySecret
+     * @return name:Expiration type:string default:-- desc:Expiration
+     */
+    public function getVideoCredentials()
+    {
+        //构建一个阿里云客户端,用于发起请求。
+
+        //设置调用者(RAM用户或RAM角色)的AccessKey ID和AccessKey Secret。
+        AlibabaCloud::accessKeyClient($this->access_key, $this->access_secret)->regionId('cn-hangzhou')->asDefaultClient();
+        //设置参数,发起请求。
+        try {
+            $result = AlibabaCloud::rpc()
+                ->product('Sts')
+                ->scheme('https') // https | http
+                ->version('2015-04-01')
+                ->action('AssumeRole')
+                ->method('POST')
+                ->host('sts.aliyuncs.com')
+                ->options([
+                    'query' => [
+                        'RegionId' => "cn-hangzhou",
+                        'RoleArn' => $this->role_arn,
+                        'RoleSessionName' =>$this->role_session_name,
+                    ],])
+                ->request();
+            $ret = $result->toArray();
+            $ret['Credentials']['region'] = 'cn-shanghai';
+            $this->success('请求成功',$ret);
+        } catch (ClientException $e) {
+            $this->error($e->getErrorMessage() . PHP_EOL);
+        } catch (ServerException $e) {
+            $this->error($e->getErrorMessage() . PHP_EOL);
+        }
+    }
+
+
+
+    /**
+     * @title 获取视频播放凭证[通过视频ID获取]
+     * @desc 获取视频播放凭证[通过视频ID获取]
+     * @author qc
+     * @url /api/Video_demand/getVideoCredentials
+     * @method GET
+     * @tag 视频播放凭证
+     * @header name:Authorization require:1 desc:Token
+     * @param name:ali_vid type:int require:1  default:0 desc:ali_vid
+     * @return name:playAuth type:string default:-- desc:playAuth(时效3000s)
+     * @return name:requestId type:string default:-- desc:requestId
+     */
+    public function getVideoCredentialsByVideoId()
+    {
+        $client = self::createClient($this->access_key, $this->access_secret);
+        $getVideoPlayAuthRequest = new GetVideoPlayAuthRequest([
+            'videoId'=>input('ali_vid'),
+            "authInfoTimeout" => 3000
+        ]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            $res = $client->getVideoPlayAuthWithOptions($getVideoPlayAuthRequest, $runtime);
+            $json_res =  json_encode($res,true);
+            $res_arr = json_decode($json_res,true);
+        }catch (\Exception $error){
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            $this->error($error->message);
+        }
+        // 复制代码运行请自行打印 API 的返回值
+
+        $this->success('ok',$res_arr['body'] );
+    }
+
+    /**
+     * @title 获取视频上传凭证
+     * @desc 获取视频上传凭证
+     * @author qc
+     * @url /api/Video_demand/createUploadVideo
+     * @method POST
+     * @tag 获取视频上传凭证
+     * @header name:Authorization require:1 desc:Token
+     * @name name:file type:string default:-- desc:视频文件
+     * @return name:requestId type:string default:-- desc:requestId
+     * @return name:uploadAddress type:string default:-- desc:uploadAddress
+     * @return name:uploadAuth type:string default:-- desc:uploadAuth
+     * @return name:videoId type:string default:-- desc:videoId
+     */
+    public  function createUploadVideo(){
+        if (!($file = $this->getUploadFile()) || empty($file)) $this->error('文件上传异常,文件可能过大或未上传!');
+        if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) $this->error('文件上传类型受限,请在后台配置!');
+        if ($file->checkExt('php,sh')) $this->error('可执行文件禁止上传到本地服务器!');
+        $size = $file->getSize();
+        $file_name = $file->getInfo('name');
+        $extend = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION);
+        $up_param = [
+            'fileName'=>$file_name,
+            'FileSize'=>$size,
+            'title'=>'视频上传',
+        ];
+        try {
+            $client = self::createClient($this->access_key, $this->access_secret);
+            $createUploadVideoRequest = new CreateUploadVideoRequest($up_param);
+            $runtime = new RuntimeOptions([]);
+            $res =  $client->createUploadVideoWithOptions($createUploadVideoRequest, $runtime);
+            $json_res =  json_encode($res,true);
+            $res_arr = json_decode($json_res,true);
+        }catch (\Exception $error){
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            $this->error($error->message);
+        }
+        $this->success('ok',$res_arr['body']);
+    }
+
+
+    /**
+     * @title 刷新视频上传凭证
+     * @desc 刷新视频上传凭证
+     * @author qc
+     * @url /api/Video_demand/refreshUploadVideoToken
+     * @method GET
+     * @tag 刷新视频上传凭证
+     * @header name:Authorization require:1 desc:Token
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:ali_vid type:string default:-- desc:videoId
+     * @return name:uploadAddress type:string default:-- desc:uploadAddress
+     * @return name:uploadAuth type:string default:-- desc:uploadAuth
+     * @return name:videoId type:string default:-- desc:videoId
+     */
+    public function refreshUploadVideoToken()
+    {
+        $client = self::createClient($this->access_key, $this->access_secret);
+        $refreshUploadVideoRequest = new RefreshUploadVideoRequest([
+            'videoId'=>input('ali_vid'),
+        ]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            $res =  $client->refreshUploadVideoWithOptions($refreshUploadVideoRequest, $runtime);
+            $json_res =  json_encode($res,true);
+            $res_arr = json_decode($json_res,true);
+        }
+        catch (\Exception $error) {
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            $this->error($error->message);
+        }
+        $this->success('ok',$res_arr['body'] );
+    }
+
+
+    /**
+     * @title 获取视频播放地址[通过视频ID获取]
+     * @desc 获取视频播放地址[通过视频ID获取]
+     * @author qc
+     * @url /api/Video_demand/getVideoPath
+     * @method GET
+     * @tag 视频播放凭证
+     * @header name:Authorization require:1 desc:Token
+     * @param name:ali_vid type:int require:1  default:0 desc:ali_vid
+     * @return name:playInfoList type:array default:-- desc:playInfoList
+     * @return name:playInfoList.playInfo.playURL type:string default:-- desc:播放地址
+     */
+    public function getVideoPath()
+    {
+        $client = self::createClient($this->access_key, $this->access_secret);
+        $getVideoPlayAuthRequest = new GetPlayInfoRequest(['videoId'=>input('ali_vid')]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            $res = $client->getPlayInfoWithOptions($getVideoPlayAuthRequest, $runtime);
+            $json_res =  json_encode($res,true);
+            $res_arr = json_decode($json_res,true);
+        }catch (\Exception $error){
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            $this->error($error->message);
+        }
+         $this->success('ok',$res_arr['body'] );
+    }
+
+
+
+
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 279 - 0
application/api/controller/WalletManage.php

@@ -0,0 +1,279 @@
+<?php
+
+
+namespace app\api\controller;
+use app\common\model\GoodsOrderItem;
+use app\common\model\UserBank;
+use app\common\model\UserIntegralLog;
+use app\common\model\UserLevel;
+use app\common\model\UserMoneyInfo;
+use app\common\model\UserWallet;
+use app\common\model\UserWithdrawLog;
+use think\Db;
+use app\common\model\User;
+/**
+ * @title 会员钱包管理(佣金提现,积分,经验...)
+ * @controller WalletManage
+ * @group base
+ */
+class WalletManage extends Base
+{
+    public function initialize()
+    {
+        parent::initialize();
+        parent::checkLogin();
+    }
+
+    /**
+     * @title 获取钱包详情
+     * @desc 获取钱包详情
+     * @author qc
+     * @url /api/Wallet_manage/walletInfo
+     * @method GET
+     * @tag 个人信息
+     * @header name:Authorization require:1 desc:Token
+     * @return name:detail type:array default:-- desc:钱包
+     * @return name:detail.integral type:int default:-- desc:积分
+     * @return name:detail.growth type:int default:-- desc:经验值(分销等级成长值)
+     * @return name:detail.money type:float default:-- desc:佣金
+     * @return name:detail.level_exp type:int default:-- desc:等级经验(会员等级经验值)
+     * @return name:detail.withdraw type:float default:-- desc:累积提现
+     * @return name:openid type:string default:-- desc:绑定的微信openid
+     * @return name:ali_account type:array default:-- desc:支付宝账号
+     * @return name:ali_account.real_name type:string default:-- desc:支付宝姓名
+     * @return name:ali_account.card_no type:string default:-- desc:支付宝账号
+     * @return name:bank_list type:array default:-- desc:绑定银行卡列表
+     * @return name:bank_list.real_name type:string require:1 default:-- desc:真实姓名
+     * @return name:bank_list.card_no type:string require:1 default:-- desc:账号
+     * @return name:bank_list.bank_name type:string require:1 default:-- desc:所属银行
+     *
+     */
+    public function walletInfo()
+    {
+        $wallet = UserWallet::where('user_id',$this->user_id)->find();
+        if(!$wallet) $wallet =  UserWallet::create(['user_id'=>$this->user_id]);
+        $user_info = User::field('id,name,openid,headimg')->where('id',$this->user_id)->find();
+        $ali_account = UserBank::field('id,real_name,card_no')->where(['user_id'=>$this->user_id,'type'=>1,'is_deleted'=>0])->find();
+        $bank_list = UserBank::field('id,real_name,card_no,bank_name')->where(['user_id'=>$this->user_id,'type'=>2,'is_deleted'=>0])->order('id desc')->select()->toArray();
+        $this->success('获取成功',['detail'=> $wallet->toArray(),'user_info'=>$user_info,'ali_account'=>$ali_account,'bank_list'=>$bank_list]);
+    }
+
+    /**
+     * @title 获取个人钱包信息
+     * @desc 获取个人钱包信息
+     * @author qc
+     * @url /api/Wallet_manage/getUserWallet
+     * @method GET
+     * @tag 获取个人钱包信息
+     * @header name:Authorization require:1 desc:Token
+     * @return name:phone type:int default:-- desc:手机号
+     * @return name:name type:string default:-- desc:昵称
+     * @return name:headimg type:string default:-- desc:头像地址
+     * @return name:card_front type:string default:-- desc:身份证正面
+     * @return name:card_back type:string default:-- desc:身份证背面
+     * @return name:level_name type:string default:-- desc:等级名称
+     * @return name:partner_lev type:int default:-- desc:分销商等级id(0不是分销商)
+     * @return name:is_agency type:int default:-- desc:是否是区域代理(0不是)
+     * @return name:wallet type:array default:-- desc:钱包
+     * @return name:wallet.integral type:int default:-- desc:积分
+     * @return name:wallet.growth type:int default:-- desc:经验值(分销等级成长值)
+     * @return name:wallet.money type:float default:-- desc:佣金
+     * @return name:wallet.level_exp type:int default:-- desc:经验值(会员等级)
+     *
+     */
+    public function getUserWallet()
+    {
+        $field = 'id,name,level_id,headimg,true_name,birthday,is_agency,partner_lev';
+        $user_info = User::with('wallet')->field($field)->where('id',$this->user_id)->find()->toArray();
+        $user_info['level_name'] = UserLevel::where('id',$user_info['level_id'])->value('name');
+        if(empty($user_info)) $this->error('用户信息不正确');
+        $this->success('获取成功',['user_info'=>$user_info]);
+    }
+
+
+    /**
+     * @title 佣金提现
+     * @desc 佣金提现
+     * @author qc
+     * @url /api/Wallet_manage/withdraw
+     * @method POST
+     * @tag 佣金提现
+     * @header name:Authorization require:1 desc:Token
+     * @param name:money type:float default:-- desc:提现金额
+     * @param name:type type:int default:-- desc:到账类型(1支付宝,2银行卡,3微信)
+     * @param name:pay_password type:string default:-- desc:支付密码
+     * @param name:bank_id type:int default:-- desc:账号id(type=1或2必传)
+     */
+    public function withdraw()
+    {
+       $rate        = 0.03;// 提现手续费
+       $min_money   = 100 ;// 最低提现金额
+       $max_money   = 1000;// 最大提现金额
+       $money = input('post.money',0);
+       $type = input('post.type',0);
+       $bank_id = input('post.bank_id',0);
+       $pay_password = input('post.pay_password',0);
+       if($money < $min_money) $this->error('最低提现金额:'.$min_money);
+       if($money > $max_money) $this->error('最大提现金额:'.$max_money);
+       $user_info = User::where('id',$this->user_id)->find()->toArray();
+       if(!$user_info['pay_password']) $this->error('请设置提现密码');
+       if(!check_password($pay_password,$user_info['pay_password'])) $this->error('密码错误');
+       if($type == 3 && !$user_info['openid']) $this->error('请先绑定微信!');
+       if(in_array($type,[1,2])) {
+           $acc_info = UserBank::where(['id'=>$bank_id,'user_id'=>$this->user_id])->find();
+           if(!$acc_info) $this->error('账号信息有误');
+       }
+       Db::startTrans();
+       try {
+           $wallet = UserWallet::where(['user_id'=>$this->user_id])->find();
+           if($wallet->money < $money)  $this->exception('佣金余额不足');
+           $service_fee = bcmul($money,$rate,2);
+           $account =  bcsub($money,$service_fee,2);
+           $ins_data = [
+               'user_id' => $this->user_id,
+               'money' => $money,// 提现金额
+               'rate' => $rate,// 手续费率
+               'service_fee' => $service_fee,// 手续费
+               'account' => $account,// 实际到账金额
+               'type' => $type,
+               'user_name' => $type == 3 ? $user_info['name'] : $acc_info->real_name,
+               'card_no' => $type == 3 ?  $user_info['openid'] : $acc_info->card_no,
+               'bank_name' => $type == 3 ? '微信账户' : $acc_info->bank_name,
+           ];
+           $ins_res = UserWithdrawLog::create($ins_data);// 提现日志
+           UserWallet::userMoneyChange($this->user_id,$money,'提现申请',3,-1,$ins_res->id);
+           $this->ret_msg = '申请成功';
+       }catch (\Exception $e){
+            $this->is_commit = false;
+            $this->ret_msg = $e->getMessage();
+       }
+       $this->transReturn();
+    }
+
+    /**
+     * @title 获取用户提现日志
+     * @desc 获取用户提现日志
+     * @author qc
+     * @url /api/Wallet_manage/getWithdrawLog
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:status type:int default:-1 desc:状态(0待处理,1已审核 2已到账 3已拒绝 4异常)
+     * @param  name:type type:int default:-- desc:类型
+     * @param  name:page type:int  : default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @return name:money type:float default:-- desc:提现金额
+     * @return name:type type:int default:-- desc:到账类型(1支付宝,2银行卡,3微信)
+     * @return name:money type:float default:-- desc:申请提现金额
+     * @return name:rate type:float default:-- desc:手续费率
+     * @return name:service_fee type:float default:-- desc:手续费
+     * @return name:desc type:float default:-- desc:描述
+     * @return name:status type:int default:-- desc:状态(0待处理,1已审核 2已到账 3已拒绝 4异常)
+     * @return name:user_name type:string default:-- desc:收款人
+     * @return name:card_no type:string default:-- desc:收款账号
+     * @return name:bank_name type:string default:-- desc:名称
+     */
+    public function getWithdrawLog()
+    {
+        $status = input('get.status',-1);
+        $where = [];
+        $where['is_deleted'] = 0;
+        $where['user_id'] = $this->user_id;
+        if($status) $where['status'] =  $status;
+        $list = UserWithdrawLog::where($where)->limit($this->off_set,$this->page_num)
+            ->order('id desc')->select();
+        $this->success('ok',['list'=>$list ? $list->toArray():[]]);
+    }
+
+    /**
+     * @title 获取用户佣金变更记录
+     * @desc 获取用户佣金变更记录
+     * @author qc
+     * @url /api/Wallet_manage/getUserMoneyInfo
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int  : default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @return name:money type:float default:-- desc:金额
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:desc type:float default:-- desc:描述
+     */
+    public function getUserMoneyInfo()
+    {
+        $where = [];
+        $where['user_id'] = $this->user_id;
+        $list = UserMoneyInfo::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
+        $this->success('ok',['list'=>$list ? $list->toArray():[]]);
+    }
+
+    /**
+     * @title 获取用户积分变更记录
+     * @desc 获取用户积分变更记录
+     * @author qc
+     * @url /api/Wallet_manage/getUserIntegralLog
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int  : default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @param  name:type type:int  : default:0 desc:类型(0全部,1增加,2减少)
+     * @return name:integral type:int default:-- desc:变更数量
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:desc type:float default:-- desc:描述
+     */
+    public function getUserIntegralLog()
+    {
+        $where = [];
+        $where[] = ['user_id','=',$this->user_id];
+        $where[] = ['is_deleted','=',0];
+        if(input('type') == 1) $where[] = ['integral','>','0'];
+        if(input('type') == 2) $where[] = ['integral','<','0'];
+        $list = UserIntegralLog::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
+        $this->success('ok',['list'=>$list ? $list->toArray():[]]);
+    }
+
+
+    /**
+     * @title 获取用户分销佣金记录
+     * @desc 获取用户分销佣金记录
+     * @author qc
+     * @url /api/Wallet_manage/getDistributionMoney
+     * @method GET
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:page type:int  : default:1 desc:页数
+     * @param  name:page_num type:int  : default:20 desc:每页数
+     * @return name:money type:float default:-- desc:金额
+     * @return name:create_at type:string default:-- desc:时间
+     * @return name:desc type:float default:-- desc:描述
+     * @return name:type type:float default:-- desc:类型(7一级分销,8二级分销)
+     * @return name:user_info type:array default:-- desc:会员信息
+     * @return name:user_info.name type:string default:-- desc:会员名
+     * @return name:user_info.headimg type:string default:-- desc:会员头像
+     * @return name:goods_list type:array default:-- desc:商品列表
+     * @return name:goods_list.cover type:array default:-- desc:商品图
+     * @return name:goods_list.goods_name type:string default:-- desc:商品名
+     * @return name:goods_list.goods_spec type:string default:-- desc:商品规格
+     * @return name:goods_list.sell_money type:float default:-- desc:商品价格
+     * @return name:goods_list.is_dist type:int default:-- desc:是否是分销商品(0否,1是)
+     */
+    public function getDistributionMoney()
+    {
+        $where = [];
+        $where[] = ['user_id','=',$this->user_id];
+        $where[] = ['type','in','7,8'];
+        $list = UserMoneyInfo::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
+        array_walk($list,function ($val){
+            $val['user_info']  = User::where('id',$val['user_id'])->field('id,name,headimg')->find()->toArray();
+            $goods_list = GoodsOrderItem::where('i.order_id',$val['id'])
+                ->alias('i')
+                ->leftJoin('StoreGoods g','g.id = i.goods_id')
+                ->field('i.cover,i.sell_money,i.num,g.is_dist,i.goods_name,i.goods_spec')
+                ->select()->toArray();
+            $val['goods_list'] = $goods_list;
+        });
+        $this->success('ok',['list'=>$list ? $list->toArray():'']);
+    }
+
+
+
+
+
+}

+ 172 - 0
application/api/controller/WeChatPay.php

@@ -0,0 +1,172 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkAdmin
+// +----------------------------------------------------------------------
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// +----------------------------------------------------------------------
+// | 官方网站: http://demo.thinkadmin.top
+// +----------------------------------------------------------------------
+// | 开源协议 ( https://mit-license.org )
+// +----------------------------------------------------------------------
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
+// +----------------------------------------------------------------------
+
+namespace app\api\controller;
+use app\common\model\GoodsOrder;
+use app\common\service\OrderCallback;
+use EasyWeChat\Factory;
+use think\Controller;
+use think\Db;
+use think\Exception;
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+/**
+ * 微信支付管理类
+ * Class WeChatPay
+ * @package app\api\controller\WeChatPay
+ */
+class WeChatPay extends Controller
+{
+    //小程序微信支付(type为1时是货主端微信配置,type为2时是接单端微信配置)
+    public static function wxPay($name='订单支付',$out_trade_no,$total_fee,$notify_url,$trade_type = 'JSAPI',$openid = ''){
+        try{
+            if(empty($out_trade_no) || empty($total_fee) || empty($notify_url)) return false;
+            $parameter = [
+                'body'          => $name,
+                'out_trade_no'  => $out_trade_no,
+                'total_fee'     => $total_fee*100,
+                'notify_url'    => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+                'trade_type'    => $trade_type, // 请对应换成你的支付方式对应的值类型
+                'openid'        => $openid,
+            ];
+            switch ($trade_type){
+                case 'JSAPI':
+                    $app = Factory::payment(config('app.wx_pay'));
+                    break;
+                case 'NATIVE':
+                    $app = Factory::payment(config('app.wx_pay'));
+                    break;
+                case 'APP':
+                    $app = Factory::payment(config('app.app_wx'));
+                    break;
+                case 'MWEB':
+                    $app = Factory::payment(config('app.wx_pay'));
+                    break;
+                case 'WAP':
+                    $app = Factory::payment(config('app.wx_pay'));
+                    break;
+            }
+            if(in_array($trade_type ,['JSAPI'])) $parameter['openid'] = $openid;
+            if(in_array($trade_type ,['MWEB'])) $parameter['spbill_create_ip'] = request()->ip();
+            $result = $app->order->unify($parameter);
+            $jssdk = $app->jssdk;
+            if($trade_type == 'APP') {
+                $config = $jssdk->appConfig($result['prepay_id']);
+            }else if($trade_type == 'MWEB'){
+                $config = $jssdk->bridgeConfig($result['prepay_id']);
+            }else{
+                $config = $jssdk->sdkConfig($result['prepay_id']);
+            }
+            if(!is_array($config) && $config) $config = json_decode($config,true);
+            return ['code'=> $config ? 200 : 201 , 'config'=>$config,'msg'=>'ok','mweb_url'=> isset($result['mweb_url']) ?  $result['mweb_url']:''];
+        }catch (\Exception $e){
+            return ['code'=> 201,'config'=>[],'msg'=>$e->getMessage(),'mweb_url'=>''];
+        }
+    }
+
+    /**
+     * 商城订单支付回调
+     */
+    public function goodsOrderNotify()
+    {
+        $app = Factory::payment(config('app.wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            $this->payResultLog($message,'dd_goods_order');
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            // 如果订单不存在 或者 订单已经支付过了  告诉微信,我已经处理完了,订单没找到,别再通知我了
+            if ($message['result_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                $order_info = GoodsOrder::with('orderItem')->where('pay_no',$pay_no)->find();
+                if(!$order_info) return false;
+                $order_info = $order_info->toArray();
+                if($order_info['status'] != 0) return true;
+                $back_res = OrderCallback::goodsOrderCallBack($order_info,1);// 支付完成后回调
+                return $back_res['ret_val'];
+            } else if ($message['return_code'] != 'SUCCESS'){
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+
+    // 开通会员支付回调
+    public function LevelOrderNotify()
+    {
+        $app = Factory::payment(config('app.wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            $this->payResultLog($message,'dd_level_order');
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            // 如果订单不存在 或者 订单已经支付过了  告诉微信,我已经处理完了,订单没找到,别再通知我了
+            if ($message['result_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                $order_info = \app\common\model\LevelOrder::where('pay_no',$pay_no)->find();
+                if(!$order_info) return false;
+                $order_info = $order_info->toArray();
+                if($order_info['status'] != 0) return true;
+                $back_res = OrderCallback::levelOrderCallBack($order_info,1);// 支付完成后回调
+                return $back_res['ret_val'];
+            } else if ($message['return_code'] != 'SUCCESS'){
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+
+    // 活动报名回调
+    public function applyOrderNotify()
+    {
+        $app = Factory::payment(config('app.wx_pay'));
+        $response = $app->handlePaidNotify(function ($message, $fail) {
+            $this->payResultLog($message,'dd_activity_apply');
+            // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
+            $pay_no = $message['out_trade_no'];
+            // 如果订单不存在 或者 订单已经支付过了  告诉微信,我已经处理完了,订单没找到,别再通知我了
+            if ($message['result_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+                $order_info = \app\common\model\ActivityApply::where('pay_no',$pay_no)->find();
+                if(!$order_info) return false;
+                $order_info = $order_info->toArray();
+                if($order_info['status'] != 0) return true;
+                $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
+                return $back_res['ret_val'];
+            } else if ($message['return_code'] != 'SUCCESS'){
+                return $fail('通信失败,请稍后再通知我');
+            }
+        });
+        $response->send();
+    }
+
+
+    /**
+     * 记录支付日志
+     * @param $message
+     * @param $table_name
+     */
+    public function payResultLog($message,$table_name)
+    {
+        // 回调记录
+        $ret_arr = [];
+        $ret_arr['transaction_id'] =    isset($message['transaction_id']) ?$message['transaction_id']: '';
+        $ret_arr['trade_no'] =          isset($message['out_trade_no']) ?$message['out_trade_no']: '';
+        $ret_arr['return_code'] =       isset($message['return_code']) ?$message['return_code']: '';
+        $ret_arr['result_code'] =       isset($message['result_code']) ?$message['result_code']: '';
+        $ret_arr['create_at'] =         date('Y-m-d H:i:s');
+        $ret_arr['order_table'] =       $table_name;
+        $ret_arr['result'] =            json_encode($message);
+        Db::name('order_pay_result')->insert($ret_arr);
+    }
+
+
+}

+ 26 - 0
application/api/controller/WeChatPort.php

@@ -0,0 +1,26 @@
+<?php
+namespace app\api\controller;
+use EasyWeChat\Factory;
+use EasyWeChat\MiniProgram\Application;
+use think\Controller;
+
+/**
+ * 微信接口
+ * Class WeChatPort
+ * @package app\api\controller\WeChatPay
+ */
+class WeChatPort extends Controller
+{
+    // 获取微信小程序AccessToken
+    public static function getAccessToken($code)
+    {
+        $res = http_curl('https://api.weixin.qq.com/cgi-bin/token?appid='.config('mini_program')['app_id'].'&secret='.config('mini_program')['secret'].'&code='.$code.'&grant_type=client_credential');
+        return $res;
+    }
+
+    public  static function getUserInfo($code)
+    {
+
+    }
+
+}

+ 251 - 51
application/common.php

@@ -1,11 +1,5 @@
 <?php
-/**
- * @param string $address 地址
- * @return array
- */
-
 use think\Db;
-use Dm\Request\V20151123 as Dm;
 /**
  * 秒转换为天
  */
@@ -26,42 +20,6 @@ function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
     }
     return $day;
 }
-/**
- * get请求
- * @param $url
- * @param string $msg
- * @return mixed
- */
-function requestGet($url , $msg = ''){
-    // 1. 初始化一个cURL会话
-    $ch = curl_init();
-    //设置选项,包括URL
-    curl_setopt($ch, CURLOPT_URL, $url);
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    curl_setopt($ch, CURLOPT_HEADER, 0);
-    //执行并获取HTML文档内容
-    $response = curl_exec($ch);
-    // 4. 释放cURL句柄,关闭一个cURL会话
-    curl_close($ch);
-    return $response;
-}
-function requestPost($url , $post_data = array() ){
-    // 1. 初始化一个cURL会话
-    $ch = curl_init();
-    // 2. 设置请求选项, 包括具体的url
-    curl_setopt($ch, CURLOPT_URL, $url);
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    // 设置请求为post类型
-    curl_setopt($ch, CURLOPT_POST, 1);
-    // 添加post数据到请求中
-    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
-    curl_setopt($ch, CURLOPT_HEADER, 0);
-    // 3. 执行一个cURL会话并且获取相关回复
-    $response = curl_exec($ch);
-    // 4. 释放cURL句柄,关闭一个cURL会话
-    curl_close($ch);
-    return $response;
-}
 //获取全图片地址 $image_data
 function image_path($image_data){
     if(empty($image_data)){
@@ -76,13 +34,255 @@ function image_path($image_data){
     }
     return $image_res;
 }
-function get_order_sn(){
-    $order_id_main = date('YmdHis') . rand(10000000,99999999);
-    $order_id_len = strlen($order_id_main);
-    $order_id_sum = 0;
-    for($i=0; $i<$order_id_len; $i++){
-        $order_id_sum += (int)(substr($order_id_main,$i,1));
-    }
-    $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
-    return $osn;
+
+/**
+ * @param $id_card
+ * @return false|string
+ */
+function get_age($id_card){
+    # 1.从身份证中获取出生日期
+    $birth_Date = strtotime(substr($id_card, 6, 8));//截取日期并转为时间戳
+
+    # 2.格式化[出生日期]
+    $Year = date('Y', $birth_Date);//yyyy
+    $Month = date('m', $birth_Date);//mm
+    $Day = date('d', $birth_Date);//dd
+
+    # 3.格式化[当前日期]
+    $current_Y = date('Y');//yyyy
+    $current_M = date('m');//mm
+    $current_D = date('d');//dd
+
+    # 4.计算年龄()
+    $age = $current_Y - $Year;//今年减去生日年
+    if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
+        $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
+    }
+    # 返回
+    return $age;
+
+}
+
+function create_invite_code($user_id){
+    // 生成12位邀请码
+    $code_str = '';
+    $base_code = explode(',',"A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z");
+    $code_key = array_rand($base_code, 10 - strlen($user_id));
+    array_map(function ($val)use (&$code_str,$base_code){
+        $code_str .=$base_code[$val] ;
+    },$code_key);
+    return $code_str.$user_id;
+}
+
+// 获取模板区域
+function get_city_area()
+{
+    $field=['id','pid','name'];
+    $list=Db::name('china_area')->where('pid',0)->field($field)->select();
+    foreach ($list as $k=>&$v){
+        $v['children']= Db::name('china_area')->where('pid',$v['id'])->field($field)->select();
+    }
+    return $list;
+}
+
+function http_curl($url,$type='get',$res='json',$arr=''){
+
+    $headers = array();
+    //根据API的要求,定义相对应的Content-Type
+    array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
+    $curl = curl_init();
+    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
+    curl_setopt($curl, CURLOPT_URL, $url);
+    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+    curl_setopt($curl, CURLOPT_FAILONERROR, false);
+    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($curl, CURLOPT_HEADER, false);
+    $output = curl_exec($curl);
+    curl_close($curl);
+    if($res=='json'){
+        if($output === false){
+            //请求失败,返回错误信息
+            return curl_error($curl);
+        }else{
+            //请求成功,返回信息
+            return json_decode($output,true);
+        }
+    }
+}
+
+function curl_get($url)
+{
+    $ch = curl_init();
+    curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    $output = curl_exec($ch);
+    curl_close($ch);
+    if($output === false){
+        return curl_error($ch);
+    }else{
+        return json_decode($output,true);
+    }
+}
+
+// 获取物流信息
+function get_delivery($send_no = 'JD0053309649641',$express_code=''){
+        error_reporting(E_ALL || ~E_NOTICE);
+        $AppKey     = 204111217;
+        $AppSecret  ='LGUYqAh335HMec0eyJZdiHwMhrapU1fH';
+        $AppCode    ='5f96216347b547579e2417685ee8e647';//开通服务后 买家中心-查看AppCode
+        $host = "https://wuliu.market.alicloudapi.com";//api访问链接
+        $path = "/kdi";//API访问后缀
+        $method = "GET";
+        $body  ='';
+        $headers = array();
+        array_push($headers, "Authorization:APPCODE " . $AppCode);
+        $querys = "no={$send_no}&type={$express_code}";  //参数写在这里
+        $url = $host . $path . "?" . $querys;
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_HEADER, true);
+        if (1 == strpos("$" . $host, "https://")) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        $out_put = curl_exec($curl);
+        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+        list($header, $body) = explode("\r\n\r\n", $out_put, 2);
+        if ($httpCode == 200) {
+            return json_decode($body,true)['result'];
+        } else {
+            return [];
+        }
+    }
+
+// 实名认证
+function user_certification($id_card,$name){
+    $host = "http://checkone.market.alicloudapi.com";
+    $path = "/chinadatapay/1882";
+    $method = "POST";
+    $appcode = "30be8bdcc65842919980a8276ffc4995";
+    $headers = array();
+    array_push($headers, "Authorization:APPCODE " . $appcode);
+    //根据API的要求,定义相对应的Content-Type
+    array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
+
+    $bodys = "idcard=".$id_card."&name=".$name;
+    $url = $host . $path;
+
+    $curl = curl_init();
+    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+    curl_setopt($curl, CURLOPT_URL, $url);
+    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+    curl_setopt($curl, CURLOPT_FAILONERROR, false);
+    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($curl, CURLOPT_HEADER, false);
+    if (1 == strpos("$".$host, "https://"))
+    {
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+    }
+    curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
+    $res = curl_exec($curl);
+    if($res){
+        $res = json_decode($res,true);
+        if($res['data']['result'] == 1){
+           return 1;
+        }else{
+            return 0;
+        }
+    }else{
+       return 0;
+    }
+}
+
+/**
+ * 把返回的数据集转换成Tree
+ * @param array $list 要转换的数据集
+ * @param string $pk 自增字段(栏目id)
+ * @param string $pid parent标记字段
+ * @return array
+ */
+function make_tree($list,$pk='id',$pid='pid',$child='children',$root=0){
+    if(is_object($list)) $list = $list->toArray();
+    $tree=array();
+    $packData=array();
+    foreach ($list as $data) {
+        $packData[$data[$pk]] = $data;
+    }
+    foreach ($packData as $key =>$val){
+       if($val[$pid]==$root){//代表跟节点
+            $tree[]=& $packData[$key];
+        }else{
+            $packData[$val[$pid]][$child][]=& $packData[$key]; //找到其父类
+        }
+    }
+    return $tree;
+}
+
+
+//判断字段存在并不为空
+function isset_full($arr, $key)
+{
+    if (isset($arr[$key]) && !empty($arr[$key])) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+//判断字段存在并不为空 并且等于验证值
+function isset_full_check($arr, $key,$check_val)
+{
+    if (isset($arr[$key]) && !empty($arr[$key]) && $arr[$key] == $check_val) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+
+function all_pay_type()
+{
+    return [ '--','微信[H5]','支付宝[H5]','微信[APP]','支付宝[APP]','微信[公众号]' ];
+}
+
+/**
+ * @param $start 验证开始时间
+ * @param $end   验证结束时间
+ * @param $check_st  已有活动开始时间
+ * @param $check_end 已有活动结束时间
+ * @return bool  true 可以创建活动
+ */
+function check_act_time($start,$end,$check_st,$check_end)
+{
+    $check_val = false;
+    if($start > $check_end || $end < $check_st) $check_val = true;
+    return  $check_val;
+}
+
+
+/**
+ * 生成32位随机数
+ */
+function get32Str($length='32'){
+    $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+    $len = strlen($str)-1;
+    $randstr = '';
+    for ($i=0;$i<$length;$i++) {
+        $num=mt_rand(0,$len);
+        $randstr .= $str[$num];
+    }
+    return $randstr;
 }
+
+
+
+
+
+
+
+

+ 9 - 0
application/common/model/Activity.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 活动
+class Activity extends Model
+{
+
+
+}

+ 22 - 0
application/common/model/ActivityApply.php

@@ -0,0 +1,22 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 活动报名明细
+class ActivityApply extends Model
+{
+    // 验证会员是否报名某个活动
+    public static function checkApply($user_id,$act_id)
+    {
+        $id = static::where(['user_id'=>$user_id,'act_id'=>$act_id,'is_deleted'=>0,'status'=>1])->count('id');
+        return $id ? 1: 0;
+    }
+
+    // 获取报名详情
+    public static function getApplyInfo($user_id,$act_id)
+    {
+        $detail = static::where(['user_id'=>$user_id,'act_id'=>$act_id,'is_deleted'=>0,'status'=>1])->find();
+        return $detail ? $detail->toArray() : null;
+    }
+
+
+}

+ 9 - 0
application/common/model/ArticleCate.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文单一分类
+class ArticleCate extends Model
+{
+
+
+}

+ 8 - 0
application/common/model/ArticleComment.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文评论
+class ArticleComment extends Model
+{
+
+}

+ 8 - 0
application/common/model/ArticleCommentLike.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文评论点赞
+class ArticleCommentLike extends Model
+{
+
+}

+ 15 - 0
application/common/model/ArticleIntro.php

@@ -0,0 +1,15 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文
+class ArticleIntro extends Model
+{
+
+    public function itemList(){
+        return $this->hasMany('ArticleItem','article_id')
+            ->where('is_deleted',0)
+            ->field('id,article_id,cover,is_vip,sort,transmit_num,read_num,title,images,content,video_id,video_item,datum_id,datum_item')
+            ->order('sort desc');
+    }
+
+}

+ 9 - 0
application/common/model/ArticleItem.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文
+class ArticleItem extends Model
+{
+
+
+}

+ 9 - 0
application/common/model/ArticleLike.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 图文点赞
+class ArticleLike extends Model
+{
+
+
+}

+ 16 - 0
application/common/model/ChinaArea.php

@@ -0,0 +1,16 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 地址管理
+class ChinaArea extends Model
+{
+    public static function getAllCity()
+    {
+        $all_first = self::field('first')->order('first asc')->group('first')->select()->toArray();
+        array_walk($all_first,function (&$v,$k){
+            $v['city_list'] = self::field('id,name,short_name')->where(['first'=>$v['first'],'level'=>2])->select()->toArray();
+        });
+        return  $all_first;
+    }
+
+}

+ 12 - 0
application/common/model/DatumCate.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 资料目录
+class DatumCate extends Model
+{
+
+
+
+
+
+}

+ 12 - 0
application/common/model/DatumIntro.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 资料
+class DatumIntro extends Model
+{
+    public function urlArr()
+    {
+        return $this->hasMany('DatumUrl','datum_id')->field('id,datum_id,title,url,sort,is_vip,transmit_num,down_num,read_num')->where('is_deleted',0)->order('sort desc');
+    }
+
+}

+ 9 - 0
application/common/model/DatumLike.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 资料点赞
+class DatumLike extends Model
+{
+
+
+}

+ 12 - 0
application/common/model/DatumUrl.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 资料
+class DatumUrl extends Model
+{
+
+
+
+
+
+}

+ 9 - 0
application/common/model/DeliveryAddress.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+
+class DeliveryAddress extends Model
+{
+
+
+}

+ 8 - 0
application/common/model/DemandComment.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 需求评论
+class DemandComment extends Model
+{
+
+}

+ 10 - 0
application/common/model/ForumReply.php

@@ -0,0 +1,10 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 论坛回复
+class ForumReply extends Model
+{
+
+
+
+}

+ 10 - 0
application/common/model/ForumReplyComment.php

@@ -0,0 +1,10 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 论坛回答的评论
+class ForumReplyComment extends Model
+{
+
+
+
+}

+ 14 - 0
application/common/model/GoodsCate.php

@@ -0,0 +1,14 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 商品分类
+class GoodsCate extends Model
+{
+
+    public static function getCateTree()
+    {
+        $all_cate = self::field('id,title,pid,lev')->where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->select();
+        return make_tree($all_cate);
+    }
+
+}

+ 22 - 0
application/common/model/GoodsOrder.php

@@ -0,0 +1,22 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 订单
+class GoodsOrder extends Model
+{
+    protected $name='store_order';
+    public function orderItem()
+    {
+        return $this->hasMany('GoodsOrderItem','order_id');
+    }
+
+    public function orderBill()
+    {
+        return $this->hasOne('OrderBill','order_id');
+    }
+
+    public function orderRefund(){
+        return $this->hasOne('GoodsOrderRefund','order_id')->field('id,order_id,status,refund_type,refund_money,audit_desc,is_deleted');
+    }
+
+}

+ 20 - 0
application/common/model/GoodsOrderItem.php

@@ -0,0 +1,20 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 订单item
+class GoodsOrderItem extends Model
+{
+    protected  $name = 'store_order_item';
+
+    public function getOrderItem($order_id)
+    {
+        $data = $this->where(['order_id'=>$order_id])->alias('o')
+            ->field('o.id,o.num,o.sell_price,o.goods_spec,g.cover,g.name')
+            ->leftJoin('StoreGoods g','o.goods_id = g.id')->select();
+        return $data;
+    }
+
+
+
+
+}

+ 9 - 0
application/common/model/GoodsOrderRefund.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 订单
+class GoodsOrderRefund extends Model
+{
+    protected $name='store_order_refund';
+    
+}

+ 8 - 0
application/common/model/GoodsParam.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 商品参数
+class GoodsParam extends Model
+{
+
+}

+ 14 - 0
application/common/model/GoodsSeason.php

@@ -0,0 +1,14 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 商品时令
+class GoodsSeason extends Model
+{
+
+    public static function getSeasonTree()
+    {
+        $all_season = self::where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->select();
+        return make_tree($all_season);
+    }
+
+}

+ 8 - 0
application/common/model/GoodsSellInfo.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 商品销售记录
+class GoodsSellInfo extends Model
+{
+
+}

+ 12 - 0
application/common/model/GoodsServe.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 商品服务标签
+class GoodsServe extends Model
+{
+    public static function getServeLabelTitle($ids)
+    {
+        return static::where('id','in',$ids)->column('title');
+    }
+
+}

+ 9 - 0
application/common/model/InviteInfo.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 邀请模型
+class InviteInfo extends Model
+{
+    //protected $resultSetType = 'collection';// 设置返回类型
+
+}

+ 9 - 0
application/common/model/LabelMessage.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 标签消息
+class LabelMessage extends Model
+{
+
+
+}

+ 9 - 0
application/common/model/LevelOrder.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 会员等级订单
+class LevelOrder extends Model
+{
+
+
+}

+ 20 - 0
application/common/model/NewsCate.php

@@ -0,0 +1,20 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 资讯分类
+class NewsCate extends Model
+{
+    /**
+     * 获取分类
+     */
+    public static function getCates()
+    {
+        $list = self::where(['is_deleted'=>0,'pid'=>0])->field('id,logo,title,pid')->order('sort desc')->select();
+        foreach ($list as $v){
+            $child_ren = self::where(['is_deleted'=>0,'pid'=>$v->id])->field('id,logo,title,pid')->order('sort desc')->select();
+            if($child_ren) $v->child_ren =  $child_ren;
+        }
+        return $list ? $list->toArray() : [];
+    }
+
+}

+ 12 - 0
application/common/model/OrderComment.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 订单评论表
+class OrderComment extends Model
+{
+    public function user()
+    {
+        return $this->belongsTo('User','user_id','id')->field('id,name,headimg');
+    }
+
+}

+ 8 - 0
application/common/model/PlatformDemand.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 平台发布需求
+class PlatformDemand extends Model
+{
+
+}

+ 56 - 0
application/common/model/PlatformLike.php

@@ -0,0 +1,56 @@
+<?php
+namespace app\common\model;
+use library\tools\Data;
+use think\Model;
+// 平台点赞
+class PlatformLike extends Model
+{
+    // 点赞类型
+    static $type_desc = [
+        1=>'新闻点赞',
+        2=>'新闻评论点赞',
+        3=>'论坛回答',
+        4=>'活动',
+        5=>'招聘',
+        6=>'需求评论',
+        7=>'供应商商品',
+        8=>'论坛评论',
+        9=>'需求',
+    ];
+    /**
+     *  验证是否点赞
+     * @param $user_id
+     * @param $id
+     * @param $type
+     * @return int
+     */
+    public static function checkTags($user_id,$id,$type){
+        return self::where(['user_id'=>$user_id,'like_id'=>$id,'type'=>$type])->value('id') ? 1:0;
+    }
+    /**
+     * @param $user_id
+     * @param $id
+     * @param $type
+     */
+    public static function userTags($user_id,$id,$type)
+    {
+        $ret_val = 0;
+        $check_tags =  self::checkTags($user_id,$id,$type);
+        if($check_tags) {
+            static::where(['user_id'=>$user_id,'like_id'=>$id,'type'=>$type])->delete();
+        }else{
+            Data::save('PlatformLike',
+                ['user_id'=>$user_id,'like_id'=>$id,'type'=>$type],'user_id',
+                ['user_id'=>$user_id,'like_id'=>$id,'type'=>$type]);
+            $ret_val = 1;
+        }
+        return $ret_val;
+    }
+
+    // 点赞数量
+    public static function getPraiseNum($id,$type)
+    {
+        return self::where(['like_id'=>$id,'type'=>$type])->count() ;
+    }
+
+}

+ 38 - 0
application/common/model/PlatformSwitch.php

@@ -0,0 +1,38 @@
+<?php
+namespace app\common\model;
+use library\tools\Data;
+use think\Model;
+// 用户开关
+class PlatformSwitch extends Model
+{
+    /**
+     * 验证开关状态
+     * @param $user_id
+     * @param $id
+     * @param $type 1论坛
+     * @return int
+     */
+    public static function checkSwitch($user_id,$id,$type){
+        return self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->value('id') ? 1:0;
+    }
+    /**
+     * @param $user_id
+     * @param $id
+     * @param $type 1论坛
+     */
+    public static function userSwitch($user_id,$id,$type)
+    {
+        $ret_val = 0;
+        $check_tags =  self::checkSwitch($user_id,$id,$type);
+        if($check_tags) {
+            self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->delete();
+        }else{
+            Data::save('PlatformSwitch',
+                ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type],'user_id',
+                ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type]);
+            $ret_val = 1;
+        }
+        return $ret_val;
+    }
+
+}

+ 9 - 0
application/common/model/Press.php

@@ -0,0 +1,9 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 新闻
+class Press extends Model
+{
+
+
+}

+ 8 - 0
application/common/model/PressComment.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 新闻评论
+class PressComment extends Model
+{
+
+}

+ 8 - 0
application/common/model/Recruit.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 招聘
+class Recruit extends Model
+{
+
+}

+ 8 - 0
application/common/model/RecruitCate.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 招聘分类
+class RecruitCate extends Model
+{
+
+}

+ 8 - 0
application/common/model/ReportCase.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+class ReportCase extends Model
+{
+
+
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio