ProgramTemplateService.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\core\util;
  3. use app\admin\model\wechat\WechatUser;
  4. use app\admin\model\wechat\StoreService as ServiceModel;
  5. use app\core\implement\ProviderInterface;
  6. /**
  7. * 小程序模板消息
  8. * Class RoutineTemplate
  9. * @package app\routine\model\routine
  10. */
  11. class ProgramTemplateService implements ProviderInterface
  12. {
  13. //订单支付成功
  14. const ORDER_PAY_SUCCESS = 'AT0009';
  15. //砍价成功
  16. const BARGAIN_SUCCESS = 'AT1173';
  17. //申请退款通知
  18. const ORDER_REFUND_STATUS = 'AT0036';
  19. //退款成功
  20. const ORDER_REFUND_SUCCESS = 'AT0787';
  21. //退款失败
  22. const ORDER_REFUND_FILE = 'AT0329';
  23. //订单发货提醒(快递)
  24. const ORDER_POSTAGE_SUCCESS = 'AT0007';
  25. //订单发货提醒(送货)
  26. const ORDER_DELIVER_SUCCESS = 'AT0177';
  27. //拼团取消通知
  28. const PINK_REMOVE='AT2430';
  29. //拼团失败
  30. const PINK_Fill='AT0310';
  31. //拼团成功
  32. const PINK_TRUE='AT0051';
  33. //开团成功
  34. const OPEN_PINK_SUCCESS='AT0541';
  35. //确认收货通知
  36. const OREDER_TAKEVER='AT0241';
  37. public static function getConstants($code='')
  38. {
  39. $oClass = new \ReflectionClass(__CLASS__);
  40. $stants=$oClass->getConstants();
  41. if($code) return isset($stants[$code]) ? $stants[$code] : '';
  42. else return $stants;
  43. }
  44. public function register($config)
  45. {
  46. }
  47. /**
  48. * 根据模板编号获取模板ID
  49. * @param string $tempKey
  50. * @return mixed|string
  51. */
  52. public static function setTemplateId($tempKey = ''){
  53. if($tempKey == '') return '';
  54. return \think\Db::name('RoutineTemplate')->where('tempkey',$tempKey)->where('status',1)->value('tempid');
  55. }
  56. /**
  57. * 发送模板消息
  58. * @param string $tempCode 所需下发的模板编号
  59. * @param string $openId 接收者(用户)的 openid
  60. * @param array $dataKey 模板内容,不填则下发空模板
  61. * @param string $formId 表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id
  62. * @param string $link 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  63. * @param string $emphasisKeyword 模板需要放大的关键词,不填则默认无放大
  64. * @return bool|mixed
  65. */
  66. public static function sendTemplate($tempCode = '',$openId = '',$dataKey = array(),$formId = '',$link = '',$defaultColor=null)
  67. {
  68. if($openId == '' || $tempCode == '' || $formId == '') return false;
  69. try{
  70. return MiniProgramService::sendTemplate($openId,trim(self::setTemplateId(self::getConstants($tempCode))),$dataKey,$formId,$link,$defaultColor);
  71. }catch (\Exception $e){
  72. return false;
  73. }
  74. }
  75. /**服务进度通知
  76. * @param array $data
  77. * @param null $url
  78. * @param string $defaultColor
  79. * @return bool
  80. */
  81. public static function sendAdminNoticeTemplate(array $data,$url = null,$defaultColor = '')
  82. {
  83. $adminIds = explode(',',trim(SystemConfigService::get('site_store_admin_uids')));
  84. $kefuIds = ServiceModel::where('notify',1)->column('uid');
  85. if(empty($adminIds[0])){
  86. $adminList = array_unique($kefuIds);
  87. }else{
  88. $adminList = array_unique(array_merge($adminIds,$kefuIds));
  89. }
  90. if(!is_array($adminList) || empty($adminList)) return false;
  91. foreach ($adminList as $uid){
  92. try{
  93. $openid = WechatUser::uidToRoutineOpenid($uid);
  94. }catch (\Exception $e){
  95. continue;
  96. }
  97. // self::sendTemplate($openid,self::ADMIN_NOTICE,$data,$url,$defaultColor);
  98. }
  99. }
  100. /**
  101. * 返回所有支持的行业列表
  102. * @return \EasyWeChat\Support\Collection
  103. */
  104. public static function getIndustry()
  105. {
  106. return MiniProgramService::noticeService()->getIndustry();
  107. }
  108. /**
  109. * 修改账号所属行业
  110. * 主行业 副行业 代码
  111. * IT科技 互联网/电子商务 1
  112. * IT科技 IT软件与服务 2
  113. * IT科技 IT硬件与设备 3
  114. * IT科技 电子技术 4
  115. * IT科技 通信与运营商 5
  116. * IT科技 网络游戏 6
  117. * 金融业 银行 7
  118. * 金融业 基金|理财|信托 8
  119. * 金融业 保险 9
  120. * 餐饮 餐饮 10
  121. * 酒店旅游 酒店 11
  122. * 酒店旅游 旅游 12
  123. * 运输与仓储 快递 13
  124. * 运输与仓储 物流 14
  125. * 运输与仓储 仓储 15
  126. * 教育 培训 16
  127. * 教育 院校 17
  128. * 政府与公共事业 学术科研 18
  129. * 政府与公共事业 交警 19
  130. * 政府与公共事业 博物馆 20
  131. * 政府与公共事业 公共事业|非盈利机构 21
  132. * 医药护理 医药医疗 22
  133. * 医药护理 护理美容 23
  134. * 医药护理 保健与卫生 24
  135. * 交通工具 汽车相关 25
  136. * 交通工具 摩托车相关 26
  137. * 交通工具 火车相关 27
  138. * 交通工具 飞机相关 28
  139. * 房地产 建筑 29
  140. * 房地产 物业 30
  141. * 消费品 消费品 31
  142. * 商业服务 法律 32
  143. * 商业服务 会展 33
  144. * 商业服务 中介服务 34
  145. * 商业服务 认证 35
  146. * 商业服务 审计 36
  147. * 文体娱乐 传媒 37
  148. * 文体娱乐 体育 38
  149. * 文体娱乐 娱乐休闲 39
  150. * 印刷 印刷 40
  151. * 其它 其它 41
  152. * @param $industryId1
  153. * @param $industryId2
  154. * @return \EasyWeChat\Support\Collection
  155. */
  156. public static function setIndustry($industryId1, $industryId2)
  157. {
  158. return MiniProgramService::noticeService()->setIndustry($industryId1, $industryId2);
  159. }
  160. /**
  161. * 获取所有模板列表
  162. * @return \EasyWeChat\Support\Collection
  163. */
  164. public static function getPrivateTemplates()
  165. {
  166. return MiniProgramService::noticeService()->getPrivateTemplates();
  167. }
  168. /**
  169. * 删除指定ID的模板
  170. * @param $templateId
  171. * @return \EasyWeChat\Support\Collection
  172. */
  173. public static function deletePrivateTemplate($templateId)
  174. {
  175. return MiniProgramService::noticeService()->deletePrivateTemplate($templateId);
  176. }
  177. /**
  178. * 添加模板并获取模板ID
  179. * @param $shortId
  180. * @return \EasyWeChat\Support\Collection
  181. */
  182. public static function addTemplate($shortId)
  183. {
  184. return MiniProgramService::noticeService()->addTemplate($shortId);
  185. }
  186. }