...
|
...
|
@@ -115,7 +115,58 @@ class Address extends Api |
|
|
* @ApiParams (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name="address", type="string", required=true, description="地址信息")
|
|
|
* @ApiParams (name="address_con", type="int", required=true, description="详细地址")
|
|
|
* @ApiParams (name="name", type="int", required=true, description="姓名")
|
|
|
* @ApiParams (name="name", type="int", required=true, description="收货人姓名")
|
|
|
* @ApiParams (name="mobile", type="int", required=true, description="手机号")
|
|
|
* @ApiParams (name="type", type="int", required=true, description="是否设置为默认[1=是,0=否]")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
"data": {
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function NewAddress()
|
|
|
{
|
|
|
$user_id = $this->is_token($this->request->header());
|
|
|
$param = $this->request->param();
|
|
|
//判断是否有默认地址
|
|
|
if ($param['type'] == 1) {
|
|
|
$is_TypeAdress = Db::name('address')->where(['user_id' => $user_id])->where(['status' => 1])->find();
|
|
|
if ($is_TypeAdress) {
|
|
|
Db::name('address')->where(['id' => $is_TypeAdress['id']])->update(['status' => 0]);
|
|
|
}
|
|
|
}
|
|
|
$data = [
|
|
|
'user_id' => $user_id,
|
|
|
'address' => $param['address'],
|
|
|
'address_con' => $param['address_con'],
|
|
|
'name' => $param['name'],
|
|
|
'mobile' => $param['mobile'],
|
|
|
'status' => $param['type'],
|
|
|
'createtime' => time(),
|
|
|
'updatetime' => time(),
|
|
|
];
|
|
|
$res = Db::name('address')->insert($data);
|
|
|
if ($res) {
|
|
|
$this->success('成功', 1);
|
|
|
} else {
|
|
|
$this->error('失败', 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (地址接口-修改地址)
|
|
|
* @ApiSummary (修改地址)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/address/ChangeAddress)
|
|
|
* @ApiParams (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name="address", type="string", required=true, description="地址信息")
|
|
|
* @ApiParams (name="address_con", type="int", required=true, description="详细地址")
|
|
|
* @ApiParams (name="name", type="int", required=true, description="收货人姓名")
|
|
|
* @ApiParams (name="mobile", type="int", required=true, description="手机号")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="地址ID")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
...
|
...
|
@@ -123,12 +174,59 @@ class Address extends Api |
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
"data": {
|
|
|
"name": "王二蛋",
|
|
|
"address": "天津市",
|
|
|
"address_con": "天津市西青区",
|
|
|
"mobile": "13223332122",
|
|
|
"id": 1
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function ChangeAddress()
|
|
|
{
|
|
|
$user_id = $this->is_token($this->request->header());
|
|
|
$param = $this->request->param();
|
|
|
$res = Db::name('address')->where(['user_id' => $user_id])->where(['id' => $param['id']])
|
|
|
->update([
|
|
|
'address' => $param['address'],
|
|
|
'address_con' => $param['address_con'],
|
|
|
'name' => $param['name'],
|
|
|
'mobile' => $param['mobile'],
|
|
|
'updatetime' => time()
|
|
|
]);
|
|
|
if ($res) {
|
|
|
$this->success('修改成功', 1);
|
|
|
} else {
|
|
|
$this->error('修改失败', 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (地址接口-设为默认地址)
|
|
|
* @ApiSummary (设为默认地址)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/address/SetAsDefaultAddress)
|
|
|
* @ApiParams (name="token", type="string", required=true, description="token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="地址ID")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
"data": {
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function SetAsDefaultAddress()
|
|
|
{
|
|
|
$user_id = $this->is_token($this->request->header());
|
|
|
$id = input('id');
|
|
|
//检查是否已有默认地址
|
|
|
$is_TypeAdress = Db::name('address')->where(['user_id' => $user_id])->where(['status' => 1])->find();
|
|
|
if ($is_TypeAdress) {
|
|
|
Db::name('address')->where(['id' => $is_TypeAdress['id']])->update(['status' => 0]);
|
|
|
}
|
|
|
$res = Db::name('address')->where(['id' => $id])->where(['user_id' => $user_id])->update(['status' => 1]);
|
|
|
if ($res) {
|
|
|
$this->success('成功', 1);
|
|
|
} else {
|
|
|
$this->error('失败', 0);
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|