feat : auto dispense coupon
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Service\ServiceTrait\Api;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Extend\DateUtil;
|
||||
use App\Model\UserCoupon;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -38,4 +39,25 @@ trait CouponTrait
|
||||
|
||||
if (!$couponInfo->save()) throw new Exception('CancelOrderConsumer:error:couponStatusUpdateError:'.json_encode($orderInfo->toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
* @param string $value
|
||||
* @return array
|
||||
*/
|
||||
protected function getValidityTime(int $type,string $value): array
|
||||
{
|
||||
switch ($type) {
|
||||
case CouponCode::VALIDITY_TIME_TYPE_CYCLE:
|
||||
$validityValue = json_decode($value,true);
|
||||
return [
|
||||
'start_time' => date('Y-m-d H:i:s'),
|
||||
'end_time' => date('Y-m-d H:i:s', time() + ($validityValue['day_num'] * DateUtil::DAY))
|
||||
];
|
||||
case CouponCode::VALIDITY_TIME_TYPE_FIX:
|
||||
return json_decode($value,true);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user