|
|
|
@ -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 |
|
|
|
{ |
|
|
|
@ -22,6 +23,12 @@ class CouponService implements CouponServiceInterface |
|
|
|
*/ |
|
|
|
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; |
|
|
|
|