店滴云控制器开发示例 [ 2.0 版本 ]
控制器
手机端接口控制器
- 继承父类 api\controllers\AController
- 设置操作的 modelClass
- 设置不需要签名验证的方法 signOptional
<?php
/**
* @Author: Wang Chunsheng 2192138785@qq.com
* @Date: 2020-03-10 14:00:06
* @Last Modified by: Wang chunsheng email:2192138785@qq.com
* @Last Modified time: 2022-06-16 17:52:34
*/
namespace addons\diandi_distribution\api;
use addons\diandi_distribution\models\goods\DistributionGoodsBaseCollect;
use addons\diandi_distribution\services\CartService;
use api\controllers\AController;
use common\helpers\ImageHelper;
use common\helpers\ResultHelper;
use Yii;
/**
* Class CartController.
*/
class CartController extends AController
{
public $modelClass = '\common\models\DdGoods';
protected $signOptional = ['Integral'];
public function actionSearch()
{
return [
'error_code' => 20,
'res_msg' => 'ok',
];
}
/**
* @SWG\Post(path="/diandi_shop/cart/add",
* tags={"购物车"},
* summary="Retrieves the collection of Goods resources.",
* @SWG\Response(
* response = 200,
* description = "Goods collection response",
* ),
* @SWG\Parameter(
* in="query",
* name="access-token",
* type="string",
* description="用户验证token",
* required=true,
* ),
* @SWG\Parameter(
* in="formData",
* name="goods_id",
* type="string",
* description="商品id",
* required=true,
* ),
* @SWG\Parameter(
* in="formData",
* name="num",
* type="integer",
* description="商品数量",
* required=true,
* ),
* @SWG\Parameter(
* in="formData",
* name="spec_id",
* type="string",
* description="规格组合id",
* required=false,
* ),
* )
*/
public function actionAdd()
{
global $_GPC;
$user_id = Yii::$app->user->identity->member_id;
$goods_id = intval($_GPC['goods_id']);
$num = intval($_GPC['num']);
$spec_id = $_GPC['spec_id'];
$list = CartService::confirm($user_id, $goods_id, $num, $spec_id);
return ResultHelper::json(200, '加入购物车成功', $list);
}
}
后台接口控制器
- 继承父类 admin\controllers\AController
- 设置操作的 modelClass
- 设置检索类名称 modelSearchName (注意:需要与原检索类文件名称相同,不能与as后的名称相同)
- 设置不需要签名验证的方法 signOptional
<?php
/**
* @Author: Wang chunsheng email:2192138785@qq.com
* @Date: 2021-11-10 12:36:05
* @Last Modified by: Wang chunsheng email:2192138785@qq.com
* @Last Modified time: 2022-03-07 18:48:09
*/
namespace addons\diandi_honorary\admin;
use addons\diandi_honorary\models\HonoraryAar;
use addons\diandi_honorary\models\searchs\HonoraryAar as HonoraryAarSearch;
use admin\controllers\AController;
use common\helpers\DateHelper;
use common\helpers\ErrorsHelper;
use common\helpers\ImageHelper;
use common\helpers\ResultHelper;
use common\helpers\StringHelper;
use Yii;
use yii\web\NotFoundHttpException;
/**
* ArrController implements the CRUD actions for HonoraryAar model.
*/
class ArrController extends AController
{
public $modelSearchName = 'HonoraryAar';
public $modelClass = '';
/**
* @SWG\Get(path="/diandi_honorary/arr/index",
* tags={"ARR分享"},
* summary="列表数据",
* @SWG\Response(
* response = 200,
* description = "列表数据",
* ),
* @SWG\Parameter(ref="#/parameters/access-token"),
* @SWG\Parameter(ref="#/parameters/bloc-id"),
* @SWG\Parameter(ref="#/parameters/store-id"),
* @SWG\Parameter(
* in="query",
* name="HonoraryAar[title]",
* type="string",
* description="标题",
* required=false,
* ),
* @SWG\Parameter(
* in="query",
* name="HonoraryAar[status]",
* type="integer",
* description="状态",
* required=false,
* ),
* @SWG\Parameter(
* in="query",
* name="HonoraryAar[type]",
* type="integer",
* description="类型",
* required=false,
* )
* )
*/
public function actionIndex()
{
$searchModel = new HonoraryAarSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$time = DateHelper::monthsAgo(3);
$d = date('d', time());
return ResultHelper::json(200, '获取成功', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'export_time' => [
date('Y-m-'.$d.' 00:00:00', $time['start']),
date('Y-m-d 00:00:00', time()),
],
]);
}
}
店滴多商户开源框架
注册时间:2017-12-25
最后登录:2024-05-05
在线时长:26小时16分
最后登录:2024-05-05
在线时长:26小时16分
- 粉丝1
- 金钱255
- 威望30
- 积分815
共 0 条评论