Payment.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\service\message\order;
  13. use app\common\service\message\Basics;
  14. use app\common\model\store\Setting as SettingModel;
  15. use app\common\enum\setting\sms\Scene as SettingSmsScene;
  16. /**
  17. * 消息通知服务 [订单支付成功]
  18. * Class Payment
  19. * @package app\common\service\message\order
  20. */
  21. class Payment extends Basics
  22. {
  23. /**
  24. * 参数列表
  25. * @var array
  26. */
  27. protected $param = [
  28. 'order' => []
  29. ];
  30. /**
  31. * 发送消息通知
  32. * @param array $param
  33. * @return mixed|void
  34. * @throws \cores\exception\BaseException
  35. * @throws \think\Exception
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function send(array $param)
  41. {
  42. // 记录参数
  43. $this->param = $param;
  44. // 短信通知商家
  45. $this->onSendSms();
  46. }
  47. /**
  48. * 短信通知商家
  49. * @throws \think\Exception
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. private function onSendSms(): void
  55. {
  56. $orderInfo = $this->param['order'];
  57. // 获取商家的手机号 (用于接受短信通知)
  58. $acceptPhone = $this->getStoreAcceptPhone();
  59. if (empty($acceptPhone)) {
  60. return;
  61. }
  62. // 发送短信通知
  63. $this->sendSms(SettingSmsScene::ORDER_PAY, $acceptPhone, ['order_no' => $orderInfo['order_no']]);
  64. }
  65. /**
  66. * 获取商家手机号(用于接受短信通知)
  67. * @return string|false
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. private function getStoreAcceptPhone()
  73. {
  74. // 短信通知设置
  75. $smsConfig = SettingModel::getItem('sms', $this->storeId);
  76. // 商家手机号 (后台设置)
  77. return $smsConfig['scene'][SettingSmsScene::ORDER_PAY]['acceptPhone'] ?? false;
  78. }
  79. }