71 lines
2.7 KiB
PHP
71 lines
2.7 KiB
PHP
<?php
|
|
namespace common\jobs\templateMessage;
|
|
|
|
use common\core\BaseModel;
|
|
use common\enums\PrescriptionEnum;
|
|
use common\jobs\BaseJob;
|
|
use common\models\Prescription;
|
|
use common\models\PrescriptionLog;
|
|
use common\services\WechatService;
|
|
use yii\base\Exception;
|
|
use yii\helpers\Json;
|
|
use yii\queue\JobInterface;
|
|
use yii\queue\Queue;
|
|
|
|
/**
|
|
* 处方订单生成支付提醒通知
|
|
*/
|
|
class PrescriptionCreated extends BaseJob implements JobInterface
|
|
{
|
|
public $orderId;
|
|
|
|
/**
|
|
* @param Queue $queue which pushed and is handling the job
|
|
*/
|
|
public function execute($queue)
|
|
{
|
|
PrescriptionLog::saveLog($this->orderId,'处方订单生成通知用户支付订阅消息发送队列 start');
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
$this->setRequest();
|
|
$Prescription = Prescription::find()->where([
|
|
'id' => $this->orderId
|
|
])->with(['user','doctorInfo','userPatient'])->one();
|
|
if (!$Prescription||!$Prescription->user||!$Prescription->doctorInfo) {
|
|
throw new Exception('处方不存在或已取消');
|
|
}
|
|
|
|
$result = WechatService::getInstance()->app->subscribe_message->send([
|
|
'touser' => $Prescription->user->openid,
|
|
'template_id' => \Yii::$app->params['template']['user']['prescription_created'],
|
|
'page' => 'subPackages/my/myrecord-detail?id='.$Prescription->id.'&no='.$Prescription->prescription_no,
|
|
'data' => [
|
|
'name1' => [
|
|
'value' => $Prescription->userPatient->name,
|
|
],
|
|
'thing2' => [
|
|
'value' => $Prescription->clinical_diagnose,
|
|
],
|
|
'name4' => [
|
|
'value' => $Prescription->doctorInfo->name,
|
|
],
|
|
'time9' => [
|
|
'value' => date('Y-m-d H:i:s',$Prescription->created_at),
|
|
],
|
|
'thing11' => [
|
|
'value' => '医生已为您开具处方,请尽快前往支付!',
|
|
]
|
|
]
|
|
]);
|
|
if(isset($result['errcode']) && $result['errcode']){
|
|
throw new Exception('发送失败,失败原因:'.$result['errmsg']);
|
|
}
|
|
PrescriptionLog::saveLog($this->orderId,'处方订单生成通知用户支付订阅消息发送队列 end');
|
|
} catch (\Exception $exception) {
|
|
$t->rollBack();
|
|
PrescriptionLog::saveLog($this->orderId,'处方订单生成通知用户支付订阅消息发送队列异常:'.$exception->getMessage());
|
|
return;
|
|
}
|
|
}
|
|
}
|