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('操作成功'); } }