From 7f2c9fbf9388992807d25d7c85297c6e5f122e43 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 6 Feb 2024 16:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E9=9D=9E=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E5=95=86=E6=88=B7=E6=94=AF=E6=8C=81=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=85=A8=E5=B9=B3=E5=8F=B0=E7=94=A8=E6=88=B7=E4=B8=BA=E5=BA=97?= =?UTF-8?q?=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/UserMerchantDao.php | 81 ++++++++++++------- .../user/UserMerchantRepository.php | 19 ++++- app/controller/merchant/user/UserMerchant.php | 30 ++++++- 3 files changed, 97 insertions(+), 33 deletions(-) diff --git a/app/common/dao/user/UserMerchantDao.php b/app/common/dao/user/UserMerchantDao.php index 515fec0..60aed27 100644 --- a/app/common/dao/user/UserMerchantDao.php +++ b/app/common/dao/user/UserMerchantDao.php @@ -64,37 +64,62 @@ class UserMerchantDao extends BaseDao * @author xaboy * @day 2020/10/20 */ - public function search(array $where) - { - return UserMerchant::getDB()->alias('A')->leftJoin('User B', 'A.uid = B.uid') - ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) { - $query->where('A.mer_id', $where['mer_id']); - })->when(isset($where['nickname']) && $where['nickname'], function (BaseQuery $query) use ($where) { - return $query->where('B.nickname', 'like', '%' . $where['nickname'] . '%'); - })->when(isset($where['sex']) && $where['sex'] !== '', function (BaseQuery $query) use ($where) { - return $query->where('B.sex', intval($where['sex'])); - })->when(isset($where['is_promoter']) && $where['is_promoter'] !== '', function (BaseQuery $query) use ($where) { - return $query->where('B.is_promoter', $where['is_promoter']); - })->when(isset($where['uids']), function (BaseQuery $query) use ($where) { - return $query->whereIn('A.uid', $where['uids']); - })->when(isset($where['user_time_type']) && $where['user_time_type'] !== '' && $where['user_time'] != '', function ($query) use ($where) { - if ($where['user_time_type'] == 'visit') { - getModelTime($query, $where['user_time'], 'A.last_time'); + public function search(array $where){ + $merchantType = $where['merchant_type'] ?? 0; + return UserMerchant::getDB() + ->alias('A') + ->when($merchantType > 0, function($query){ + $query->rightJoin('User B','A.uid = B.uid'); + },function($query){ + $query->leftJoin('User B','A.uid = B.uid'); + }) + ->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query) use ($where){ + $query->where('A.mer_id',$where['mer_id']); + }) + ->when(isset($where['nickname']) && $where['nickname'],function(BaseQuery $query) use ($where){ + return $query->where('B.nickname','like','%'.$where['nickname'].'%'); + }) + ->when(isset($where['sex']) && $where['sex'] !== '',function(BaseQuery $query) use ($where){ + return $query->where('B.sex',intval($where['sex'])); + }) + ->when(isset($where['uid']) && $where['uid'] !== '',function(BaseQuery $query) use ($where){ + return $query->where('B.uid',intval($where['uid'])); + }) + ->when(isset($where['is_promoter']) && $where['is_promoter'] !== '',function(BaseQuery $query) use ($where){ + return $query->where('B.is_promoter',$where['is_promoter']); + }) + ->when(isset($where['uids']),function(BaseQuery $query) use ($where){ + return $query->whereIn('A.uid',$where['uids']); + }) + ->when(isset($where['user_time_type']) && $where['user_time_type'] !== '' && $where['user_time'] != '',function($query) use ($where){ + if($where['user_time_type'] == 'visit'){ + getModelTime($query,$where['user_time'],'A.last_time'); } - if ($where['user_time_type'] == 'add_time') { - getModelTime($query, $where['user_time'], 'A.create_time'); + if($where['user_time_type'] == 'add_time'){ + getModelTime($query,$where['user_time'],'A.create_time'); } - })->when(isset($where['pay_count']) && $where['pay_count'] !== '', function ($query) use ($where) { - if ($where['pay_count'] == -1) { - $query->where('A.pay_num', 0); - } else { - $query->where('A.pay_num', '>', $where['pay_count']); + }) + ->when(isset($where['pay_count']) && $where['pay_count'] !== '',function($query) use ($where){ + if($where['pay_count'] == -1){ + $query->where('A.pay_num',0); } - })->when(isset($where['label_id']) && $where['label_id'] !== '', function (BaseQuery $query) use ($where) { - return $query->whereRaw('CONCAT(\',\',A.label_id,\',\') LIKE \'%,' . $where['label_id'] . ',%\''); - })->when(isset($where['user_type']) && $where['user_type'] !== '', function (BaseQuery $query) use ($where) { - return $query->where('B.user_type', $where['user_type']); - })->where('A.status', 1); + else{ + $query->where('A.pay_num','>',$where['pay_count']); + } + }) + ->when(isset($where['label_id']) && $where['label_id'] !== '',function(BaseQuery $query) use ($where){ + return $query->whereRaw('CONCAT(\',\',A.label_id,\',\') LIKE \'%,'.$where['label_id'].',%\''); + }) + ->when(isset($where['user_type']) && $where['user_type'] !== '',function(BaseQuery $query) use ($where){ + return $query->where('B.user_type',$where['user_type']); + }) + ->whereNull('B.cancel_time') + ->when($merchantType > 0, function($query){ + $query->group('B.uid'); + },function($query){ + $query->where('A.status',1); + }); + } public function numUserIds($mer_id, $min, $max = null) diff --git a/app/common/repositories/user/UserMerchantRepository.php b/app/common/repositories/user/UserMerchantRepository.php index de00e79..ddcca6a 100644 --- a/app/common/repositories/user/UserMerchantRepository.php +++ b/app/common/repositories/user/UserMerchantRepository.php @@ -38,7 +38,24 @@ class UserMerchantRepository extends BaseRepository $make = app()->make(UserLabelRepository::class); $integralMake = app()->make(IntegralRepository::class); $list = $query->setOption('field',[]) - ->field('A.uid,A.user_merchant_id,B.avatar,B.nickname,B.user_type,A.last_pay_time,A.first_pay_time,A.label_id,A.create_time,A.last_time,A.pay_num,A.pay_price,B.phone,B.is_svip,B.svip_endtime,B.advance_exchange_integral') + ->field([ + 'B.uid', + 'A.user_merchant_id', + 'B.avatar', + 'B.nickname', + 'B.user_type', + 'A.last_pay_time', + 'A.first_pay_time', + 'A.label_id', + 'A.create_time', + 'A.last_time', + 'A.pay_num', + 'A.pay_price', + 'B.phone', + 'B.is_svip', + 'B.svip_endtime', + 'B.advance_exchange_integral' + ]) ->page($page,$limit) ->order('A.user_merchant_id DESC') ->select() diff --git a/app/controller/merchant/user/UserMerchant.php b/app/controller/merchant/user/UserMerchant.php index 6a33cc4..84896dd 100644 --- a/app/controller/merchant/user/UserMerchant.php +++ b/app/controller/merchant/user/UserMerchant.php @@ -8,6 +8,7 @@ namespace app\controller\merchant\user; use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\user\UserLabelRepository; use app\common\repositories\user\UserMerchantRepository; use crmeb\basic\BaseController; @@ -46,12 +47,33 @@ class UserMerchant extends BaseController * @author xaboy * @day 2020/10/20 */ - public function getList() - { - $where = $this->request->params(['nickname', 'sex', 'is_promoter', 'user_time_type', 'user_time', 'pay_count', 'label_id', 'user_type']); + public function getList(){ + $isSearch = $this->request->param('is_search', 0); + $where = $this->request->params([ + 'nickname', + 'sex', + 'is_promoter', + 'user_time_type', + 'user_time', + 'pay_count', + 'label_id', + 'user_type', + 'uid' + ]); [$page, $limit] = $this->getPage(); $where['mer_id'] = $this->request->merId(); - return app('json')->success($this->repository->getList($where, $page, $limit)); + $where['merchant_type'] = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id'=>$where['mer_id']])->value('merchant_type'); + if($where['merchant_type'] != 0) { + // 非普通商户 查询所有用户;必须通过搜索 + $where['mer_id'] = ''; + // 判断:是否必须搜索 + $data = []; + if(!empty($where['nickname']) || !empty($where['uid'])) $data = $this->repository->getList($where, $page, $limit); + }else{ + $data = $this->repository->getList($where, $page, $limit); + } + + return app('json')->success($data); }