| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/30
- */
- namespace app\controller\api\user;
- use app\common\repositories\store\order\StoreCartRepository;
- use crmeb\basic\BaseController;
- use app\common\repositories\user\UserRelationRepository as repository;
- use think\App;
- use think\facade\Db;
- class UserRelation extends BaseController
- {
- /**
- * @var repository
- */
- protected $repository;
- /**
- * UserRelation constructor.
- * @param App $app
- * @param repository $repository
- */
- public function __construct(App $app, repository $repository)
- {
- parent::__construct($app);
- $this->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('收藏成功');
- }
- }
|