chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
1166
app/services/message/NoticeService.php
Normal file
1166
app/services/message/NoticeService.php
Normal file
File diff suppressed because it is too large
Load Diff
126
app/services/message/SystemMessageServices.php
Normal file
126
app/services/message/SystemMessageServices.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\message;
|
||||
|
||||
use app\dao\message\SystemMessageDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\message\service\StoreServiceRecordServices;use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 站内信
|
||||
* Class SystemMessageServices
|
||||
* @package app\services\message
|
||||
* @mixin SystemMessageDao
|
||||
*/
|
||||
class SystemMessageServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var SystemMessageDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemMessageDao $dao;
|
||||
|
||||
/**
|
||||
* 获取用户信息数量
|
||||
* @param int $uid
|
||||
* @param array $type
|
||||
* @return int
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getUserMessageNum(int $uid, array $type = [0, 1])
|
||||
{
|
||||
$num = 0;
|
||||
if (in_array(0, $type)) {//客服消息
|
||||
/** @var StoreServiceRecordServices $servicesRecord */
|
||||
$servicesRecord = app()->make(StoreServiceRecordServices::class);
|
||||
$service_num = $servicesRecord->sum(['user_id' => $uid], 'mssage_num');
|
||||
$num = bcadd((string)$num, (string)$service_num, 0);
|
||||
}
|
||||
if (in_array(1, $type)) {//站内信
|
||||
$system = $this->dao->count(['uid' => $uid, 'look' => 0, 'is_del' => 0]);
|
||||
$num = bcadd((string)$num, (string)$system, 0);
|
||||
}
|
||||
return (int)$num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 站内信列表
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getMessageSystemList($uid)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$where['is_del'] = 0;
|
||||
$where['uid'] = $uid;
|
||||
$list = $this->dao->getMessageList($where, '*', $page, $limit);
|
||||
$count = $this->dao->getCount($where);
|
||||
if (!$list) {
|
||||
return ['list' => [], 'count' => 0];
|
||||
}
|
||||
$ids = [];
|
||||
foreach ($list as &$item) {
|
||||
if (!$item['look']) {//没查看
|
||||
$ids[] = $item['id'];
|
||||
}
|
||||
$item['add_time'] = time_tran($item['add_time']);
|
||||
}
|
||||
$message = $this->dao->count(['uid' => $uid, 'look' => 0, 'is_del' => 0]);
|
||||
if ($ids) {
|
||||
$this->dao->batchUpdate($ids, ['look' => 1], 'id');
|
||||
}
|
||||
return ['list' => $list, 'count' => $count, 'service_num' => $message];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站内信详情
|
||||
* @param array $where 查询条件
|
||||
* @return array
|
||||
* @throws ValidateException
|
||||
*/
|
||||
public function getInfo($where)
|
||||
{
|
||||
$info = $this->dao->getOne($where);
|
||||
if (!$info || $info['is_del'] == 1) {
|
||||
throw new ValidateException('数据不存在');
|
||||
}
|
||||
$info = $info->toArray();
|
||||
if ($info['look'] == 0) {
|
||||
$this->update($info['id'], ['look' => 1]);
|
||||
}
|
||||
$info['add_time'] = time_tran($info['add_time']);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 站内信发放
|
||||
* @param int $uid
|
||||
* @param array $noticeInfo
|
||||
* @return \crmeb\basic\BaseModel|\think\Model
|
||||
*/
|
||||
public function systemSend(int $uid, array $noticeInfo)
|
||||
{
|
||||
$data = [];
|
||||
$data['mark'] = $noticeInfo['mark'];
|
||||
$data['uid'] = $uid;
|
||||
$data['title'] = $noticeInfo['title'];
|
||||
$data['content'] = $noticeInfo['content'];
|
||||
$data['type'] = 1;
|
||||
$data['add_time'] = time();
|
||||
return $this->dao->save($data);
|
||||
}
|
||||
}
|
||||
193
app/services/message/SystemNotificationServices.php
Normal file
193
app/services/message/SystemNotificationServices.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\message;
|
||||
|
||||
use app\dao\message\SystemNotificationDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\serve\ServeServices;
|
||||
use crmeb\services\template\Template;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\wechat\OfficialAccount;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Cache;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class SystemNotificationServices
|
||||
* @package app\services\system
|
||||
* @mixin SystemNotificationDao
|
||||
*/
|
||||
class SystemNotificationServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var SystemNotificationDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemNotificationDao $dao;
|
||||
|
||||
/**
|
||||
* 单个配置
|
||||
* @param int $where
|
||||
* @return Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOneNotce(array $where)
|
||||
{
|
||||
return $this->dao->getOne($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台获取列表
|
||||
* @param $where
|
||||
*/
|
||||
public function getNotList(array $where)
|
||||
{
|
||||
$industry = CacheService::get('wechat_industry', function () {
|
||||
try {
|
||||
$cache = (new Template('wechat'))->getIndustry();
|
||||
if (is_object($cache)) $cache = $cache->toArray();
|
||||
return $cache;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}, 0) ?: [];
|
||||
!is_array($industry) && $industry = [];
|
||||
$industry['primary_industry'] = isset($industry['primary_industry']) ? $industry['primary_industry']['first_class'] . ' | ' . $industry['primary_industry']['second_class'] : '';
|
||||
$industry['secondary_industry'] = isset($industry['secondary_industry']) ? $industry['secondary_industry']['first_class'] . ' | ' . $industry['secondary_industry']['second_class'] : '';
|
||||
$list = [
|
||||
'industry' => $industry,
|
||||
'list' => $this->dao->getList($where),
|
||||
];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条数据
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNotInfo(array $where)
|
||||
{
|
||||
/** @var TemplateMessageServices $TemplateMessageServices */
|
||||
$TemplateMessageServices = app()->make(TemplateMessageServices::class);
|
||||
|
||||
$type = $where['type'];
|
||||
unset($where['type']);
|
||||
$info = $this->dao->getOne($where);
|
||||
if (!$info) return [];
|
||||
$info = $info->toArray();
|
||||
switch ($type) {
|
||||
case 'is_system':
|
||||
$info['content'] = $info['system_text'] ?? '';
|
||||
break;
|
||||
case 'is_sms':
|
||||
$info['content'] = $info['sms_text'] ?? '';
|
||||
break;
|
||||
case 'is_wechat':
|
||||
$wechat = $TemplateMessageServices->getTemplateOne(['notification_id' => $info['id'], 'type' => 1]);
|
||||
$info['tempid'] = $wechat['tempid'] ?? '';
|
||||
$info['content'] = $wechat['content'] ?? '';
|
||||
$info['wechat_id'] = $wechat['tempkey'] ?? '';
|
||||
break;
|
||||
case 'is_routine':
|
||||
$wechat = $TemplateMessageServices->getTemplateOne(['notification_id' => $info['id'], 'type' => 0]);
|
||||
$info['tempid'] = $wechat['tempid'] ?? '';
|
||||
$info['content'] = $wechat['content'] ?? '';
|
||||
$info['routine_id'] = $wechat['tempkey'] ?? '';
|
||||
break;
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param array $data
|
||||
*/
|
||||
public function saveData(array $data)
|
||||
{
|
||||
$type = $data['type'];
|
||||
$id = $data['id'];
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new AdminException('数据不存在');
|
||||
}
|
||||
/** @var TemplateMessageServices $TemplateMessageServices */
|
||||
$TemplateMessageServices = app()->make(TemplateMessageServices::class);
|
||||
$res = true;
|
||||
switch ($type) {
|
||||
case 'is_system':
|
||||
$update = [];
|
||||
$update['name'] = $data['name'];
|
||||
$update['title'] = $data['title'];
|
||||
$update['is_system'] = $data['is_system'];
|
||||
$update['is_app'] = $data['is_app'];
|
||||
$update['system_title'] = $data['system_title'];
|
||||
$update['system_text'] = $data['system_text'];
|
||||
$res = $this->dao->update((int)$id, $update);
|
||||
break;
|
||||
case 'is_sms':
|
||||
$update = [];
|
||||
$update['name'] = $data['name'];
|
||||
$update['title'] = $data['title'];
|
||||
$update['is_sms'] = $data['is_sms'];
|
||||
$update['sms_id'] = $data['sms_id'];
|
||||
$res = $this->dao->update((int)$id, $update);
|
||||
break;
|
||||
case 'is_wechat':
|
||||
$update['name'] = $data['name'];
|
||||
$update['title'] = $data['title'];
|
||||
$update['is_wechat'] = $data['is_wechat'];
|
||||
$res1 = $this->dao->update((int)$id, $update);
|
||||
$res2 = $TemplateMessageServices->update(['tempkey' => $data['wechat_id']], ['tempid' => $data['tempid']]);
|
||||
$res = $res1 && $res2;
|
||||
break;
|
||||
case 'is_routine':
|
||||
$update['name'] = $data['name'];
|
||||
$update['title'] = $data['title'];
|
||||
$update['is_routine'] = $data['is_routine'];
|
||||
$res1 = $this->dao->update((int)$id, $update);
|
||||
$res2 = $TemplateMessageServices->update(['tempkey' => $data['routine_id']], ['tempid' => $data['tempid']]);
|
||||
$res = $res1 && $res2;
|
||||
break;
|
||||
case 'is_ent_wechat':
|
||||
$update['name'] = $data['name'];
|
||||
$update['title'] = $data['title'];
|
||||
$update['is_ent_wechat'] = $data['is_ent_wechat'];
|
||||
$update['ent_wechat_text'] = $data['ent_wechat_text'];
|
||||
$update['url'] = $data['url'];
|
||||
$res = $this->dao->update((int)$id, $update);
|
||||
break;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除模版、消息缓存
|
||||
* @return bool
|
||||
*/
|
||||
public function clearTemplateCache()
|
||||
{
|
||||
CacheService::handler('TEMPLATE')->clear();
|
||||
CacheService::redisHandler('NOTCEINFO')->clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
61
app/services/message/TemplateMessageServices.php
Normal file
61
app/services/message/TemplateMessageServices.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\message;
|
||||
|
||||
|
||||
use app\dao\message\TemplateMessageDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 模板消息
|
||||
* Class TemplateMessageServices
|
||||
* @package app\services\other
|
||||
* @mixin TemplateMessageDao
|
||||
*/
|
||||
class TemplateMessageServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var TemplateMessageDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected TemplateMessageDao $dao;
|
||||
|
||||
/**
|
||||
* 获取模板消息列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getTemplateList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getTemplateList($where, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
if ($item['content']) $item['content'] = explode("\n", $item['content']);
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板消息id
|
||||
* @param string $templateId
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTempId(string $templateId, int $type = 0)
|
||||
{
|
||||
return $this->dao->value(['type' => $type, 'tempkey' => $templateId, 'status' => 1], 'tempid');
|
||||
}
|
||||
}
|
||||
118
app/services/message/notice/BaseNoticeService.php
Normal file
118
app/services/message/notice/BaseNoticeService.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* +----------------------------------------------------------------------
|
||||
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: CRMEB Team <admin@crmeb.com>
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
namespace app\services\message\notice;
|
||||
|
||||
|
||||
use app\services\wechat\WechatUserServices;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Class BaseNoticeService
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/9/20
|
||||
* @package app\services\message\notice
|
||||
*/
|
||||
abstract class BaseNoticeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @var array
|
||||
*/
|
||||
protected array $config;
|
||||
|
||||
/**
|
||||
* 发送数据
|
||||
* @var array
|
||||
*/
|
||||
protected array $data;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected bool $switchLog = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $noticeSwitch = false;
|
||||
|
||||
/**
|
||||
* BaseNoticeService constructor.
|
||||
* @param array $config
|
||||
* @param bool $noticeSwitch
|
||||
* @param bool $switchLog
|
||||
*/
|
||||
public function __construct(array $config, bool $noticeSwitch, bool $switchLog = true)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->noticeSwitch = $noticeSwitch;
|
||||
$this->switchLog = $switchLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录日志
|
||||
* @param string $message
|
||||
* @param array $content
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/9/20
|
||||
*/
|
||||
protected function log(string $message, array $content = [])
|
||||
{
|
||||
$this->switchLog && Log::error($message, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
* @param callable $callable
|
||||
* @param array $params
|
||||
* @return false
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/9/20
|
||||
*/
|
||||
protected function handle(callable $callable, array $params = [])
|
||||
{
|
||||
try {
|
||||
|
||||
if ($this->noticeSwitch) {
|
||||
return $callable(...$params);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$this->log($e->getMessage(), [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine()
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据UID,user_type获取openid
|
||||
* @param int $uid
|
||||
* @param string $userType
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOpenidByUid(int $uid, string $userType = 'wechat')
|
||||
{
|
||||
/** @var WechatUserServices $wechatServices */
|
||||
$wechatServices = app()->make(WechatUserServices::class);
|
||||
return $wechatServices->uidToOpenid($uid, $userType);
|
||||
}
|
||||
}
|
||||
40
app/services/message/notice/EnterpriseWechatService.php
Normal file
40
app/services/message/notice/EnterpriseWechatService.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\notice;
|
||||
|
||||
use app\jobs\notice\EnterpriseWechatJob;
|
||||
|
||||
/**
|
||||
* 企业微信发送消息
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2021/9/22 1:23 PM
|
||||
*/
|
||||
class EnterpriseWechatService extends BaseNoticeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param array $data 模板内容
|
||||
* @return bool
|
||||
*/
|
||||
public function sendMsg($data)
|
||||
{
|
||||
return $this->handle(function ($data) {
|
||||
$url = $this->config['url'] ?? '';
|
||||
$ent_wechat_text = $this->config['ent_wechat_text'] ?? '';
|
||||
EnterpriseWechatJob::dispatchDo('doJob', [$data, $url, $ent_wechat_text]);
|
||||
}, [$data]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
111
app/services/message/notice/NoticeSmsService.php
Normal file
111
app/services/message/notice/NoticeSmsService.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\message\notice;
|
||||
|
||||
use app\jobs\notice\SmsJob;
|
||||
use app\services\message\service\StoreServiceServices;
|
||||
use app\services\system\admin\SystemAdminServices;
|
||||
|
||||
/**
|
||||
* 短信发送消息列表
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2021/9/22 1:23 PM
|
||||
*/
|
||||
class NoticeSmsService extends BaseNoticeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送短信消息
|
||||
* @param $phone
|
||||
* @param array $data 模板内容
|
||||
* @param string $template
|
||||
* @return void
|
||||
*/
|
||||
public function sendSms($phone, array $data, string $template)
|
||||
{
|
||||
if ($phone) {
|
||||
$this->handle(fn() => SmsJob::dispatch('doJob', [$phone, $data, $template]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款发送管理员消息任务
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendAdminRefund($order, $store_id = 0)
|
||||
{
|
||||
if (isset($order['supplier_id']) && $order['supplier_id']) {
|
||||
/** @var SystemAdminServices $systemAdminServices */
|
||||
$systemAdminServices = app()->make(SystemAdminServices::class);
|
||||
$adminList = $systemAdminServices->getNotifySupplierList((int)$order['supplier_id'], 'phone,real_name as nickname');
|
||||
} else {
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
}
|
||||
if ($adminList) {
|
||||
foreach ($adminList as $item) {
|
||||
$data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname'] ?? ''];
|
||||
$this->sendSms($item['phone'], $data, 'ADMIN_RETURN_GOODS_CODE');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户确认收货管理员短信提醒
|
||||
* @param $switch
|
||||
* @param $adminList
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendAdminConfirmTakeOver($order)
|
||||
{
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
foreach ($adminList as $item) {
|
||||
$data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname']];
|
||||
$this->sendSms($item['phone'], $data, 'ADMIN_TAKE_DELIVERY_CODE');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下单成功给客服管理员发送短信
|
||||
* @param $switch
|
||||
* @param $adminList
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendAdminPaySuccess($order, $store_id = 0)
|
||||
{
|
||||
if (isset($order['supplier_id']) && $order['supplier_id']) {
|
||||
/** @var SystemAdminServices $systemAdminServices */
|
||||
$systemAdminServices = app()->make(SystemAdminServices::class);
|
||||
$adminList = $systemAdminServices->getNotifySupplierList((int)$order['supplier_id'], 'phone,real_name as nickname');
|
||||
} else {
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
}
|
||||
if ($adminList) {
|
||||
foreach ($adminList as $item) {
|
||||
$data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname'] ?? ''];
|
||||
$this->sendSms($item['phone'], $data, 'ADMIN_PAY_SUCCESS_CODE');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
376
app/services/message/notice/RoutineTemplateListService.php
Normal file
376
app/services/message/notice/RoutineTemplateListService.php
Normal file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\notice;
|
||||
|
||||
use app\jobs\notice\template\TemplateJob;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序模板消息消息队列
|
||||
* Class RoutineTemplateJob
|
||||
* @package crmeb\jobs
|
||||
*/
|
||||
class RoutineTemplateListService extends BaseNoticeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
* @param string $tempCode 模板消息常量名称
|
||||
* @param int $uid uid
|
||||
* @param array $data 模板内容
|
||||
* @param string|null $link 跳转链接
|
||||
* @param string|null $color 文字颜色
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendTemplate(string $tempCode, int $uid, array $data, string $link = null, string $color = null)
|
||||
{
|
||||
if (!$this->noticeSwitch) {
|
||||
return false;
|
||||
}
|
||||
if (!$uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$openid = $this->getOpenidByUid($uid, 'routine');
|
||||
if (!$openid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TemplateJob::dispatchDo('doJob', ['subscribe', $openid, $tempCode, $data, $link, $color]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @param $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderTakeOver($uid, $order, $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_TAKE', $uid, [
|
||||
'thing1' => $order['order_id'],
|
||||
'thing2' => mb_substr_str($title, 20),
|
||||
'date5' => date('Y-m-d H:i:s', time()),
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @param $storeTitle
|
||||
* @param array $data
|
||||
* @param int $isGive 0 = 同城配送, 1 = 快递发货
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPostage($uid, $order, $storeTitle, array $data, int $isGive = 0)
|
||||
{
|
||||
if ($isGive) {//快递发货
|
||||
return $this->sendTemplate('ORDER_DELIVER_SUCCESS', $uid, [
|
||||
'character_string2' => $data['delivery_id'] ?? '',
|
||||
'thing1' => mb_substr_str($data['delivery_name'] ?? '', 20),
|
||||
'time3' => date('Y-m-d H:i:s', time()),
|
||||
'thing5' => mb_substr_str($storeTitle, 20),
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
} else {//同城配送
|
||||
return $this->sendTemplate('ORDER_POSTAGE_SUCCESS', $uid, [
|
||||
'thing8' => mb_substr_str($storeTitle, 20),
|
||||
'character_string1' => $order['order_id'],
|
||||
'name4' => mb_substr_str($data['delivery_name'] ?? '', 10, '...', 1),
|
||||
'phone_number10' => $data['delivery_id'] ?? ''
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值金额退款
|
||||
* @param $uid
|
||||
* @param $UserRecharge
|
||||
* @param $now_money
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendRechargeSuccess($uid, $UserRecharge, $now_money)
|
||||
{
|
||||
return $this->sendTemplate('RECHARGE_SUCCESS', $uid, [
|
||||
'character_string1' => $UserRecharge['order_id'],
|
||||
'amount3' => $UserRecharge['price'],
|
||||
'amount4' => $now_money,
|
||||
'date5' => date('Y-m-d H:i:s', time()),
|
||||
], '/pages/users/user_bill/index?type=2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款成功发送消息
|
||||
* @param string $openid
|
||||
* @param array $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderRefundSuccess($openid, $order, $storeTitle)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND', $openid, [
|
||||
'thing1' => '已成功退款',
|
||||
'thing2' => mb_substr_str($storeTitle, 20),
|
||||
'amount3' => $order['pay_price'],
|
||||
'character_string6' => $order['order_id']
|
||||
], '/pages/goods/order_after_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款失败
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @param $storeTitle
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderRefundFail($uid, $order, $storeTitle)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND', $uid, [
|
||||
'thing1' => '退款失败',
|
||||
'thing2' => mb_substr_str($storeTitle, 20),
|
||||
'amount3' => $order['pay_price'],
|
||||
'character_string6' => $order['order_id']
|
||||
], '/pages/goods/order_after_details/index?order_id=' . $order['order_id'] . '&isReturen=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户申请退款给管理员发送消息
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderRefundStatus($uid, $order)
|
||||
{
|
||||
$data['character_string4'] = $order['order_id'];
|
||||
$data['date5'] = date('Y-m-d H:i:s', time());
|
||||
$data['amount2'] = $order['pay_price'];
|
||||
$data['phrase7'] = '申请退款中';
|
||||
$data['thing8'] = '请及时处理';
|
||||
return $this->sendTemplate('ORDER_REFUND_STATUS', $uid, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 砍价成功通知
|
||||
* @param $uid
|
||||
* @param array $bargain
|
||||
* @param array $bargainUser
|
||||
* @param int $bargainUserId
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendBargainSuccess($uid, $bargain = [], $bargainUser = [], $bargainUserId = 0)
|
||||
{
|
||||
$data['thing1'] = mb_substr_str($bargain['title'], 20);
|
||||
$data['amount2'] = $bargain['min_price'];
|
||||
$data['thing3'] = '恭喜您,已经砍到最低价了';
|
||||
return $this->sendTemplate('BARGAIN_SUCCESS', $uid, $data, '/pages/activity/goods_bargain_details/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付成功发送模板消息
|
||||
* @param $uid
|
||||
* @param $pay_price
|
||||
* @param $orderId
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderSuccess($uid, $pay_price, $orderId)
|
||||
{
|
||||
if ($orderId == '') return true;
|
||||
$data['character_string1'] = $orderId;
|
||||
$data['amount2'] = $pay_price . '元';
|
||||
$data['date3'] = date('Y-m-d H:i:s', time());
|
||||
return $this->sendTemplate('ORDER_PAY_SUCCESS', $uid, $data, '/pages/goods/order_details/index?order_id=' . $orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益到账通知
|
||||
* @param $uid
|
||||
* @param $orderId
|
||||
* @param $extract_price
|
||||
* @param $msg
|
||||
* @param $type
|
||||
* @return bool|mixed
|
||||
* User: liusl
|
||||
* DateTime: 2025/2/17 上午11:57
|
||||
*/
|
||||
public function sendRevenueReceived($uid, $extract_price, $msg, $link)
|
||||
{
|
||||
$data['amount3'] = $extract_price . '元';
|
||||
$data['thing4'] = $msg;
|
||||
$data['time9'] = date('Y-m-d H:i:s', time());
|
||||
return $this->sendTemplate('REVENUE_RECEIVED', $uid, $data, $link);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员订单支付成功发送消息
|
||||
* @param $uid
|
||||
* @param $pay_price
|
||||
* @param $orderId
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendMemberOrderSuccess($uid, $pay_price, $orderId)
|
||||
{
|
||||
if ($orderId == '') return true;
|
||||
$data['character_string1'] = $orderId;
|
||||
$data['amount2'] = $pay_price . '元';
|
||||
$data['date3'] = date('Y-m-d H:i:s', time());
|
||||
return $this->sendTemplate('ORDER_PAY_SUCCESS', $uid, $data, '/pages/annex/vip_paid/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现失败
|
||||
* @param $uid
|
||||
* @param $msg
|
||||
* @param $extract_number
|
||||
* @param $nickname
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendExtractFail($uid, $msg, $extract_number, $nickname)
|
||||
{
|
||||
return $this->sendTemplate('USER_EXTRACT', $uid, [
|
||||
'thing1' => mb_substr_str('提现失败:' . $msg, 20),
|
||||
'amount2' => $extract_number . '元',
|
||||
'thing3' => mb_substr_str($nickname, 20),
|
||||
'date4' => date('Y-m-d H:i:s', time())
|
||||
], '/pages/users/user_spread_money/index?type=2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现成功
|
||||
* @param $uid
|
||||
* @param $extract_number
|
||||
* @param $nickname
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendExtractSuccess($uid, $extract_number, $nickname)
|
||||
{
|
||||
return $this->sendTemplate('USER_EXTRACT', $uid, [
|
||||
'thing1' => '提现成功',
|
||||
'amount2' => $extract_number . '元',
|
||||
'thing3' => mb_substr_str($nickname, 20),
|
||||
'date4' => date('Y-m-d H:i:s', time())
|
||||
], '/pages/users/user_spread_money/index?type=2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团成功通知
|
||||
* @param $uid
|
||||
* @param $pinkTitle
|
||||
* @param $nickname
|
||||
* @param $pinkTime
|
||||
* @param $count
|
||||
* @param string $link
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendPinkSuccess($uid, $pinkTitle, $nickname, $pinkTime, $count, string $link = '')
|
||||
{
|
||||
return $this->sendTemplate('PINK_TRUE', $uid, [
|
||||
'thing1' => mb_substr_str($pinkTitle, 20),
|
||||
'name3' => mb_substr_str($nickname, 10, '...', 1),
|
||||
'date5' => date('Y-m-d H:i:s', $pinkTime),
|
||||
'number2' => $count
|
||||
], $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团状态通知
|
||||
* @param $uid
|
||||
* @param $pinkTitle
|
||||
* @param $count
|
||||
* @param $remarks
|
||||
* @param $link
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendPinkFail($uid, $pinkTitle, $count, $remarks, $link)
|
||||
{
|
||||
return $this->sendTemplate('PINK_STATUS', $uid, [
|
||||
'thing2' => mb_substr_str($pinkTitle, 20),
|
||||
'thing1' => mb_substr_str($count, 20),
|
||||
'thing3' => mb_substr_str($remarks, 20)
|
||||
], $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 赠送积分消息提醒
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @param $storeTitle
|
||||
* @param $gainIntegral
|
||||
* @param $integral
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendUserIntegral($uid, $order, $storeTitle, $gainIntegral, $integral)
|
||||
{
|
||||
if (!$order || !$uid) return true;
|
||||
if (is_string($order['cart_id']))
|
||||
$order['cart_id'] = json_decode($order['cart_id'], true);
|
||||
return $this->sendTemplate('INTEGRAL_ACCOUT', $uid, [
|
||||
'character_string2' => $order['order_id'],
|
||||
'thing3' => mb_substr_str($storeTitle, 20),
|
||||
'amount4' => $order['pay_price'],
|
||||
'number5' => $gainIntegral,
|
||||
'number6' => $integral
|
||||
], '/pages/users/user_integral/index');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得推广佣金发送提醒
|
||||
* @param string $uid
|
||||
* @param string $brokeragePrice
|
||||
* @param string $goods_name
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderBrokerageSuccess(string $uid, string $brokeragePrice, string $goods_name)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_BROKERAGE', $uid, [
|
||||
'thing2' => mb_substr_str($goods_name, 20),
|
||||
'amount4' => $brokeragePrice . '元',
|
||||
'time1' => date('Y-m-d H:i:s', time())
|
||||
], '/pages/users/user_spread_user/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定推广关系发送消息提醒
|
||||
* @param string $uid
|
||||
* @param string $userName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendBindSpreadUidSuccess(string $uid, string $userName)
|
||||
{
|
||||
return $this->sendTemplate('BIND_SPREAD_UID', $uid, [
|
||||
'name3' => mb_substr_str($userName . "加入您的团队", 10, '...', 1),
|
||||
'date4' => date('Y-m-d H:i:s', time())
|
||||
], '/pages/users/user_spread_user/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户签到发送消息提醒
|
||||
* @param int $uid
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendSignRemind(int $uid)
|
||||
{
|
||||
return $this->sendTemplate('SIGN_REMIND_TIME', $uid, [
|
||||
'thing3' => '每日签到',
|
||||
'thing2' => '今天还没有签到哟!'
|
||||
], '/pages/users/user_sgin/index');
|
||||
}
|
||||
}
|
||||
92
app/services/message/notice/SystemMsgService.php
Normal file
92
app/services/message/notice/SystemMsgService.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\message\notice;
|
||||
|
||||
use app\jobs\notice\SystemMsgJob;
|
||||
use app\services\message\service\StoreServiceServices;
|
||||
use app\services\message\SystemMessageServices;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 短信发送消息列表
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2021/9/22 1:23 PM
|
||||
*/
|
||||
class SystemMsgService extends BaseNoticeService
|
||||
{
|
||||
/**
|
||||
* 发送消息
|
||||
* @param int $uid uid
|
||||
* @param array $data 模板内容
|
||||
*/
|
||||
public function sendMsg(int $uid, $data)
|
||||
{
|
||||
if ($uid) {
|
||||
$this->handle(fn() => SystemMsgJob::dispatch([$uid, $this->config, $data]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给客服发站内信
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function kefuSystemSend($data)
|
||||
{
|
||||
if (!$this->noticeSwitch) {
|
||||
return false;
|
||||
}
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
try {
|
||||
if ($adminList) {
|
||||
foreach ($adminList as $item) {
|
||||
$uid = $item['uid'] ?? 0;
|
||||
$data['admin_name'] = $item['staff_name'] ?? ($item['nickname'] ?? '');
|
||||
//放入队列执行
|
||||
SystemMsgJob::dispatch([$uid, $this->config, $data, 2]);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 站内信发放
|
||||
* @param int $uid
|
||||
* @param array $noticeInfo
|
||||
* @return \crmeb\basic\BaseModel|\think\Model
|
||||
*/
|
||||
public function systemSend(int $uid, array $noticeInfo)
|
||||
{
|
||||
$data = [];
|
||||
$data['mark'] = $noticeInfo['mark'];
|
||||
$data['uid'] = $uid;
|
||||
$data['title'] = $noticeInfo['title'];
|
||||
$data['content'] = $noticeInfo['content'];
|
||||
$data['type'] = 1;
|
||||
$data['add_time'] = time();
|
||||
return app()->make(SystemMessageServices::class)->save($data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
622
app/services/message/notice/WechatTemplateListService.php
Normal file
622
app/services/message/notice/WechatTemplateListService.php
Normal file
@@ -0,0 +1,622 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\message\notice;
|
||||
|
||||
use app\jobs\notice\template\TemplateJob;
|
||||
use app\services\message\service\StoreServiceServices;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 微信模版消息列表
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2021/9/22 1:23 PM
|
||||
*/
|
||||
class WechatTemplateListService extends BaseNoticeService
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
* @param string $tempCode 模板消息常量名称
|
||||
* @param int $uid uid
|
||||
* @param array $data 模板内容
|
||||
* @param string|null $link 跳转链接
|
||||
* @param string|null $color 文字颜色
|
||||
* @return bool
|
||||
*/
|
||||
public function sendTemplate(string $tempCode, int $uid, array $data, string $link = null, string $color = null)
|
||||
{
|
||||
if (!$this->noticeSwitch) {
|
||||
return false;
|
||||
}
|
||||
if (!$uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$openid = $this->getOpenidByUid($uid, 'wechat');
|
||||
if (!$openid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TemplateJob::dispatchDo('doJob', ['wechat', $openid, $tempCode, $data, $link, $color]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功发送模板消息
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @param $link
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderPaySuccess($uid, $order, $link)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_PAY_SUCCESS', $uid, [
|
||||
'character_string2' => $order['order_id'],
|
||||
'thing3' => $order['storeName'],
|
||||
'amount5' => bcadd((string)$order['pay_price'], '0', 2),
|
||||
'phrase18' => $order['send_name'],
|
||||
'time4' => date('Y-m-d H:i:s', $order['pay_time'])
|
||||
], $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益到账通知
|
||||
* @param $uid
|
||||
* @param $msg
|
||||
* @param $extract_price
|
||||
* @param $link
|
||||
* @return bool
|
||||
* User: liusl
|
||||
* DateTime: 2025/2/18 下午5:35
|
||||
*/
|
||||
public function sendRevenueReceivedSuccess($uid, $msg, $extract_price, $link)
|
||||
{
|
||||
return $this->sendTemplate('REVENUE_RECEIVED', $uid, [
|
||||
'amount2' => $extract_price,
|
||||
'const5' => $msg,
|
||||
'time3' => date('Y-m-d H:i:s', time())
|
||||
], $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买会员成功
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendMemberOrderPaySuccess($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_PAY_SUCCESS', $uid, [
|
||||
'first' => '亲,购买会员成功,恭喜您成为本平台尊贵会员!',
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $order['pay_price'],
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/annex/vip_paid/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
* @param $order
|
||||
* @param array $data
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderDeliver($uid, string $goodsName, $order, array $data)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_DELIVER_SUCCESS', $uid, [
|
||||
'first' => '亲,您的订单已发货,请注意查收',
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $order['pay_price'],
|
||||
'keyword3' => $order['delivery_name'],
|
||||
'keyword4' => $order['delivery_id'],
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
* @param $order
|
||||
* @param array $data
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPostage($uid, $order, array $data, $storeTitle)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_POSTAGE_SUCCESS', $uid, [
|
||||
'character_string2' => $order['order_id'],
|
||||
'thing4' => $storeTitle,
|
||||
'thing13' => $data['delivery_name'],
|
||||
'character_string14' => $data['delivery_id'],
|
||||
'time12' => date('Y-m-d H:i:s', time())
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送客服消息
|
||||
* @param $order
|
||||
* @param string|null $link
|
||||
* @return bool
|
||||
*/
|
||||
public function sendServiceNotice($uid, $data)
|
||||
{
|
||||
return $this->sendTemplate('ADMIN_NOTICE', $uid,
|
||||
[
|
||||
'keyword1' => '新订单',
|
||||
'keyword2' => $data['delivery_name'],
|
||||
'keyword3' => $data['delivery_id'],
|
||||
'first' => '亲,您有新的订单待处理',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/goods/order_details/index?order_id=' . $data['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款发送客服消息
|
||||
* @param $order
|
||||
* @param string|null $link
|
||||
* @return bool
|
||||
*/
|
||||
public function sendRefundServiceNotice($uid, $data, ?string $link = null)
|
||||
{
|
||||
return $this->sendTemplate('ADMIN_NOTICE', $uid, $data, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货发送模板消息
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderTakeSuccess($uid, $order, $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_TAKE_SUCCESS', $uid, [
|
||||
'character_string7' => $order['order_id'],
|
||||
'thing6' => $title,
|
||||
'time4' => date('Y-m-d H:i:s', time())
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送退款申请模板消息
|
||||
* @param array $data
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderApplyRefund($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND_STATUS', $uid, [
|
||||
'first' => '你有一笔退款订单需要处理',
|
||||
'keyword1' => $order['pay_price'],
|
||||
'keyword2' => date('Y-m-d H:i:s', $order['add_time']),
|
||||
'keyword3' => $order['order_id'],
|
||||
'remark' => '点击查看退款详情'
|
||||
], '/pages/admin/orderDetail/index?id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送退款模板消息
|
||||
* @param array $data
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderRefundSuccess($uid, array $data, $order)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND_STATUS', $uid, [
|
||||
'amount2' => bcadd((string)$data['refund_price'], '0', 2),
|
||||
'time4' => date('Y-m-d H:i:s', $order['add_time']),
|
||||
'character_string5' => $order['order_id']
|
||||
], '/pages/goods/order_after_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送退款模板消息
|
||||
* @param array $data
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderRefundNoStatus($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND_FAIL', $uid, [
|
||||
'amount5' => $order['pay_price'],
|
||||
'character_string8' => $order['order_id'],
|
||||
'thing6' => '审核未通过',
|
||||
'time9' => date('Y-m-d H:i:s', $order['add_time'])
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送用户充值退款模板消息
|
||||
* @param array $data
|
||||
* @param $userRecharge
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendRechargeRefundStatus($uid, array $data, $userRecharge)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_REFUND_STATUS', $uid, [
|
||||
'first' => '亲,您充值的金额已退款,本次退款',
|
||||
'keyword1' => $data['refund_price'],
|
||||
'keyword2' => date('Y-m-d H:i:s', $userRecharge['add_time']),
|
||||
'keyword3' => $userRecharge['order_id'],
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/users/user_bill/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 佣金提现失败发送模板消息
|
||||
* @param $uid
|
||||
* @param $extract_number
|
||||
* @param $fail_msg
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendUserBalanceChangeFail($uid, $extract_number, $fail_msg)
|
||||
{
|
||||
return $this->sendTemplate('USER_BALANCE_CHANGE', $uid, [
|
||||
'first' => '提现失败,退回佣金' . $extract_number . '元',
|
||||
'keyword1' => '佣金提现',
|
||||
'keyword2' => date('Y-m-d H:i:s', time()),
|
||||
'keyword3' => $extract_number,
|
||||
'remark' => '错误原因:' . $fail_msg
|
||||
], '/pages/users/user_spread_money/index?type=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 佣金提现成功发送模板消息
|
||||
* @param $uid
|
||||
* @param $extractNumber
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendUserBalanceChangeSuccess($uid, $extractNumber)
|
||||
{
|
||||
return $this->sendTemplate('USER_BALANCE_CHANGE', $uid, [
|
||||
'first' => '成功提现佣金' . $extractNumber . '元',
|
||||
'keyword1' => '佣金提现',
|
||||
'keyword2' => date('Y-m-d H:i:s', time()),
|
||||
'keyword3' => $extractNumber,
|
||||
'remark' => '点击查看我的佣金明细'
|
||||
], '/pages/users/user_spread_money/index?type=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团成功发送模板消息
|
||||
* @param $uid
|
||||
* @param $order_id
|
||||
* @param $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPinkSuccess($uid, $orderInfo, $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_USER_GROUPS_SUCCESS', $uid, [
|
||||
'first' => '亲,您的拼团已经完成了',
|
||||
'keyword1' => $orderInfo['order_id'],
|
||||
'keyword2' => $title,
|
||||
'keyword3' => $orderInfo['total_price'],
|
||||
'keyword4' => '拼团完成',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_combination_status/index?id=' . $orderInfo['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参团成功发送模板消息
|
||||
* @param $uid
|
||||
* @param $order_id
|
||||
* @param $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPinkUseSuccess($uid, array $orderInfo, string $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_USER_GROUPS_SUCCESS', $uid, [
|
||||
'first' => '亲,您已成功参与拼团',
|
||||
'keyword1' => $orderInfo['order_id'],
|
||||
'keyword2' => $title,
|
||||
'keyword3' => $orderInfo['total_price'],
|
||||
'keyword4' => '拼团完成',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_combination_status/index?id=' . $orderInfo['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消拼团发送模板消息
|
||||
* @param $uid
|
||||
* @param StorePink $order_id
|
||||
* @param $price
|
||||
* @param string $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPinkClone($uid, $pink, $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_USER_GROUPS_LOSE', $uid, [
|
||||
'first' => '亲,您的拼团取消',
|
||||
'keyword1' => $pink['order_id'],
|
||||
'keyword2' => $title,
|
||||
'keyword3' => '拼团失败',
|
||||
'keyword4' => '用户取消拼团',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_combination_status/index?id=' . $pink['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团失败发送模板消息
|
||||
* @param $uid
|
||||
* @param StorePink $pink
|
||||
* @param $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPinkFial($uid, $pink, $title)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_USER_GROUPS_LOSE', $uid, [
|
||||
'first' => '亲,您的拼团失败',
|
||||
'keyword1' => $pink['order_id'],
|
||||
'keyword2' => $title,
|
||||
'keyword3' => '拼团失败',
|
||||
'keyword4' => '拼团时间超时',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_combination_status/index?id=' . $pink['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开团成功发送模板消息
|
||||
* @param $uid
|
||||
* @param StorePink $pink
|
||||
* @param $title
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPinkOpenSuccess($uid, $pink, $title)
|
||||
{
|
||||
return $this->sendTemplate('OPEN_PINK_SUCCESS', $uid, [
|
||||
'first' => '您好,您已成功开团!赶紧与小伙伴们分享吧!!!',
|
||||
'keyword1' => $title,
|
||||
'keyword2' => $pink['nickname'],
|
||||
'keyword3' => $pink['people'],
|
||||
'keyword4' => date('Y-m-d H:i:s', $pink['stop_time']),
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_combination_status/index?id=' . $pink['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 砍价成功发送模板消息
|
||||
* @param $uid
|
||||
* @param StoreBargain $bargain
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendBargainSuccess($uid, $bargain, $bargainUser = [], $bargainUserId = 0)
|
||||
{
|
||||
return $this->sendTemplate('BARGAIN_SUCCESS', $uid, [
|
||||
'first' => '好腻害!你的朋友们已经帮你砍到底价了!',
|
||||
'keyword1' => $bargain['title'],
|
||||
'keyword2' => $bargain['price'],
|
||||
'keyword3' => $bargain['min_price'],
|
||||
'keyword4' => date('Y-m-d H:i:s', time()),
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/activity/goods_bargain_details/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 佣金到账发送模板消息
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderBrokerageSuccess(string $uid, string $brokeragePrice, string $goodsName, string $goodsPrice, $orderTime)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_BROKERAGE', $uid, [
|
||||
'first' => '亲,您有一笔佣金入账!',
|
||||
'keyword1' => $brokeragePrice,//分销佣金
|
||||
// 'keyword2' => $goodsPrice . "元",//交易金额
|
||||
'keyword2' => date('Y-m-d H:i:s', $orderTime),//结算时间
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/users/user_spread_user/index');
|
||||
}
|
||||
|
||||
/** 绑定推广关系发送消息提醒
|
||||
* @param string $uid
|
||||
* @param string $userName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendBindSpreadUidSuccess(string $uid, string $userName)
|
||||
{
|
||||
return $this->sendTemplate('BIND_SPREAD_UID', $uid, [
|
||||
'first' => '恭喜,加入您的团队',
|
||||
'keyword1' => $userName,
|
||||
'keyword2' => date('Y-m-d H:i:s', time()),
|
||||
'remark' => '授人以鱼不如授人以渔,一起分享赚钱吧,点击查看详情!'
|
||||
], '/pages/users/user_spread_user/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新订单给客服提醒
|
||||
* @param $switch
|
||||
* @param $adminList
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendAdminNewOrder($order, $store_id = 0)
|
||||
{
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
foreach ($adminList as $item) {
|
||||
$this->sendTemplate('ADMIN_NOTICE', $item['uid'],
|
||||
[
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $order['storeName'],
|
||||
'keyword3' => '新订单',
|
||||
'keyword4' => date('Y-m-d H:i:s', time()),
|
||||
'first' => '亲,您有新的订单待处理',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/admin/orderDetail/index?id=' . $order['order_id']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款给客服提醒
|
||||
* @param $switch
|
||||
* @param $adminList
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public function sendAdminNewRefund($order, $store_id = 0)
|
||||
{
|
||||
/** @var StoreServiceServices $StoreServiceServices */
|
||||
$StoreServiceServices = app()->make(StoreServiceServices::class);
|
||||
$adminList = $StoreServiceServices->getStoreServiceOrderNotice();
|
||||
foreach ($adminList as $item) {
|
||||
$this->sendTemplate('ADMIN_NOTICE', $item['uid'],
|
||||
[
|
||||
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $order['storeName'],
|
||||
'keyword3' => '退款申请',
|
||||
'keyword4' => date('Y-m-d H:i:s', time()),
|
||||
'first' => '亲,您有个退款订单待处理',
|
||||
'remark' => '点击查看订单详情'
|
||||
], '/pages/admin/orderDetail/index?id=' . $order['order_id']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单改价
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendPriceRevision($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('PRICE_REVISION', $uid, [
|
||||
'first' => '亲,您的订单已改价',
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $order['storeName'],
|
||||
'keyword3' => date('Y-m-d H:i:s', $order['add_time']),
|
||||
'keyword4' => $order['pay_price'],
|
||||
'keyword5' => '待付款',
|
||||
'remark' => '点击查看订单详情!'
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值成功
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendRechargeSuccess($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('RECHARGE_SUCCESS', $uid, [
|
||||
'time11' => date('Y-m-d H:i:s', $order['add_time']),
|
||||
'amount5' => bcadd((string)$order['price'], '0', 2)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得积分
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendUserIntegral($uid, $order, $data)
|
||||
{
|
||||
return $this->sendTemplate('INTEGRAL_ACCOUT', $uid, [
|
||||
'first' => '亲,您的积分已到账',
|
||||
'keyword1' => $data['storeTitle'],
|
||||
'keyword2' => $order['pay_price'],
|
||||
'keyword3' => $order['use_integral'],
|
||||
'keyword4' => $data['give_integral'],
|
||||
'keyword5' => date('Y-m-d H:i:s', $order['add_time']),
|
||||
'remark' => '点击查看订单详情!'
|
||||
], '/pages/goods/order_details/index?order_id=' . $order['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒付款通知
|
||||
* @param $uid
|
||||
* @param $order
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendOrderPayFalse($uid, $order)
|
||||
{
|
||||
return $this->sendTemplate('ORDER_PAY_FALSE', $uid, [
|
||||
'first' => '亲,您有订单还未付款',
|
||||
'keyword1' => $order['pay_price'],
|
||||
'keyword2' => $order['storeName'],
|
||||
'keyword3' => $order['order_id'],
|
||||
'remark' => '感谢您的光临!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现成功
|
||||
* @param $uid
|
||||
* @param $extractNumber
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendUserExtract($uid, $extractNumber)
|
||||
{
|
||||
return $this->sendTemplate('USER_EXTRACT', $uid, [
|
||||
'amount3' => bcadd((string)$extractNumber, '0', 2),
|
||||
'time4' => date('Y-m-d H:i:s', time())
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现失败
|
||||
* @param $uid
|
||||
* @param $extractNumber
|
||||
* @param $message
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendExtractFail($uid, $extractNumber, $message)
|
||||
{
|
||||
return $this->sendTemplate('USER_EXTRACT_FAIL', $uid, [
|
||||
'first' => '亲,您的提现申请未通过',
|
||||
'keyword1' => $extractNumber,
|
||||
'keyword2' => date('Y-m-d H:i:s', time()),
|
||||
'keyword3' => $message,
|
||||
'remark' => '请联系管理员!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务消息(新)
|
||||
* @param $openid
|
||||
* @param $data
|
||||
* @param $url
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendServiceNoticeNew($openid, $data, $url)
|
||||
{
|
||||
return $this->sendTemplate('ADMIN_NOTICE', $openid, [
|
||||
'first' => $data['first'],
|
||||
'keyword1' => $data['keyword1'],
|
||||
'keyword2' => $data['keyword2'],
|
||||
'keyword3' => $data['keyword3'],
|
||||
'remark' => $data['remark']
|
||||
], $url);
|
||||
}
|
||||
|
||||
/**虚拟商品发货消息
|
||||
* @param $uid
|
||||
* @param $data
|
||||
* @param $url
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function sendKamiDeliverGoods($uid, $value, $url)
|
||||
{
|
||||
return $this->sendTemplate('KAMI_DELIVER_GOODS_CODE', $uid, [
|
||||
'first' => '亲,你的虚拟商品购买成功',
|
||||
'keyword1' => '虚拟数字卡密',
|
||||
'keyword2' => $value,
|
||||
'remark' => '感谢您的支持!'
|
||||
], $url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceAuxiliaryDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class StoreServiceAuxiliaryServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceAuxiliaryDao
|
||||
*/
|
||||
class StoreServiceAuxiliaryServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var StoreServiceAuxiliaryDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceAuxiliaryDao $dao;
|
||||
|
||||
/**
|
||||
* 保存转接信息
|
||||
* @param array $data
|
||||
* @return bool|\crmeb\basic\BaseModel|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function saveAuxliary(array $data)
|
||||
{
|
||||
$auxliaryInfo = $this->dao->get(['type' => 0, 'binding_id' => $data['binding_id'], 'relation_id' => $data['relation_id']]);
|
||||
if ($auxliaryInfo) {
|
||||
$auxliaryInfo->update_time = time();
|
||||
return $auxliaryInfo->save();
|
||||
} else {
|
||||
return $this->dao->save([
|
||||
'type' => 0,
|
||||
'binding_id' => $data['binding_id'],
|
||||
'relation_id' => $data['relation_id'],
|
||||
'update_time' => time(),
|
||||
'add_time' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceFeedbackDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 客服反馈
|
||||
* Class StoreServiceFeedbackServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceFeedbackDao
|
||||
*/
|
||||
class StoreServiceFeedbackServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var StoreServiceFeedbackDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceFeedbackDao $dao;
|
||||
|
||||
/**
|
||||
* 获取反馈列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getFeedbackList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$data = $this->dao->getFeedback($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('data', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function editForm(int $id)
|
||||
{
|
||||
$feedInfo = $this->dao->get($id);
|
||||
if (!$feedInfo) {
|
||||
throw new ValidateException('反馈内容没有查到');
|
||||
}
|
||||
$feedInfo = $feedInfo->toArray();
|
||||
$field = [
|
||||
FormBuilder::textarea('make', '备注', $feedInfo['make'])->col(22),
|
||||
];
|
||||
if (!$feedInfo['status']) {
|
||||
$field[] = FormBuilder::radio('status', '状态', 0)->setOptions([
|
||||
['label' => '已处理', 'value' => 1],
|
||||
['label' => '未处理', 'value' => 0]
|
||||
]);
|
||||
}
|
||||
return create_form($feedInfo['status'] ? '备注' : '处理', $field, $this->url('/app/feedback/' . $id), 'PUT');
|
||||
}
|
||||
}
|
||||
231
app/services/message/service/StoreServiceLogServices.php
Normal file
231
app/services/message/service/StoreServiceLogServices.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceLogDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderRefundServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 客服聊天记录
|
||||
* Class StoreServiceLogServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceLogDao
|
||||
*/
|
||||
class StoreServiceLogServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 消息类型
|
||||
* @var array 1=文字 2=表情 3=图片 4=语音 5 = 商品链接 6 = 订单类型
|
||||
*/
|
||||
const MSN_TYPE = [1, 2, 3, 4, 5, 6, 7];
|
||||
|
||||
/**
|
||||
* 商品链接消息类型
|
||||
*/
|
||||
const MSN_TYPE_GOODS = 5;
|
||||
|
||||
/**
|
||||
* 订单信息消息类型
|
||||
*/
|
||||
const MSN_TYPE_ORDER = 6;
|
||||
|
||||
/**
|
||||
* 退款订单消息类型
|
||||
*/
|
||||
const MSN_TYPE_REFUND_ORDER = 7;
|
||||
|
||||
/**
|
||||
* @var StoreServiceLogDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceLogDao $dao;
|
||||
|
||||
/**
|
||||
* 获取聊天记录中的uid和to_uid
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function getChatUserIds(int $uid)
|
||||
{
|
||||
$list = $this->dao->getServiceUserUids($uid);
|
||||
$arr_user = $arr_to_user = [];
|
||||
foreach ($list as $key => $value) {
|
||||
$arr_user[] = $value["uid"];
|
||||
$arr_to_user[] = $value["to_uid"];
|
||||
}
|
||||
$uids = array_merge($arr_user, $arr_to_user);
|
||||
$uids = array_flip(array_flip($uids));
|
||||
$uids = array_flip($uids);
|
||||
unset($uids[$uid]);
|
||||
return array_flip($uids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个用户的客服聊天记录
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getChatLogList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getServiceList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天记录列表
|
||||
* @param array $where
|
||||
* @param int $uid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getChatList(array $where, int $uid)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getServiceList($where, $page, $limit);
|
||||
return $this->tidyChat($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 聊天列表格式化
|
||||
* @param array $list
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function tidyChat(array $list)
|
||||
{
|
||||
$productIds = $orderIds = $productList = $orderInfo = $toUser = $user = $orderIds_refund = [];
|
||||
$toUid = $list[0]['to_uid'] ?? 0;
|
||||
$uid = $list[0]['uid'] ?? 0;
|
||||
foreach ($list as &$item) {
|
||||
$item['_add_time'] = $item['add_time'];
|
||||
$item['add_time'] = strtotime($item['_add_time']);
|
||||
$item['productInfo'] = $item['orderInfo'] = [];
|
||||
if ($item['msn_type'] == self::MSN_TYPE_GOODS && $item['msn']) {
|
||||
$productIds[] = $item['msn'];
|
||||
} elseif ($item['msn_type'] == self::MSN_TYPE_ORDER && $item['msn']) {
|
||||
$orderIds[] = $item['msn'];
|
||||
} elseif ($item['msn_type'] == self::MSN_TYPE_REFUND_ORDER && $item['msn']) {
|
||||
$orderIds_refund[] = $item['msn'];
|
||||
}
|
||||
}
|
||||
if ($productIds) {
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$where = [
|
||||
['id', 'in', $productIds],
|
||||
['is_del', '=', 0],
|
||||
['is_show', '=', 1],
|
||||
];
|
||||
$productList = get_thumb_water($productServices->getColumn($where, '*', 'id'));
|
||||
}
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
if ($orderIds) {
|
||||
$orderWhere = [
|
||||
['order_id|unique', 'in', $orderIds],
|
||||
['is_del', '=', 0],
|
||||
];
|
||||
$orderInfo = $orderServices->getColumn($orderWhere, '*', 'order_id');
|
||||
}
|
||||
/** @var StoreOrderRefundServices $orderRefundService */
|
||||
$orderRefundService = app()->make(StoreOrderRefundServices::class);
|
||||
if ($orderIds_refund) {
|
||||
$orderWhere = [
|
||||
['order_id', 'in', $orderIds_refund],
|
||||
['is_del', '=', 0],
|
||||
];
|
||||
$orderInfo_refund = $orderRefundService->getColumn($orderWhere, '*', 'order_id');
|
||||
}
|
||||
if ($toUid && $uid) {
|
||||
/** @var StoreServiceRecordServices $recordServices */
|
||||
$recordServices = app()->make(StoreServiceRecordServices::class);
|
||||
$toUser = $recordServices->get(['user_id' => $uid, 'to_uid' => $toUid], ['nickname', 'avatar']);
|
||||
$user = $recordServices->get(['user_id' => $toUid, 'to_uid' => $uid], ['nickname', 'avatar']);
|
||||
}
|
||||
|
||||
foreach ($list as &$item) {
|
||||
if ($item['msn_type'] == self::MSN_TYPE_GOODS && $item['msn']) {
|
||||
$item['productInfo'] = $productList[$item['msn']] ?? [];
|
||||
} elseif ($item['msn_type'] == self::MSN_TYPE_ORDER && $item['msn']) {
|
||||
$order = $orderInfo[$item['msn']] ?? null;
|
||||
if ($order) {
|
||||
$order = $orderServices->tidyOrder($order, true, true);
|
||||
$order['add_time_y'] = date('Y-m-d', $order['add_time']);
|
||||
$order['add_time_h'] = date('H:i:s', $order['add_time']);
|
||||
$item['orderInfo'] = $order;
|
||||
} else {
|
||||
$item['orderInfo'] = [];
|
||||
}
|
||||
} elseif ($item['msn_type'] == self::MSN_TYPE_REFUND_ORDER && $item['msn']) {
|
||||
$order_refund = $orderInfo_refund[$item['msn']] ?? null;
|
||||
if ($order_refund) {
|
||||
$order_refund['cartInfo'] = json_decode($order_refund['cart_info'], true);
|
||||
$order_refund['add_time_y'] = date('Y-m-d', $order_refund['add_time']);
|
||||
$order_refund['add_time_h'] = date('H:i:s', $order_refund['add_time']);
|
||||
$order_refund['total_num'] = $order_refund['refund_num'];
|
||||
$order_refund['total_price'] = $order_refund['refund_price'];
|
||||
$order_refund['pay_price'] = $order_refund['refund_price'];
|
||||
$item['orderInfo'] = $order_refund;
|
||||
} else {
|
||||
$item['orderInfo'] = [];
|
||||
}
|
||||
}
|
||||
$item['msn_type'] = (int)$item['msn_type'];
|
||||
if (!isset($item['nickname'])) {
|
||||
$item['nickname'] = '';
|
||||
}
|
||||
if (!isset($item['avatar'])) {
|
||||
$item['avatar'] = '';
|
||||
}
|
||||
|
||||
if (!$item['avatar'] && !$item['nickname']) {
|
||||
if ($item['uid'] == $uid && $item['to_uid'] == $toUid) {
|
||||
$item['nickname'] = $user['nickname'] ?? '';
|
||||
$item['avatar'] = $user['avatar'] ?? '';
|
||||
}
|
||||
if ($item['uid'] == $toUid && $item['to_uid'] == $uid) {
|
||||
$item['nickname'] = $toUser['nickname'] ?? '';
|
||||
$item['avatar'] = $toUser['avatar'] ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天记录
|
||||
* @param array $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param bool $isUp
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getServiceChatList(array $where, int $limit, int $upperId)
|
||||
{
|
||||
return $this->dao->getChatList($where, $limit, $upperId);
|
||||
}
|
||||
}
|
||||
121
app/services/message/service/StoreServiceRecordServices.php
Normal file
121
app/services/message/service/StoreServiceRecordServices.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceRecordDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class StoreServiceRecordServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceRecordDao
|
||||
*/
|
||||
class StoreServiceRecordServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var StoreServiceRecordDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceRecordDao $dao;
|
||||
|
||||
/**
|
||||
* 获取客服用户聊天列表
|
||||
* @param int $userId
|
||||
* @param string $nickname
|
||||
* @param int $isTourist
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getServiceList(int $userId, string $nickname = '', int $isTourist = 0)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getServiceList(['user_id' => $userId, 'title' => $nickname, 'is_tourist' => $isTourist], $page, $limit, ['user', 'service']);
|
||||
foreach ($list as &$item) {
|
||||
if ($item['message_type'] == 1) {
|
||||
$item['message'] = substrUTf8($item['message'], '10', 'UTF-8', '');
|
||||
}
|
||||
if (isset($item['kefu_nickname']) && $item['kefu_nickname']) {
|
||||
$item['nickname'] = $item['kefu_nickname'];
|
||||
}
|
||||
if (isset($item['wx_nickname']) && $item['wx_nickname'] && !$item['nickname']) {
|
||||
$item['nickname'] = $item['wx_nickname'];
|
||||
}
|
||||
if (isset($item['kefu_avatar']) && $item['kefu_avatar']) {
|
||||
$item['avatar'] = $item['kefu_avatar'];
|
||||
}
|
||||
if (isset($item['wx_avatar']) && $item['wx_avatar'] && !$item['avatar']) {
|
||||
$item['avatar'] = $item['wx_avatar'];
|
||||
}
|
||||
$item['_update_time'] = date('Y-m-d H:i', $item['update_time']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新客服用户信息
|
||||
* @param int $uid
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateRecord(array $where, array $data)
|
||||
{
|
||||
return $this->dao->update($where, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入聊天相关人数据
|
||||
* @param int $uid
|
||||
* @param int $toUid
|
||||
* @param string $message
|
||||
* @param int $type
|
||||
* @param int $messageType
|
||||
* @param int $num
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function saveRecord(int $uid, int $toUid, string $message, int $type, int $messageType, int $num, int $isTourist = 0, string $nickname = '', string $avatar = '')
|
||||
{
|
||||
$info = $this->dao->get(['user_id' => $toUid, 'to_uid' => $uid]);
|
||||
if ($info) {
|
||||
$info->type = $type;
|
||||
$info->message = $message;
|
||||
$info->message_type = $messageType;
|
||||
$info->update_time = time();
|
||||
$info->mssage_num = $num;
|
||||
if ($avatar) $info->avatar = $avatar;
|
||||
if ($nickname) $info->nickname = $nickname;
|
||||
$info->save();
|
||||
$this->dao->update(['user_id' => $uid, 'to_uid' => $toUid], ['message' => $message, 'message_type' => $messageType]);
|
||||
return $info->toArray();
|
||||
} else {
|
||||
return $this->dao->save([
|
||||
'user_id' => $toUid,
|
||||
'to_uid' => $uid,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'avatar' => $avatar,
|
||||
'nickname' => $nickname,
|
||||
'message_type' => $messageType,
|
||||
'mssage_num' => $num,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
'is_tourist' => $isTourist
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
233
app/services/message/service/StoreServiceServices.php
Normal file
233
app/services/message/service/StoreServiceServices.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 客服
|
||||
* Class StoreServiceServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceDao
|
||||
*/
|
||||
class StoreServiceServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 创建form表单
|
||||
* @var FormBuilder
|
||||
*/
|
||||
#[Inject]
|
||||
protected FormBuilder $builder;
|
||||
|
||||
/**
|
||||
* @var StoreServiceDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceDao $dao;
|
||||
|
||||
/**
|
||||
* 获取客服列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getServiceList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getServiceList($where, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
if (!isset($item['workMember'])) {
|
||||
$item['workMember'] = [];
|
||||
}
|
||||
if (isset($item['wx_name']) && !isset($item['nickname'])) {
|
||||
$item['nickname'] = $item['wx_name'];
|
||||
}
|
||||
}
|
||||
$this->updateNonExistentService(array_column($list, 'uid'));
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $uids
|
||||
* @return bool
|
||||
*/
|
||||
public function updateNonExistentService(array $uids = [])
|
||||
{
|
||||
if (!$uids) {
|
||||
return true;
|
||||
}
|
||||
/** @var UserServices $services */
|
||||
$services = app()->make(UserServices::class);
|
||||
$userUids = $services->getColumn([['uid', 'in', $uids]], 'uid');
|
||||
$unUids = array_diff($uids, $userUids);
|
||||
return $this->dao->deleteNonExistentService($unUids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客服表单
|
||||
* @param array $formData
|
||||
* @return mixed
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createServiceForm(array $formData = [])
|
||||
{
|
||||
if ($formData) {
|
||||
$field[] = $this->builder->frameImage('avatar', '客服头像:', $this->url('admin/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
} else {
|
||||
$field[] = $this->builder->frameImage('image', '商城用户:', $this->url('admin/system.user/list', ['fodder' => 'image'], true))->icon('ios-add')->width('960px')->height('550px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
|
||||
$field[] = $this->builder->hidden('uid', 0);
|
||||
$field[] = $this->builder->hidden('avatar', '');
|
||||
}
|
||||
$field[] = $this->builder->input('nickname', '客服名称:', $formData['nickname'] ?? '')->col(24)->required();
|
||||
$field[] = $this->builder->input('phone', '手机号码:', $formData['phone'] ?? '')->col(24)->required();
|
||||
if ($formData) {
|
||||
$field[] = $this->builder->input('account', '客服账号:', $formData['account'] ?? '')->col(24)->required();
|
||||
$field[] = $this->builder->input('password', '客服密码:')->type('password')->col(24);
|
||||
$field[] = $this->builder->input('true_password', '确认密码:')->type('password')->col(24);
|
||||
} else {
|
||||
$field[] = $this->builder->input('account', '客服账号:')->col(24)->required();
|
||||
$field[] = $this->builder->input('password', '客服密码:')->type('password')->col(24)->required();
|
||||
$field[] = $this->builder->input('true_password', '确认密码:')->type('password')->col(24)->required();
|
||||
}
|
||||
$field[] = $this->builder->switches('account_status', '账号状态:', (int)($formData['account_status'] ?? 0))->appendControl(1, [
|
||||
$this->builder->switches('status', '客服状态:', (int)($formData['status'] ?? 0))->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
|
||||
$this->builder->switches('customer', '手机订单管理:', $formData['customer'] ?? 0)->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
|
||||
$this->builder->switches('notify', '订单通知:', $formData['notify'] ?? 0)->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
|
||||
])->falseValue(0)->trueValue(1)->openStr('开启')->closeStr('关闭')->size('large');
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客服获取表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return create_form('添加客服', $this->createServiceForm(), $this->url('/app/wechat/kefu'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑获取表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function edit(int $id)
|
||||
{
|
||||
$serviceInfo = $this->dao->get($id);
|
||||
if (!$serviceInfo) {
|
||||
throw new AdminException('数据不存在!');
|
||||
}
|
||||
return create_form('编辑客服', $this->createServiceForm($serviceInfo->toArray()), $this->url('/app/wechat/kefu/' . $id), 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某人的聊天记录用户列表
|
||||
* @param int $uid
|
||||
* @return array|array[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getChatUser(int $uid)
|
||||
{
|
||||
/** @var StoreServiceLogServices $serviceLog */
|
||||
$serviceLog = app()->make(StoreServiceLogServices::class);
|
||||
/** @var UserServices $serviceUser */
|
||||
$serviceUser = app()->make(UserServices::class);
|
||||
$uids = $serviceLog->getChatUserIds($uid);
|
||||
if (!$uids) {
|
||||
return [];
|
||||
}
|
||||
return $serviceUser->getUserList(['uid' => $uids], 'nickname,uid,avatar as headimgurl');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否是客服
|
||||
* @param array $where
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function checkoutIsService(array $where)
|
||||
{
|
||||
return (bool)$this->dao->count($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询聊天记录和获取客服uid
|
||||
* @param int $uid 当前用户uid
|
||||
* @param int $uidTo 上翻页id
|
||||
* @param int $limit 展示条数
|
||||
* @param int $toUid 客服uid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getRecord(int $uid, int $uidTo, int $limit = 10, int $toUid = 0)
|
||||
{
|
||||
if (!$toUid) {
|
||||
$serviceInfoList = $this->getServiceList(['noId' => [$uid], 'status' => 1, 'account_status' => 1, 'online' => 1]);
|
||||
if (!count($serviceInfoList)) {
|
||||
throw new ValidateException('暂无客服人员在线,请稍后联系');
|
||||
}
|
||||
$uids = array_column($serviceInfoList['list'], 'uid');
|
||||
if (!$uids) {
|
||||
throw new ValidateException('暂无客服人员在线,请稍后联系');
|
||||
}
|
||||
/** @var StoreServiceRecordServices $recordServices */
|
||||
$recordServices = app()->make(StoreServiceRecordServices::class);
|
||||
//上次聊天客服优先对话
|
||||
$toUid = $recordServices->getLatelyMsgUid(['to_uid' => $uid], 'user_id');
|
||||
//如果上次聊天的客不在当前客服中从新
|
||||
if (!in_array($toUid, $uids)) {
|
||||
$toUid = 0;
|
||||
}
|
||||
if (!$toUid) {
|
||||
mt_srand();
|
||||
$toUid = $uids[array_rand($uids)] ?? 0;
|
||||
}
|
||||
if (!$toUid) {
|
||||
throw new ValidateException('暂无客服人员在线,请稍后联系');
|
||||
}
|
||||
}
|
||||
$userInfo = $this->dao->get(['uid' => $toUid], ['nickname', 'avatar']);
|
||||
if (!$userInfo) {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userInfo = $userServices->get(['uid' => $toUid], ['nickname', 'avatar']);
|
||||
if (!$userInfo) {
|
||||
$userInfo['nickname'] = '';
|
||||
$userInfo['avatar'] = '';
|
||||
}
|
||||
}
|
||||
/** @var StoreServiceLogServices $logServices */
|
||||
$logServices = app()->make(StoreServiceLogServices::class);
|
||||
$result = ['serviceList' => [], 'uid' => $toUid, 'nickname' => $userInfo['nickname'], 'avatar' => $userInfo['avatar']];
|
||||
$serviceLogList = $logServices->getServiceChatList(['chat' => [$uid, $toUid], 'is_tourist' => 0], $limit, $uidTo);
|
||||
$result['serviceList'] = array_reverse($logServices->tidyChat($serviceLogList));
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\other\CategoryDao;
|
||||
use app\services\other\CategoryServices;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class StoreServiceSpeechcraftCateServices
|
||||
* @package app\services\message\service
|
||||
*/
|
||||
class StoreServiceSpeechcraftCateServices extends CategoryServices
|
||||
{
|
||||
/**
|
||||
* 获取分类表单
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function serviceSpeechcraftCateForm(array $data = [])
|
||||
{
|
||||
$f[] = FormBuilder::input('name', '分类名称:', $data['name'] ?? '')->required();
|
||||
$f[] = FormBuilder::number('sort', '排序:', (int)($data['sort'] ?? 0))->min(0);
|
||||
return $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取创建表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm()
|
||||
{
|
||||
return create_form('添加分类', $this->serviceSpeechcraftCateForm(), $this->url('/app/wechat/speechcraftcate'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取编辑表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function editForm(int $id)
|
||||
{
|
||||
$cateInfo = $this->dao->get($id);
|
||||
if (!$cateInfo) {
|
||||
throw new ValidateException('分类没有查询到');
|
||||
}
|
||||
return create_form('修改分类', $this->serviceSpeechcraftCateForm($cateInfo->toArray()), $this->url('/app/wechat/speechcraftcate/' . $id), 'PUT');
|
||||
}
|
||||
|
||||
}
|
||||
101
app/services/message/service/StoreServiceSpeechcraftServices.php
Normal file
101
app/services/message/service/StoreServiceSpeechcraftServices.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\service;
|
||||
|
||||
|
||||
use app\dao\message\service\StoreServiceSpeechcraftDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 话术
|
||||
* Class StoreServiceSpeechcraftServices
|
||||
* @package app\services\message\service
|
||||
* @mixin StoreServiceSpeechcraftDao
|
||||
*/
|
||||
class StoreServiceSpeechcraftServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var StoreServiceSpeechcraftDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceSpeechcraftDao $dao;
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSpeechcraftList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getSpeechcraftList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建form表单
|
||||
* @param int $cate_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function createForm(int $cate_id = 0)
|
||||
{
|
||||
return create_form('添加话术', $this->speechcraftForm([], $cate_id), $this->url('/app/wechat/speechcraft'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function updateForm(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('您修改的话术内容不存在');
|
||||
}
|
||||
return create_form('编辑话术', $this->speechcraftForm($info->toArray()), $this->url('/app/wechat/speechcraft/' . $id), 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $infoData
|
||||
* @param int $cate_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function speechcraftForm(array $infoData = [], int $cate_id = 0)
|
||||
{
|
||||
/** @var StoreServiceSpeechcraftCateServices $services */
|
||||
$services = app()->make(StoreServiceSpeechcraftCateServices::class);
|
||||
$cateList = $services->getCateList(['owner_id' => 0, 'type' => 0, 'group' => 1]);
|
||||
$data = [];
|
||||
foreach ($cateList['data'] as $item) {
|
||||
$data[] = ['value' => $item['id'], 'label' => $item['name']];
|
||||
}
|
||||
$form[] = FormBuilder::select('cate_id', '话术分类:', $infoData['cate_id'] ?? $cate_id)->setOptions($data);
|
||||
$form[] = FormBuilder::textarea('title', '话术标题:', $infoData['title'] ?? '');
|
||||
$form[] = FormBuilder::textarea('message', '话术内容:', $infoData['message'] ?? '')->required();
|
||||
$form[] = FormBuilder::number('sort', '排序:', (int)($infoData['sort'] ?? 0))->min(0);
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
54
app/services/message/sms/SmsAdminServices.php
Normal file
54
app/services/message/sms/SmsAdminServices.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\sms;
|
||||
|
||||
|
||||
use app\dao\system\config\SystemConfigDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\HttpService;
|
||||
use crmeb\services\sms\Sms;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 短信平台注册登陆
|
||||
* Class SmsAdminServices
|
||||
* @package app\services\message\sms
|
||||
* @mixin SystemConfigDao
|
||||
*/
|
||||
class SmsAdminServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var SystemConfigDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemConfigDao $dao;
|
||||
|
||||
/**
|
||||
* 更新短信配置
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateSmsConfig(string $account, string $password)
|
||||
{
|
||||
return $this->transaction(function () use ($account, $password) {
|
||||
$this->dao->update('sms_account', ['value' => json_encode($account)], 'menu_name');
|
||||
$this->dao->update('sms_token', ['value' => json_encode($password)], 'menu_name');
|
||||
\crmeb\services\SystemConfigService::clear();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
70
app/services/message/sms/SmsRecordServices.php
Normal file
70
app/services/message/sms/SmsRecordServices.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\sms;
|
||||
|
||||
|
||||
use app\dao\message\sms\SmsRecordDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\serve\ServeServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 短信发送记录
|
||||
* Class SmsRecordServices
|
||||
* @package app\services\message\sms
|
||||
* @mixin SmsRecordDao
|
||||
*/
|
||||
class SmsRecordServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var SmsRecordDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SmsRecordDao $dao;
|
||||
|
||||
/**
|
||||
* 获取短信发送列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getRecordList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$data = $this->dao->getRecordList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('data', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改短信发送记录短信状态
|
||||
*/
|
||||
public function modifyResultCode()
|
||||
{
|
||||
$recordIds = $this->dao->getCodeNull();
|
||||
if (count($recordIds)) {
|
||||
/** @var ServeServices $smsHandle */
|
||||
$smsHandle = app()->make(ServeServices::class);
|
||||
$codeLists = $smsHandle->sms()->getStatus($recordIds);
|
||||
foreach ($codeLists as $item) {
|
||||
if (isset($item['id']) && isset($item['resultcode'])) {
|
||||
if ($item['resultcode'] == '' || $item['resultcode'] == null) $item['resultcode'] = 134;
|
||||
$this->dao->update($item['id'], ['resultcode' => $item['resultcode']], 'record_id');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
62
app/services/message/sms/SmsSendServices.php
Normal file
62
app/services/message/sms/SmsSendServices.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\sms;
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\services\message\SystemNotificationServices;
|
||||
use app\services\serve\ServeServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 短信发送
|
||||
* Class SmsSendServices
|
||||
* @package app\services\message\sms
|
||||
*/
|
||||
class SmsSendServices extends BaseServices
|
||||
{
|
||||
private $smsType = ['yihaotong', 'aliyun', 'tencent'];
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
* @param bool $switch
|
||||
* @param $phone
|
||||
* @param array $data
|
||||
* @param string $template
|
||||
* @return bool
|
||||
*/
|
||||
public function send(bool $switch, $phone, array $data, string $template)
|
||||
{
|
||||
if ($switch && $phone) {
|
||||
/** @var ServeServices $services */
|
||||
$services = app()->make(ServeServices::class);
|
||||
|
||||
$type = $this->smsType[sys_config('sms_type', 0)];
|
||||
//获取短信ID
|
||||
$templateId = CacheService::handler('TEMPLATE')->remember('NOTICE_SMS_' . $type . '_' . $template, function () use ($services, $template) {
|
||||
/** @var SystemNotificationServices $notifyServices */
|
||||
$notifyServices = app()->make(SystemNotificationServices::class);
|
||||
return $notifyServices->value(['mark' => $template], 'sms_id') ?? 0;
|
||||
});
|
||||
//获取发送短信驱动类型
|
||||
$smsMake = $services->sms($type);
|
||||
$res = $smsMake->send($phone, $templateId, $data);
|
||||
if ($res === false) {
|
||||
throw new ValidateException($services->getError());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
57
app/services/message/sms/SmsTemplateApplyServices.php
Normal file
57
app/services/message/sms/SmsTemplateApplyServices.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\sms;
|
||||
|
||||
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 短信模板
|
||||
* Class SmsTemplateApplyServices
|
||||
* @package app\services\message\sms
|
||||
*/
|
||||
class SmsTemplateApplyServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var FormBuilder
|
||||
*/
|
||||
#[Inject]
|
||||
protected FormBuilder $builder;
|
||||
|
||||
/**
|
||||
* 创建短信模板表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createSmsTemplateForm()
|
||||
{
|
||||
$field = [
|
||||
$this->builder->input('title', '模板名称')->placeholder('模板名称,如:订单支付成功'),
|
||||
$this->builder->input('content', '模板内容')->type('textarea')->placeholder('模板内容,如:您购买的商品已支付成功,支付金额{$pay_price}元,订单号{$order_id},感谢您的光临!(注:模板内容不用添加短信签名,可在一号通主页单独修改签名)')->rows(3),
|
||||
$this->builder->radio('type', '模板类型', 1)->options([['label' => '验证码', 'value' => 1], ['label' => '通知', 'value' => 2], ['label' => '推广', 'value' => 3]])
|
||||
];
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信申请模板
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getSmsTemplateForm()
|
||||
{
|
||||
return create_form('申请短信模板', $this->createSmsTemplateForm(), $this->url('/notify/sms/temp'), 'POST');
|
||||
}
|
||||
|
||||
}
|
||||
426
app/services/message/wechat/MessageServices.php
Normal file
426
app/services/message/wechat/MessageServices.php
Normal file
@@ -0,0 +1,426 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\message\wechat;
|
||||
|
||||
|
||||
use app\services\activity\bargain\StoreBargainServices;
|
||||
use app\services\activity\combination\StoreCombinationServices;
|
||||
use app\services\activity\combination\StorePinkServices;
|
||||
use app\services\activity\seckill\StoreSeckillServices;
|
||||
use app\services\BaseServices;
|
||||
use app\services\other\QrcodeServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\user\LoginServices;
|
||||
use app\services\user\UserCardServices;
|
||||
use app\services\user\UserServices;
|
||||
use app\services\wechat\WechatQrcodeServices;
|
||||
use app\services\wechat\WechatReplyServices;
|
||||
use app\services\wechat\WechatUserServices;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use crmeb\services\wechat\message\Image;
|
||||
use crmeb\services\wechat\message\News;
|
||||
use crmeb\services\wechat\message\Text;
|
||||
use crmeb\services\wechat\message\TextCard;
|
||||
use crmeb\services\wechat\message\Voice;
|
||||
use crmeb\services\wechat\Messages;
|
||||
use crmeb\services\wechat\OfficialAccount;
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
|
||||
use EasyWeChat\Kernel\Exceptions\RuntimeException;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Class MessageServices
|
||||
* @package app\services\message\wechat
|
||||
*/
|
||||
class MessageServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* 事件处理
|
||||
* @param $qrInfo
|
||||
* @param $openid
|
||||
* @return array|Image|News|Text|TextCard|Voice|string
|
||||
* @throws InvalidArgumentException
|
||||
* @throws InvalidConfigException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function wechatEvent($qrInfo, $openid)
|
||||
{
|
||||
$response = Messages::transfer();
|
||||
$thirdType = explode('-', $qrInfo['third_type']);
|
||||
$baseUrl = sys_config('site_url');
|
||||
switch (strtolower($thirdType[0])) {
|
||||
case 'spread':
|
||||
try {
|
||||
$spreadUid = $qrInfo['third_id'];
|
||||
/** @var WechatUserServices $wechatUser */
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
$uid = $wechatUser->getFieldValue($openid, 'openid', 'uid');
|
||||
/** @var UserServices $userService */
|
||||
$userService = app()->make(UserServices::class);
|
||||
$userInfo = $userService->get($uid);
|
||||
if ($userInfo && $spreadUid != $uid && !$userInfo['spread_uid']) {
|
||||
/** @var LoginServices $loginService */
|
||||
$loginService = app()->make(LoginServices::class);
|
||||
if (!$loginService->updateUserInfo(['spread_uid' => $spreadUid], $userInfo)) {
|
||||
$response = '绑定推荐人失败!';
|
||||
}
|
||||
}
|
||||
$data = SystemConfigService::more(['site_name', 'site_logo', 'wechat_share_title']);
|
||||
$wechatNews['title'] = $data['site_name'] ?? '';
|
||||
$wechatNews['image'] = $data['site_logo'] ?? '';
|
||||
$wechatNews['description'] = $data['wechat_share_title'] ?? '';
|
||||
$wechatNews['url'] = $baseUrl . '/pages/index/index?spid=' . $thirdType[1] ?? 0;
|
||||
$messages = Messages::newMessage($wechatNews);
|
||||
OfficialAccount::staffSend($messages, $openid);
|
||||
// OfficialAccount::staffService()->message($messages)->to($openid)->send();
|
||||
} catch (\Exception $e) {
|
||||
$response = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
case 'reply':
|
||||
/** @var WechatReplyServices $replyServices */
|
||||
$replyServices = app()->make(WechatReplyServices::class);
|
||||
$data = $replyServices->get($qrInfo['third_id']);
|
||||
if ($data) {
|
||||
$response = $replyServices->replyDataByMessage($data->toArray());
|
||||
}
|
||||
break;
|
||||
case 'product':
|
||||
/** @var StoreProductServices $productService */
|
||||
$productService = app()->make(StoreProductServices::class);
|
||||
$productInfo = $productService->get($thirdType[1] ?? 0);
|
||||
$wechatNews['title'] = $productInfo->store_name;
|
||||
$wechatNews['image'] = $productInfo->image;
|
||||
$wechatNews['description'] = $productInfo->store_info;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/goods_details/index?id=' . $thirdType[1] . '&spid=' . ($thirdType[2] ?? 0);
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
break;
|
||||
case 'combination':
|
||||
/** @var StoreCombinationServices $combinationService */
|
||||
$combinationService = app()->make(StoreCombinationServices::class);
|
||||
$productInfo = $combinationService->get($thirdType[1] ?? 0);
|
||||
$wechatNews['title'] = $productInfo->title;
|
||||
$wechatNews['image'] = $productInfo->image;
|
||||
$wechatNews['description'] = $productInfo->info;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/activity/goods_details/index?type=3&id=' . $thirdType[1] . '&spid=' . ($thirdType[2] ?? 0);
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
break;
|
||||
case 'seckill':
|
||||
/** @var StoreSeckillServices $seckillService */
|
||||
$seckillService = app()->make(StoreSeckillServices::class);
|
||||
$productInfo = $seckillService->get($thirdType[1] ?? 0);
|
||||
$wechatNews['title'] = $productInfo->title;
|
||||
$wechatNews['image'] = $productInfo->image;
|
||||
$wechatNews['description'] = $productInfo->info;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/activity/goods_details/index?type=1&id=' . $thirdType[1] . '&spid=' . ($thirdType[2] ?? 0) . '&time=' . $thirdType[3] . '&status=' . $thirdType[4];
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
break;
|
||||
case 'bargain':
|
||||
/** @var StoreBargainServices $bargainService */
|
||||
$bargainService = app()->make(StoreBargainServices::class);
|
||||
$productInfo = $bargainService->get($thirdType[1] ?? 0);
|
||||
$wechatNews['title'] = $productInfo->title;
|
||||
$wechatNews['image'] = $productInfo->image;
|
||||
$wechatNews['description'] = $productInfo->info;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/activity/goods_bargain_details/index?id=' . $thirdType[1] . '&bargain=' . $thirdType[2] . '&spid=' . $thirdType[2];
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
break;
|
||||
case 'pink':
|
||||
/** @var StorePinkServices $pinkService */
|
||||
$pinkService = app()->make(StorePinkServices::class);
|
||||
/** @var StoreCombinationServices $combinationService */
|
||||
$combinationService = app()->make(StoreCombinationServices::class);
|
||||
$pinktInfo = $pinkService->get($thirdType[1]);
|
||||
$productInfo = $combinationService->get($pinktInfo->cid);
|
||||
$wechatNews['title'] = $productInfo->title;
|
||||
$wechatNews['image'] = $productInfo->image;
|
||||
$wechatNews['description'] = $productInfo->info;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/activity/goods_combination_status/index?id=' . $thirdType[1] . '&spid=' . $thirdType[2];
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
break;
|
||||
case 'lucklottery':
|
||||
try {
|
||||
$lottery = $qrInfo['lottery'] ?? [];
|
||||
$wechatNews['title'] = $lottery['name'] ?? '关注成功,立即参与抽奖';
|
||||
$wechatNews['image'] = $lottery['image'] ?? '';
|
||||
$wechatNews['description'] = $lottery['name'] ?? '关注成功,获得一次抽奖机会';
|
||||
$uid = $thirdType[1] ?? 0;
|
||||
$wechatNews['url'] = $baseUrl . '/pages/goods/lottery/grids/index?type=5&spread=' . $uid . '&spid=' . $uid;
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openid);
|
||||
} catch (\Exception $e) {
|
||||
\think\facade\Log::error('发送关注抽奖失败:' . $e->getMessage());
|
||||
$response = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
case 'wechatqrcode'://渠道码
|
||||
/** @var WechatQrcodeServices $wechatQrcodeService */
|
||||
$wechatQrcodeService = app()->make(WechatQrcodeServices::class);
|
||||
/** @var WechatUserServices $wechatUser */
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
/** @var UserServices $userService */
|
||||
$userService = app()->make(UserServices::class);
|
||||
/** @var LoginServices $loginService */
|
||||
$loginService = app()->make(LoginServices::class);
|
||||
try {
|
||||
//wechatqrcode类型的二维码数据中,third_id为渠道码的id
|
||||
$qrcodeInfo = $wechatQrcodeService->qrcodeInfo($qrInfo['third_id']);
|
||||
$spreadUid = $qrcodeInfo['uid'];
|
||||
$spreadInfo = $userService->get($spreadUid);
|
||||
$is_new = $wechatUser->saveUser($openid);
|
||||
$uid = $wechatUser->getFieldValue($openid, 'openid', 'uid', ['user_type', '<>', 'h5']);
|
||||
$userInfo = $userService->get($uid);
|
||||
|
||||
if ($qrcodeInfo['status'] == 0 || $qrcodeInfo['is_del'] == 1 || ($qrcodeInfo['end_time'] < time() && $qrcodeInfo['end_time'] > 0)) {
|
||||
$response = '二维码已失效';
|
||||
} else if ($spreadUid == $uid) {
|
||||
$response = '自己不能推荐自己';
|
||||
} else if (!$userInfo) {
|
||||
$response = '用户不存在';
|
||||
} else if (!$spreadInfo) {
|
||||
$response = '上级用户不存在';
|
||||
} else if ($loginService->updateUserInfo(['code' => $spreadUid], $userInfo, $is_new)) {
|
||||
//写入扫码记录,返回内容
|
||||
$response = $wechatQrcodeService->wechatQrcodeRecord($qrcodeInfo, $userInfo, $spreadInfo, 1);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$response = $e->getMessage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码发送图文消息
|
||||
* @param $title
|
||||
* @param $image
|
||||
* @param $info
|
||||
* @param $url
|
||||
* @param $openId
|
||||
* @throws InvalidArgumentException
|
||||
* @throws InvalidConfigException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function sendMessage($title, $image, $info, $url, $openId)
|
||||
{
|
||||
$wechatNews['title'] = $title;
|
||||
$wechatNews['image'] = $image;
|
||||
$wechatNews['description'] = $info;
|
||||
$wechatNews['url'] = $url;
|
||||
OfficialAccount::staffSend(Messages::newMessage($wechatNews), $openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码
|
||||
* @param $message
|
||||
* @return array|Image|News|Text|Transfer|Voice|string
|
||||
* @throws InvalidArgumentException
|
||||
* @throws InvalidConfigException
|
||||
* @throws RuntimeException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function wechatEventScan($message)
|
||||
{
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
/** @var WechatReplyServices $wechatReplyService */
|
||||
$wechatReplyService = app()->make(WechatReplyServices::class);
|
||||
$response = $wechatReplyService->reply('subscribe', $message['FromUserName']);
|
||||
if ($message['EventKey'] && ($qrInfo = $qrcodeService->getQrcode($message['Ticket'], 'ticket'))) {
|
||||
$qrcodeService->scanQrcode($message['Ticket'], 'ticket');
|
||||
$response = $this->wechatEvent($qrInfo, $message['FromUserName']);
|
||||
}
|
||||
$ticket = $message['EventKey'];
|
||||
if (strpos($ticket, 'wechat_scan_login:') === 0) {
|
||||
$openId = $message['FromUserName'];
|
||||
$key = str_replace('wechat_scan_login:', '', $ticket);
|
||||
/** @var WechatUserServices $wechatUserSerives */
|
||||
$wechatUserSerives = app()->make(WechatUserServices::class);
|
||||
$wechatUser = $wechatUserSerives->getWechatUserInfo(['openid' => $openId]);
|
||||
if ($wechatUser) {
|
||||
CacheService::set('wechat_scan_login:' . $key, $wechatUser['uid']);
|
||||
}
|
||||
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消关注
|
||||
* @param $message
|
||||
*/
|
||||
public function wechatEventUnsubscribe($message)
|
||||
{
|
||||
/** @var WechatUserServices $wechatUser */
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
$wechatUser->unSubscribe($message['FromUserName']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号关注
|
||||
* @param $message
|
||||
* @param $spread_uid
|
||||
* @return array|Image|News|Text|Transfer|Voice|string
|
||||
* @throws InvalidArgumentException
|
||||
* @throws InvalidConfigException
|
||||
* @throws RuntimeException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function wechatEventSubscribe($message, $spread_uid)
|
||||
{
|
||||
/** @var WechatReplyServices $wechatReplyService */
|
||||
$wechatReplyService = app()->make(WechatReplyServices::class);
|
||||
$response = $wechatReplyService->reply('subscribe', $message['FromUserName']);
|
||||
if (isset($message['EventKey'])) {
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
if ($message['EventKey'] && ($qrInfo = $qrcodeService->getQrcode($message['Ticket'], 'ticket'))) {
|
||||
$qrcodeService->scanQrcode($message['Ticket'], 'ticket');
|
||||
$response = $this->wechatEvent($qrInfo, $message['FromUserName']);
|
||||
}
|
||||
}
|
||||
//是否开启
|
||||
if (sys_config('create_wechat_user', 1)) {
|
||||
try {
|
||||
/** @var WechatUserServices $wechatUserSerives */
|
||||
$wechatUserSerives = app()->make(WechatUserServices::class);
|
||||
$wechatUserSerives->saveUser($message['FromUserName'], $spread_uid);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('关注公众号生成用户失败,原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位置 事件
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatEventLocation($message)
|
||||
{
|
||||
//return 'location';
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转URL 事件
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatEventView($message)
|
||||
{
|
||||
//return 'view';
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片 消息
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatMessageImage($message)
|
||||
{
|
||||
//return 'image';
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音 消息
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatMessageVoice($message)
|
||||
{
|
||||
//return 'voice';
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频 消息
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatMessageVideo($message)
|
||||
{
|
||||
//return 'video';
|
||||
}
|
||||
|
||||
/**
|
||||
* 位置 消息
|
||||
*/
|
||||
public function wechatMessageLocation($message)
|
||||
{
|
||||
//return 'location';
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接 消息
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function wechatMessageLink($message)
|
||||
{
|
||||
//return 'link';
|
||||
}
|
||||
|
||||
/**
|
||||
* 其它消息 消息
|
||||
*/
|
||||
public function wechatMessageOther($message)
|
||||
{
|
||||
//return 'other';
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取卡券
|
||||
* @param $message
|
||||
*/
|
||||
public function wechatEventUserGetCard($message)
|
||||
{
|
||||
try {
|
||||
/** @var UserCardServices $userCardServices */
|
||||
$userCardServices = app()->make(UserCardServices::class);
|
||||
$userCardServices->userGetCard($message);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('领取微信卡券失败,原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活卡券
|
||||
* @param $message
|
||||
*/
|
||||
public function wechatEventSubmitMembercardUserInfo($message)
|
||||
{
|
||||
try {
|
||||
/** @var UserCardServices $userCardServices */
|
||||
$userCardServices = app()->make(UserCardServices::class);
|
||||
$userCardServices->userSubmitCard($message);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('激活微信卡券失败,原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除卡券
|
||||
* @param $message
|
||||
*/
|
||||
public function wechatEventUserDelCard($message)
|
||||
{
|
||||
/** @var UserCardServices $userCardServices */
|
||||
$userCardServices = app()->make(UserCardServices::class);
|
||||
$userCardServices->userDelCard($message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user