Files
huangjingfen/pro_v3.5.1_副本/crmeb/traits/service/ContactWayQrCode.php

207 lines
7.4 KiB
PHP
Raw Normal View History

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
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\traits\service;
use app\dao\BaseDao;
use app\services\work\WorkMediaServices;
use crmeb\services\wechat\ErrorMessage;
use crmeb\services\wechat\WechatResponse;
use crmeb\services\wechat\Work;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
/**
* 客户联系
* Trait ContactWayQrCode
* @package crmeb\traits\service
* @property BaseDao $dao
*/
trait ContactWayQrCode
{
/**
* 检测欢迎语字段
* @param array $welcomeWords
* @param int $type
*/
public function checkWelcome(array $welcomeWords, int $type)
{
if (1 === $type) {
return;
}
if (empty($welcomeWords['text']['content']) && empty($welcomeWords['attachments'])) {
throw new ValidateException('请填写欢迎语');
}
if (!empty($welcomeWords['text']['content']) && strlen($welcomeWords['text']['content']) > 3000) {
throw new ValidateException('内容不能超过4000字');
}
foreach ($welcomeWords['attachments'] as $item) {
switch ($item['msgtype']) {
case 'image':
if (empty($item['image']['pic_url'])) {
throw new ValidateException('请上传欢迎语图片');
}
break;
case 'link':
if (empty($item['link']['title'])) {
throw new ValidateException('请填写连接标题');
}
if (empty($item['link']['url'])) {
throw new ValidateException('请填写连接地址');
}
break;
case 'miniprogram':
if (empty($item['miniprogram']['title'])) {
throw new ValidateException('请填写小程序消息标题');
}
if (empty($item['miniprogram']['appid'])) {
throw new ValidateException('请填写小程序Appid');
}
if (empty($item['miniprogram']['page'])) {
throw new ValidateException('请填写小程序页面路径');
}
if (empty($item['miniprogram']['pic_url'])) {
throw new ValidateException('请选择小程序消息封面图');
}
break;
case 'video':
if (empty($item['video']['url'])) {
throw new ValidateException('请上传视频文件');
}
break;
case 'file':
if (empty($item['file']['url'])) {
throw new ValidateException('请上传文件');
}
break;
}
}
}
/**
* 执行创建或者修改【联系我】成员情况
* @param int $channleId
* @param array $userIds
* @param bool $skipVerify
* @param string|null $wxConfigId
* @throws TransportExceptionInterface
*/
public function handleQrCode(int $channleId, array $userIds, bool $skipVerify = true, string $wxConfigId = null)
{
if (!$wxConfigId) {
$qrCodeRes = Work::createQrCode($channleId, $userIds, $skipVerify);
} else {
$qrCodeRes = Work::updateQrCode($channleId, $userIds, $wxConfigId, $skipVerify);
}
if ($qrCodeRes['errcode'] !== 0) {
throw new ValidateException(ErrorMessage::getWorkMessage($qrCodeRes['errcode'], $qrCodeRes['errmsg'] ?? '生成企业渠道码失败'));
}
if (!$wxConfigId) {
$this->dao->update($channleId, [
'qrcode_url' => $qrCodeRes['qr_code'],
'config_id' => $qrCodeRes['config_id']
]);
}
}
/**
* 创建企业微信群发
* @param array $externalUserid
* @param array $attachments
* @param string $chatType
* @param string|null $sender
* @return WechatResponse
* @throws TransportExceptionInterface
* @throws InvalidConfigException
* @throws GuzzleException
* @throws ClientExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function sendMsgTemplate(array $externalUserid, array $attachments, string $chatType = 'single', string $sender = null)
{
$msg = [
'chat_type' => $chatType,
'external_userid' => $externalUserid,
];
if ('group' == $chatType) {
if (!$sender) {
throw new ValidateException('群发消息成员userid为必须填写');
}
}
if ($sender) {
$msg['sender'] = $sender;
}
if (empty($msg['external_userid'])) {
unset($msg['external_userid']);
}
//转换欢迎语当中的图片为素材库中
/** @var WorkMediaServices $mediaService */
$mediaService = app()->make(WorkMediaServices::class);
$attachments = $mediaService->resolvingWelcome($attachments);
$msg = array_merge($msg, $attachments);
return Work::addMsgTemplate($msg);
}
/**
* 创建发送朋友圈
* @param array $attachments
* @param array $userIds
* @param array $tag
* @return WechatResponse
* @throws ClientExceptionInterface
* @throws DataNotFoundException
* @throws DbException
* @throws GuzzleException
* @throws InvalidConfigException
* @throws ModelNotFoundException
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
*/
public function addMomentTask(array $attachments, array $userIds = [], array $tag = [])
{
//转换欢迎语当中的图片为素材库中
/** @var WorkMediaServices $mediaService */
$mediaService = app()->make(WorkMediaServices::class);
$data = $mediaService->resolvingWelcome($attachments, 1);
if ($userIds) {
$data['visible_range']['sender_list']['user_list'] = $userIds;
}
if ($tag) {
$data['visible_range']['external_contact_list']['tag_list'] = $tag;
}
return Work::addMomentTask($data);
}
}