Explorar o código

wesmiler 抢表商城

APPLE %!s(int64=3) %!d(string=hai) anos
pai
achega
df1595abcb

+ 2 - 4
app/Http/Controllers/Api/v1/IndexController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
 use App\Services\Common\AdService;
+use App\Services\Common\NoticeService;
 
 /**
  * 测试
@@ -19,10 +20,7 @@ class IndexController extends webApp
         $data = [
             'banners'=>  AdService::make()->getListByPosition(1),
             'menus'=> AdService::make()->getListByPosition(2,2),
-            'notices'=>[
-                ['id'=>1,'title'=>'测试公告1'],
-                ['id'=>2,'title'=>'测试公告2'],
-            ],
+            'notices'=> NoticeService::make()->getDataList([], 6),
             'ad'=> isset($ads[0])? $ads[0] : [],
         ];
         return message(1010, true, $data);

+ 39 - 0
app/Services/BaseService.php

@@ -167,6 +167,45 @@ class BaseService
     }
 
     /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1,'status'=>1];
+        $status = isset($params['status'])? $params['status'] : 0;
+        if($status>0){
+            $where['a.status'] = $status;
+        }
+        $list = $this->model->from('notices as a')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $keyword = isset($params['keyword'])? $params['keyword'] : '';
+                if($keyword){
+                    $query->where('a.title','like',"%{$keyword}%");
+
+                }
+            })
+            ->select(['a.*'])
+            ->orderBy('a.id','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') : '';
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    /**
      * 获取记录详情
      * @return array
      * @since 2020/11/11