You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\CouponServiceInterface;use Hyperf\Redis\Redis;use Hyperf\Utils\ApplicationContext;
class CouponService implements CouponServiceInterface{
/** * @inheritDoc */ public function do() { // TODO: Implement do() method.
}
/** * @inheritDoc */ public function check() { // TODO: Implement check() method.
}
/** * @inheritDoc */ public function undo() { // TODO: Implement undo() method.
}
/** * @inheritDoc */ public function countAvailableByUser($userId) { return mt_rand(0,10); }
/** * 缓存优惠券今日使用情况 * @param $userId * @param $couponId * @param $couponRecId * @return bool */ function cacheTodayCouponUsed($userId, $couponId, $couponRecId) { $redis = ApplicationContext::getContainer()->get(Redis::class); $setRes = $redis->sAdd('coupon_' . date('Ymd') . '_used_' . $userId, $couponId); $expireRes = $redis->expire('coupon_' . date('Ymd') . '_used_' . $userId, strtotime(date('Y-m-d') . ' 23:59:59') - time()); return $setRes && $expireRes; }}
|