allocatr/application/common/Logic/NoticeLogic.php
2025-06-06 15:49:46 +08:00

111 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\Logic;
use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\SingleCallByTtsResponse;
use app\common\model\OrderDispatch;
use app\common\services\alibaba\DyvmsService;
use think\Exception;
/**
* 通知
*/
class NoticeLogic
{
const TTS_DISPATCH1 ='TTS_313465270'; //手动派单通知
const TTS_DISPATCH2 ='TTS_313485240'; //手动派单通知
const TTS_OVER_FINISHED = 'TTS_315365191'; //完成时间已过
const TTS_GOGOGO = 'TTS_313570203'; //上门前一小时打电话通知师傅
public function __construct($types = [])
{
}
public function callIt($log)
{
$dispatch = OrderDispatch::get($log->dispatch_id);
//1=派单2=提前通知3=超时通知
$ttsCode = null;
$dispatch->tts_check_time = date('Y-m-d H:i:s',time()+5*60);
if($log->type == 1)
{
$dispatch->tts_notice = 1;
if($dispatch->type == 1){
$ttsCode = self::TTS_DISPATCH1;
$dispatch->save();
}else{
$ttsCode = self::TTS_DISPATCH2;
}
}elseif($log->type == 2)
{
$dispatch->tts_notice = 2;
$ttsCode = self::TTS_GOGOGO;
}elseif($log->type == 3){
$dispatch->tts_notice = 3;
$ttsCode = self::TTS_OVER_FINISHED;
}
if(empty($ttsCode)){
$log->status = -1;
$log->content = 'TTSID为空';
$log->save();
return;
}
$status = config('alibaba_dyvms.status');
if($status){
$reponse = DyvmsService::getInstance()->call($dispatch->worker_tel, $ttsCode, md5(time()));
if($reponse->statusCode == 200 && $reponse->body->code == 'OK'){
$log->status = 1;
$log->callId = $reponse->body->callId;
$log->save();
}else{
$log->status = -1;
$log->content = $reponse->body->message;
$log->save();
}
}else{
$log->status = -1;
$log->content = 'TTSID为空';
$log->save();
//throw new Exception('语音通知服务未开启');
}
}
/**
* 派单通知
* @return SingleCallByTtsResponse|array
*/
public function dispatchNotice($dispatch): array|SingleCallByTtsResponse
{
if($dispatch->type == 1){
$ttsCode = self::TTS_DISPATCH1;
}else{
$ttsCode = self::TTS_DISPATCH2;
}
try {
$reponse = DyvmsService::getInstance()->call($dispatch->worker_tel, $ttsCode, md5(time()));
}catch (Exception $exception){
throw $exception;
}
return $reponse;
}
/**
* 超时通知
* @return void
*/
public function overTimeNotice(){
}
}