Files
huangjingfen/pro_v3.5.1_副本/app/jobs/HolidayGiftPushJob.php
apple 434aa8c69d feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods

Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口

Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则

Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)

Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口

Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单

Made-with: Cursor
2026-03-23 22:32:19 +08:00

199 lines
6.3 KiB
PHP

<?php
declare(strict_types=1);
namespace app\jobs;
use app\services\activity\holiday\HolidayGiftPushServices;
use app\services\activity\holiday\HolidayGiftServices;
use app\services\message\sms\SmsSendServices;
use app\services\wechat\WechatServices;
use crmeb\basic\BaseJobs;
use crmeb\traits\QueueTrait;
use think\facade\Log;
/**
* 节日有礼推送任务
* Class HolidayGiftPushJob
* @package app\jobs
*/
class HolidayGiftPushJob extends BaseJobs
{
use QueueTrait;
/**
* 执行推送任务
* @param int $pushId 推送记录ID
* @return bool
*/
public function doJob(int $pushId): bool
{
try {
/** @var HolidayGiftPushServices $pushServices */
$pushServices = app()->make(HolidayGiftPushServices::class);
/** @var HolidayGiftServices $giftServices */
$giftServices = app()->make(HolidayGiftServices::class);
// 获取推送记录
$pushInfo = $pushServices->get($pushId);
if (!$pushInfo || $pushInfo->status != 0) {
return true;
}
// 获取活动信息
$activity = $giftServices->get($pushInfo->holiday_gift_id);
if (!$activity || $activity->status != 1) {
// 更新推送状态为失败
$pushServices->update($pushId, ['status' => 2, 'push_time' => time()]);
return true;
}
// 根据推送类型执行不同的推送
$result = false;
switch ($pushInfo->push_type) {
case 1: // 短信
$result = $this->sendSms($pushInfo->uid, $activity->toArray());
break;
case 2: // 公众号
$result = $this->sendWechat($pushInfo->uid, $activity->toArray());
break;
case 3: // 弹框广告
$result = $this->sendPopup($pushInfo->uid, $activity->toArray());
break;
}
// 更新推送状态
$pushServices->update($pushId, [
'status' => $result ? 1 : 2,
'push_time' => time()
]);
return true;
} catch (\Throwable $e) {
Log::error('节日有礼推送任务执行失败:' . $e->getMessage());
return false;
}
}
/**
* 发送短信
* @param int $uid 用户ID
* @param array $activity 活动信息
* @return bool
*/
protected function sendSms(int $uid, array $activity): bool
{
try {
/** @var SmsSendServices $smsServices */
$smsServices = app()->make(SmsSendServices::class);
// 获取用户手机号
$userInfo = app()->make(\app\services\user\UserServices::class)->getUserInfo($uid);
if (!$userInfo || !$userInfo['phone']) {
return false;
}
// 短信模板变量
$data = [
'activity_name' => $activity['name'],
'gift_type' => $this->getGiftTypeName($activity['gift_type']),
'date' => date('Y-m-d')
];
// 发送短信
return $smsServices->send($userInfo['phone'], $data, 'HOLIDAY_GIFT_NOTICE');
} catch (\Throwable $e) {
Log::error('节日有礼短信推送失败:' . $e->getMessage());
return false;
}
}
/**
* 发送公众号消息
* @param int $uid 用户ID
* @param array $activity 活动信息
* @return bool
*/
protected function sendWechat(int $uid, array $activity): bool
{
try {
/** @var WechatServices $wechatServices */
$wechatServices = app()->make(WechatServices::class);
// 获取用户openid
$userInfo = app()->make(\app\services\user\UserServices::class)->getUserInfo($uid);
if (!$userInfo || !$userInfo['openid']) {
return false;
}
// 消息内容
$title = '节日有礼通知';
$description = "亲爱的用户,您有一个节日礼物待领取\n\n活动名称:{$activity['name']}\n礼物类型:{$this->getGiftTypeName($activity['gift_type'])}\n有效期至:" . date('Y-m-d', $activity['end_time']);
$url = sys_config('site_url') . '/pages/activity/holiday_gift/detail?id=' . $activity['id'];
$image = $activity['wechat_image'] ?: sys_config('site_logo');
// 发送图文消息
return $wechatServices->sendTemplate($userInfo['openid'], $title, $description, $url, $image);
} catch (\Throwable $e) {
Log::error('节日有礼公众号推送失败:' . $e->getMessage());
return false;
}
}
/**
* 发送弹框广告
* @param int $uid 用户ID
* @param array $activity 活动信息
* @return bool
*/
protected function sendPopup(int $uid, array $activity): bool
{
try {
// 创建弹框广告记录
$popupData = [
'uid' => $uid,
'title' => '节日有礼',
'image' => $activity['popup_image'] ?: '',
'type' => 'holiday_gift',
'link' => '/pages/activity/holiday_gift/detail?id=' . $activity['id'],
'status' => 1,
'add_time' => time(),
'is_show' => 1,
'sort' => 0
];
// 保存弹框广告记录
return (bool)app()->make(\app\services\user\UserPopupServices::class)->save($popupData);
} catch (\Throwable $e) {
Log::error('节日有礼弹框广告推送失败:' . $e->getMessage());
return false;
}
}
/**
* 获取礼物类型名称
* @param string $giftType
* @return string
*/
protected function getGiftTypeName(string $giftType): string
{
$types = [
'1' => '优惠券',
'2' => '积分',
'3' => '多倍积分',
'4' => '余额',
'5' => '全场包邮'
];
$names = [];
$giftTypes = explode(',', $giftType);
foreach ($giftTypes as $type) {
if (isset($types[$type])) {
$names[] = $types[$type];
}
}
return implode('、', $names) ?: '礼品';
}
}