170 lines
6.2 KiB
PHP
170 lines
6.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年6月8日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\modules\api\controllers;
|
||
|
||
use app\modules\api\behaviors\LoginBehavior;
|
||
use app\components\SiteHelper;
|
||
use app\components\SysConst;
|
||
use app\models\common\CommonBalanceLogListForm;
|
||
use app\models\common\CommonBalanceLogActionForm;
|
||
use app\models\common\CommonRechargeActionForm;
|
||
use app\models\Balance;
|
||
|
||
class BalanceController extends Controller
|
||
{
|
||
public function behaviors() {
|
||
return array_merge(parent::behaviors(),[
|
||
'login' => [
|
||
'class' => LoginBehavior::className(),
|
||
'ignore' => [
|
||
]
|
||
]
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息/钱包余额
|
||
* @title 钱包余额明细列表
|
||
* @description 本接口提供钱包余额明细
|
||
* @method get
|
||
* @url /api/balance/log
|
||
* @param keywords 非必选 string 关键词
|
||
* @param page 必选 int 页码
|
||
* @param limit 非必选 int 每页记录数
|
||
* @param year 非必选 string 年份,格式YYYY
|
||
* @param month 非必选 string 月份,格式MM
|
||
* @param type 非必选 string 类型,1=充值记录2=消费记录3=退款记录4=入账记录
|
||
* @return {"code":0,"msg":"ok","data":[{"nickname":"admin","avatar_url":"http://app.tpl.dev.1nww.com/statics/images/avatar.jpg","real_name":"","id":"3","cx_mch_id":"0","user_id":"1","type":"1","scene":"0","money":"10.10","before_account_balance":"20.20","after_account_balance":"30.30","desc":"新用户注册","order_type":"0","order_no":"111111111","ext":"","created_at":"1623146573","created_at_cn":"2021-06-08 18:02:53"}],"count":"3","page_size":20,"page_count":1,"page_no":1,"end_flag":false}
|
||
* @return_param count int 记录条数
|
||
* @return_param page_size int 每页记录数
|
||
* @return_param page_count int 总页数
|
||
* @return_param page_no int 当前页码
|
||
* @return_param end_flag bool 是否加载结束
|
||
* @remark
|
||
*/
|
||
public function actionLog()
|
||
{
|
||
$form = new CommonBalanceLogListForm();
|
||
$form->scenario = 'user';
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->scene = Balance::$cxBalanceSceneUserWallet;
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->search2();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* hidedoc
|
||
* @catalog 用户信息/钱包余额
|
||
* @title 钱包余额明细详情
|
||
* @description 本接口提供钱包余额明细详情
|
||
* @method get
|
||
* @url /api/balance/log-detail
|
||
* @param blog_id 必选 int 钱包明细ID
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @return_param after_account_balance number 变化后账户余额
|
||
* @remark
|
||
*/
|
||
public function actionLogDetail()
|
||
{
|
||
$form = new CommonBalanceLogListForm();
|
||
$form->scenario = 'detail';
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->scene = Balance::$cxBalanceSceneUserWallet;
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$res = $form->search();
|
||
if($res['code'] != 0)
|
||
return $this->responseHandler($res);
|
||
if(count($res['data']) == 0)
|
||
return $this->responseHandler(['code' => 1, 'msg' => '钱包明细详情不存在']);
|
||
$data = [
|
||
'code' => 0,
|
||
'msg' => 'ok',
|
||
'data' => $res['data'][0]
|
||
];
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* hidedoc
|
||
* @catalog 用户信息/钱包余额
|
||
* @title 删除钱包余额明细
|
||
* @description 本接口提供删除钱包余额明细详情
|
||
* @method post
|
||
* @url /api/balance/log-delete
|
||
* @param blog_id 必选 int 钱包明细ID
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @return_param * *
|
||
* @remark
|
||
*/
|
||
public function actionLogDelete()
|
||
{
|
||
$form = new CommonBalanceLogActionForm();
|
||
$form->scenario = 'delete';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->scene = Balance::$cxBalanceSceneUserWallet;
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->delete();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 用户信息/钱包余额
|
||
* @title 钱包余额充值
|
||
* @description 本接口提供钱包余额充值
|
||
* @method post
|
||
* @url /api/balance/recharge
|
||
* @param money 必选 number 充值金额
|
||
* @param pay_type 必选 string 支付方式,固定wxpay
|
||
* @param rule_id 非必选 int 充值方案ID
|
||
* @return {"code":0,"msg":"ok","data":{}}
|
||
* @return_param recharge_rules array 充值方案
|
||
* @return_param pay_types array 支持支付类型
|
||
* @remark get请求获取充值方案以及支持支付方式
|
||
*/
|
||
public function actionRecharge()
|
||
{
|
||
$form = new CommonRechargeActionForm();
|
||
if(\Yii::$app->request->isGet){
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->scene = Balance::$cxBalanceSceneUserWallet;
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->setting();
|
||
return $this->responseHandler($data);
|
||
}
|
||
$redis_name = "cxgyc:api:actionRecharge:lock";
|
||
$setnx = \Yii::$app->redis->setnx($redis_name,1);
|
||
if(empty($setnx)){
|
||
$ttl = \Yii::$app->redis->ttl($redis_name);
|
||
if($ttl == -1){
|
||
\Yii::$app->redis->expire($redis_name,5);
|
||
}
|
||
return $this->responseHandler(['code'=>1,'msg'=>'请求过快']);
|
||
}
|
||
\Yii::$app->redis->expire($redis_name,5);
|
||
$form->scenario = 'auto_recharge';
|
||
$form->attributes = \Yii::$app->request->post();
|
||
$form->scene = Balance::$cxBalanceSceneUserWallet;
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->user_id = \Yii::$app->user->identity->id;
|
||
$data = $form->autoRecharge();
|
||
return $this->responseHandler($data);
|
||
}
|
||
}
|
||
|