<?php
namespace eapie\source\request\house;
use eapie\main;
use eapie\error;
class admin_config extends \eapie\source\request\house {
public function api_data($data = array()){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_CONFIG_READ);
$config = array(
'house_product_add_reward_user_money'
);
if( isset($data['config_id']) ){
object(parent::ERROR)->check($data, 'config_id', parent::TABLE_CONFIG, array('args'));
if( !in_array($data['config_id'], $config)){
return NULL;
}
$output = object(parent::TABLE_CONFIG)->find($data['config_id']);
if( empty($output)){
return NULL;
}
$output = object(parent::TABLE_CONFIG)->data($output);
}else{
$select_config = array(
"where" => array(),
"orderby" => array()
);
$select_config['where'][] = array("config_id IN ([-])", "\"".implode("\",\"", $config)."\"", true);
$select_config['orderby'][] = array('config_sort', false);
$select_config['orderby'][] = array('config_id', false);
$output = object(parent::TABLE_CONFIG)->select($select_config);
if( empty($output)){
return NULL;
}
foreach($output as $key => $value){
$output[$key] = object(parent::TABLE_CONFIG)->data($value);
}
}
return $output;
}
public function api_edit($data = array()){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_CONFIG_EDIT);
$old = array();
if( isset($data['house_product_add_reward_user_money']) ){
$old = object(parent::TABLE_CONFIG)->find('house_product_add_reward_user_money');
if( empty($old) ){
throw new error('未知配置编辑');
}else{
$old = object(parent::TABLE_CONFIG)->data($old);
}
object(parent::ERROR)->check( $data['house_product_add_reward_user_money'], 'user_money', parent::TABLE_CONFIG, array('args'), "house_product_add_reward_user_money[user_money]" );
object(parent::ERROR)->check( $data['house_product_add_reward_user_money'], 'random_min_user_money', parent::TABLE_CONFIG, array('args'), "house_product_add_reward_user_money[random_min_user_money]" );
object(parent::ERROR)->check( $data['house_product_add_reward_user_money'], 'random_max_user_money', parent::TABLE_CONFIG, array('args'), "house_product_add_reward_user_money[random_max_user_money]" );
object(parent::ERROR)->check( $data['house_product_add_reward_user_money'], 'random_state', parent::TABLE_CONFIG, array('args'), "house_product_add_reward_user_money[random_state]" );
object(parent::ERROR)->check( $data['house_product_add_reward_user_money'], 'state', parent::TABLE_CONFIG, array('args'), "house_product_add_reward_user_money[state]" );
$whitelist = array(
'user_money',
'random_min_user_money',
'random_max_user_money',
'random_state',
'state',
);
$whitelist_data = cmd(array($data['house_product_add_reward_user_money'], $whitelist), 'arr whitelist');
$value = cmd(array($whitelist_data), 'json encode');
if( !empty($whitelist_data) ){
foreach($whitelist_data as $k => $v){
if( isset($old['config_value'][$k])
&& $old['config_value'][$k] == $v ){
unset($whitelist_data[$k]);
}
}
}
if (empty($whitelist_data)){
throw new error('没有需要更新的数据');
}
$bool = object(parent::TABLE_CONFIG)->update_value('house_product_add_reward_user_money', $value);
}
if( !empty($bool) ){
object(parent::TABLE_ADMIN_LOG)->insert($data, $old);
return true;
} else {
throw new error('操作失败');
}
}
}
?>