Exemple #1
0
 public function getThemeItemAttribute()
 {
     if ($this->type == 0) {
         return Themes::find($this->item_id)->toArray();
     } else {
         return null;
     }
 }
Exemple #2
0
 public function getItemAttribute()
 {
     if ($this->type == 0) {
         $subjects = Subject::find($this->item_id);
         if ($subjects == null) {
             return null;
         }
         $subjects = $subjects->toArray();
         $themes = $subjects['themes'];
         $subjects['themes'] = [];
         foreach ($themes as $t) {
             array_push($subjects['themes'], $t['themes'][0]);
         }
         return $subjects;
     } else {
         $themes = Themes::find($this->item_id);
         if ($themes == null) {
             return null;
         }
         return $themes->toArray();
     }
 }
 /**
  *
  * @SWG\Api(
  *   path="/collection/batch_store",
  *   @SWG\Operation(
  *     method="POST", summary="批量添加收藏", notes="批量添加收藏",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="collection_list",
  *         description="提交的收藏信息",
  *         paramType="body",
  *         required=true,
  *         type="newCollectionList"
  *     )
  *   )
  * )
  */
 public function batchStore(Request $request)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $content = json_decode($request->getContent(false));
     $itemList = $content->itemList;
     foreach ($itemList as $v) {
         $co = Collection::where('user_id', $v->user_id)->where('type', $v->type)->where('item_id', $v->item_id)->first();
         if ($co == null) {
             if ($v->type == 0) {
                 $item = Goods::find($v->item_id);
             } else {
                 $item = Themes::find($v->item_id);
             }
             if ($item == null) {
                 DB::rollback();
                 return (new BaseResponse(BaseResponse::CODE_ERROR_BUSINESS, '该项不存在'))->toJson();
             }
             $collection = new Collection();
             $collection->user_id = $v->user_id;
             $collection->type = $v->type;
             $collection->item_id = $v->item_id;
             $collection->save();
         }
     }
     DB::commit();
     return $response->toJson();
 }
Exemple #4
0
 /**
  *
  * @SWG\Api(
  *   path="/wap/themes_description/{id}",
  *   @SWG\Operation(
  *     method="GET", summary="主题描述wap", notes="主题描述wap",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="主题id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     )
  *
  *   )
  * )
  */
 public function themesDescription($id)
 {
     $data['themes'] = Themes::find($id)->toArray();
     return view('wap.themes_description', $data);
 }
Exemple #5
0
 public function delete($id)
 {
     $sub = SubjectThemes::where('theme_id', $id)->first();
     if ($sub != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到专题,对应id为' . $sub->subject_id;
         echo json_encode($ret);
         return;
     }
     $home = Home::where('item_id', $id)->where('type', 1)->first();
     if ($home != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该主题已绑定到首页,对应id为' . $home->id;
         echo json_encode($ret);
         return;
     }
     Themes::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }
Exemple #6
0
 /**
  *
  * @SWG\Api(
  *   path="/themes/{id}",
  *   @SWG\Operation(
  *     method="PUT", summary="更新分享次数", notes="更新分享次数",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="主题id",
  *         paramType="path",
  *         required=true,
  *         type="string"
  *     )
  *   )
  * )
  */
 public function update(Request $request, $id)
 {
     $response = new BaseResponse();
     $themes = Themes::find($id);
     if ($themes != null) {
         $themes->share_times = $themes->share_times + 1;
         $themes->save();
     }
     return $response->toJson();
 }
Exemple #7
0
 public function getThemesAttribute()
 {
     $themes = Themes::where('id', $this->theme_id)->select()->get()->toArray();
     return $themes;
 }
Exemple #8
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();
 }