0) { $user_id = $post['user_id']; }else{ $user_id = \Yii::$app->user->identity->getId(); } $productOrder = ProductOrder::find()->where([ 'user_id' => $user_id, 'id' => $post['order_id'] ])->one(); if(!$productOrder || $productOrder->cancel_status){ throw new Exception('订单不存在'); } if($productOrder->is_pay == 1){ throw new Exception('订单无法取消'); } if($productOrder->order_type == 1){ $prescription = Prescription::findOne(['id' => $productOrder->p_id]); $prescription->cancel_status = 1; $prescription->cancel_time = time(); $prescription->cancel_remark = '主动取消订单'; $prescription->saveOrFail(); } $productOrder->status = ProductOrderEnum::CANCEL; $productOrder->cancel_status = 1; $productOrder->cancel_time = time(); $productOrder->cancel_remark = $remark; $productOrder->saveOrFail(); //药品库存回滚 $DrugRollBackForm = new DrugRollBackForm(); $DrugRollBackForm->rollBack($productOrder->order_type == 1?$productOrder->p_id:$productOrder->id, $productOrder->order_type); if($productOrder->is_online){ //平台订单状态同步 \Yii::$app->queue->push(new ProductOrderSyncPlatformJob([ 'orderId' => $productOrder->id, 'status' => 2 ])); } return ['取消成功']; } }