diff --git a/admin/controllers/OpenApiController.php b/admin/controllers/OpenApiController.php index 6af1822..7dced2c 100644 --- a/admin/controllers/OpenApiController.php +++ b/admin/controllers/OpenApiController.php @@ -12,6 +12,7 @@ use common\jobs\ProductOrderSyncJob; use common\jobs\Sms\WaitApprovalMessageJob; use common\jobs\templateMessage\PrescriptionCreated; use common\models\oldDb\Prescription; +use common\models\oldDb\PrescriptionLog; use common\models\oldDb\ProductOrder; use common\models\oldDb\ProductOrderLog; use common\models\oldDb\Reconciliation; @@ -20,6 +21,7 @@ use common\models\oldDb\Store; use common\models\oldDb\User; use common\services\JacErpService; use common\services\WeappService; +use common\services\WechatService; use yii\db\ActiveRecord; use yii\db\Exception; use yii\helpers\Json; @@ -38,6 +40,7 @@ class OpenApiController extends BaseAdminController { $prescription = \Yii::$app->request->post('prescription'); + $this->sendUserNote($prescription); //处方开具待支付订阅消息通知 \Yii::$app->queue->push(new PrescriptionCreated([ 'orderId' => $prescription, @@ -45,12 +48,83 @@ class OpenApiController extends BaseAdminController //处方生成短信通知药师审方 - \Yii::$app->queue->push(new WaitApprovalMessageJob([ - 'orderId' => $prescription, - ])); +// \Yii::$app->queue->push(new WaitApprovalMessageJob([ +// 'orderId' => $prescription, +// ])); return ['ok']; } + public function sendUserNote($orderId) + { + + PrescriptionLog::saveLog($orderId,'处方订单生成通知用户支付订阅消息发送队列 start'); + $t = \Yii::$app->db->beginTransaction(); + try { + $this->setRequest(); + $Prescription = Prescription::find()->where([ + 'id' => $orderId + ])->with(['user','doctorInfo','userPatient'])->one(); + if (!$Prescription||!$Prescription->user||!$Prescription->doctorInfo) { + throw new \yii\base\Exception('处方不存在或已取消'); + } + + PrescriptionLog::saveLog($orderId,'处方订单生成通知用户支付订阅消息发送队列 load'); + PrescriptionLog::saveLog($orderId,json_encode([ + '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' => '医生已为您开具处方,请尽快前往支付!', + ] + ] + ])); + PrescriptionLog::saveLog($orderId,'处方订单生成通知用户支付订阅消息发送队列 load end'); + $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($orderId,'处方订单生成通知用户支付订阅消息发送队列 end'); + } catch (\Exception $exception) { + $t->rollBack(); + PrescriptionLog::saveLog($orderId,'处方订单生成通知用户支付订阅消息发送队列异常:'.$exception->getMessage()); + return; + } + } + /** * 处理处方过期 * @return string[]