cx_mch_id = $cx_mch_id; $res = $form->search(); $pay_type_list = $res['pay_types']; $pay_types = []; foreach($pay_type_list as $index => $item){ if(!$item['is_show'] || !$item['is_open']) continue; //排除 if(in_array($item['short_name'], [SysConst::$cxPayTypeEnBalance, SysConst::$cxPayTypeEnBank])) continue; //@TODO 根据平台来源显示支付方式 $pay_types[] = $item; } return $pay_types; } //创建支付订单 public function createPayment() { if(!$this->validate()){ return $this->getModelError(); } //支付方式检查 $pay_types = $this->getPayType($this->cx_mch_id); if(!in_array($this->pay_type, array_column($pay_types, 'short_name'))){ return $this->apiReturnError('不支持此支付方式'); } $paymentOrders = []; $order = Order::findOne(['id' => $this->id,'user_id' => $this->user_id]); if(empty($order)){ return Model::asReturnError("订单不存在"); } $t = \Yii::$app->db->beginTransaction(); $title = ''; $notifyClass = ''; if($order->plugin_sign == SysConst::$cxPluginSceneBallCart){ $title = '球车租赁'; $notifyClass = '\\app\\models\\common\\notify\\payment\\BallCartPayMentNotify'; } elseif($order->plugin_sign == SysConst::$cxPluginSceneDeposit){ $title = '缴纳押金'; $notifyClass = '\\app\\models\\common\\notify\\payment\\DepositPayMentNotify'; }else{ return Model::asReturnError("支付项目异常"); } if(empty($title) || empty($notifyClass)){ $t->rollBack(); return Model::asReturnError("支付数据异常"); } $paymentOrder = new PaymentOrder([ 'orderNo' => $order->order_no, 'amount' => (float) $order->total_price, 'title' => $title, 'notifyClass' => $notifyClass, 'supportPayTypes' => array_column($pay_types, 'short_name'), 'payType' => PaymentTypes::payTypeKeyToId($this->pay_type) ]); $payment = new Payment(); $paymentOrders[] = $paymentOrder; $res = $payment->createOrder($paymentOrders); if($res['code'] != 0){ $t->rollBack(); return $res; } $t->commit(); return $res; } }