Browse Source

新订单通知

shish 7 months ago
parent
commit
76e697e985
1 changed files with 30 additions and 19 deletions
  1. 30 19
      common/components/push.php

+ 30 - 19
common/components/push.php

@@ -1,6 +1,8 @@
 <?php
+
 namespace common\components;
 
+use bizGhs\custom\classes\CustomClass;
 use yii\db\ActiveRecord;
 use Yii;
 
@@ -22,7 +24,8 @@ class push
     private $client = '';
     private $msgType = '';
 
-    public function __construct($client, $msgType) {
+    public function __construct($client, $msgType)
+    {
         $this->client = $client;
         if ($client == 'ghs') {
             $this->url = self::GHS_URL;
@@ -38,7 +41,8 @@ class push
      * 实现部分厂商特定功能,包括仅部分厂商支持、不常用或厂商临时新增的功能(不依赖 uni-push,厂商文档支持的参数可直接使用)。
      * 例如:推送渠道 ID、消息分类(部分厂商未配置时可能被限量推送或静默推送,即静音且需下拉系统通知栏才可见通知内容)、通知栏富文本
      */
-    public function getOptions($client) {
+    public function getOptions($client)
+    {
         if ($client == 'ghs') {
             return $this->initGhsOptions();
         }
@@ -50,11 +54,12 @@ class push
      * 花店的厂商options
      * @return array
      */
-    public function initHdOptions() {
+    public function initHdOptions()
+    {
         $optionsArr = [];
         switch ($this->msgType) {
             case self::MSG_TYPE_ORDER:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142737" //小米后台申请的通知类别id -- https://admin.xmpush.xiaomi.com/zh_CN/channel/list?appId=2882303761520146676
@@ -69,7 +74,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_LOGISTICS:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142737"
@@ -84,7 +89,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_ACCOUNT:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "143019"
@@ -99,7 +104,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_WORK:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "143018"
@@ -114,7 +119,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_SUBSCRIPTION:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "0" // TODO 暂无
@@ -143,11 +148,12 @@ class push
      * 批发商的厂商options
      * @return array
      */
-    public function initGhsOptions() {
+    public function initGhsOptions()
+    {
         $optionsArr = [];
         switch ($this->msgType) {
             case self::MSG_TYPE_ORDER:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142743" //小米后台申请的通知类别id -- https://admin.xmpush.xiaomi.com/zh_CN/channel/list?appId=2882303761520146676
@@ -162,7 +168,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_LOGISTICS:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142744"
@@ -177,7 +183,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_ACCOUNT:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142895"
@@ -192,7 +198,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_WORK:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "142892"
@@ -207,7 +213,7 @@ class push
                 ];
                 break;
             case self::MSG_TYPE_SUBSCRIPTION:
-                $optionsArr = [ "android" =>
+                $optionsArr = ["android" =>
                     [
                         "XM" => [
                             "/extra.channel_id" => "0" // TODO 暂无
@@ -231,9 +237,9 @@ class push
 
         $optionsArr = $this->getOptions($this->client);
         // 测试环境的特殊处理
-        if ( getenv('YII_ENV') == 'dev') {
+        if (getenv('YII_ENV') == 'dev') {
             $optionsArr["android"]["HW"]["/message/android/target_user_type"] = 1; //华为 -- 值为int 类型。1 表示华为测试消息,华为每个应用每日可发送该测试消息500条,此target_user_type 参数请勿发布至线上。
-            $optionsArr["android"]["VV"]["/pushMode"] =  1;                 //VIVO  --  值为int 类型。0 表示正式推送;1 表示测试推送,不填默认为0。线上请勿使用测试推送
+            $optionsArr["android"]["VV"]["/pushMode"] = 1;                 //VIVO  --  值为int 类型。0 表示正式推送;1 表示测试推送,不填默认为0。线上请勿使用测试推送
             $optionsArr["android"]["HO"]["/android/targetUserType"] = 1;    //荣耀  -- 值为int 类型。1 表示测试推送,不填默认为0。荣耀每个应用每日可发送该测试消息1000条。此测试参数请勿发布至线上。
         }
 
@@ -285,11 +291,16 @@ class push
     public function ghsOrderMessage($shop, $cgShop, $order)
     {
         try {
-            $allDevices = \bizGhs\device\classes\GhsDeviceClass::getAllByCondition(['shopId'=>$shop->id]);
+            $allDevices = \bizGhs\device\classes\GhsDeviceClass::getAllByCondition(['shopId' => $shop->id]);
             $cids = array_column($allDevices, 'clientId');
             $title = '你有新的订单';
-            $shopName = $cgShop->merchantName . ($cgShop->shopName != '首店' ? '(' . $cgShop->shopName . ')' : '');
-            $content = $shopName . ' ¥' . $order->actPrice;
+
+            $customId = $order->customId ?? 0;
+            $custom = CustomClass::getById($customId, true);
+            $customName = $custom->name ?? '';
+
+            $content = $customName . ' ¥' . $order->actPrice;
+            noticeUtil::push($content, '15280215347');
             $payload = [
                 "page" => "pagesOrder/detail",
                 "params" => ["id" => $order->id]