Esempio n. 1
0
 /**
  *
  * @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();
 }