SubscribeMessageService.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\common\service;
  3. use think\Log;
  4. class SubscribeMessageService
  5. {
  6. const MSG_TEMP_DEMAND_RECEIVE = 'Ozqp33NFV4qgJQWMYnWUygx0V63cvyL02BiVflkP67o'; //接单成功
  7. const MSG_TEMP_DEMAND_MATCH_SUCCESS = 'zj8oNEXLfLyJxPA-wal9rpSkubnf1nXRRt-hX_rl98U'; //工单匹配成功
  8. const MSG_TEMP_DEMAND_SETTLE = 'NVTH7KEGZxVaXQaojmbXX8A_FP3RI8u56rgm9q_v37M'; //工单结算
  9. const MSG_TEMP_WORK_START = 'GWtWOOPsbpwocaOfvWy-pR5gbO3gI_5vxR_jmA6HJa0'; //项目开工
  10. const MSG_TEMP_WORK_ACCEPT = 'n6OCDU8zwI-JTNLDlXcXpKnKEgdDi-6ZnJaj-WAMou8'; //工单验收
  11. const MSG_TEMP_WORK_ACCEPT_RESULT = 'yaqaf5lGihxb8hf9qaV1_Ip2MgMg94DcutVXmBzZ3cg'; //验收结果
  12. const MSG_TEMP_CONTRACT_PAY = 'QRBIPCZUjMhBWkQDYkHCRVBRshXAv0fuzKbFUs2k5Og'; //合同付款
  13. const MSG_TEMP_CONTRACT_SIGN = 'mksLFWxPCFZmORvWof-4QWjHBbo0i274SAoY1XgmkCU'; //合同签约
  14. const MSG_TEMP_ORDER_SHIPPED = 'OzA14wCKihBZBrZUiaE-WpSVoFFSecun-vlDWUtEEEE'; //订单发货
  15. const MSG_TEMP_DEVELOPER_JOIN = 'ctqgNLWaHJ7RRnu9LwWTxu_g21lKil5v5Gv-Pg7XOE8'; //申请入驻
  16. const PAGE_DEMAND_LIST = 'pages/demand/list/index';
  17. const PAGE_ORDER_LIST = 'pages/order/order-list/index';
  18. const PAGE_HOME = 'pages/home/home';
  19. const MSG_MAP = [
  20. self::MSG_TEMP_DEMAND_RECEIVE => [
  21. 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我的报价需求列表
  22. 'remark' => '恭喜中标,请到我投标的需求确认接单!',
  23. /*
  24. 工单号:JG202003310001
  25. 服务项目:logo设计
  26. 任务名称:共享精英团队logo设计
  27. 备注:接单成功,请尽快安排排产
  28. */
  29. 'fields' => ['character_string1', 'thing9', 'thing10', 'thing4']
  30. ],
  31. self::MSG_TEMP_DEMAND_MATCH_SUCCESS => [
  32. 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
  33. 'remark' => '匹配工程师成功,请到需求详情查看沟通',
  34. /*
  35. 匹配服务方:字节
  36. 服务类别:安装预约
  37. 温馨提醒:您的工单已成功匹配,请您电话保持畅通。
  38. */
  39. 'fields' => ['thing1', 'phrase2', 'thing5'],
  40. ],
  41. self::MSG_TEMP_DEMAND_SETTLE => [
  42. 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
  43. 'remark' => '该工单已结算完成',
  44. /*
  45. 订单编号:200912162851392635fdbf4149
  46. 结算金额:99.9元
  47. 结算说明:订单已收货结算完成
  48. */
  49. 'fields' => ['character_string4', 'amount1', 'thing2'],
  50. ],
  51. self::MSG_TEMP_WORK_START => [
  52. 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
  53. 'remark' => '客户已支付预付款,可以开始工作',
  54. /*
  55. 项目名称:比克大厦四期
  56. 工作日期:2020.12.02 ~ 2020.12.08
  57. 备注:请在上下班时间安排对工人进行考勤
  58. */
  59. 'fields' => ['thing1', 'time2', 'thing4'],
  60. ],
  61. self::MSG_TEMP_WORK_ACCEPT => [
  62. 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
  63. 'remark' => '需求开发工作已完成,请前去验收成果',
  64. /*
  65. 工单编号:11021024307548
  66. 工单标题:电脑问题
  67. 验收内容:验收工单以及现场完工图
  68. 温馨提醒:登录平台确保验收,给予工程师中肯评价吧~
  69. */
  70. 'fields' => ['character_string1', 'thing8', 'thing2', 'thing5'],
  71. ],
  72. self::MSG_TEMP_WORK_ACCEPT_RESULT => [
  73. 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
  74. 'remark' => '客户已验收并支付尾款,可以发送源码',
  75. 'remarkFail' => '客户验收未通过,请根据要求修改',
  76. /*
  77. 验收阶段:第一阶段(1/2)
  78. 验收结果:拒绝
  79. 备注:阶段结算金额7日后即可提现
  80. 原因:不符合需求描述的内容
  81. */
  82. 'fields' => ['thing1', 'thing3', 'thing5', 'thing4'],
  83. ],
  84. self::MSG_TEMP_CONTRACT_PAY => [
  85. 'page' => self::PAGE_ORDER_LIST, //我的订单列表
  86. 'remark' => '请到我的订单完成合同尾款支付',
  87. /*
  88. 项目名称:峰爆剧组
  89. 合同编号:Q001
  90. 结算金额:1.23元
  91. 结算周期:2025.01.01~2025.03.31
  92. 备注:您有以上合同需要付款,请及时发起流程
  93. */
  94. 'fields' => ['thing1', 'character_string2', 'amount5', 'time4', 'thing3'],
  95. ],
  96. self::MSG_TEMP_CONTRACT_SIGN => [
  97. 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
  98. 'remark' => '需求已确认,请前去完成合同签约',
  99. /*
  100. 合同编号:2019年合字001号
  101. 项目名称:某某项目
  102. 签约金额:3000
  103. 备注:【签约成功】请及时缴纳首期款办理入住
  104. */
  105. 'fields' => ['thing1', 'thing2', 'amount12', 'thing5'],
  106. ],
  107. self::MSG_TEMP_ORDER_SHIPPED => [
  108. 'page' => self::PAGE_ORDER_LIST, //订单列表
  109. 'remark' => '发货成功,请到订单详情查看激活码',
  110. /*
  111. 订单号:A12345678984
  112. 商品名称:2019秋冬女装春装新款上衣连衣裙加绒蕾丝
  113. 订单状态:充值成功
  114. 备注:快递配送中,请留意电话或者短信
  115. */
  116. 'fields' => ['character_string2', 'thing1', 'phrase19', 'thing6'],
  117. ],
  118. self::MSG_TEMP_DEVELOPER_JOIN => [
  119. 'page' => self::PAGE_HOME, //首页
  120. 'remark' => '开发者入驻成功,前去接单大厅接单',
  121. /*
  122. 申请人:周星星
  123. 申请时间:2021-10-16 00:00:00
  124. 状态:审核通过
  125. 备注:备注说明
  126. */
  127. 'fields' => ['thing2', 'time3', 'phrase4', 'thing5'],
  128. ],
  129. ];
  130. /**
  131. * 订阅消息
  132. * @param $user_id
  133. * @param $template_ids
  134. * @return mixed
  135. * @throws \Exception
  136. */
  137. public static function subMsg($user_id, $template_ids)
  138. {
  139. $template_ids = explode(',', $template_ids);
  140. foreach ($template_ids as $template_id) {
  141. if (!isset(self::MSG_MAP[$template_id])) {
  142. throw new \Exception('该模板消息未定义');
  143. }
  144. $data = [
  145. 'user_id' => $user_id,
  146. 'template_id' => $template_id,
  147. 'page' => self::MSG_MAP[$template_id]['page'] ?? '',
  148. ];
  149. }
  150. return true;
  151. }
  152. /**
  153. * @param $user_id
  154. * @param $template_id
  155. * @param array $param
  156. * @return array
  157. */
  158. public static function packMsg($user_id, $template_id, array $param = [])
  159. {
  160. $paramStr = http_build_query($param['param'] ?? []);
  161. $user = UserService::getOne(['id' => $user_id]);
  162. $page = $param['page'] ?? (self::MSG_MAP[$template_id]['page'] ?? '');
  163. return [
  164. 'template_id' => $template_id,
  165. 'touser' => $user->openid ?? '',
  166. 'page' => $page && $paramStr ? $page . '?' . $paramStr : $page,
  167. 'data' => self::packData($template_id, $param['values'] ?? []),
  168. ];
  169. }
  170. /**
  171. * @param $template_id
  172. * @param $values
  173. * @return array
  174. */
  175. public static function packData($template_id, $values): array
  176. {
  177. $fields = self::MSG_MAP[$template_id]['fields'] ?? [];
  178. foreach ($fields as $key => $field) {
  179. $param_data[$field] = ['value' => $values[$key] ?? ''];
  180. }
  181. return $param_data ?? [];
  182. }
  183. }