123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\api\user;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\common\repositories\store\StorePercentageRepository;
- use app\common\repositories\user\UserRepository;
- use crmeb\basic\BaseController;
- use app\common\repositories\user\UserRelationRepository as repository;
- use think\App;
- use think\console\command\Make;
- 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(StorePercentageRepository $store_percentage, UserRepository $repository, StoreOrderRepository $order_epository)
- {
- $params = $this->request->params(['type_id', 'type']);
- $params['uid'] = $this->request->uid();
- if (!$params['type_id'])
- return app('json')->fail('参数丢失');
- if (!in_array($params['type'], [0,1,2,3,4,10]))
- 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);
- //关注店铺返利
- $user = $repository->get($params['uid']);
- if($user->order_id){
- $order_info = $order_epository->findOrCreate(array('order_id'=>$user->order_id));
- $percentage_info = $store_percentage->getWhere(array('passivity_user_id'=>$params['uid'],'deduction_type'=>5));
- if(empty($percentage_info)){
- //一级关注店铺折扣百分比
- $store_percentage->deduction_percentage(5,$user->uid,$user->order_id);
- $p_user = $repository->get($order_info->uid);
- if($p_user->order_id){
- $store_percentage->deduction_percentage(6,$user->uid,$p_user->order_id);
- }
- }
- }
- return app('json')->success('关注成功');
- }
- /**
- * @return mixed
- * @author Qinii
- */
- public function productList()
- {
- [$page, $limit] = $this->getPage();
- $where = ['uid'=>$this->request->uid(),'type'=>1];
- 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(),'type'=>10];
- return app('json')->success($this->repository->search($where, $page,$limit));
- }
- /**
- * TODO 收藏列表的删除
- * @return \think\response\Json
- * @author Qinii
- * @day 7/12/21
- */
- public function lstDelete()
- {
- $params = $this->request->params(['type_id','type']);
- $params['uid'] = $this->request->uid();
- if(!$this->repository->getWhere($params))
- return app('json')->fail('信息不存在');
- $this->repository->destory($params,1);
- return app('json')->success('已取消关注');
- }
- /**
- * TODO 商品详情中的取消收藏
- * @return \think\response\Json
- * @author Qinii
- * @day 7/12/21
- */
- public function delete()
- {
- $params = $this->request->params(['type_id','type']);
- if (!$this->repository->getUserRelation($params,$this->request->uid()))
- return app('json')->fail('信息不存在');
- $this->repository->destory($params);
- return app('json')->success('已取消关注');
- }
- /**
- * @return mixed
- * @author Qinii
- */
- public function batchCreate()
- {
- $params = $this->request->params(['type_id','type']);
- if(!count($params['type_id']) || !in_array($params['type'], [1,10]))
- return app('json')->fail('请选择商品');
- $this->repository->batchCreate($this->request->uid(),$params);
- return app('json')->success('收藏成功');
- }
- }
|