From 232b3c48830136cfa8e8a1d9d43cfe54af2aae0e Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 13 Aug 2020 17:04:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8E=A5=E5=8F=A3-=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E9=99=90=E5=88=B6=E5=92=8C=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/Controller/CouponController.php | 4 ++-- app/Controller/CouponRebateController.php | 11 ++------- app/Service/CouponService.php | 27 ++++++++++++++++++----- config/autoload/dependencies.php | 1 + 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 9091e68..9454e2b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ vendor/ *.lock .phpunit* /watch +.vscode/ diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 6212782..648039a 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -20,13 +20,13 @@ use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; use App\Request\CouponGetListRequest; -use App\Service\CouponService; +use App\Service\CouponServiceInterface; class CouponController extends BaseController { /** * @Inject - * @var CouponService + * @var CouponServiceInterface */ protected $couponService; diff --git a/app/Controller/CouponRebateController.php b/app/Controller/CouponRebateController.php index 3f4064b..7765de3 100644 --- a/app/Controller/CouponRebateController.php +++ b/app/Controller/CouponRebateController.php @@ -11,24 +11,17 @@ declare(strict_types=1); */ namespace App\Controller; -use Hyperf\DbConnection\Db; -use Hyperf\Redis\Redis; -use Hyperf\Utils\ApplicationContext; + use App\Service\CouponRebateServiceInterface; -use http\Client\Curl\User; use Hyperf\Di\Annotation\Inject; -use App\Model\Coupon; -use App\Model\CouponUserRecType; -use App\Model\CouponRec; use App\Request\CouponRebateReceiveRequest; -use App\Service\CouponRebateService; use App\Request\CouponRebateTieRequest; class CouponRebateController extends BaseController { /** * @Inject - * @var CouponRebateService + * @var CouponRebateServiceInterface */ protected $CouponRebateService; diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 994b899..9fc4f97 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -13,6 +13,7 @@ use App\Constants\SsdbKeysPrefix; use App\Constants\LogLabel; use App\Commons\Log; use Exception; +use App\Service\CommonService; class CouponService implements CouponServiceInterface { @@ -21,6 +22,12 @@ class CouponService implements CouponServiceInterface * @var Log */ protected $log; + + /** + * @Inject + * @var CommonService + */ + protected $commonService; /** * 获取用户可领取优惠卷接口 @@ -45,13 +52,17 @@ class CouponService implements CouponServiceInterface ]; $nowTime = time(); $c_ids = []; - + $whereC = [ + ['end_time','>',$nowTime], + ['start_time','<=',$nowTime], + ['status','=',1] + ]; // 渠道开启,查询该渠道可以领取的优惠券ID // 渠道未开启,查询所有优惠券 if (env('SUB_CHANNEL') == 1) { - $c_ids = CouponUserRecType::where('receive_type', $receiveType)->pluck('system_coupon_user_id'); + $c_ids = CouponUserRecType::where('receive_type', $receiveType)->where($whereC)->pluck('system_coupon_user_id'); } else { - $c_ids = Coupon::pluck('id'); + $c_ids = Coupon::where($whereC)->pluck('id'); } $couponReceive = CouponRec::where('user_id',$userId); @@ -71,13 +82,17 @@ class CouponService implements CouponServiceInterface $couponIds = array_diff($c_ids, $cr_ids); // 转发型优惠券 - $couponReceiveIds = $couponActivity === false ? [] : explode(',',$couponActivity['forward']); + $couponReceiveIds = ($couponActivity === false || $this->commonService->empty($couponActivity['forward']) )? [] : explode(',',$couponActivity['forward']); + // 所有优惠券 + $couponIds = array_merge($couponIds,$couponReceiveIds); $whereC = [ ['u.end_time','>',$nowTime], ['u.start_time','<=',$nowTime], ['u.status','=',1] ]; + // 查询领取型1 和 转发型2 + $whereActiveType = [1,2]; if (env('SUB_CHANNEL') == 1) { array_push($whereC, ['type.receive_type','=', $receiveType]); @@ -86,16 +101,16 @@ class CouponService implements CouponServiceInterface $coupons = Db::table('ims_system_coupon_user as u') ->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') ->whereIn('u.id', $couponIds) + ->whereIn('u.active_type', $whereActiveType) ->where($whereC) ->whereRaw('u.inventory_use < u.inventory and u.inventory-u.inventory_use >= type.one_receive_number') ->select('u.*','type.one_receive_number') ->orderBy('u.weigh','desc') - ->limit(4) ->get(); foreach ($coupons as $k => &$v){ - if($v->active_type == 1){ + if($v->active_type == 1 && count($result['not_receive']) < 4){ $result['not_receive'][] = $v; }else if($v->active_type == 2 && in_array($v->id,$couponReceiveIds)){ $result['jump_data']['coupons'][] = $v->id; diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 2b8b2ad..28a2970 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -17,4 +17,5 @@ return [ \App\Commons\Log::class => \App\Commons\Log::class, \App\Service\CouponRebateServiceInterface::class => \App\Service\CouponRebateService::class, \App\Service\UserServiceInterface::class => \App\Service\UserService::class, + \App\Service\CouponServiceInterface::class => \App\Service\CouponService::class, ]; From 4da66fe1f9892112f5e520813125ae2ff64f71e7 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 14 Aug 2020 14:51:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=BA=E6=AD=A3=E5=BC=8Foos=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/CouponService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 9fc4f97..6708822 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -45,8 +45,8 @@ class CouponService implements CouponServiceInterface 'jump_data' => [ 'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, 'src2' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, - 'share_bg' => env('OSS_IMG_HOST').'/attachment/images/png/2020/08/11/d697d43b91913f861f931649f0898815.png', - 'receive_bg' => env('OSS_IMG_HOST')."/attachment/images/png/2020/08/11/9c7d7c95b5de29539fad4bc9a2fcb98d.png", + 'share_bg' => env('OSS_IMG_HOST').'/static/img/coupon_bg.png', + 'receive_bg' => env('OSS_IMG_HOST').'/static/img/coupon_share.png', 'coupons' => [] ] ]; From 11e2bf44cd57029153e4e6598ca78467280d4a7a Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 14 Aug 2020 20:13:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=BF=94?= =?UTF-8?q?=E5=88=B8=E6=B4=BB=E5=8A=A8--=E4=BF=AE=E6=94=B9amqp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/couponRebateConsumer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Amqp/Consumer/couponRebateConsumer.php b/app/Amqp/Consumer/couponRebateConsumer.php index 239aee7..bca6310 100644 --- a/app/Amqp/Consumer/couponRebateConsumer.php +++ b/app/Amqp/Consumer/couponRebateConsumer.php @@ -16,7 +16,7 @@ use Hyperf\Di\Annotation\Inject; /** - * @Consumer(exchange="couponRebate1", routingKey="couponRebate1", queue="couponRebate1", name ="couponRebateConsumer", nums=1) + * @Consumer(exchange="couponRebate", routingKey="couponRebate", queue="couponRebate", name ="couponRebateConsumer", nums=1) */ class couponRebateConsumer extends ConsumerMessage {