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/GoodsNew.php

77 lines
1.9 KiB

6 months ago
<?php
namespace app\api\controller;
use app\common\service\GoodsEs;
use think\App;
6 months ago
class GoodsNew extends Controller
{
public function index()
{
$goodsService = new GoodsEs();
$data = $goodsService->list([]);
dd($data);
}
public function search()
{
$keyword = $this->request->param('keyword');
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
if (!$keyword) {
$this->renderError('请输入搜索关键字');
}
$params = ['goods_name' => $keyword];
$goodsService = new GoodsEs();
$list = $goodsService->list($params, $page, $limit);
$data['list'] = $list;
$data['total'] = $goodsService->count($params);
return $this->renderSuccess($data);
}
/**
* 添加商品
*/
public function add()
{
$goods_id = 1;
$goods_data = \app\common\model\Goods::where('goods_id', '=', $goods_id)
->order('goods_id desc')
->find()
->toArray();
$goodsService = new GoodsEs();
$data = $goodsService->createData($goods_id, $goods_data);
$this->renderSuccess($data);
}
/**
* 更新商品
*/
public function update()
{
$goods_id = 1;
$update = [
'goods_name' => '测试商品',
'selling_point' => '测试商品',
'goods_price_min' => 100,
'goods_price_max' => 100,
];
$goodsService = new GoodsEs();
$data = $goodsService->updateData($goods_id, $update);
$this->renderSuccess($data);
}
/**
* 删除
*/
public function delete()
{
$goods_id = 1;
$goodsService = new GoodsEs();
$data = $goodsService->delete($goods_id);
$this->renderSuccess($data);
}
6 months ago
}