100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
namespace app\controller;
|
|
|
|
use think\facade\Db;
|
|
|
|
class Address
|
|
{
|
|
//地址管理
|
|
public function lists(){
|
|
$userid = $GLOBALS['data']['userid'];
|
|
if (empty($userid)) {
|
|
return show("请登录后再发布!",NEED_LOGIN);
|
|
}
|
|
$list = Db::name("app_address")->where("userid",$userid)->select()->toArray();
|
|
return show("获取成功!",SUCCESS_CODE,$list);
|
|
}
|
|
|
|
//地址详细信息
|
|
public function getaddress(){
|
|
$userid = $GLOBALS['data']['userid'];
|
|
if (empty($userid)) {
|
|
return show("请登录后再发布!",NEED_LOGIN);
|
|
}
|
|
|
|
$address_id = $GLOBALS['data']['data']['address_id'];
|
|
if (empty($address_id)) {
|
|
return show("请输入地址编号!");
|
|
}
|
|
|
|
$info = Db::name("app_address")->where("id",$address_id)->find();
|
|
if(empty($info) || $info['userid']!=$userid){
|
|
return show("找不到该地址信息!");
|
|
}
|
|
return show("获取成功!",SUCCESS_CODE,$info);
|
|
}
|
|
|
|
//添加地址
|
|
public function plus()
|
|
{
|
|
$post = $GLOBALS['data']['data'];
|
|
$userid = $GLOBALS['data']['userid'];
|
|
if (empty($userid)) {
|
|
return show("请登录后再发布!",NEED_LOGIN);
|
|
}
|
|
|
|
if(empty($post['name'])) return show("请输入收货人收件人姓名!");
|
|
if(empty($post['mobile'])) return show("请输入收货人电话!");
|
|
if(empty($post['province'])) return show("请输入省份!");
|
|
if(empty($post['city'])) return show("请输入城市!");
|
|
if(empty($post['area'])) return show("请输入区!");
|
|
if(empty($post['detail'])) return show("请输入详细地址!");
|
|
|
|
$default = $post['is_default'];
|
|
if(!in_array($default, [0,1])){
|
|
return show("默认地址值超出范围!");
|
|
}else{
|
|
if($default == 1){
|
|
Db::name("app_address")->where("userid",$userid)->update(["is_default"=>0]);
|
|
}
|
|
}
|
|
$datas = [
|
|
"userid"=>$userid,
|
|
"name"=>$post['name'],
|
|
"mobile"=>$post['mobile'],
|
|
"province"=>$post['province'],
|
|
"city"=>$post['city'],
|
|
"area"=>$post['area'],
|
|
"detail"=>$post['detail'],
|
|
"is_default"=>$post['is_default'],
|
|
];
|
|
|
|
if(!empty($post['id'])){
|
|
$d = Db::name("app_address")->where("id",$post['id'])->find();
|
|
if($userid != $d['userid']){
|
|
return show("找不到地址信息!");
|
|
}
|
|
Db::name("app_address")->where("id",$post['id'])->update($datas);
|
|
return show("修改成功!", SUCCESS_CODE, []);
|
|
}else{
|
|
Db::name("app_address")->insert($datas);
|
|
}
|
|
return show("添加成功!", SUCCESS_CODE, []);
|
|
}
|
|
public function delete(){
|
|
$post = $GLOBALS['data']['data'];
|
|
$userid = $GLOBALS['data']['userid'];
|
|
if (empty($userid)) {
|
|
return show("请登录!",NEED_LOGIN);
|
|
}
|
|
if(empty($post['id'])) {
|
|
return show("参数不正确!");
|
|
}
|
|
$d = Db::name("app_address")->where("id",$post['id'])->find();
|
|
if($userid != $d['userid']){
|
|
return show("找不到地址信息!");
|
|
}
|
|
Db::name("app_address")->where("id",$post['id'])->delete();
|
|
return show("删除成功!", SUCCESS_CODE, []);
|
|
}
|
|
} |