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, ];