120 lines
3.6 KiB
PHP
120 lines
3.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021-5-13
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\api\models;
|
|
|
|
|
|
use app\components\SysConst;
|
|
use app\models\common\CommonPaymentSettingForm;
|
|
use app\models\common\payment\Payment;
|
|
use app\models\common\payment\PaymentOrder;
|
|
use app\models\Model;
|
|
use app\models\Order;
|
|
use app\models\PaymentTypes;
|
|
use app\models\StoreEarnings;
|
|
use app\models\User;
|
|
use app\models\sms\SmsMsgHelper;
|
|
use app\models\sms\SmsTpl;
|
|
use app\components\EncryptHelper;
|
|
|
|
class PaymentOrderForm extends ApiModel
|
|
{
|
|
public $cx_mch_id;
|
|
public $user_id;
|
|
public $id;
|
|
public $pay_type;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['cx_mch_id', 'user_id','id'], 'integer'],
|
|
[['id','pay_type'], 'string'],
|
|
[['cx_mch_id', 'user_id','id'], 'required'],
|
|
];
|
|
}
|
|
|
|
private function getPayType($cx_mch_id, $platform = 'wxmp')
|
|
{
|
|
$form = new CommonPaymentSettingForm();
|
|
$form->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;
|
|
}
|
|
|
|
} |