<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */

defined('IN_UQ') or exit('Access Denied'); class address_uqcms extends control { function __construct() { $this->uid = @$_SESSION['user']['uid']; parent::__construct(); } function edit_save() { if($_POST){ $uq0 = $uq1[] = P('prov/i'); $uq2 = $uq1[] = P('city/i'); $uq3 = $uq1[] = P('dist/i'); $uq4 = $this->module('address')->get_cn($uq1); $uq5['prov'] = $uq4[$uq0]['id']; $uq5['prov_cn'] = $uq4[$uq0]['name']; $uq5['city'] = $uq4[$uq2]['id']?:'0'; $uq5['city_cn'] = $uq4[$uq2]['name']?:''; $uq5['dist'] = $uq4[$uq3]['id']?:'0'; $uq5['dist_cn'] = $uq4[$uq3]['name']?:''; $uq5['name'] = P('name', '姓名不能为空'); $uq5['mobile'] = P('mobile/m', '电话不能为空'); $uq5['address'] = P('address', '地址不能为空'); $uq5['zip'] = P('zip/i', ''); $uq5['addtime'] = time(); $uq6 = P('id/i', false); if(cfg('order_settle_login')){ if($uq6){ $uq7 = $this->db->update(table('member_address'), $uq5, 'uid = '.$this->uid.' and id = '.$uq6); }else{ $uq8 = $this->db->get_one("select count(id) as total from ".table('member_address')." where uid = ".$this->uid); if($uq8['total'] >= cfg('user_address_num')){ error_json('已经超出最大的数量'); } $uq5['uid'] = $this->uid; $uq7 = $this->db->add(table('member_address'), $uq5); $uq6 = $this->db->insert_id(); } }else{ $uq5['uid'] = '0'; } if(!empty($_POST['is_default'])){ $this->set_default_func($uq6); } if($uq7){ $uq9 = $uq5; $uq9['error'] = '0'; $uq9['id'] = $uq6; echo json_encode($uq9); }else{ error_json('保存失败'); } }else{ error_json('提交错误'); } } public function del() { $uq6 = P('id/i', '提交编号错误'); $uq7 = $this->db->delete(table('member_address'), 'uid = '.$this->uid.' and id = '.$uq6); if($uq7){ right_json(); }else{ error_json('删除失败'); } } function set_default() { $uq6 = P('id/i', '访问错误'); $uq7 = $this->set_default_func($uq6); if($uq7){ right_json(); }else{ error_json('设置失败'); } } function set_default_func($uq6) { $this->db->autocommit(); $query1 = $this->db->update(table('member_address'), ['is_default'=>'0'], 'uid = '.$this->uid); $query2 = $this->db->update(table('member_address'), ['is_default'=>'1'], 'uid = '.$this->uid.' and id = '.$uq6); if($query1 && $query2){ $this->db->commit(); return true; }else{ $this->db->rollback(); return false; } } }