增加数据接口

This commit is contained in:
Anyon 2020-09-10 11:25:14 +08:00
parent 758eb47a47
commit fefbe6391b
2 changed files with 28 additions and 4 deletions

View File

@ -39,10 +39,10 @@ class Goods extends Controller
*/ */
public function getGoods() public function getGoods()
{ {
$query = $this->_query('ShopGoods')->like('name')->equal('cate'); $map = ['deleted' => 0, 'status' => 1];
$query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc'); $query = $this->_query('ShopGoods')->like('name,mark')->equal('code,cate');
$result = $query->page(true, false, false, 10); $result = $query->where($map)->order('sort desc,id desc')->page(true, false, false, 10);
// @todo 处理商品列表 GoodsService::instance()->buildItemData($result['list']);
$this->success('获取商品数据成功', $result); $this->success('获取商品数据成功', $result);
} }

View File

@ -81,6 +81,30 @@ class GoodsService extends Service
return $query->where($map)->order('sort desc,id desc')->column('name'); return $query->where($map)->order('sort desc,id desc')->column('name');
} }
/**
* 商品数据绑定
* @param array $list
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function buildItemData(array &$list = []): array
{
$codes = array_unique(array_column($list, 'code'));
$map = [['goods_code', 'in', $codes], ['status', '=', 1]];
$items = $this->app->db->name('ShopGoodsItem')->where($map)->select()->toArray();
foreach ($list as &$vo) {
$vo['items'] = [];
foreach ($items as $item) {
if ($item['goods_code'] === $vo['code']) {
$vo['items'][] = $item;
}
}
}
return $list;
}
/** /**
* 最大分类级别 * 最大分类级别
* @return integer * @return integer