Example #1
0
 public function getThemesAttribute()
 {
     $themes = Themes::where('id', $this->theme_id)->select()->get()->toArray();
     return $themes;
 }
Example #2
0
 /**
  *
  * @SWG\Api(
  *   path="/search",
  *   description="搜索(新20160216)",
  *   @SWG\Operation(
  *     method="GET", summary="获得搜索列表", notes="获得搜索列表",
  *     type="array",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="user_id",
  *         description="用户id",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=-1
  *     ),@SWG\Parameter(
  *         name="device_token",
  *         description="设备号",
  *         paramType="query",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer"
  *     ),@SWG\Parameter(
  *         name="type",
  *         description="搜索类型,0:商品,1:主题",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=0
  *     ),@SWG\Parameter(
  *         name="keywords",
  *         description="搜索关键字",
  *         paramType="query",
  *         required=true,
  *         allowMultiple=false,
  *         type="string"
  *     ),
  *     @SWG\Parameter(
  *         name="PageNum",
  *         description="分页开始位置",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=1
  *     ),@SWG\Parameter(
  *         name="PerPage",
  *         description="取得长度",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=10
  *     )
  *
  *   )
  * )
  */
 public function index(Request $request)
 {
     $start = $request->input('PageNum', 0);
     $length = $request->input('PerPage', 10);
     $type = $request->input('type', 0);
     //0--->商品 1--->主题
     $keywords = $request->input('keywords', '');
     $user_id = $request->input('user_id', -1);
     $device_token = $request->input('device_token');
     $response = new BaseResponse();
     $start = ($start - 1) * $length;
     if ($type == 0) {
         $goods = Goods::where('name', 'like', '%' . $keywords . '%')->orWhere('goods_description', 'like', '%' . $keywords . '%');
         $total = $goods->count();
         $goods = $goods->skip($start)->take($length)->orderBy('id', 'desc');
         $rows = $goods->get()->toArray();
     } else {
         $themes = Themes::where('title', 'like', '%' . $keywords . '%')->orWhere('subhead', 'like', '%' . $keywords . '%')->orWhere('themes_description', 'like', '%' . $keywords . '%');
         $total = $themes->count();
         $themes = $themes->skip($start)->take($length)->orderBy('id', 'desc');
         $rows = $themes->get()->toArray();
     }
     foreach ($rows as &$v) {
         $v['has_collection'] = 0;
         if ($user_id != -1 && $user_id != 0) {
             $collection = Collection::where('user_id', $user_id)->where('type', $type)->where('id', $v['id'])->first();
             if ($collection != null) {
                 $v['has_collection'] = 1;
             }
         }
     }
     //搜索记录
     $searchRecords = new SearchRecords();
     $searchRecords->user_id = $user_id;
     $searchRecords->device_token = $device_token;
     $searchRecords->keywords = $keywords;
     $searchRecords->save();
     $response->rows = $rows;
     $response->total = $total;
     return $response->toJson();
 }