初始化项目
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\service\message;
|
||||
|
||||
use cores\traits\ErrorTrait;
|
||||
use app\common\service\BaseService;
|
||||
use app\common\library\sms\Driver as SmsDriver;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\common\model\wxapp\Setting as WxappSettingModel;
|
||||
|
||||
/**
|
||||
* 消息通知服务[基类]
|
||||
* Class Basics
|
||||
* @package app\common\service\message
|
||||
*/
|
||||
abstract class Basics extends BaseService
|
||||
{
|
||||
use ErrorTrait;
|
||||
|
||||
// 参数列表
|
||||
protected $param = [];
|
||||
|
||||
// 商城ID
|
||||
protected $storeId;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Basics constructor.
|
||||
* @param int $storeId
|
||||
*/
|
||||
public function __construct(int $storeId)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->storeId = $storeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息通知
|
||||
* @param array $param 参数
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function send(array $param);
|
||||
|
||||
/**
|
||||
* 发送短信通知
|
||||
* @param string $sceneValue 短信发送场景
|
||||
* @param string $acceptPhone 接收的手机号
|
||||
* @param array $templateParams 短信模板参数
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function sendSms(string $sceneValue, string $acceptPhone, array $templateParams): bool
|
||||
{
|
||||
// 短信通知设置
|
||||
$smsConfig = $this->getSmsConfig();
|
||||
// 短信服务
|
||||
$SmsDriver = new SmsDriver($smsConfig);
|
||||
try {
|
||||
// 判断短信服务是否开启
|
||||
$this->isEnableSms($smsConfig, $sceneValue);
|
||||
// 获取短信模板ID
|
||||
$templateCode = $this->getSmsTemplateCode($smsConfig, $sceneValue);
|
||||
// 执行发送短信
|
||||
$SmsDriver->sendSms($acceptPhone, $templateCode, $templateParams);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信通知设置
|
||||
* @return array|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getSmsConfig()
|
||||
{
|
||||
return SettingModel::getItem('sms', $this->storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断短信服务是否开启
|
||||
* @param array $smsConfig 短信设置
|
||||
* @param string $sceneValue 短信发送场景
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
private function isEnableSms(array $smsConfig, string $sceneValue)
|
||||
{
|
||||
if (!$smsConfig['scene'][$sceneValue]['isEnable']) {
|
||||
throwError('短信通知服务未开启,请在商户后台中设置');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信模板ID
|
||||
* @param array $smsConfig 短信设置
|
||||
* @param string $sceneValue 短信发送场景
|
||||
* @return string
|
||||
*/
|
||||
private function getSmsTemplateCode(array $smsConfig, string $sceneValue): string
|
||||
{
|
||||
return $smsConfig['scene'][$sceneValue]['templateCode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串截取前20字符
|
||||
* [用于兼容thing数据类型]
|
||||
* @param string $content
|
||||
* @param int $length
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function getSubstr(string $content, int $length = 20)
|
||||
{
|
||||
return str_substr($content, $length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\service\message\order;
|
||||
|
||||
use app\common\service\message\Basics;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
|
||||
/**
|
||||
* 消息通知服务 [订单发货]
|
||||
* Class Delivery
|
||||
* @package app\common\service\message\order
|
||||
*/
|
||||
class Delivery extends Basics
|
||||
{
|
||||
/**
|
||||
* 参数列表
|
||||
* @var array
|
||||
*/
|
||||
protected $param = [
|
||||
'order' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* 订单页面链接
|
||||
* @var string
|
||||
*/
|
||||
private $pageUrl = 'pages/order/detail';
|
||||
|
||||
/**
|
||||
* 发送消息通知
|
||||
* @param array $param
|
||||
* @return mixed|void
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function send(array $param)
|
||||
{
|
||||
// 记录参数
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化物流公司
|
||||
* @param $orderInfo
|
||||
* @return mixed
|
||||
*/
|
||||
private function getFormatExpressName($orderInfo)
|
||||
{
|
||||
return $this->getSubstr($orderInfo['express']['express_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化用户收货地址
|
||||
* @param $orderInfo
|
||||
* @return string
|
||||
*/
|
||||
private function getFormatAddress($orderInfo)
|
||||
{
|
||||
return implode('', $orderInfo['address']['region']) . $orderInfo['address']['detail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化商品名称
|
||||
* @param $goodsData
|
||||
* @return string
|
||||
*/
|
||||
private function getFormatGoodsName($goodsData)
|
||||
{
|
||||
return $this->getSubstr($goodsData[0]['goods_name']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\service\message\order;
|
||||
|
||||
use app\common\service\message\Basics;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\common\enum\setting\sms\Scene as SettingSmsScene;
|
||||
|
||||
/**
|
||||
* 消息通知服务 [订单支付成功]
|
||||
* Class Payment
|
||||
* @package app\common\service\message\order
|
||||
*/
|
||||
class Payment extends Basics
|
||||
{
|
||||
/**
|
||||
* 参数列表
|
||||
* @var array
|
||||
*/
|
||||
protected $param = [
|
||||
'order' => []
|
||||
];
|
||||
|
||||
/**
|
||||
* 订单页面链接
|
||||
* @var array
|
||||
*/
|
||||
private $pageUrl = 'pages/order/detail';
|
||||
|
||||
/**
|
||||
* 发送消息通知
|
||||
* @param array $param
|
||||
* @return mixed|void
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function send(array $param)
|
||||
{
|
||||
// 记录参数
|
||||
$this->param = $param;
|
||||
// 短信通知商家
|
||||
$this->onSendSms();
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信通知商家
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function onSendSms(): void
|
||||
{
|
||||
$orderInfo = $this->param['order'];
|
||||
// 获取商家的手机号 (用于接受短信通知)
|
||||
$acceptPhone = $this->getStoreAcceptPhone();
|
||||
if (empty($acceptPhone)) {
|
||||
return;
|
||||
}
|
||||
// 发送短信通知
|
||||
$this->sendSms(SettingSmsScene::ORDER_PAY, $acceptPhone, ['order_no' => $orderInfo['order_no']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商家手机号(用于接受短信通知)
|
||||
* @return string|false
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getStoreAcceptPhone()
|
||||
{
|
||||
// 短信通知设置
|
||||
$smsConfig = SettingModel::getItem('sms', $this->storeId);
|
||||
// 商家手机号 (后台设置)
|
||||
return $smsConfig['scene'][SettingSmsScene::ORDER_PAY]['acceptPhone'] ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\service\message\order;
|
||||
|
||||
use app\common\service\message\Basics;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
|
||||
/**
|
||||
* 消息通知服务 [订单售后]
|
||||
* Class Refund
|
||||
* @package app\common\service\message\order
|
||||
*/
|
||||
class Refund extends Basics
|
||||
{
|
||||
/**
|
||||
* 参数列表
|
||||
* @var array
|
||||
*/
|
||||
protected $param = [
|
||||
'refund' => [], // 退款单信息
|
||||
'order_no' => [], // 订单信息
|
||||
];
|
||||
|
||||
/**
|
||||
* 订单页面链接
|
||||
* @var array
|
||||
*/
|
||||
private $pageUrl = 'pages/order/refund/index';
|
||||
|
||||
/**
|
||||
* 发送消息通知
|
||||
* @param array $param
|
||||
* @return mixed|void
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function send(array $param)
|
||||
{
|
||||
// 记录参数
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\common\service\message\passport;
|
||||
|
||||
use app\common\service\message\Basics;
|
||||
use app\common\enum\setting\sms\Scene as SettingSmsScene;
|
||||
|
||||
/**
|
||||
* 消息通知服务 [短信验证码]
|
||||
* Class Captcha
|
||||
* @package app\common\service\message\passport
|
||||
*/
|
||||
class Captcha extends Basics
|
||||
{
|
||||
/**
|
||||
* 发送消息通知
|
||||
* @param array $param
|
||||
* @return bool|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function send(array $param)
|
||||
{
|
||||
// 发送短信
|
||||
if (!$this->sendSms(SettingSmsScene::CAPTCHA, $param['mobile'], ['code' => $param['code']])) {
|
||||
throwError('短信发送失败:' . $this->getError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user