| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace bizGhs\ws\services;
- use biz\shop\classes\ShopAdminClass;
- use biz\sj\classes\SjClass;
- use common\components\baiduAip;
- use common\components\dict;
- use common\components\goWs;
- use common\components\imgUtil;
- use common\components\oss;
- use common\components\util;
- use GatewayClient\Gateway;
- use Yii;
- class WsService
- {
- //到账通知 $adminId 为 shopAdminId
- public static function arrivalNotice($adminId, $money, $payWay)
- {
- //暂时关闭通知,请勿打开 ssh 20210726
- return true;
- $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
- $msg = $payment . '收款' . $money . '元';
- $audio = baiduAip::transfer($msg, 4, 0);
- Yii::info("触发到账通知:" . $adminId . " " . $money);
- if (!is_array($audio)) {
- try {
- //上传到oss
- $file = time() . rand(10000, 999999) . '.mp3';
- $filePath = 'tmp/arrival/money/' . $file;
- oss::uploadTmpAudio($filePath, $audio);
- //收款暂时只有零售平台有
- $url = Yii::$app->params['hdImgHost'] . $filePath;
- // $audio = base64_encode($audio);
- $data = ['type' => 'money', 'url' => $url, 'msg' => $msg, 'money' => $money];
- $dataString = json_encode($data);
- goWs::sendToUid($adminId, $dataString);
- //判断是否在线
- // $online = Gateway::isUidOnline($adminId);
- //Gateway::sendToUid($adminId, json_encode($data));
- //$client = Gateway::getClientIdByUid($adminId);
- //Yii::info("getClientIdByUid res :".json_encode($client));
- } catch (\Exception $exception) {
- Yii::warning("ws arrivalNotice error " . $exception->getMessage());
- }
- } else {
- Yii::warning("到账通知 语音获取失败" . json_encode($audio));
- }
- return true;
- }
- //零售端采购时,提示供货商(下所有有开启通知的员工),你有新订单
- //商城客户下单时,提示零售花店(下所有有开启通知的员工) 你有新的订单
- public static function newOrderNotice($shopAdminId)
- {
- return true;
- $shopAdmin = ShopAdminClass::getById($shopAdminId, true);
- if (empty($shopAdmin)) {
- return false;
- }
- $sjId = $shopAdmin->sjId;
- $sj = SjClass::getById($sjId, true);
- $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
- $prefix = '';
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $prefix = Yii::$app->params['hdImgHost'];
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $prefix = Yii::$app->params['ghsImgHost'];
- } elseif ($ptStyle == dict::getDict('ptStyle', 'mall')) {
- $prefix = Yii::$app->params['mallImgHost'];
- } else {
- util::fail('平台无效');
- }
- $url = $prefix . 'audio/new_order0.mp3';
- $data = [
- 'type' => 'new_order',
- 'url' => $url,
- ];
- Yii::info("触发订单通知:" . $shopAdminId);
- try {
- //判断是否在线
- //$online = Gateway::isUidOnline($shopAdminId);
- $dataString = json_encode($data);
- goWs::sendToUid($shopAdminId, $dataString);
- //Gateway::sendToUid($shopAdminId, json_encode($data));
- // if($online){
- //
- // }else{
- // Yii::info("用户不在线:".$shopAdminId);
- // }
- } catch (\Exception $exception) {
- Yii::warning("ws arrivalNotice error " . $exception->getMessage());
- }
- return true;
- }
- }
|