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
This commit is contained in:
228
pro_v3.5.1_副本/app/services/work/WorkMomentServices.php
Normal file
228
pro_v3.5.1_副本/app/services/work/WorkMomentServices.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\work;
|
||||
|
||||
|
||||
use app\dao\work\WorkMomentDao;
|
||||
use app\jobs\work\WorkMomentJob;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\wechat\Work;
|
||||
use crmeb\traits\service\ContactWayQrCode;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 创建发布朋友圈
|
||||
* Class WorkMomentServices
|
||||
* @package app\services\work
|
||||
* @mixin WorkMomentDao
|
||||
*/
|
||||
class WorkMomentServices extends BaseServices
|
||||
{
|
||||
|
||||
use ContactWayQrCode;
|
||||
|
||||
/**
|
||||
* @var WorkMomentDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected WorkMomentDao $dao;
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getDataList($where, ['*'], $page, $limit, 'create_time', [
|
||||
'sendResult' => function ($query) {
|
||||
$query->field(['status', 'moment_id']);
|
||||
}
|
||||
]);
|
||||
$userIds = $userList = [];
|
||||
foreach ($list as $v) {
|
||||
$userIds = array_merge($userIds, $v['user_ids']);
|
||||
}
|
||||
if ($userIds) {
|
||||
$userIds = array_merge(array_unique(array_filter($userIds)));
|
||||
/** @var WorkMemberServices $service */
|
||||
$service = app()->make(WorkMemberServices::class);
|
||||
$userList = $service->getColumn([
|
||||
['userid', 'in', $userIds]
|
||||
], 'name', 'userid');
|
||||
}
|
||||
foreach ($list as &$item) {
|
||||
$item['user_count'] = $item['unuser_count'] = $userCount = $unuserCount = 0;
|
||||
if (!empty($item['sendResult'])) {
|
||||
foreach ($item['sendResult'] as $value) {
|
||||
if ($value['status']) {
|
||||
$userCount++;
|
||||
} else {
|
||||
$unuserCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$item['user_count'] = $userCount;
|
||||
$item['unuser_count'] = $unuserCount;
|
||||
$item['user_list'] = [];
|
||||
foreach ($userList as $k => $v) {
|
||||
if (in_array($k, $item['user_ids'])) {
|
||||
$item['user_list'][] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加发送朋友圈任务
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function createMomentTask(array $data)
|
||||
{
|
||||
$this->checkWelcome($data['welcome_words'], 0);
|
||||
|
||||
return $this->transaction(function () use ($data) {
|
||||
|
||||
$res = $this->dao->save($data);
|
||||
//立即发送或者过了发送时间直接发送
|
||||
if (!$data['send_type'] || ($data['send_type'] == 1 && $data['send_time'] < time())) {
|
||||
$this->sendMomentTask($res->id, $data['welcome_words'], $data['type'] ? $data['user_ids'] : [], $data['type'] ? $data['client_tag_list'] : []);
|
||||
}
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送
|
||||
* @param int $id
|
||||
* @param array $content
|
||||
* @param array $userIds
|
||||
* @param array $tags
|
||||
*/
|
||||
public function sendMomentTask(int $id, array $content, array $userIds, array $tags = [])
|
||||
{
|
||||
|
||||
$resTask = $this->addMomentTask($content, $userIds, $tags);
|
||||
|
||||
$this->dao->update($id, ['jobid' => $resTask['jobid']]);
|
||||
|
||||
WorkMomentJob::dispatchSece(60 * 3, 'task', [$resTask['jobid']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取异步任务执行结果
|
||||
* @param string $jobId
|
||||
* @return bool
|
||||
*/
|
||||
public function getTaskInfo(string $jobId)
|
||||
{
|
||||
try {
|
||||
|
||||
$res = Work::getMomentTask($jobId);
|
||||
|
||||
if ($res['status'] !== 3) {
|
||||
WorkMomentJob::dispatchSece(60 * 3, 'task', [$jobId]);
|
||||
return true;
|
||||
}
|
||||
$this->dao->update(['jobid' => $jobId], [
|
||||
'moment_id' => $res['result']['moment_id'],
|
||||
'invalid_sender_list' => isset($res['result']['invalid_sender_list']) ? json_encode($res['result']['invalid_sender_list']) : null,
|
||||
'invalid_external_contact_list' => isset($res['result']['invalid_external_contact_list']) ? json_encode($res['result']['invalid_external_contact_list']) : null,
|
||||
]);
|
||||
|
||||
//执行获取任务详情
|
||||
WorkMomentJob::dispatchDo('getTaskPage', [$res['result']['moment_id'], '']);
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error(
|
||||
json_encode([
|
||||
'message' => '获取异步任务结果失败:' . $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine()
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发送朋友圈详情
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function getMomentInfo(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('没有查询到此朋友圈信息');
|
||||
}
|
||||
$userCount = $sendUserCount = $unSendUserCount = $externalUserCount = 0;
|
||||
if ($info->moment_id) {
|
||||
/** @var WorkMomentSendResultServices $service */
|
||||
$service = app()->make(WorkMomentSendResultServices::class);
|
||||
$userCount = $service->count(['moment_id' => $info->moment_id]);
|
||||
$sendUserCount = $service->count(['moment_id' => $info->moment_id, 'status' => 1]);
|
||||
$unSendUserCount = $service->count(['moment_id' => $info->moment_id, 'status' => 0]);
|
||||
$list = $service->getMomentList(['moment_id' => $info->moment_id, 'status' => 1], ['external_userid']);
|
||||
$externalUserid = [];
|
||||
foreach ($list as $item) {
|
||||
$externalUserid = array_merge($externalUserid, $item['external_userid']);
|
||||
}
|
||||
$externalUserCount = count($externalUserid);
|
||||
|
||||
if ($info->moment_id) {
|
||||
//执行获取任务详情
|
||||
WorkMomentJob::dispatchDo('getTaskPage', [$info->moment_id, '']);
|
||||
}
|
||||
}
|
||||
$info = $info->toArray();
|
||||
$info['info'] = compact('userCount', 'sendUserCount', 'unSendUserCount', 'externalUserCount');
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deleteMoment(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('没有查询到此朋友圈信息');
|
||||
}
|
||||
|
||||
/** @var WorkMomentSendResultServices $service */
|
||||
$service = app()->make(WorkMomentSendResultServices::class);
|
||||
return $this->transaction(function () use ($info, $id, $service) {
|
||||
if ($info->moment_id) {
|
||||
$service->delete(['moment_id' => $info->moment_id]);
|
||||
}
|
||||
return $info->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行定时任务发送朋友圈
|
||||
*/
|
||||
public function cronHandle()
|
||||
{
|
||||
$time = time();
|
||||
|
||||
$list = $this->dao->getDataList(['send_time' => $time, 'send_type' => 1, 'jobid_null' => true]);
|
||||
|
||||
foreach ($list as $item) {
|
||||
$this->sendMomentTask($item['id'], $item['welcome_words'], $item['type'] ? $item['user_ids'] : [], $item['type'] ? $item['client_tag_list'] : []);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user