root
5 years ago
14 changed files with 315 additions and 82 deletions
-
2api/config/main.php
-
43api/controllers/AddressController.php
-
6api/controllers/AdminController.php
-
24api/controllers/CartController.php
-
38api/controllers/CommonController.php
-
16api/controllers/GoodsController.php
-
16api/controllers/OrderController.php
-
68api/logic/AddressLogic.php
-
29api/logic/CartLogic.php
-
2api/logic/Helper.php
-
18api/logic/OrderLogic.php
-
3backend/models/ars/Order.php
-
1common/config/bootstrap.php
-
131composer.lock
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
namespace api\controllers; |
|||
|
|||
use backend\models\ars\Address; |
|||
use Yii; |
|||
use yii\web\NotFoundHttpException; |
|||
|
|||
/** |
|||
* @author iron |
|||
* @email weiriron@gmail.com |
|||
*/ |
|||
class AddressController extends CommonController |
|||
{ |
|||
public $modelClass = 'backend\models\ars\Address'; |
|||
|
|||
|
|||
|
|||
|
|||
public function actions() |
|||
{ |
|||
$action = parent::actions(); |
|||
return $action; |
|||
} |
|||
|
|||
public function actionIndex() |
|||
{ |
|||
return Address::find() |
|||
->where(['user_id' => Yii::$app->user->getId()]) |
|||
->all(); |
|||
} |
|||
|
|||
public function actionUpdate() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public function actionCreate() |
|||
{ |
|||
return Yii::$app->address->create(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,68 @@ |
|||
<?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('地址未找到'); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue