cxfoot/modules/admin/controllers/balance/RechargeController.php
2023-10-24 14:54:18 +08:00

105 lines
3.1 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021年9月30日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\controllers\balance;
use yii\helpers\VarDumper;
use app\modules\admin\controllers\Controller;
use app\modules\admin\behaviors\LoginBehavior;
use app\models\common\CommonRechargeRuleActionForm;
use app\models\common\CommonRechargeRuleEditForm;
use app\models\common\CommonRechargeRuleListForm;
use app\models\common\CommonRechargeActionForm;
use app\models\RechargeRule;
use app\models\Balance;
class RechargeController extends Controller
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'login' => [
'class' => LoginBehavior::className(),
],
]);
}
public function actionRule()
{
if(\Yii::$app->request->isAjax){
$form = new CommonRechargeRuleListForm();
$form->attributes = \Yii::$app->request->get();
$form->cx_mch_id = $this->cx_mch_id;
$data = $form->search();
return $this->responseHandler($data);
}
return $this->render('rule');
}
public function actionRuleEdit($id = 0)
{
$model = RechargeRule::findOne([
'cx_mch_id' => $this->cx_mch_id,
'is_delete' => 0,
'id' => $id,
]);
if($model == null)
$model = new RechargeRule();
if(\Yii::$app->request->isPost){
$form = new CommonRechargeRuleEditForm();
$form->attributes = \Yii::$app->request->post();
$form->cx_mch_id = $this->cx_mch_id;
$form->model = $model;
$data = $form->save();
return $this->responseHandler($data);
}
$return_url = \Yii::$app->request->referrer;
return $this->render('rule-edit', [
'model' => $model,
'return_url' => $return_url,
]);
}
public function actionRuleDelete()
{
if(!\Yii::$app->request->isPost){
$data = $this->invaildRequest();
return $this->responseHandler($data);
}
$form = new CommonRechargeRuleActionForm();
$form->attributes = \Yii::$app->request->post();
$form->cx_mch_id = $this->cx_mch_id;
$data = $form->delete();
return $this->responseHandler($data);
}
public function actionRecharge()
{
if(!\Yii::$app->request->isPost){
$data = $this->invaildRequest();
return $this->responseHandler($data);
}
$form = new CommonRechargeActionForm();
$form->scenario = 'recharge';
$form->attributes = \Yii::$app->request->post();
$form->cx_mch_id = $this->cx_mch_id;
$form->scene = Balance::$cxBalanceSceneUserWallet;
$nickname = \Yii::$app->admin->identity->user->nickname;
$username = \Yii::$app->admin->identity->user->username;
$form->operator_name = "{$nickname}[$username]";
$data = $form->recharge();
return $this->responseHandler($data);
}
}