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.
yanzong/app/api/controller/Active.php

106 lines
3.3 KiB

10 months ago
<?php
namespace app\api\controller;
use app\api\model\Goods as GoodsModel;
10 months ago
use app\api\model\ActiveMain;
10 months ago
use app\common\model\Goods;
use think\response\Json;
use app\common\library\helper;
10 months ago
/**
* 活动相关接口
*/
class Active extends Controller
{
/**
* 新年换新机活动详情
* @return void
*/
public function detail(): Json {
$param = $this->request->param();
if (empty($param['active_id'])) {
return $this->renderSuccess('活动ID必填');
}
$model = new ActiveMain();
10 months ago
$list = $model->getList($param);
10 months ago
if ($list) {
foreach ($list['col'] as $k => $row) {
$goodsModel = new GoodsModel();
$goods_list = $goodsModel->getListByIdsFromApi(explode(',', $row['col_goods_ids']));
10 months ago
// 隐藏冗余的属性
$goods_list->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images']));
10 months ago
$list['col'][$k]['goods_list'] = $goods_list;
}
return $this->renderSuccess($list->toArray());
}
return $this->renderSuccess('暂无数据');
}
/**
* 新年换新机活动
* @return Json
*/
public function info(): Json{
$model = new ActiveMain();
$type = $this->request->param('type');
$data = $model
->where('type', $type)
10 months ago
->field('id,name,title')->find();
10 months ago
if (!$data) {
return $this->renderSuccess('暂无数据');
}
$list = $model->getList(['active_id' => $data['id']]);
if ($list) {
foreach ($list['col'] as $k => $row) {
$goodsModel = new GoodsModel();
$goods_list = $goodsModel->getListByIdsFromApi(explode(',', $row['col_goods_ids']));
// 隐藏冗余的属性
$goods_list->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images']));
$list['col'][$k]['goods_list'] = $goods_list;
}
return $this->renderSuccess($list->toArray());
}
10 months ago
return $this->renderSuccess($data->toArray());
}
/**
* 活动商品分页加载
* @return Json
* @throws ]
*/
public function getGoodsByPage(): Json {
$page = $this->request->get('page');
$limit = $this->request->get('limit');
$goodsModel = new GoodsModel();
$goods_list = $goodsModel->getList([], $limit);
return $this->renderSuccess($goods_list->toArray());
}
public function funTest() {
$data = [
[
'id' => 1,
'name' => 'ztt'
],
[
'id' => 2,
'name' => 'ztt2'
],
[
'id' => 3,
'name' => 'ztt3'
],
];
// $res = helper::getArrayColumns($data, ['id', 'name']);
$res = helper::getArrayColumn($data, 'id');
// $res = helper::arrayColumn2Key($data, 'id');
// $res = array_column($data, 'id'); // ==> helper::getArrayColumn
// $res = array_column($data, null, 'id'); // ==> helper::arrayColumn2Key
// $ids = array_keys($res);
// $res = array_column($data, 'name', 'id');
// $res = helper::getArrayColumnSum();
dd($res);
}
10 months ago
}