feat : coupon
This commit is contained in:
@@ -11,13 +11,19 @@ declare(strict_types=1);
|
||||
namespace App\Service\Api\Login;
|
||||
|
||||
use App\Cache\Redis\Api\ApiRedisKey;
|
||||
use App\Cache\Redis\Common\ConfigCache;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Constants\Common\UserCode;
|
||||
use App\Constants\ConfigCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Extend\StringUtil;
|
||||
use App\Extend\SystemUtil;
|
||||
use App\Lib\Crypto\CryptoFactory;
|
||||
use App\Model\CouponTemplate;
|
||||
use App\Model\User;
|
||||
use App\Model\UserAccount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserThird;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
@@ -50,6 +56,12 @@ abstract class LoginBaseService extends BaseService
|
||||
#[Inject]
|
||||
protected UserThird $userThirdModel;
|
||||
|
||||
/**
|
||||
* @var ConfigCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected ConfigCache $configCache;
|
||||
|
||||
|
||||
/**
|
||||
* 锁定注册
|
||||
@@ -163,5 +175,62 @@ abstract class LoginBaseService extends BaseService
|
||||
$this->userInfo = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加账户
|
||||
* @return void
|
||||
*/
|
||||
protected function addAccount(): void
|
||||
{
|
||||
$model = new UserAccount();
|
||||
|
||||
$model->user_id = $this->userId;
|
||||
$model->balance = 0;
|
||||
$model->integral = 0;
|
||||
|
||||
if (!$model->save()) throw new ErrException('注册失败-00002');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var CouponTemplate $couponTemplateModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected CouponTemplate $couponTemplateModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function addCoupon(): void
|
||||
{
|
||||
$couponTemplateId = $this->configCache->getConfigValue(ConfigCode::COUPONS_FOR_NEWCOMERS);
|
||||
$couponValidity = $this->configCache->getConfigValue(ConfigCode::NEWBIE_COUPON_VALIDITY);
|
||||
|
||||
// 随便一个为0代表不赠送
|
||||
if ($couponValidity == 0 || $couponTemplateId == 0) return;
|
||||
|
||||
$couponTemplateId = explode(',', $couponTemplateId);
|
||||
$couponTemplateList = $this->couponTemplateModel->getDataByIds($couponTemplateId);
|
||||
|
||||
$insertCoupon = [];
|
||||
foreach ($couponTemplateId as $one){
|
||||
if ($couponTemplateList[$one]['status'] == CouponCode::COUPON_TEMPLATE_STATUS_ENABLE) continue;
|
||||
|
||||
$insertCoupon[] = [
|
||||
'coupon_template_id' => $one,
|
||||
'coupon_dispense_id' => CouponCode::SYSTEMIC_DISTRIBUTION,
|
||||
'user_id' => $this->userId,
|
||||
'status' => CouponCode::COUPON_STATUS_UNUSED,
|
||||
'coupon_name' => $couponTemplateList[$one]['name'],
|
||||
'validity_start_time' => date('Y-m-d H:i:s'),
|
||||
'validity_end_time' => date('Y-m-d', strtotime('+'.$couponValidity.' days')),
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($insertCoupon)) return;
|
||||
|
||||
if (!(new UserCoupon)->insert($insertCoupon)) throw new ErrException('注册失败-00003');
|
||||
}
|
||||
|
||||
abstract protected function register();
|
||||
}
|
||||
Reference in New Issue
Block a user