canyin-project/ybcy/models/common/Voice.php
2024-11-01 16:07:54 +08:00

101 lines
3.6 KiB
PHP

<?php
namespace app\models\common;
use Yii;
use yii\base\Model;
use yii\db\ActiveRecord;
use yii\db\Expression;
use app\models\common\Config;
class Voice extends ActiveRecord{
/**
*
* @param $uniacid 小程序ID
* @param $storeId 商户Id
* @param int $type 1 外卖类型,2店内类型
* @param null $item 播放语音类型
* @param null $datas 数组 ['orderNumber'=>'1333','money'=>'100','variety'=>'这里是菜品']
* @param null $message 试听使用
* @return mixed
* @author Administrator
* @date 2020-12-02 16:14
*/
static function noticeVoice($uniacid,$storeId,$type=1,$item=null,$datas=null,$message=null){
$config=Config::getStoreSet('voice', $storeId,$uniacid);
$result=[];
if($item) {
$where = array(
'deleteAt' => 0,
'uniacid' => $uniacid,
'storeId' => $storeId,
'type' => $type
);
$data = (new \yii\db\Query())
->from('{{%ybwm_voice_notice}}')
->where($where)
->one();
$message = json_decode($data['message'], true);
$message=$message[0];
if($message){
foreach ($message as &$v) {
$v = str_replace("orderNumber", $datas['orderNumber'], $v);
$v = str_replace("money", $datas['money'], $v);
$v = str_replace("variety", $datas['variety'], $v);
$v = str_replace("takeNo", $datas['takeNo'], $v);
$v = str_replace("table", $datas['table'], $v);
}
}
$content = '测试播放';
switch ($item) {
case 'newOrder':
$content = $message['newOrder'];
break;
case 'advanceOrder':
$content = $message['advanceOrder'];
break;
case 'reminder':
$content = $message['reminder'];
break;
case 'chargeback':
$content = $message['chargeback'];
break;
case 'afterSale':
$content = $message['afterSale'];
break;
case 'fastNewOrder':
$content = $message['fastNewOrder'];
break;
case 'fastPickOrder':
$content = $message['fastPickOrder'];
break;
case 'inNewOrder':
$content = $message['inNewOrder'];
break;
case 'inOutOrder':
$content = $message['inOutOrder'];
break;
case 'collection':
$content = $message['collection'];
break;
}
}else{
$content=$message;
$content = str_replace("orderNumber", 1233, $content);
$content = str_replace("money", 10, $content);
$content = str_replace("variety", '商品一', $content);
$content = str_replace("takeNo", 'A001', $content);
$content = str_replace("table", '大厅-圆桌-Y001', $content);
}
if($content){
$sn=$config['sn']?:'31006345';
$speed=$config['speed']?:'55';
$token=$config['token']?:'105827801114';
$version=$config['version']?:1;
$url="https://speaker.17laimai.cn/notify.php?id=".$sn."&token=".$token."&message=".$content."&speed=".$speed."&version=".$version;
$result=httpRequest($url);
}
return $result;die;
}
}