123 lines
3.5 KiB
PHP
123 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2022年7月12日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common;
|
|
|
|
use app\models\PaymentConfig;
|
|
use app\models\Model;
|
|
|
|
|
|
class CommonPaymentConfigActionForm extends Model
|
|
{
|
|
public $config_id;
|
|
public $cx_mch_id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['cx_mch_id'], 'integer'],
|
|
[['config_id', ], 'safe'],
|
|
[['config_id', 'cx_mch_id'], 'required'],
|
|
];
|
|
}
|
|
|
|
|
|
public function delete()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
if(is_array($this->config_id)){
|
|
foreach ($this->config_id as $config_id){
|
|
$model = PaymentConfig::findOne([
|
|
'id' => $config_id,
|
|
'is_delete' => 0,
|
|
'status' => PaymentConfig::STATUS_OFF,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null)
|
|
continue;
|
|
$model->is_delete = 1;
|
|
if(!$model->save()){
|
|
return $this->getModelError($model);
|
|
}
|
|
}
|
|
} else {
|
|
$model = PaymentConfig::findOne([
|
|
'id' => $this->config_id,
|
|
'is_delete' => 0,
|
|
'status' => PaymentConfig::STATUS_OFF,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('支付配置不存在或已经删除');
|
|
}
|
|
$model->is_delete = 1;
|
|
if(!$model->save()){
|
|
return $this->getModelError($model);
|
|
}
|
|
}
|
|
return $this->apiReturnSuccess('删除成功');
|
|
}
|
|
|
|
public function open()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$model = PaymentConfig::findOne([
|
|
'id' => $this->config_id,
|
|
'is_delete' => 0,
|
|
'status' => PaymentConfig::STATUS_OFF,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('支付配置不存在或已经启用');
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
//其余同支付类型的关闭
|
|
PaymentConfig::updateAll(['status' => PaymentConfig::STATUS_OFF],[
|
|
'status' => PaymentConfig::STATUS_ON,
|
|
'pay_type' => $model->pay_type,
|
|
'is_delete' => 0
|
|
]);
|
|
$model->status = PaymentConfig::STATUS_ON;
|
|
if(!$model->save()){
|
|
$t->rollBack();
|
|
return $this->getModelError($model);
|
|
}
|
|
$t->commit();
|
|
return $this->apiReturnSuccess('操作成功');
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$model = PaymentConfig::findOne([
|
|
'id' => $this->config_id,
|
|
'is_delete' => 0,
|
|
'status' => PaymentConfig::STATUS_ON,
|
|
'cx_mch_id' => $this->cx_mch_id
|
|
]);
|
|
if($model == null){
|
|
return $this->apiReturnError('支付配置不存在或已经停用');
|
|
}
|
|
$model->status = PaymentConfig::STATUS_OFF;
|
|
if(!$model->save()){
|
|
return $this->getModelError($model);
|
|
}
|
|
return $this->apiReturnSuccess('操作成功');
|
|
}
|
|
}
|
|
|