Эх сурвалжийг харах

首页公共轮播,包括官方公告和新闻中心

董荣正 4 долоо хоног өмнө
parent
commit
c50f9fb40f

+ 2 - 2
application/api/controller/Home.php

@@ -54,12 +54,12 @@ class Home extends Api
         // 最新公告
         $resp['notice_list'] = $announcement
             ->field('id,title as title,img_url,createtime')
-            ->where('type_id', $announcement::Announ)
+            ->whereIn('type_id', $announcement::AnnounList)
             ->where('status', $announcement::Normal)
             ->where('is_show', $announcement::Normal)
             ->where('to_lang', $this->lan)
             ->limit(0,10)
-            ->order('id DESC,weigh desc')
+            ->order('weigh desc,id DESC')
             ->select();
         //分类
         $resp['type_list'] = $productsModel->where('status', $productsModel::Normal)

+ 12 - 13
application/common/model/AnnouncementModel.php

@@ -14,7 +14,7 @@ class AnnouncementModel  extends Model
     //定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
-    
+
     // 追加属性
     protected $append = [
         'createtime_text',
@@ -22,11 +22,12 @@ class AnnouncementModel  extends Model
     ];
 
     const Announ         = 1;
+    const AnnounList     = [1, 4];
     const Banner         = 2;
 
     const Stop           = 2;
     const Normal         = 1;
-    
+
     //状态
     public $status_list = [
         '-1'                    => '全部',
@@ -40,20 +41,19 @@ class AnnouncementModel  extends Model
     {
         $product_arr = array_filter($product_arr);
         $row = self::get($announcement_id);
-        if($row) $product_arr = array_unique(array_merge($product_arr, explode(',', $row->product_id)));
+        if ($row) $product_arr = array_unique(array_merge($product_arr, explode(',', $row->product_id)));
         $row->product_id = rtrim(implode(',', $product_arr), ',');
         return $row->save();
     }
 
     public static function getTypeList()
-    {   
+    {
         return [1 => __('官方公告'), 2 => __('系统信息'), 3 => __('茶说'), 4 => __('新闻中心')];
-  
     }
 
     public static function getTypeAllList(string $lan)
-    {   
-        $typeList = [['key'=>1, 'value' => __('官方公告')], ['key'=>4,'value' => __('新闻中心')]];
+    {
+        $typeList = [['key' => 1, 'value' => __('官方公告')], ['key' => 4, 'value' => __('新闻中心')]];
         foreach ($typeList as &$item) {
             $item['sun_type_name'] = AnnouncementType::getSubTypeByPId($item['key'], $lan);
         }
@@ -70,18 +70,17 @@ class AnnouncementModel  extends Model
 
     public function getUpdatetimeTextAttr($value, $data)
     {
-          $value = $value ? $value : (isset($data['updatetime']) ? $data['updatetime'] : '');
-          return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+        $value = $value ? $value : (isset($data['updatetime']) ? $data['updatetime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
     }
 
     protected function setCreatetimeAttr($value)
     {
-          return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
 
     protected function setUpdatetimeAttr($value)
     {
-          return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
-
-}
+}