155 lines
4.6 KiB
PHP
155 lines
4.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年6月15日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\api\controllers;
|
|
|
|
use app\modules\api\behaviors\LoginBehavior;
|
|
use app\models\common\CommonCartActionForm;
|
|
use app\models\common\CommonCartAddForm;
|
|
use app\models\common\CommonCartEditForm;
|
|
use app\models\common\CommonCartListForm;
|
|
|
|
|
|
class CartController extends Controller
|
|
{
|
|
public function behaviors() {
|
|
return array_merge(parent::behaviors(),[
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
'ignore' => [
|
|
'api/cart/index'
|
|
]
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* hidedoc
|
|
* @catalog 购物车
|
|
* @title 购物车列表
|
|
* @description 本接口提供购物车列表
|
|
* @method get
|
|
* @url /api/cart/index
|
|
* @param plugin_sign 必选 int 插件标识
|
|
* @return {"code":0,"msg":"操作成功","data":[]}
|
|
* @return_param name type desc
|
|
* @remark *
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
$form = new CommonCartListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->user_id = \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id;
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
/**
|
|
* hidedoc
|
|
* @catalog 购物车
|
|
* @title 加入购物车
|
|
* @description 本接口提供发起加入购物车
|
|
* @method post
|
|
* @url /api/cart/add
|
|
* @param goods_id 必选 int 商品ID
|
|
* @param attr 必选 int 规格ID
|
|
* @param num 必选 int 数量
|
|
* @param plugin_sign 必选 int 插件标识
|
|
* @return {"code":0,"msg":"操作成功","data":[]}
|
|
* @return_param name type desc
|
|
* @remark list => "[{\"attr\":0,\"num\":0,\"goods_id\":0}]"
|
|
*/
|
|
public function actionAdd()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CommonCartAddForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->user_id = \Yii::$app->user->identity->id;
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
/**
|
|
* hidedoc
|
|
* @catalog 购物车
|
|
* @title 编辑购物车
|
|
* @description 本接口提供发起编辑购物车
|
|
* @method post
|
|
* @url /api/cart/edit
|
|
* @param list 必选 string(JSON) 购物车数组JSON字符串
|
|
* @param plugin_sign 必选 int 插件标识
|
|
* @return {"code":0,"msg":"操作成功","data":[]}
|
|
* @return_param name type desc
|
|
* @remark list => "[{\"attr\":0,\"num\":0,\"goods_id\":0}]"
|
|
*/
|
|
public function actionEdit()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CommonCartEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->user_id = \Yii::$app->user->identity->id;
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
/**
|
|
* hidedoc
|
|
* @catalog 购物车
|
|
* @title 删除购物车
|
|
* @description 本接口提供发起删除购物车
|
|
* @method post
|
|
* @url /api/cart/delete
|
|
* @param cart_ids 必选 string(JSON) 购物车ID数组JSON字符串
|
|
* @param plugin_sign 必选 int 插件标识
|
|
* @return {"code":0,"msg":"操作成功","data":[]}
|
|
* @return_param name type desc
|
|
* @remark *
|
|
*/
|
|
public function actionDelete()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CommonCartActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->user_id = \Yii::$app->user->identity->id;
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
public function actionClearAll()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CommonCartActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->user_id = \Yii::$app->user->identity->id;
|
|
$data = $form->clear();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
}
|
|
|