SubscribeTemplateService.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public static function getConstants($code = '')
  46. {
  47. $oClass = new \ReflectionClass(__CLASS__);
  48. $stants = $oClass->getConstants();
  49. if ($code) return isset($stants[$code]) ? $stants[$code] : '';
  50. else return $stants;
  51. }
  52. public function register($config)
  53. {
  54. }
  55. /**
  56. * 根据模板编号获取模板ID
  57. * @param string $tempKey
  58. * @return mixed|string
  59. */
  60. public static function setTemplateId($tempKey = '')
  61. {
  62. if ($tempKey == '') return '';
  63. return RoutineTemplate::where('tempkey', $tempKey)->where('type', 0)->where('status', 1)->value('tempid');
  64. }
  65. /**
  66. * 发送订阅模板消息
  67. * @param string $tempCode 所需下发的模板编号
  68. * @param string $openId 接收者(用户)的 openid
  69. * @param array $dataKey 模板内容,不填则下发空模板
  70. * @param string $link 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转
  71. * @return bool|\EasyWeChat\Support\Collection|null
  72. */
  73. public static function sendTemplate(string $tempCode, string $openId, array $dataKey, string $link = '')
  74. {
  75. if (!$openId || !$tempCode) return false;
  76. return MiniProgramService::sendSubscribeTemlate($openId, trim(self::setTemplateId(self::getConstants($tempCode))), $dataKey, $link);
  77. }
  78. }