multi-store/app/api/controller/user/AddressController.php

99 lines
2.8 KiB
PHP

<?php
namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\lists\user\UserAddressList;
use app\api\logic\user\AddressLogic;
use app\api\validate\UserAddressValidate;
class AddressController extends BaseApiController
{
public function lists(){
return $this->dataLists(new UserAddressList());
}
/**
* 添加地址
* @return \support\Response
*/
public function create()
{
$params = (new UserAddressValidate())->post()->goCheck('add');
$params['uid'] = $this->request->userId;
$res=AddressLogic::add($params);
if(AddressLogic::hasError()){
return $this->fail(AddressLogic::getError());
}else{
return $this->success('添加成功');
}
}
/**
* 商户给用户添加地址
*/
/* public function merchant_create()
{
$params = $this->request->post();
if($params['order_id'] && $params['order_id']!=0){
$uid=Cashierclass::where('id',$params['order_id'])->value('uid');
if(!$uid || $uid<=0){
return $this->fail('订单不存在');
}
}
$params['uid'] = $uid;
$res=AddressLogic::add($params);
if(AddressLogic::hasError()){
return $this->fail(AddressLogic::getError());
}else{
Cashierclass::where('id',$params['order_id'])->update(['address_id'=>$res,'real_name'=>$params['real_name'],'user_phone'=>$params['phone'],'user_address'=>$params['detail']]);
return $this->success('添加成功');
}
}*/
/**
* @notes 编辑地址
* @return \support\Response
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function edit()
{
$params = (new UserAddressValidate())->post()->goCheck('edit');
$params['uid'] = $this->request->userId;
if(AddressLogic::edit($params)){
return $this->success('编辑成功');
}else{
return $this->fail(AddressLogic::getError());
}
}
/**
* @notes 删除地址
* @return \support\Response
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function delete()
{
$params = (new UserAddressValidate())->post()->goCheck('delete');
if(AddressLogic::delete($params)){
return $this->success('删除成功');
}else{
return $this->fail(AddressLogic::getError());
}
}
/**
* @notes 获取地址详情
* @return \support\Response
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function detail()
{
$params = (new UserAddressValidate())->goCheck('detail');
return $this->success('获取成功',AddressLogic::detail($params));
}
}