InformAdminService.php 2.1 KB

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