wesmiler 2 месяцев назад
Родитель
Сommit
7a6d12875d

+ 3 - 68
app/Http/Controllers/Api/v1/IndexController.php

@@ -3,7 +3,7 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
-use App\Services\Api\CartService;
+use App\Services\Api\ArticleService;
 use App\Services\Api\GoodsService;
 use App\Services\Api\OrderService;
 use App\Services\Api\SocialCircleService;
@@ -32,21 +32,14 @@ class IndexController extends webApp
             $cacheKey = "caches:config:app_{$appSources}";
             $config = RedisService::get($cacheKey);
             if (empty($config)) {
-                //$socialOpen = ConfigService::make()->getConfigByCode('social_open', 0);
                 $config = [
                     'app_name' => ConfigService::make()->getConfigByCode('app_name'),
                     'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
                     'app_version' => ConfigService::make()->getConfigByCode('app_version'),
                     'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
                     'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
-                    'agent_apply_desc' => format_content(ConfigService::make()->getConfigByCode('agent_apply_desc', '')),
                     'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
-                    'recharge_desc_1' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_1', '')),
-                    'recharge_desc_2' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_2', '')),
-                    'recharge_desc_3' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_3', '')),
                     'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
-                    'pay_recharge_open' => ConfigService::make()->getConfigByCode('pay_recharge_open', 0),
-                    //'social_open' => $socialOpen,
                     'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
                     'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
                     'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
@@ -63,76 +56,18 @@ class IndexController extends webApp
     }
 
     /**
-     * 菜单
-     * @param int $socialOpen
-     * @return array[]
-     */
-    public function getMenus($socialOpen=-1)
-    {
-        $socialOpen = $socialOpen>=0?$socialOpen:ConfigService::make()->getConfigByCode('social_open', 0);
-        return [
-            [
-                "name" => '首页',
-                "code" => 'home',
-                "icon" => 'home',
-                "status"=> 1,
-                "page" => '/pages/index/index'
-            ], [
-                "name" => '客服',
-                "code" => 'custom',
-                "icon" => 'custom',
-                "status"=> 1,
-            ], [
-                "name" => '',
-                "code" => 'social',
-                "icon" => 'social',
-                "status"=> $socialOpen?1:0,
-                "page" => '/pages/social/index'
-            ], [
-                "name" => '购物车',
-                "code" => 'cart',
-                "icon" => 'cart',
-                "badge" => OrderService::make()->getCountByStatus($this->userId,1),
-                "status"=> 1,
-                "page" => '/pages/cart/index'
-            ], [
-                "name" => '我的',
-                "code" => 'mine',
-                "icon" => 'mine',
-                "status"=> 1,
-                "page" => '/pages/mine/index'
-            ]
-        ];
-    }
-
-    /**
      * 首页数据
      * @return array
      */
     public function data()
     {
         try {
-            $params = request()->all();
-            $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
-            $position = isset($params['position']) && $params['position'] ? $params['position'] : 1;
             $data = [
                 // 轮播
-                'banners' => AdService::make()->getListByPosition($position),
+                'banners' => AdService::make()->getListByPosition(1),
+                'articles' => ArticleService::make()->getListByType(1),
             ];
 
-            if ($type == 2) {
-                $data['socials'] = SocialCircleService::make()->getIndexList();
-            } else {
-                $data['notices'] = NoticeService::make()->getRecommandList();
-                $data['cates'] = GoodsService::make()->getCategoryList();
-
-                $params['user_id'] = $this->userId;
-                $data['stores'] = StoreService::make()->getGoodsList($params);
-                //$data['social_open'] = ConfigService::make()->getConfigByCode('social_open', 0);
-                $data['pay_recharge_open'] = ConfigService::make()->getConfigByCode('pay_recharge_open', 0);
-//                $data['cart_count'] = CartService::make()->getCount($this->userId);
-            }
-
             return showJson(1010, true, $data);
         } catch (\Exception $exception) {
             $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];

+ 10 - 0
app/Models/ArticleCateModel.php

@@ -22,4 +22,14 @@ class ArticleCateModel extends BaseModel
     // 设置数据表
     protected $table = 'article_cates';
 
+    /**
+     * 分类文章
+     * @return \Illuminate\Database\Eloquent\Relations\HasMany
+     */
+    public function articles()
+    {
+        return $this->hasMany(ArticleModel::class, 'cate_id', 'cate_id')
+            ->where(['status'=>1,'mark'=>1]);
+    }
+
 }

+ 23 - 25
app/Services/Api/ArticleService.php

@@ -84,13 +84,13 @@ class ArticleService extends BaseService
     public function getDataList($params, $pageSize = 15)
     {
         $query = $this->getQuery($params);
-        $list = $query->select(['a.id','a.type','a.title','a.cover','a.views','a.create_time','a.content','a.status'])
+        $list = $query->select(['a.id','a.type','a.title','a.cover','a.views','a.cate_id','a.create_time','a.content','a.status'])
             ->orderBy('a.create_time','desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list? $list->toArray() :[];
         if($list){
             foreach($list['data'] as &$item){
-                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
+                $item['create_time'] = $item['create_time']? dateFormat($item['create_time']) : '';
                 $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
                 $item['content'] = $item['content']? get_format_content($item['content']) : '';
             }
@@ -113,6 +113,8 @@ class ArticleService extends BaseService
         $where = ['a.mark' => 1];
         $status = isset($params['status'])? $params['status'] : 0;
         $type = isset($params['type'])? $params['type'] : 0;
+        $cateId = isset($params['cate_id'])? $params['cate_id'] : 0;
+
         if($status>0){
             $where['a.status'] = $status;
         }
@@ -120,7 +122,11 @@ class ArticleService extends BaseService
             $where['a.type'] = $type;
         }
 
-        return $this->model->from('article as a')
+        if($cateId>0){
+            $where['a.cate_id'] = $cateId;
+        }
+
+        return $this->model->with(['category'])->from('article as a')
             ->where($where)
             ->where(function ($query) use($params){
                 $keyword = isset($params['keyword'])? $params['keyword'] : '';
@@ -145,7 +151,7 @@ class ArticleService extends BaseService
         }
 
         $info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
-            ->select(['id','title','cover','views','create_time','type','content'])
+            ->select(['id','title','cover','views','cate_id','create_time','type','content'])
             ->first();
         $info = $info? $info->toArray() : [];
         if($info){
@@ -160,31 +166,25 @@ class ArticleService extends BaseService
         return $info;
     }
 
+
     /**
-     * 获取分类文章推荐
-     * @param int $cateId 推荐分类ID
-     * @param int $type 类别:3-普通文章,4-客服回复
+     * 按类型获取文章
+     * @param int $type
      * @return array|mixed
      */
-    public function getCustomRecommend($cateId=0, $type=4)
+    public function getListByType($type=1)
     {
-        $cacheKey = "caches:articles:list_{$cateId}";
+        $cacheKey = "caches:articles:indexList_{$type}";
         $datas = RedisService::get($cacheKey);
         if($datas){
             return $datas;
         }
 
-        $limitNum = ConfigService::make()->getConfigByCode('custom_recommend_num', 6);
-        $limitNum = $limitNum? $limitNum : 6;
-        $datas = ArticleCateModel::where(function($query) use($cateId){
-                if($cateId){
-                    $query->where('cate_id', $cateId);
-                }
-            })->where(['type'=>$type,'status'=>1,'mark'=>1])
-            ->select(['id','cate_id','title','description','sort','type','status'])
-            ->limit($limitNum)
-            ->orderBy('sort','desc')
-            ->orderBy('create_time','desc')
+        $limit = ConfigService::make()->getConfigByCode('index_article_num',3);
+        $datas = ArticleCateModel::with(['articles'=>function($query) use($limit){
+            $query->limit($limit);
+        }])->where(['type'=>$type,'status'=>1,'mark'=>1])
+            ->select(['cate_id','name','sort','type'])
             ->get();
         $datas = $datas? $datas->toArray() : [];
         if($datas){
@@ -194,12 +194,13 @@ class ArticleService extends BaseService
         return $datas;
     }
 
+
     /**
      * 获取文章推荐分类
-     * @param int $type 1-普通文章分类,2-客服回复文章分类
+     * @param int $type
      * @return array|mixed
      */
-    public function getCateList($type=2)
+    public function getCateList($type=1)
     {
         $cacheKey = "caches:articles:cateList_{$type}";
         $datas = RedisService::get($cacheKey);
@@ -207,11 +208,8 @@ class ArticleService extends BaseService
             return $datas;
         }
 
-        $limitNum = ConfigService::make()->getConfigByCode('custom_cate_num', 6);
-        $limitNum = $limitNum? $limitNum : 6;
         $datas = ArticleCateModel::where(['type'=> $type,'status'=>1,'mark'=>1])
             ->select(['cate_id','name','sort','type'])
-            ->limit($limitNum)
             ->get();
         $datas = $datas? $datas->toArray() : [];
         if($datas){