171 lines
5.2 KiB
PHP
171 lines
5.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年8月13日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\modules\api\controllers;
|
||
|
||
use app\modules\api\behaviors\LoginBehavior;
|
||
use app\components\SiteHelper;
|
||
use app\models\common\payment\Payment;
|
||
use app\models\common\payment\PaymentOrder;
|
||
use app\models\common\payment\PaymentActionForm;
|
||
use app\models\UniqueOrderNo;
|
||
use app\modules\api\models\PaymentOrderForm;
|
||
|
||
class PaymentController extends Controller
|
||
{
|
||
public function behaviors() {
|
||
return array_merge(parent::behaviors(),[
|
||
'login' => [
|
||
'class' => LoginBehavior::className(),
|
||
'ignore' => [
|
||
]
|
||
]
|
||
]);
|
||
}
|
||
|
||
// public function actionTest()
|
||
// {
|
||
// $paymentOrder = new PaymentOrder([
|
||
// 'orderNo' => UniqueOrderNo::generate(UniqueOrderNo::ORDER_TYPE_PAYMENT_ORDER, "\\app\\models\\PaymentOrder"),
|
||
// 'amount' => 1,
|
||
// 'title' => '购买商品',
|
||
// 'notifyClass' => '0',
|
||
// ]);
|
||
// $payment = new Payment();
|
||
// $paymentOrders[] = $paymentOrder;
|
||
// $data = $payment->createOrder($paymentOrders);
|
||
// return $this->responseHandler($data);
|
||
// }
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 收银台
|
||
* @title 支付数据
|
||
* @description 本接口提供支付数据
|
||
* @method post
|
||
* @url /api/payment/pay-data
|
||
* @param pay_id 必选 int 合并支付ID
|
||
* @param pay_type 必选 string 支付类型
|
||
* @param code 非必选 string 微信code
|
||
* @return
|
||
* @return_param param param_type param_desc
|
||
* @remark
|
||
*/
|
||
public function actionPayData()
|
||
{
|
||
if(!\Yii::$app->request->isPost){
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
if(!$this->lock->acquire()){
|
||
$data = ['code' => 1, 'msg' => '系统繁忙!稍后再试^v^!'];
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new PaymentActionForm();
|
||
$form->scenario = 'pay_data';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->wechat_mp = $this->wechat_mp;
|
||
$data = $form->payData();
|
||
$this->lock->release();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 收银台
|
||
* @title 余额支付
|
||
* @description 本接口提供余额支付
|
||
* @method post
|
||
* @url /api/payment/balance-pay
|
||
* @param pay_id 必选 int 合并支付ID
|
||
* @return
|
||
* @return_param param param_type param_desc
|
||
* @remark
|
||
*/
|
||
public function actionBalancePay()
|
||
{
|
||
if(!\Yii::$app->request->isPost){
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
if(!$this->lock->acquire()){
|
||
$data = ['code' => 1, 'msg' => '系统繁忙!稍后再试^v^!'];
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new PaymentActionForm();
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$data = $form->balancePay();
|
||
$this->lock->release();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 收银台
|
||
* @title 积分支付
|
||
* @description 本接口提供积分支付
|
||
* @method post
|
||
* @url /api/payment/integral-pay
|
||
* @param pay_id 必选 int 合并支付ID
|
||
* @return
|
||
* @return_param param param_type param_desc
|
||
* @remark
|
||
*/
|
||
public function actionIntegralPay()
|
||
{
|
||
if(!\Yii::$app->request->isPost){
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
if(!$this->lock->acquire()){
|
||
$data = ['code' => 1, 'msg' => '系统繁忙!稍后再试^v^!'];
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new PaymentActionForm();
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$data = $form->integralPay();
|
||
$this->lock->release();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 收银台
|
||
* @title 创建支付订单
|
||
* @description 创建支付订单
|
||
* @method post
|
||
* @url /api/payment/payment-order
|
||
* @param id 必选 string 订单id
|
||
* @param pay_type 必选 string 支付方式:微信支付=wxpay,微信支付分=wxpay_points
|
||
* @return {"code":0,"msg":"ok","data":{"pay_id":"1"}}
|
||
* @return_param data.pay_id string 合并支付ID
|
||
* @author LLB
|
||
*/
|
||
public function actionPaymentOrder()
|
||
{
|
||
if(!\Yii::$app->request->isPost){
|
||
$data = $this->invaildRequest();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$form = new PaymentOrderForm();
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->createPayment();
|
||
return $this->responseHandler($data);
|
||
|
||
}
|
||
}
|
||
|