mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改商品管理
This commit is contained in:
parent
a2ccffddb6
commit
d8619e7bad
@ -30,7 +30,7 @@ class ShopGoods extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
{
|
{
|
||||||
$this->cateLevel = GoodsService::instance()->getCateLevel();
|
$this->cateLevel = GoodsService::instance()->getCateMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +80,7 @@ class ShopGoods extends Controller
|
|||||||
{
|
{
|
||||||
$this->marks = GoodsService::instance()->getMarkData();
|
$this->marks = GoodsService::instance()->getMarkData();
|
||||||
$this->cates = GoodsService::instance()->getCateData();
|
$this->cates = GoodsService::instance()->getCateData();
|
||||||
GoodsService::instance()->buildItemData($data, false);
|
GoodsService::instance()->buildData($data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,7 +218,7 @@ class ShopGoods extends Controller
|
|||||||
if ($this->request->isGet()) {
|
if ($this->request->isGet()) {
|
||||||
$list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray();
|
$list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray();
|
||||||
if (empty($list)) $this->error('无效的商品数据,请稍候再试!');
|
if (empty($list)) $this->error('无效的商品数据,请稍候再试!');
|
||||||
[$this->vo] = GoodsService::instance()->buildItemData($list);
|
[$this->vo] = GoodsService::instance()->buildData($list);
|
||||||
$this->fetch();
|
$this->fetch();
|
||||||
} else {
|
} else {
|
||||||
[$data, $post, $batch] = [[], $this->request->post(), CodeExtend::uniqidDate(12, 'B')];
|
[$data, $post, $batch] = [[], $this->request->post(), CodeExtend::uniqidDate(12, 'B')];
|
||||||
|
@ -30,7 +30,7 @@ class ShopGoodsCate extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
{
|
{
|
||||||
$this->cateLevel = GoodsService::instance()->getCateLevel();
|
$this->cateLevel = GoodsService::instance()->getCateMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,11 +45,10 @@ class Goods extends Controller
|
|||||||
'num_read' => $this->app->db->raw('num_read+1'),
|
'num_read' => $this->app->db->raw('num_read+1'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$map = ['deleted' => 0, 'status' => 1];
|
$query = $this->_query('ShopGoods')->like('name,cateids,marks,payment')->equal('code');
|
||||||
$query = $this->_query('ShopGoods')->like('name,mark')->equal('code,cate');
|
$result = $query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc')->page(true, false, false, 10);
|
||||||
$result = $query->where($map)->order('sort desc,id desc')->page(true, false, false, 10);
|
if (count($result['list']) > 0) GoodsService::instance()->buildData($result['list']);
|
||||||
GoodsService::instance()->buildItemData($result['list']);
|
$this->success('获取商品数据', $result);
|
||||||
$this->success('获取商品成功', $result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +90,7 @@ class GoodsService extends Service
|
|||||||
}
|
}
|
||||||
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
||||||
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
||||||
if ($simple && count($cates[$id]['names']) !== $this->getCateLevel()) {
|
if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) {
|
||||||
unset($cates[$key]);
|
unset($cates[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,6 +108,15 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大分类级别
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getCateMax(): int
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品数据绑定
|
* 商品数据绑定
|
||||||
* @param array $data 商品主数据
|
* @param array $data 商品主数据
|
||||||
@ -117,29 +126,19 @@ class GoodsService extends Service
|
|||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function buildItemData(array &$data = [], $simple = true): array
|
public function buildData(array &$data = [], $simple = true): array
|
||||||
{
|
{
|
||||||
$cates = $this->getCateData();
|
[$cates, $codes] = [$this->getCateData(), array_unique(array_column($data, 'code'))];
|
||||||
$codes = array_unique(array_column($data, 'code'));
|
|
||||||
$marks = $this->app->db->name('ShopGoodsMark')->where(['status' => 1])->column('name');
|
$marks = $this->app->db->name('ShopGoodsMark')->where(['status' => 1])->column('name');
|
||||||
$items = $this->app->db->name('ShopGoodsItem')->whereIn('goods_code', $codes)->where(['status' => 1])->select()->toArray();
|
$items = $this->app->db->name('ShopGoodsItem')->whereIn('goods_code', $codes)->where(['status' => 1])->select()->toArray();
|
||||||
foreach ($data as &$vo) {
|
foreach ($data as &$vo) {
|
||||||
[$vo['marks'], $vo['cateids'], $vo['cateinfo']] = [str2arr($vo['marks'], ',', $marks), str2arr($vo['cateids']), []];
|
[$vo['marks'], $vo['cateids'], $vo['cateinfo']] = [str2arr($vo['marks'], ',', $marks), str2arr($vo['cateids']), []];
|
||||||
foreach ($cates as $cate) if (in_array($cate['id'], $vo['cateids'])) $vo['cateinfo'] = $cate;
|
|
||||||
[$vo['slider'], $vo['specs'], $vo['items']] = [str2arr($vo['slider'], '|'), json_decode($vo['data_specs'], true), []];
|
[$vo['slider'], $vo['specs'], $vo['items']] = [str2arr($vo['slider'], '|'), json_decode($vo['data_specs'], true), []];
|
||||||
|
foreach ($cates as $cate) if (in_array($cate['id'], $vo['cateids'])) $vo['cateinfo'] = $cate;
|
||||||
foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item;
|
foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item;
|
||||||
if ($simple) unset($vo['marks'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs'], $vo['cateinfo']['parent']);
|
if ($simple) unset($vo['marks'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs'], $vo['cateinfo']['parent']);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 最大分类级别
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function getCateLevel(): int
|
|
||||||
{
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user