protected function getaddrdata() { $msg = array(); //名字 $data['consignee'] = empty($_POST['consignee']) ? '' : htmlspecialchars(trim($_POST['consignee'])); if (!$data['consignee']) { // $msg = '请输入姓名!\r\n'; $msg['error'] = '-1'; $msg['msg'] = '请输入姓名!'; echo json_encode($msg); throw new Exception('exit'); } //手机 $data['mobile'] = empty($_POST['mobile']) ? 0 : htmlspecialchars(trim($_POST['mobile'])); if ($data['mobile']) { $exp = "/^1\\d{10}\$/"; if (!preg_match($exp, $data['mobile'])) { // $msg .= '输入的手机格式错误!\r\n'; $msg['error'] = '-2'; $msg['msg'] = '输入的手机格式错误!'; echo json_encode($msg); throw new Exception('exit'); } } else { // $msg .= '请输入手机号码!\r\n'; $msg['error'] = '-3'; $msg['msg'] = '请输入手机号码!'; echo json_encode($msg); throw new Exception('exit'); } //电话 $tel_area = empty($_POST['tel_area']) ? '' : htmlspecialchars(trim($_POST['tel_area'])); $data['tel'] = empty($_POST['tel']) ? '' : htmlspecialchars(trim($_POST['tel'])); if ($data['tel']) { //填写了区号 if ($tel_area) { $data['tel'] = $tel_area . $data['tel']; } $exp = '/^(0?(([1-9]\\d)|([3-9]\\d{2}))-?)?\\d{7,8}$/'; if (!preg_match($exp, $data['tel'])) { // $msg .= '输入的固定电话错误!\r\n'; $msg['error'] = '-4'; $msg['msg'] = '输入的固定电话错误!'; echo json_encode($msg); throw new Exception('exit'); } } //省份 $data['province'] = empty($_POST['province']) ? 0 : htmlspecialchars(trim($_POST['province'])); if (!$data['province']) { // $msg .= '省不能为空!\r\n'; // $msg['error'] = '-5'; // $msg['msg'] = '省不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); } // Assert::num_gt_zero($data['province'], '省份不能为空'); //城市 $data['city'] = empty($_POST['city']) ? 0 : htmlspecialchars(trim($_POST['city'])); if (!$data['city']) { // $msg .= '市不能为空!\r\n'; // $msg['error'] = '-6'; // $msg['msg'] = '市不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); } // Assert::num_gt_zero($data['city'], '城市不能为空'); //地区 $data['district'] = empty($_POST['district']) ? 0 : htmlspecialchars(trim($_POST['district'])); // if( !$data['district'] ){ // // $msg .= '区不能为空!\r\n'; // $msg['error'] = '-7'; // $msg['msg'] = '区不能为空!'; // echo json_encode( $msg ); // throw new Exception('exit'); // } // Assert::num_gt_zero($data['district'], '区县不能为空'); //详细地址 $data['address'] = empty($_POST['address']) ? '' : htmlspecialchars(trim($_POST['address'])); if (!$data['address']) { // $msg .= '请输入详细地址!\r\n'; $msg['error'] = '-8'; $msg['msg'] = '请输入详细地址!'; echo json_encode($msg); throw new Exception('exit'); } //是否默认地址 $data['is_default'] = isset($_POST['is_default']) && !empty($_POST['is_default']) ? "yes" : 'no'; //用户id $data['uid'] = User::getLoginUid(); //如果有跳转地址,用户下单的时候添加地址,默认设置为默认地址 $addr_jump_url = LuS::get('addr_jump_url'); if (isset($addr_jump_url) && !empty($addr_jump_url)) { UserAddress::setDefaultAddressToNull($data['uid']); //去掉默认地址 $data['is_default'] = 'yes'; //设置当前为默认地址 } if ($msg) { // echo "$msg"; $msg['error'] = '-9'; $msg['msg'] = $msg; echo json_encode($msg); throw new Exception('exit'); } return $data; }