InformAdminService.php 2.4 KB

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