123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- namespace app\common\service;
- use think\Log;
- class SubscribeMessageService
- {
- const MSG_TEMP_DEMAND_RECEIVE = 'Ozqp33NFV4qgJQWMYnWUygx0V63cvyL02BiVflkP67o'; //接单成功
- const MSG_TEMP_DEMAND_MATCH_SUCCESS = 'zj8oNEXLfLyJxPA-wal9rpSkubnf1nXRRt-hX_rl98U'; //工单匹配成功
- const MSG_TEMP_DEMAND_SETTLE = 'NVTH7KEGZxVaXQaojmbXX8A_FP3RI8u56rgm9q_v37M'; //工单结算
- const MSG_TEMP_WORK_START = 'GWtWOOPsbpwocaOfvWy-pR5gbO3gI_5vxR_jmA6HJa0'; //项目开工
- const MSG_TEMP_WORK_ACCEPT = 'n6OCDU8zwI-JTNLDlXcXpKnKEgdDi-6ZnJaj-WAMou8'; //工单验收
- const MSG_TEMP_WORK_ACCEPT_RESULT = 'yaqaf5lGihxb8hf9qaV1_Ip2MgMg94DcutVXmBzZ3cg'; //验收结果
- const MSG_TEMP_CONTRACT_PAY = 'QRBIPCZUjMhBWkQDYkHCRVBRshXAv0fuzKbFUs2k5Og'; //合同付款
- const MSG_TEMP_CONTRACT_SIGN = 'mksLFWxPCFZmORvWof-4QWjHBbo0i274SAoY1XgmkCU'; //合同签约
- const MSG_TEMP_ORDER_SHIPPED = 'OzA14wCKihBZBrZUiaE-WpSVoFFSecun-vlDWUtEEEE'; //订单发货
- const MSG_TEMP_DEVELOPER_JOIN = 'ctqgNLWaHJ7RRnu9LwWTxu_g21lKil5v5Gv-Pg7XOE8'; //申请入驻
- const PAGE_DEMAND_LIST = 'pages/demand/list/index';
- const PAGE_ORDER_LIST = 'pages/order/order-list/index';
- const PAGE_HOME = 'pages/home/home';
- const MSG_MAP = [
- self::MSG_TEMP_DEMAND_RECEIVE => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我的报价需求列表
- 'remark' => '恭喜中标,请到我投标的需求确认接单!',
- /*
- 工单号:JG202003310001
- 服务项目:logo设计
- 任务名称:共享精英团队logo设计
- 备注:接单成功,请尽快安排排产
- */
- 'fields' => ['character_string1', 'thing9', 'thing10', 'thing4']
- ],
- self::MSG_TEMP_DEMAND_MATCH_SUCCESS => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
- 'remark' => '匹配工程师成功,请到需求详情查看沟通',
- /*
- 匹配服务方:字节
- 服务类别:安装预约
- 温馨提醒:您的工单已成功匹配,请您电话保持畅通。
- */
- 'fields' => ['thing1', 'phrase2', 'thing5'],
- ],
- self::MSG_TEMP_DEMAND_SETTLE => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
- 'remark' => '该工单已结算完成',
- /*
- 订单编号:200912162851392635fdbf4149
- 结算金额:99.9元
- 结算说明:订单已收货结算完成
- */
- 'fields' => ['character_string4', 'amount1', 'thing2'],
- ],
- self::MSG_TEMP_WORK_START => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
- 'remark' => '客户已支付预付款,可以开始工作',
- /*
- 项目名称:比克大厦四期
- 工作日期:2020.12.02 ~ 2020.12.08
- 备注:请在上下班时间安排对工人进行考勤
- */
- 'fields' => ['thing1', 'time2', 'thing4'],
- ],
- self::MSG_TEMP_WORK_ACCEPT => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
- 'remark' => '需求开发工作已完成,请前去验收成果',
- /*
- 工单编号:11021024307548
- 工单标题:电脑问题
- 验收内容:验收工单以及现场完工图
- 温馨提醒:登录平台确保验收,给予工程师中肯评价吧~
- */
- 'fields' => ['character_string1', 'thing8', 'thing2', 'thing5'],
- ],
- self::MSG_TEMP_WORK_ACCEPT_RESULT => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=myQuote', //我报价的需求列表
- 'remark' => '客户已验收并支付尾款,可以发送源码',
- 'remarkFail' => '客户验收未通过,请根据要求修改',
- /*
- 验收阶段:第一阶段(1/2)
- 验收结果:拒绝
- 备注:阶段结算金额7日后即可提现
- 原因:不符合需求描述的内容
- */
- 'fields' => ['thing1', 'thing3', 'thing5', 'thing4'],
- ],
- self::MSG_TEMP_CONTRACT_PAY => [
- 'page' => self::PAGE_ORDER_LIST, //我的订单列表
- 'remark' => '请到我的订单完成合同尾款支付',
- /*
- 项目名称:峰爆剧组
- 合同编号:Q001
- 结算金额:1.23元
- 结算周期:2025.01.01~2025.03.31
- 备注:您有以上合同需要付款,请及时发起流程
- */
- 'fields' => ['thing1', 'character_string2', 'amount5', 'time4', 'thing3'],
- ],
- self::MSG_TEMP_CONTRACT_SIGN => [
- 'page' => self::PAGE_DEMAND_LIST . '?opType=my', //我发布的需求列表
- 'remark' => '需求已确认,请前去完成合同签约',
- /*
- 合同编号:2019年合字001号
- 项目名称:某某项目
- 签约金额:3000
- 备注:【签约成功】请及时缴纳首期款办理入住
- */
- 'fields' => ['thing1', 'thing2', 'amount12', 'thing5'],
- ],
- self::MSG_TEMP_ORDER_SHIPPED => [
- 'page' => self::PAGE_ORDER_LIST, //订单列表
- 'remark' => '发货成功,请到订单详情查看激活码',
- /*
- 订单号:A12345678984
- 商品名称:2019秋冬女装春装新款上衣连衣裙加绒蕾丝
- 订单状态:充值成功
- 备注:快递配送中,请留意电话或者短信
- */
- 'fields' => ['character_string2', 'thing1', 'phrase19', 'thing6'],
- ],
- self::MSG_TEMP_DEVELOPER_JOIN => [
- 'page' => self::PAGE_HOME, //首页
- 'remark' => '开发者入驻成功,前去接单大厅接单',
- /*
- 申请人:周星星
- 申请时间:2021-10-16 00:00:00
- 状态:审核通过
- 备注:备注说明
- */
- 'fields' => ['thing2', 'time3', 'phrase4', 'thing5'],
- ],
- ];
- /**
- * 订阅消息
- * @param $user_id
- * @param $template_ids
- * @return mixed
- * @throws \Exception
- */
- public static function subMsg($user_id, $template_ids)
- {
- $template_ids = explode(',', $template_ids);
- foreach ($template_ids as $template_id) {
- if (!isset(self::MSG_MAP[$template_id])) {
- throw new \Exception('该模板消息未定义');
- }
- $data = [
- 'user_id' => $user_id,
- 'template_id' => $template_id,
- 'page' => self::MSG_MAP[$template_id]['page'] ?? '',
- ];
- }
- return true;
- }
- /**
- * @param $user_id
- * @param $template_id
- * @param array $param
- * @return array
- */
- public static function packMsg($user_id, $template_id, array $param = [])
- {
- $paramStr = http_build_query($param['param'] ?? []);
- $user = UserService::getOne(['id' => $user_id]);
- $page = $param['page'] ?? (self::MSG_MAP[$template_id]['page'] ?? '');
- return [
- 'template_id' => $template_id,
- 'touser' => $user->openid ?? '',
- 'page' => $page && $paramStr ? $page . '?' . $paramStr : $page,
- 'data' => self::packData($template_id, $param['values'] ?? []),
- ];
- }
- /**
- * @param $template_id
- * @param $values
- * @return array
- */
- public static function packData($template_id, $values): array
- {
- $fields = self::MSG_MAP[$template_id]['fields'] ?? [];
- foreach ($fields as $key => $field) {
- $param_data[$field] = ['value' => $values[$key] ?? ''];
- }
- return $param_data ?? [];
- }
- }
|