mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
增加数据接口
This commit is contained in:
parent
758eb47a47
commit
fefbe6391b
@ -39,10 +39,10 @@ class Goods extends Controller
|
||||
*/
|
||||
public function getGoods()
|
||||
{
|
||||
$query = $this->_query('ShopGoods')->like('name')->equal('cate');
|
||||
$query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc');
|
||||
$result = $query->page(true, false, false, 10);
|
||||
// @todo 处理商品列表
|
||||
$map = ['deleted' => 0, 'status' => 1];
|
||||
$query = $this->_query('ShopGoods')->like('name,mark')->equal('code,cate');
|
||||
$result = $query->where($map)->order('sort desc,id desc')->page(true, false, false, 10);
|
||||
GoodsService::instance()->buildItemData($result['list']);
|
||||
$this->success('获取商品数据成功', $result);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,30 @@ class GoodsService extends Service
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user