repository = $repository; } /** * @return mixed * @author Qinii */ public function create() { $params = $this->request->params(['type_id','type']); if(!$params['type_id'] || !$params['type']) return app('json')->fail('缺少必备参数'); if(!$this->repository->fieldExists($params)) return app('json')->fail('信息不存在'); if($this->repository->getUserRelation($params,$this->request->uid())) return app('json')->fail('您已经收藏过了'); $params['uid'] = $this->request->uid(); $this->repository->create($params); return app('json')->success('收藏成功'); } /** * @return mixed * @author Qinii */ public function productList() { [$page, $limit] = $this->getPage(); $where = ['uid'=>$this->request->uid()]; $keyword = $this->request->params(['keywords']); $where['keyword'] =$keyword['keywords']; return app('json')->success($this->repository->search($where, $page,$limit)); } /** * @return mixed * @author Qinii */ public function merchantList() { [$page, $limit] = $this->getPage(); $where = ['uid'=>$this->request->uid()]; $keyword = $this->request->params(['keywords']); $where['keyword'] =$keyword['keywords']; return app('json')->success($this->repository->searchMer($where, $page,$limit)); } public function businessSchoolList(){ [$page, $limit] = $this->getPage(); $where = ['uid'=>$this->request->uid()]; if($this->source=='yhc' && $this->merId){ $mer_id=$this->merId; $query =Db::name("user_relation")->field('type_id,type,create_time')->whereIn('type',[1,11])->where('uid',$where['uid'])->order("create_time",'desc'); $count = $query->count(); $list = $query->page($page, $limit)->select()->each(function ($item) use ($mer_id) { if($item['type']==11){ $item['business_school']=Db::name('business_school')->where('mer_id',$mer_id)->where('id',$item['type_id'])->field('id,name,image,type,reading,create_time')->find(); } return $item; }); return compact('count', 'list'); } } /** * @return mixed * @author Qinii */ public function delete() { $params = $this->request->params(['type_id','type']); if(!$this->repository->getUserRelation($params,$this->request->uid())) return app('json')->fail('信息不存在'); $params['uid'] = $this->request->uid(); $this->repository->destory($params); return app('json')->success('删除成功'); } /** * @return mixed * @author Qinii */ public function batchDelete() { $params = $this->request->params(['type_id','type']); $params['uid'] = $this->request->uid(); if (!count($params['type_id'])) return app('json')->fail('缺少必备参数'); foreach ($params['type_id'] as $type_id){ $this->repository->destory([ 'type_id' => $type_id, 'type' => $params['type'] ]); } return app('json')->success('删除成功'); } /** * @return mixed * @author Qinii */ public function batchCreate() { $params = $this->request->params(['type_id','type']); if(!count($params['type_id']) || !$params['type']) return app('json')->fail('缺少必备参数'); $this->repository->batchCreate($this->request->uid(),$params); return app('json')->success('收藏成功'); } /** * @return mixed * @author Qinii */ public function batchCreateRemoveCart() { $params = $this->request->params(['type_id']); $params['type'] = 1; if (!count($params['type_id'])) return app('json')->fail('缺少必备参数'); $this->repository->batchCreate($this->request->uid(),$params); $ids = Db::name('store_cart')->where('uid', $this->request->uid())->whereIn('product_id', $params['type_id'])->column('cart_id'); app()->make(StoreCartRepository::class)->batchDelete($ids,$this->request->uid()); return app('json')->success('收藏成功'); } }