SubscribeTemplateService.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace crmeb\services;
  3. use app\admin\model\wechat\WechatUser;
  4. use app\admin\model\wechat\StoreService as ServiceModel;
  5. use app\models\routine\RoutineTemplate;
  6. use crmeb\interfaces\ProviderInterface;
  7. use think\facade\Db;
  8. /**
  9. * 小程序模板消息
  10. * Class RoutineTemplate
  11. * @package app\routine\model\routine
  12. */
  13. class SubscribeTemplateService implements ProviderInterface
  14. {
  15. //订单发货提醒(送货)
  16. const ORDER_POSTAGE_SUCCESS = 1128;
  17. //提现成功通知
  18. const USER_EXTRACT = 1470;
  19. //确认收货通知
  20. const OREDER_TAKEVER = 1481;
  21. //订单取消
  22. const ORDER_CLONE = 1134;
  23. //订单发货提醒(快递)
  24. const ORDER_DELIVER_SUCCESS = 1458;
  25. //拼团成功
  26. const PINK_TRUE = 3098;
  27. //砍价成功
  28. const BARGAIN_SUCCESS = 2727;
  29. //核销成功通知
  30. const ORDER_WRITE_OFF = 3116;
  31. //新订单提醒
  32. const ORDER_NEW = 1476;
  33. //退款通知
  34. const ORDER_REFUND = 1451;
  35. //充值成功
  36. const RECHARGE_SUCCESS = 755;
  37. //订单支付成功
  38. const ORDER_PAY_SUCCESS = 1927;
  39. //申请退款通知 管理员提醒
  40. const ORDER_REFUND_STATUS = 1468;
  41. //积分到账提醒
  42. const INTEGRAL_ACCOUT = 335;
  43. //拼团状态通知
  44. const PINK_STATUS = 3353;
  45. //下级绑定通知
  46. const SUBORDINATE_BINDING = 60720;
  47. public static function getConstants($code = '')
  48. {
  49. $oClass = new \ReflectionClass(__CLASS__);
  50. $stants = $oClass->getConstants();
  51. if ($code) return isset($stants[$code]) ? $stants[$code] : '';
  52. else return $stants;
  53. }
  54. public function register($config)
  55. {
  56. }
  57. /**
  58. * 根据模板编号获取模板ID
  59. * @param string $tempKey
  60. * @return mixed|string
  61. */
  62. public static function setTemplateId($tempKey = '')
  63. {
  64. if ($tempKey == '') return '';
  65. return RoutineTemplate::where('tempkey', $tempKey)->where('type', 0)->where('status', 1)->value('tempid');
  66. }
  67. /**
  68. * 发送订阅模板消息
  69. * @param string $tempCode 所需下发的模板编号
  70. * @param string $openId 接收者(用户)的 openid
  71. * @param array $dataKey 模板内容,不填则下发空模板
  72. * @param string $link 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转
  73. * @return bool|\EasyWeChat\Support\Collection|null
  74. */
  75. public static function sendTemplate(string $tempCode, string $openId, array $dataKey, string $link = '')
  76. {
  77. if (!$openId || !$tempCode) return false;
  78. return MiniProgramService::sendSubscribeTemlate($openId, trim(self::setTemplateId(self::getConstants($tempCode))), $dataKey, $link);
  79. }
  80. }