<?php
namespace eapie\source\request\user;
use eapie\main;
use eapie\error;
class admin extends \eapie\source\request\user {
public function api_account_excel_option(){
$account_excel_option = array();
if( object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_MONEY_ANNUITY_EXCEL, true) ){
$account_excel_option[] = array(
'api'=>'USERADMINMONEYANNUITYEXCEL',
'title'=>'用户养老基金Excel导出'
);
}
if( object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_MONEY_HELP_EXCEL, true) ){
$account_excel_option[] = array(
'api'=>'USERADMINMONEYHELPEXCEL',
'title'=>'用户扶贫基金Excel导出'
);
}
if( object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_MONEY_SERVICE_EXCEL, true) ){
$account_excel_option[] = array(
'api'=>'USERADMINMONEYSERVICEEXCEL',
'title'=>'用户服务费Excel导出'
);
}
if( object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_MONEY_EXCEL, true) ){
$account_excel_option[] = array(
'api'=>'USERADMINMONEYEXCEL',
'title'=>'用户钱包Excel导出'
);
}
return empty($account_excel_option)? '' : $account_excel_option;
}
public function api_add_parent_user_id($data){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_ADD_PARENT_USER);
$user_recommend_data = object(parent::TABLE_USER_RECOMMEND)->select_by_recommend_id($data['user_id']);
if( !empty($user_recommend_data) )
throw new error('用户已有下级');
$user_data = object(parent::TABLE_USER)->find($data['user_id']);
if(empty($user_data))
throw new error('用户不存在');
if(!empty($user_data['user_parent_id']))
throw new error('用户已有邀请人');
if(empty($user_data['user_json']))
throw new error('用户未填写地址');
$user_json = cmd(array($user_data['user_json']), 'json decode');
if( empty($user_json['address']) )
throw new error('用户未填写地址');
$user_update = array();
$region_data = object(parent::TABLE_AGENT_REGION)->find_province_city_district($user_json['address']['province'],$user_json['address']['city'],$user_json['address']['area']);
if( !empty($region_data) ){
$where = array(
array('agent_region_id=[+]',$region_data['agent_region_id']),
array('[AND]agent_user_state=1')
);
$user_parent_user = object(parent::TABLE_AGENT_USER)->find_where($where);
if ( !empty($user_parent_user) ) {
$user_update["user_parent_id"] = $user_parent_user['user_id'];
}
}
$user_update["user_update_time"] = time();
$result = array();
$result['insert_parent_id'] = object(parent::TABLE_USER)->update_user($data['user_id'],$user_update);
if($result){
$recommend_user_id = $user_update["user_parent_id"];
$recommend_data = array();
if($recommend_user_id !== false){
$time = 0;
while (true) {
$recommend_data[$time] = array(
'user_id' => $data['user_id'],
'user_recommend_id' => object(parent::TABLE_USER_RECOMMEND)->get_unique_id(),
'user_recommend_user_id' => $recommend_user_id,
'user_recommend_level' => $time + 1,
'user_recommend_update_time' => time(),
'user_recommend_insert_time' => time(),
);
$result['insert_recommend'][] = object(parent::TABLE_USER_RECOMMEND)->insert($recommend_data[$time]);
$time++;
$recommend_user_id = object(parent::TABLE_USER)->find_recommend_user_id($recommend_user_id);
if($recommend_user_id === false){
break;
}
}
}
return $result;
} else {
throw new error('用户推荐人更新失败');
}
}
public function api_list($data = array()){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_READ);
$config = array(
'orderby' => array(),
'where' => array(),
'limit' => object(parent::REQUEST)->limit($data, parent::REQUEST_ADMIN),
);
$config["orderby"] = object(parent::REQUEST)->orderby($data, array(
'id_desc' => array('user_id', true),
'id_asc' => array('user_id', false),
'parent_id_desc' => array('user_parent_id', true),
'parent_id_asc' => array('user_parent_id', false),
'nickname_desc' => array('user_nickname', true),
'nickname_asc' => array('user_nickname', false),
'sex_desc' => array('user_sex', true),
'sex_asc' => array('user_sex', false),
'compellation_desc' => array('user_compellation', true),
'compellation_asc' => array('user_compellation', false),
'register_time_desc' => array('user_register_time', true),
'register_time_asc' => array('user_register_time', false),
'update_time_desc' => array('user_update_time', true),
'update_time_asc' => array('user_update_time', false),
'phone_login_count_desc' => array('user_phone_login_count', true),
'phone_login_count_asc' => array('user_phone_login_count', false),
'phone_verify_count_desc' => array('user_phone_verify_count', true),
'phone_verify_count_asc' => array('user_phone_verify_count', false),
'user_recommend_count_desc' => array('user_recommend_count', true),
'user_recommend_count_asc' => array('user_recommend_count', false),
));
$config["orderby"][] = array('user_id', false);
if (!empty($data['search'])) {
if (isset($data['search']['user_id']) && is_string($data['search']['user_id'])) {
$config['where'][] = array('[and] u.user_id=[+]', $data['search']['user_id']);
}
if (isset($data['search']['user_nickname']) && is_string($data['search']['user_nickname'])) {
$config['where'][] = array('[and] u.user_nickname LIKE "%[-]%"', $data['search']['user_nickname']);
}
if (isset($data['search']['user_phone']) && is_string($data['search']['user_phone'])) {
$user_data = object(parent::TABLE_USER_PHONE)->find_verify_data($data['search']['user_phone'], array("u.user_id"));
if( empty($user_data['user_id']) ){
$user_id = "";
}else{
$user_id = $user_data['user_id'];
}
$config['where'][] = array('[and] u.user_id=[+]', $user_id);
}
if (isset($data['search']['user_parent_id']) && is_string($data['search']['user_parent_id'])) {
$config['where'][] = array('[and] u.user_parent_id=[+]', $data['search']['user_parent_id']);
}
if (isset($data['search']['user_parent_phone']) && is_string($data['search']['user_parent_phone'])) {
$user_data = object(parent::TABLE_USER_PHONE)->find_verify_data($data['search']['user_parent_phone'], array("u.user_id"));
if( empty($user_data['user_id']) ){
$user_id = "-";
}else{
$user_id = $user_data['user_id'];
}
$config['where'][] = array('[and] u.user_parent_id=[+]', $user_id);
}
if (isset($data['search']['user_parent_nickname']) && is_string($data['search']['user_parent_nickname'])) {
$config['where'][] = array('[and] parent_u.user_nickname LIKE "%[-]%"', $data['search']['user_parent_nickname']);
}
}
$data = object(parent::TABLE_USER)->select_page($config);
return $data;
}
public function api_get($input = array())
{
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_READ);
object(parent::ERROR)->check($input, 'user_id', parent::TABLE_USER, array('args'));
$get_data = object(parent::TABLE_USER)->find_join($input['user_id']);
if (empty($get_data)) throw new error('用户不存在');
return $get_data;
}
public function api_parent_get($input = array())
{
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_READ);
object(parent::ERROR)->check($input, 'user_id', parent::TABLE_USER, array('args'));
$get_data = object(parent::TABLE_USER)->find_self_parent($input['user_id'], array(
'parent_u.user_id',
'parent_u.user_nickname',
'parent_u.user_compellation',
'parent_up.user_phone_id as user_phone',
));
if (empty($get_data))
throw new error('用户父级数据不存在');
return $get_data;
}
public function api_edit_check(){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_EDIT);
return true;
}
public function api_edit($input = array())
{
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_EDIT);
object(parent::ERROR)->check($input, 'user_id', parent::TABLE_USER, array('args'));
if (isset($input['user_parent_id']))
object(parent::ERROR)->check($input, 'user_parent_id', parent::TABLE_USER, array('format'));
if (isset($input['user_nickname']))
object(parent::ERROR)->check($input, 'user_nickname', parent::TABLE_USER, array('args'));
if (isset($input['user_compellation']))
object(parent::ERROR)->check($input, 'user_compellation', parent::TABLE_USER, array('args'));
if (isset($input['user_wechat']))
object(parent::ERROR)->check($input, 'user_wechat', parent::TABLE_USER, array('args'));
if (isset($input['user_qq']))
object(parent::ERROR)->check($input, 'user_qq', parent::TABLE_USER, array('args'));
if (isset($input['user_email']))
object(parent::ERROR)->check($input, 'user_email', parent::TABLE_USER, array('args'));
if (isset($input['user_sex']))
object(parent::ERROR)->check($input, 'user_sex', parent::TABLE_USER, array('args'));
if (isset($input['user_state']))
object(parent::ERROR)->check($input, 'user_state', parent::TABLE_USER, array('args'));
$original = object(parent::TABLE_USER)->find($input['user_id']);
if (empty($original))
throw new error('ID有误,数据不存在');
$whitelist = array(
'user_parent_id',
'user_nickname',
'user_compellation',
'user_wechat',
'user_qq',
'user_email',
'user_sex',
'user_state'
);
$update_data = cmd(array($input, $whitelist), 'arr whitelist');
if (!empty($input['user_parent_id'])) {
object(parent::ERROR)->check($input, 'user_parent_id', parent::TABLE_USER, array('exists_id'));
if ($input['user_parent_id'] === $input['user_id'])
throw new error('推荐人不能设为自己');
$update_data['user_parent_id'] = $input['user_parent_id'];
}
if (!empty($input['user_parent'])) {
object(parent::ERROR)->check($input, 'user_parent', parent::TABLE_USER, array('format'));
$user_parent_data = object(parent::TABLE_USER)->find_id_or_phone($input['user_parent']);
if (empty($user_parent_data['user_id']))
throw new error('推荐人无效');
if ($user_parent_data['user_id'] === $input['user_id'])
throw new error('推荐人不能设为自己');
$update_data['user_parent_id'] = $user_parent_data['user_id'];
}
if (
isset($update_data['user_state'])
&& empty($update_data['user_state'])
&& $input['user_id'] === $_SESSION['user_id']
){
throw new error('不能封禁自己');
}
foreach ($update_data as $key => $value) {
if (isset($original[$key]) && $original[$key] == $value)
unset($update_data[$key]);
}
if (empty($update_data))
throw new error('没有需要更新的数据');
$update_data['user_update_time'] = time();
if (object(parent::TABLE_USER)->update( array(array('user_id=[+]', $input['user_id'])), $update_data)) {
object(parent::TABLE_ADMIN_LOG)->insert($input, $update_data);
return true;
} else {
throw new error('操作失败');
}
}
public function api_password_edit($input = array())
{
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_EDIT);
object(parent::ERROR)->check($input, 'user_id', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_password', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_confirm_password', parent::TABLE_USER, array('args'));
if ($input['user_password'] !== $input['user_confirm_password'])
throw new error ('两次密码输入不一致');
$original = object(parent::TABLE_USER)->find_password($input['user_id']);
if (empty($original))
throw new error('ID有误,数据不存在');
$update_data = array();
$update_data['user_left_password'] = md5($input['user_password'].$input['user_id']);
$update_data['user_right_password'] = md5($input['user_id'].$input['user_password']);
foreach ($update_data as $key => $value) {
if (isset($original[$key]) && $original[$key] == $value)
unset($update_data[$key]);
}
if (empty($update_data))
throw new error('没有需要更新的数据');
$update_data['user_update_time'] = time();
if (object(parent::TABLE_USER)->update( array(array('user_id=[+]', $input['user_id'])), $update_data)) {
object(parent::TABLE_ADMIN_LOG)->insert($input, $update_data);
return $input['user_id'];
} else {
throw new error('操作失败');
}
}
public function api_add( $input = array() ){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_ADD);
object(parent::ERROR)->check($input, 'user_password', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_nickname', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_sex', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_wechat', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_qq', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_email', parent::TABLE_USER, array('args'));
object(parent::ERROR)->check($input, 'user_phone', parent::TABLE_USER_PHONE, array('args', 'length'), 'user_phone_id');
$user_phone_data = object(parent::TABLE_USER_PHONE)->find($input['user_phone']);
if( !empty($user_phone_data["user_id"]) && !empty($user_phone_data["user_phone_state"]) ){
throw new error("登录手机号已经被认证登记");
}
$whitelist = array(
'user_nickname',
'user_sex',
'user_wechat',
'user_qq',
'user_email',
'user_register_province',
'user_register_city',
'user_register_area'
);
$insert_data = cmd(array($input, $whitelist), 'arr whitelist');
$insert_data['user_id'] = object(parent::TABLE_USER)->get_unique_id();
$insert_data["user_left_password"] = md5($input['user_password'].$insert_data['user_id']);
$insert_data["user_right_password"] = md5($insert_data['user_id'].$input['user_password']);
$insert_data['user_trash'] = 0;
$user_json_data = array();
if( isset($input['work_phone']) && $input['work_phone'] != '' ){
$user_json_data['work_phone'] = $input['work_phone'];
}
if(isset($input['work_address'])){
$user_json_data['work_address'] = $input['work_address'];
}
$insert_data['user_json'] = cmd(array($user_json_data), 'json encode');
if( isset($input['user_parent']) && $input['user_parent'] != '' ){
$user_data = object(parent::TABLE_USER)->find_id_or_phone($input['user_parent']);
if( empty($user_data['user_id']) ){
throw new error ('用户推荐人不合法');
}
$insert_data['user_parent_id'] = $user_data['user_id'];
}
$insert_data['user_update_time'] = time();
$insert_data['user_register_time'] = time();
if( !object(parent::TABLE_USER)->insert($insert_data) ){
throw new error ('用户添加失败');
}
if( empty($user_phone_data["user_phone_id"]) ){
$insert_user_phone = array(
'user_phone_id' => $input['user_phone'],
'user_id' => $insert_data['user_id'],
'user_phone_type' => 1,
'user_phone_state' => 1,
'user_phone_insert_time' => time(),
'user_phone_update_time' => time(),
);
if( !object(parent::TABLE_USER_PHONE)->insert($insert_user_phone) ){
object(parent::TABLE_USER)->remove($insert_data['user_id']) throw new error ('用户登录手机号登记失败');
}
}else{
$update_where = array();
$update_where[] = array("user_phone_id=[+]", $input['user_phone']);
$update_where[] = array('[and] user_phone_state=0');
$update_user_phone = array(
"user_id" => $insert_data['user_id'],
"user_phone_state" => 1,
"user_phone_type" => 1,
"user_phone_update_time" => time(),
);
if( !object(parent::TABLE_USER_PHONE)->update($update_where, $update_user_phone) ){
object(parent::TABLE_USER)->remove($insert_data['user_id']) throw new error ("用户登录手机号更新失败");
}
}
if( isset($input['admin_id']) && $input['admin_id'] != '' ){
object(parent::ERROR)->check($input, 'admin_id', parent::TABLE_ADMIN, array('args', 'exists_id'));
$insert_admin_user = array(
'user_id' => $insert_data['user_id'],
'admin_id' => $input['admin_id'],
'admin_user_state' => 1,
'admin_user_insert_time' => time(),
'admin_user_update_time' => time(),
);
if( !object(parent::TABLE_ADMIN_USER)->insert($insert_admin_user) ){
throw new error ('用户添加成功,但管理员设置失败');
}
}
if( isset($insert_data['user_parent_id']) && object(parent::TABLE_USER_RECOMMEND)->verification_distribution() ){
$recommend_data = array();
$recommend_user_id = $insert_data['user_parent_id'];
$time = 0;
while( true ){
$recommend_data[$time] = array(
'user_recommend_id' => object(parent::TABLE_USER_RECOMMEND)->get_unique_id(),
'user_id' => $insert_data['user_id'],
'user_recommend_user_id' => $recommend_user_id,
'user_recommend_level' => $time + 1,
'user_recommend_update_time' => time(),
'user_recommend_insert_time' => time(),
);
object(parent::TABLE_USER_RECOMMEND)->insert($recommend_data[$time]);
object(parent::TABLE_USER_RECOMMEND)->need_updata_admin_id($recommend_user_id);
$time = $time + 1;
$recommend_user_id = object(parent::TABLE_USER)->find_recommend_user_id($recommend_user_id);
if($recommend_user_id === false){
break;
}
}
}
if( isset($input['user_money']) ){
$insert_user_money = array(
'admin_user_id' => $_SESSION["user_id"],
'user_id' => $insert_data['user_id'],
'value' => $input['user_money'],
'type' => parent::TRANSACTION_TYPE_ADMIN_PLUS,
);
if( !object(parent::TABLE_USER_MONEY)->insert_admin($insert_user_money) ){
throw new error ('用户添加成功,用户钱包赠送失败');
}
}
if( isset($input['user_credit']) ){
$insert_user_credit = array(
'admin_user_id' => $_SESSION["user_id"],
'user_id' => $insert_data['user_id'],
'value' => $input['user_credit'],
'type' => parent::TRANSACTION_TYPE_ADMIN_PLUS,
);
if( !object(parent::TABLE_USER_CREDIT)->insert_admin($insert_user_credit) ){
throw new error ('用户添加成功,用户积分赠送失败');
}
}
}
public function api_logo_qiniu_upload($data = array()) {
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_USER_EDIT);
object(parent::ERROR)->check($data, 'user_id', parent::TABLE_USER, array('args'));
$original = object(parent::TABLE_USER)->find($data['user_id']);
if (empty($original)) throw new error('ID有误,数据不存在');
$response = object(parent::REQUEST_APPLICATION)->qiniu_image_upload();
$update_data['user_logo_image_id'] = $response['image_id'];
$update_data['user_update_time'] = time();
$update_where = array(array('user_id=[+]', $data['user_id']));
if ( !object(parent::TABLE_USER)->update($update_where, $update_data) ){
object(parent::REQUEST_APPLICATION)->qiniu_image_remove($response);
throw new error ('更新失败');
}
if (!empty($original['user_logo_image_id'])) {
$response['image_id'] = $original['user_logo_image_id'];
object(parent::REQUEST_APPLICATION)->qiniu_image_remove($response);
}
object(parent::TABLE_ADMIN_LOG)->insert($data, $original);
return $update_data['user_logo_image_id'];
}
public function api_excel($data = array()){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_EXCEL);
if (
empty($data['type']) ||
!is_string($data['type']) ||
!in_array($data['type'], array('credit', 'money'))
) {
throw new error('导出条件有误(积分或预付款)');
}
$config = array(
'orderby' => array(),
'where' => array(),
);
$config["orderby"][] = array('user_id', false);
$config["orderby"][] = array('user_' . $data['type'] . '_value', true);
$config["orderby"][] = array('user_' . $data['type'] . '_time', true);
$table = array(
'credit' => object(parent::TABLE_USER_CREDIT),
'money' => object(parent::TABLE_USER_MONEY)
);
if (
isset($data['min_value']) &&
is_numeric($data['min_value']) &&
(int) $data['min_value'] >= 0
) {
$sql_join_now_value = $table[$data['type']]->sql_join_user_now_value("u");
$config['where'][] = array('[and] (' . $sql_join_now_value . ') > []', ((int) $data['min_value'] - 1));
}
if (
isset($data['max_value']) &&
is_numeric($data['max_value']) &&
(int) $data['max_value'] >= 0
) {
$sql_join_now_value = $table[$data['type']]->sql_join_user_now_value("u");
$config['where'][] = array('[and] (' . $sql_join_now_value . ') < []', ((int) $data['max_value'] + 1));
}
$res_data = $table[$data['type']]->select_user($config);
if (empty($res_data)) {
throw new error('没有数据');
}
$credit_config = object(parent::TABLE_CONFIG)->data(object(parent::TABLE_CONFIG)->find("credit"), true);
$scale = $credit_config['scale'] ? $credit_config['scale'] : 1;
$precision = $credit_config['precision'] ? $credit_config['precision'] : 2;
$excel_datas = array();
foreach ($res_data as $key => $value) {
$date = !empty($value['user_'.$data['type'].'_time'])?date("Y-m-d", $value['user_'.$data['type'].'_time']):'--';
$number = $data['type'] == 'credit' ? $value['user_credit_value'] / $scale : $value['user_money_value'];
$excel_datas[$key] = array();
$excel_datas[$key][] = $key;
$excel_datas[$key][] = !empty($value['user_compellation'])?$value['user_compellation']:'';
$excel_datas[$key][] = !empty($value['user_nickname'])?$value['user_nickname']:'';
$excel_datas[$key][] = !empty($value['user_phone_verify_list'])?' ' . $value['user_phone_verify_list']:'';
$excel_datas[$key][] = !empty($number)?$number:'';
$excel_datas[$key][] = $date;
}
$str = $data['type'] == 'credit' ? '积分' : '预付款';
$min = !empty($data['min_value']) && $data['min_value'] > 0 ? $data['min_value']/100 : '0';
$max = !empty($data['max_value']) ? $data['max_value'] / 100 : '';
$title = $str . '范围(' . $min . '---' . $max . ')用户列表';
$fileName = $title . date('_YmdHis');
$cellName = array('序号', '姓名', '昵称', '手机', $str . '数量', '注册时间');
$topNumber = 2;
$cellKey = array(
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM',
'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'
);
object(parent::PLUGIN_EXCEL)->output($fileName, $title, function ($obj) use ($excel_datas, $title, $cellName, $topNumber, $cellKey) {
$obj->getActiveSheet()->mergeCells('A1:' . $cellKey[count($cellName) - 1] . '1'); $obj->setActiveSheetIndex(0)->setCellValue('A1', $title);
$obj->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$obj->getActiveSheet()->getStyle('A1')->getFont()->setSize(18);
$obj->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$obj->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
foreach ($cellName as $k => $v) {
$obj->setActiveSheetIndex(0)->setCellValue($cellKey[$k] . $topNumber, $v); $obj->getActiveSheet()->freezePane($cellKey[$k + 1] . ($topNumber + 1)); $obj->getActiveSheet()->getStyle($cellKey[$k] . $topNumber)->getFont()->setBold(true); $obj->getActiveSheet()->getStyle($cellKey[$k] . $topNumber)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); if ($k > 0) {
$obj->getActiveSheet()->getColumnDimension($cellKey[$k])->setWidth(16); }
}
foreach ($excel_datas as $k => $excel_data) {
foreach ($excel_data as $k1 => $val) {
$obj->getActiveSheet()->setCellValue($cellKey[$k1] . ($k + 1 + $topNumber), $val);
if (strlen($val) > 16) {
$obj->getActiveSheet()->getColumnDimension($cellKey[$k1])->setWidth(strlen($val)); }
}
}
});
exit;
}
public function api_reset_user($data){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_RESET_USER_RECOMMEND);
if(!isset($data['user_id']))
throw new error("需要重置的用户ID不能为空");
$user_id = $data['user_id'];
$result = array();
$result[] = object(parent::TABLE_USER_RECOMMEND)->remove($user_id);
$result[] = object(parent::TABLE_ADMIN_USER)->remove($user_id);
return $result;
}
public function api_replacement_coupon($data){
object(parent::REQUEST_ADMIN)->check(parent::AUTHORITY_REPLACEMENT_COUPON);
return object(parent::TABLE_USER_COUPON)->member_goods_coupon(array('user_id' => $data['user_id']));
}
public function api_self_settings($input = array())
{
$user_id = $_SESSION['user_id'];
$original = object(parent::TABLE_ADMIN_USER)->find($user_id);
$admin_user_json = cmd(array($original['admin_user_json']), 'json decode');
if (empty($admin_user_json)) {
$admin_user_json = array();
}
$update_where = array(
array('user_id=[+]', $user_id),
);
$update_data = array(
'admin_user_json' => cmd(array($admin_user_json), 'json encode'),
'admin_user_update_time' => time(),
);
$res = object(parent::TABLE_ADMIN_USER)->update($update_where, $update_data);
if ($res) {
object(parent::TABLE_ADMIN_LOG)->insert($input, $update_data);
return $input;
} else {
throw new error('操作失败');
}
}
}