WsService.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace bizGhs\ws\services;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\sj\classes\SjClass;
  5. use common\components\baiduAip;
  6. use common\components\dict;
  7. use common\components\goWs;
  8. use common\components\imgUtil;
  9. use common\components\oss;
  10. use common\components\util;
  11. use GatewayClient\Gateway;
  12. use Yii;
  13. class WsService
  14. {
  15. //到账通知 $adminId 为 shopAdminId
  16. public static function arrivalNotice($adminId, $money, $payWay)
  17. {
  18. //暂时关闭通知,请勿打开 ssh 20210726
  19. return true;
  20. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  21. $msg = $payment . '收款' . $money . '元';
  22. $audio = baiduAip::transfer($msg, 4, 0);
  23. Yii::info("触发到账通知:" . $adminId . " " . $money);
  24. if (!is_array($audio)) {
  25. try {
  26. //上传到oss
  27. $file = time() . rand(10000, 999999) . '.mp3';
  28. $filePath = 'tmp/arrival/money/' . $file;
  29. oss::uploadTmpAudio($filePath, $audio);
  30. //收款暂时只有零售平台有
  31. $url = Yii::$app->params['hdImgHost'] . $filePath;
  32. // $audio = base64_encode($audio);
  33. $data = ['type' => 'money', 'url' => $url, 'msg' => $msg, 'money' => $money];
  34. $dataString = json_encode($data);
  35. goWs::sendToUid($adminId, $dataString);
  36. //判断是否在线
  37. // $online = Gateway::isUidOnline($adminId);
  38. //Gateway::sendToUid($adminId, json_encode($data));
  39. //$client = Gateway::getClientIdByUid($adminId);
  40. //Yii::info("getClientIdByUid res :".json_encode($client));
  41. } catch (\Exception $exception) {
  42. Yii::warning("ws arrivalNotice error " . $exception->getMessage());
  43. }
  44. } else {
  45. Yii::warning("到账通知 语音获取失败" . json_encode($audio));
  46. }
  47. return true;
  48. }
  49. //零售端采购时,提示供货商(下所有有开启通知的员工),你有新订单
  50. //商城客户下单时,提示零售花店(下所有有开启通知的员工) 你有新的订单
  51. public static function newOrderNotice($shopAdminId)
  52. {
  53. return true;
  54. $shopAdmin = ShopAdminClass::getById($shopAdminId, true);
  55. if (empty($shopAdmin)) {
  56. return false;
  57. }
  58. $sjId = $shopAdmin->sjId;
  59. $sj = SjClass::getById($sjId, true);
  60. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  61. $prefix = '';
  62. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  63. $prefix = Yii::$app->params['hdImgHost'];
  64. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  65. $prefix = Yii::$app->params['ghsImgHost'];
  66. } elseif ($ptStyle == dict::getDict('ptStyle', 'mall')) {
  67. $prefix = Yii::$app->params['mallImgHost'];
  68. } else {
  69. util::fail('平台无效');
  70. }
  71. $url = $prefix . 'audio/new_order0.mp3';
  72. $data = [
  73. 'type' => 'new_order',
  74. 'url' => $url,
  75. ];
  76. Yii::info("触发订单通知:" . $shopAdminId);
  77. try {
  78. //判断是否在线
  79. //$online = Gateway::isUidOnline($shopAdminId);
  80. $dataString = json_encode($data);
  81. goWs::sendToUid($shopAdminId, $dataString);
  82. //Gateway::sendToUid($shopAdminId, json_encode($data));
  83. // if($online){
  84. //
  85. // }else{
  86. // Yii::info("用户不在线:".$shopAdminId);
  87. // }
  88. } catch (\Exception $exception) {
  89. Yii::warning("ws arrivalNotice error " . $exception->getMessage());
  90. }
  91. return true;
  92. }
  93. }