You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

68 lines
1.9 KiB

<?php
namespace api\logic;
use backend\models\ars\Address;
use Yii;
use yii\base\Component;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use yii\web\ServerErrorHttpException;
/**
* @author iron
* @email weiriron@gmail.com
* Class CartLogic
* @package api\logic
*/
class AddressLogic extends Component
{
public $viewAction = 'view';
/**
* @return Address
* @throws BadRequestHttpException
* @throws ServerErrorHttpException
*/
public function create()
{
$data['consignee'] = Yii::$app->request->getBodyParam('consignee');
$data['phone'] = Yii::$app->request->getBodyParam('phone');
$data['province'] = Yii::$app->request->getBodyParam('province');
$data['city'] = Yii::$app->request->getBodyParam('city');
$data['district'] = Yii::$app->request->getBodyParam('district');
$data['address'] = Yii::$app->request->getBodyParam('address');
if (empty($data['consignee']) || empty($data['phone']) || empty($data['province']) ||
empty($data['city']) || empty($data['district']) || empty($data['address'])) {
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS);
}
$address = new Address();
$address->user_id = Yii::$app->user->getId();
$address->load($data, '');
if (!$address->save()) {
throw new ServerErrorHttpException('地址添加失败');
}
Helper::createdResponse($address, $this->viewAction);
return $address;
}
private function setDefaultAddress($address)
{
}
private function findAddress()
{
$id = Yii::$app->request->getQueryParam('id');
$address = Address::find()
->where(['id' => $id])
->andWhere(['user_id' => Yii::$app->user->getId()])
->one();
if (!$address) {
throw new NotFoundHttpException('地址未找到');
}
}
}