cxfoot/models/common/CommonRechargeRuleActionForm.php
2023-10-24 14:54:18 +08:00

71 lines
1.7 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021年9月30日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\RechargeRule;
use app\models\User;
use app\models\Model;
class CommonRechargeRuleActionForm extends Model
{
public $rule_id;
public $cx_mch_id;
public function rules()
{
return [
[['cx_mch_id'], 'integer'],
[['rule_id', ], 'safe'],
[['rule_id', 'cx_mch_id'], 'required'],
];
}
public function delete()
{
if(!$this->validate()){
return $this->getModelError();
}
if(is_array($this->rule_id)){
foreach ($this->rule_id as $rule_id){
$model = RechargeRule::findOne([
'id' => $rule_id,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id
]);
if($model == null)
continue;
$model->is_delete = 1;
if(!$model->save()){
return $this->getModelError($model);
}
}
} else {
$model = RechargeRule::findOne([
'id' => $this->rule_id,
'is_delete' => 0,
'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("删除成功");
}
}