request->post('prescription'); //处方开具待支付订阅消息通知 $this->sendUserNote($prescription); // //处方开具待支付订阅消息通知 // \Yii::$app->queue->push(new PrescriptionCreated([ // '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[] * @throws \yii\base\Exception */ public function prescriptionOver(): array { $orderId = \Yii::$app->request->post('order_id'); $userId = \Yii::$app->request->post('user_id'); $type = \Yii::$app->request->post('type'); if($type === 1){ // 自动退款 $ProductRefundForm = new ProductRefundForm(); $ProductRefundForm->refund([ 'order_id' => $orderId, 'user_id' => $userId ]); } else { // 订单自动失效 $ProductCancelForm = new ProductCancelForm(); $ProductCancelForm->cancel([ 'order_id' => $orderId, 'user_id' => $userId ], '处方失效,订单自动失效'); } return ['ok']; } public function actionSendOrder() { // 订单自动同步任务 \Yii::$app->queue->push(new ProductOrderSyncJob([ 'orderId' => 126, ])); } public function getWeChatQrCode() { $id = \Yii::$app->request->post('id'); $store = Store::find()->where(['id' => $id])->one(); if (!$store) { return ['error' => '店铺不存在']; } if (!$store->qr_code) { $scene = 'STORE_QR_CODE'.'_'.$this->id; $weappService = new WeappService(); $url= $weappService->getQrcode($scene); $store->qr_code=$url; $store->saveOrFail(); return ['ok']; } return ['']; } }