public function getThemeItemAttribute() { if ($this->type == 0) { return Themes::find($this->item_id)->toArray(); } else { return null; } }
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(); }
/** * * @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); }
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); }
/** * * @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(); }