coupon_detail_deadline_datetime); if ($endTimeUnix < time()) { CouponDetail::where('coupon_detail_id', $detail->coupon_detail_id)->update(['coupon_detail_status' => 'EXPIRED']); echo $detail->coupon_detail_id . "已过期\n"; } } } /** * @Desc * @Author Gorden * @Date 2024/9/18 11:44 * * @return void */ public static function sendPeriodCoupon() { Db::beginTransaction(); try { $coupons = Coupon::where('coupon_is_period', 'Y')->where('coupon_status', 'ACTIVED')->get()->toArray(); foreach ($coupons as $coupon) { if (time() > strtotime($coupon['coupon_validdate_end'])) { continue; } $details = CouponDetail::where('join_detail_coupon_id',$coupon['coupon_id']) ->select('join_coupon_detail_member_id') ->groupBy('join_coupon_detail_member_id') ->get(); foreach ($details as $item) { $detail = CouponDetail::where('join_detail_coupon_id', $coupon['coupon_id']) ->where('join_coupon_detail_member_id',$item->join_coupon_detail_member_id) ->orderBy('coupon_detail_addtimes', 'DESC') ->first(); if (!empty($detail) && strtotime($detail->coupon_detail_deadline_datetime) > time()) { continue; } $params = [ 'coupon_detail_gain_datetime' => date('Y-m-d 00:00:00'), 'coupon_id' => $coupon['coupon_id'], 'member_id' => $detail->join_coupon_detail_member_id, 'coupon_detail_period_num' => $detail->coupon_detail_period_num + 1 ]; if (!empty($coupon['coupon_period_json'])) { $periodJson = json_decode($coupon['coupon_period_json'], true); if ($periodJson['nbr'] < $params['coupon_detail_period_num']){ continue; } if ($periodJson['unit'] == 'day') { $val = $periodJson['val'] - 1; if ($val < 1) { $params['coupon_detail_deadline_datetime'] = date('Y-m-d 23:59:59'); } else { $params['coupon_detail_deadline_datetime'] = date('Y-m-t 23:59:59', strtotime("+" . $val . " day")); } } elseif ($periodJson['unit'] == 'week') { $val = $periodJson['val'] - 1; if ($val < 1) { $params['coupon_detail_deadline_datetime'] = date('Y-m-d 23:59:59', strtotime('this week Sunday')); } else { $params['coupon_detail_deadline_datetime'] = date('Y-m-t 23:59:59', strtotime("+" . $val . ' week', date('Y-m-d', strtotime("+" . $val . " month")))); } } elseif ($periodJson['unit'] == 'month') { $val = $periodJson['val'] - 1; if ($val < 1) { $params['coupon_detail_deadline_datetime'] = date('Y-m-t 23:59:59'); } else { $params['coupon_detail_deadline_datetime'] = date('Y-m-t 23:59:59', strtotime("+" . $val . " month")); } } } // 写入优惠券 CouponDetailService::customSendCoupon($params); _syslog("周期券", "发放周期券", false, $params, 1001); } } Db::commit(); } catch (\Exception $e) { Db::rollBack(); } } public static function couponClassifyInfo($classify, $category, $value, $limit) { try { switch ($classify) { case "满减券": if (!empty($limit) && $category == 'NORMAL') { return "满" . $limit . '减' . $value; } elseif (!empty($limit) && !empty($value) && $category == 'PIECE') { return "满" . intval($limit) . '件减' . $value; } break; case "立减券": return "立减" . $value; break; case "抵用券": return "抵用券"; break; case "折扣券": if (!empty($limit) && $category == 'NORMAL') { return "满" . $limit . '打' . ($value / 10) . '折'; } else if (!empty($limit) && !empty($value) && $category == 'PIECE') { return "满" . intval($limit) . '件打' . ($value / 10) . '折'; } else { return $value / 10 . '折'; } break; case "赠品券": return "赠品券"; break; case "福利券": return '抵扣' . $value; break; case "年卡": return "年卡"; break; case "季卡": return "季卡"; break; case "月卡": return "月卡"; break; } } catch (\Exception $e) { } } }