|
|
|
@ -189,21 +189,19 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
* */ |
|
|
|
public function isCouponRebate($user_id) |
|
|
|
{ |
|
|
|
//获取SSDB上的活动信息
|
|
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|
|
|
$active = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_ACTIVITY); |
|
|
|
$coupon_ids = explode(',',$active['forward']); |
|
|
|
$res = Db::table('ims_system_coupon_user as u') |
|
|
|
->leftjoin('ims_system_coupon_user_receive as r', 'u.id', '=', 'r.system_coupon_user_id') |
|
|
|
->whereIn('r.system_coupon_user_id',$coupon_ids) |
|
|
|
->where([ |
|
|
|
['r.user_id', '=', $user_id], |
|
|
|
['r.receive_type', '=', 4], |
|
|
|
['u.active_type', '=', 2], |
|
|
|
]) |
|
|
|
->select('r.id') |
|
|
|
->first(); |
|
|
|
return $res; |
|
|
|
$activity = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_ACTIVITY ,'activity'); |
|
|
|
// ssdb 键值
|
|
|
|
$ssdbKey = 'activity_'.$activity.'_user_'.$user_id; |
|
|
|
|
|
|
|
// 判断是否已全部领取过
|
|
|
|
$userReceive = $ssdb->exec('hget', SsdbKeysPrefix::COUPON_REBATE_RECEIVE,$ssdbKey); |
|
|
|
if($userReceive === false || is_null($userReceive)){ |
|
|
|
return false; |
|
|
|
}else{ |
|
|
|
return $userReceive; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
@ -288,8 +286,11 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
->whereIn('r.system_coupon_user_id',$coupon_ids) |
|
|
|
->select('r.user_id', 'r.send_user_id') |
|
|
|
->first(); |
|
|
|
/* 如果使用的优惠券为转发活动优惠券 则给赠送者返一张优惠券*/ |
|
|
|
if (isset($coupon->send_user_id) && ($coupon->send_user_id) > 0) { |
|
|
|
/* 如果使用的优惠券为转发活动优惠券 |
|
|
|
**则给赠送者返一张优惠券 |
|
|
|
* **自己给自己转发的券不给返券 |
|
|
|
*/ |
|
|
|
if ($coupon && ($coupon->user_id != $coupon->send_user_id)) { |
|
|
|
//是否已返过券
|
|
|
|
$exists_coupon_rebate = Db::table('ims_system_coupon_user_receive') |
|
|
|
->where([ |
|
|
|
@ -303,7 +304,7 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
Db::beginTransaction(); |
|
|
|
try { |
|
|
|
//返券
|
|
|
|
if($exists_coupon_rebate->id){ |
|
|
|
if($exists_coupon_rebate){ |
|
|
|
//如果已有该优惠券 则领取数量 和 可用数量 自增1
|
|
|
|
Db::table('ims_system_coupon_user_receive') |
|
|
|
->where([ |
|
|
|
@ -352,34 +353,30 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
->update(['rebate_type' => 2]); |
|
|
|
//更新库存操作
|
|
|
|
Db::table('ims_system_coupon_user') |
|
|
|
->where('id', $active['repay']['repay']) |
|
|
|
->where('id', $active['repay']) |
|
|
|
->increment('inventory_use'); |
|
|
|
|
|
|
|
//添加领取记录到ssdb
|
|
|
|
$data = [ |
|
|
|
$order_id,$coupon->user_id, |
|
|
|
]; |
|
|
|
$ssdb->execWithoutTask('multi_hset', SsdbKeysPrefix::COUPON_REBATE_LIST.$coupon->send_user_id, $data); |
|
|
|
// 提交
|
|
|
|
Db::commit(); |
|
|
|
} catch (\Exception $e) { |
|
|
|
// 回滚
|
|
|
|
Db::rollBack(); |
|
|
|
//写入日志文件
|
|
|
|
$log_Data = array(); |
|
|
|
$log_Data['name'] = '返券'; |
|
|
|
$log_Data['order_main_id'] = $order_id; |
|
|
|
$log_Data['order_id'] = $order_id; |
|
|
|
$log_Data['msg'] = '返券失败'; |
|
|
|
$this->log->event( |
|
|
|
LogLabel::COUPON_LOG, |
|
|
|
$log_Data |
|
|
|
); |
|
|
|
// 回滚
|
|
|
|
Db::rollBack(); |
|
|
|
} |
|
|
|
} |
|
|
|
$log_Data = array(); |
|
|
|
$log_Data['name'] = '返券'; |
|
|
|
$log_Data['user_id'] = $order_id; |
|
|
|
$log_Data['send_user_id'] = $coupon->send_user_id; |
|
|
|
$log_Data['order_main_id'] = $order_id; |
|
|
|
$log_Data['msg'] = '返券成功'; |
|
|
|
$this->log->event( |
|
|
|
LogLabel::COUPON_LOG, |
|
|
|
$log_Data |
|
|
|
); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|