InformAdminService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace biz\message\services;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\classes\ShopAdminClass;
  5. use biz\admin\services\AdminService;
  6. use biz\admin\services\ShopAdminService;
  7. use biz\base\services\BaseService;
  8. use biz\merchant\services\MerchantService;
  9. use biz\message\classes\InformAdminClass;
  10. use biz\wx\services\WxOpenService;
  11. use common\components\sms;
  12. use common\components\util;
  13. use common\components\wxUtil;
  14. use common\services\xhTMessageService;
  15. use Yii;
  16. class InformAdminService extends BaseService
  17. {
  18. public static $baseFile = '\biz\message\classes\InformAdminClass';
  19. //通知管理员 shish 2020.1.1
  20. public static function addInform($shopId, $type, $params)
  21. {
  22. $shopAdminList = ShopAdminService::getNoticeAdminList($shopId);
  23. if (empty($shopAdminList)) {
  24. return false;
  25. }
  26. //本地环境取消通知
  27. if (getenv('YII_ENV') == 'local') {
  28. return false;
  29. }
  30. $TMList = TMessageService::getOpenList();
  31. foreach ($shopAdminList as $adminKey => $shopAdmin) {
  32. InformAdminClass::addInform($params, $shopAdmin, $type, $TMList);
  33. }
  34. }
  35. //消费通知内容 shish 2020.1.1
  36. //['messageType'=>'inform','informWay'=>'miniProgram','userType'=>'admin','shopAdminId'=>913,'mobile'=>'15280215347','tMessage'=>'','content'=>'','briefContent'=>'','isOpen'=>1]
  37. public static function consumeInformQueue($data)
  38. {
  39. $informWay = $data['informWay'];
  40. $shopAdminId = isset($data['shopAdminId']) ? $data['shopAdminId'] : 0;
  41. if (empty($shopAdminId)) {
  42. echo "\n 没有找到门店管理员 \n";
  43. util::end();
  44. }
  45. $shopAdmin = ShopAdminClass::getById($shopAdminId);
  46. $merchantId = $shopAdmin['merchantId'];
  47. $adminId = $shopAdmin['adminId'];
  48. $mobile = $data['mobile'];
  49. $isOpen = isset($data['isOpen']) ? $data['isOpen'] : 0;
  50. $merchant = WxOpenService::getWxInfo();
  51. $hasSend = 0;
  52. $noticeWay = 0;
  53. if ($informWay == 'wx') {
  54. $tMessage = json_decode($data['tMessage'], true);
  55. $r = wxUtil::sendTaskInform($tMessage, $merchant, $isOpen);
  56. print_r($r);
  57. $hasSend = 1;
  58. $noticeWay = 0;
  59. } elseif ($informWay == 'sms') {
  60. $msg = $data['content'];
  61. sms::merchantSend($mobile, $msg, $merchant);
  62. $hasSend = 1;
  63. $noticeWay = 1;
  64. } elseif ($informWay == 'miniProgram') {
  65. $tMessage = json_decode($data['tMessage'], true);
  66. $r = wxUtil::sendTaskInform($tMessage, $merchant);
  67. print_r($r);
  68. $hasSend = 1;
  69. $noticeWay = 0;
  70. } else {
  71. }
  72. //存入数据库
  73. $informData = [
  74. 'adminId' => $adminId,
  75. 'merchantId' => $merchantId,
  76. 'noticeType' => 0,
  77. 'content' => $data['briefContent'],
  78. 'noticeWay' => $noticeWay,
  79. 'status' => $hasSend,
  80. 'sourceType' => 0,
  81. 'sourceId' => 0,
  82. 'addTime' => time(),
  83. 'createTime' => date("Y-m-d H:i:s"),
  84. ];
  85. InformAdminClass::addData($informData);
  86. return true;
  87. }
  88. }