ProgramTemplateService.php 6.5 KB

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