<?php
namespace app\api\controller;

use app\api\logic\UserAddressLogic;
use app\api\validate\UserAddressValidate;

/**
 * 用户地址控制器
 * Class UserAddressController
 * @package app\api\controller
 */
class UserAddressController extends BaseApiController
{
    public function addressList()
    {
        $result = UserAddressLogic::getAddressList($this->userId);
        return $this->data($result);
    }
    /**
     * @notes 添加
     * @return \think\response\Json
     */
    public function add()
    {
        $params = (new UserAddressValidate())->post()->goCheck('add',[
            'user_id'=>$this->userId
        ]);
        $result = UserAddressLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(UserAddressLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     */
    public function edit()
    {
        $params = (new UserAddressValidate())->post()->goCheck('edit',[
            'user_id'=>$this->userId
        ]);
        $result = UserAddressLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(UserAddressLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     */
    public function delete()
    {
        $params = (new UserAddressValidate())->post()->goCheck('delete',[
            'user_id'=>$this->userId
        ]);
        UserAddressLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/18 13:51
     */
    public function detail()
    {
        $params = (new UserAddressValidate())->goCheck('detail',[
            'user_id'=>$this->userId
        ]);
        $result = UserAddressLogic::detail($params);
        return $this->data($result);
    }
}