1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\admin\service\coupon;
- use app\model\Card;
- use app\model\MemberAccount;
- use support\Log;
- use support\exception\BusinessException;
- class CardService
- {
- /**
- * @Desc 生成卡ID
- * @Author Gorden
- * @Date 2024/11/25 13:46
- *
- * @param $params
- * @param $i
- * @return false|string
- */
- public static function generateCardId($params, $i)
- {
- $prefixLength = strlen($params['card_issue_serial_prefix']);
- $suffixLength = strlen($params['card_issue_serial_suffix']);
- $cardId = $params['card_issue_serial_prefix'] . str_pad($params['card_issue_serial_begin'] + $i, $params['card_issue_serial_length'] - $prefixLength - $suffixLength, $params['card_issue_serial_fill'], STR_PAD_LEFT) . $params['card_issue_serial_suffix'];
- if (!empty($params['card_issue_not_contain'])) {
- $notContains = explode(',', $params['card_issue_not_contain']);
- foreach ($notContains as $notContain) {
- if (strpos($cardId, $notContain) !== false) {
- return false;
- }
- }
- }
- return $cardId;
- }
- public static function checkExpired()
- {
- $unixTime = time();
- $cards = Card::whereRaw("CAST(UNIX_TIMESTAMP(card_deadline_datetime) as SIGNED) <= {$unixTime}")
- ->whereRaw("CAST(UNIX_TIMESTAMP(card_deadline_datetime) as SIGNED) > 0")
- ->whereIn('card_status', ['INIT', 'WAITING', 'PENDING', 'USED'])
- ->select('card_id')
- ->get()
- ->toArray();
- foreach ($cards as $card) {
- // 检查是否关联会员账户
- $account = MemberAccount::where('member_account_nbr', $card['card_id'])->first();
- if (!empty($account) && $account->member_account_status == 'ACTIVED') {
- $account->member_account_status = 'EXPIRED';
- $account->save();
- }
- $cardNow = Card::where('card_id', $card['card_id'])->first();
- $cardNow->card_status = 'EXPIRED';
- $cardExtendJson = [];
- if (!empty($cardNow->card_extend_json)) {
- $cardExtendJson = json_decode($cardNow->card_extend_json, true);
- }
- $cardExtendJson['expired_datetime'] = date('Y-m-d H:i:s');
- $cardNow->card_extend_json = json_encode($cardExtendJson);
- $cardNow->save();
- Log::info("储值卡:【" . $card['card_id'] . '】已过期');
- }
- }
- public static $status = [
- 'INIT' => '待分配',
- 'WAITING' => '已分配,待售',
- 'PENDING' => '已售,待激活',
- 'USED' => '已激活',
- 'DONE' => '使用完成',
- 'EXPIRED' => '已过期',
- 'PAUSED' => '冻结'
- ];
- }
|