diff --git a/app/data/controller/ShopGoods.php b/app/data/controller/ShopGoods.php index 54c05664b..f9007481a 100644 --- a/app/data/controller/ShopGoods.php +++ b/app/data/controller/ShopGoods.php @@ -82,13 +82,12 @@ class ShopGoods extends Controller */ public function stock() { - $input = $this->_vali(['code.require' => '商品编号不能为空哦!']); + $map = $this->_vali(['code.require' => '商品编号不能为空哦!']); if ($this->request->isGet()) { - $goods = $this->app->db->name('ShopGoods')->where($input)->find(); - empty($goods) && $this->error('无效的商品信息,请稍候再试!'); - $map = ['goods_code' => $input['code'], 'status' => 1]; - $goods['list'] = $this->app->db->name('ShopGoodsItem')->where($map)->select()->toArray(); - $this->fetch('', ['vo' => $goods]); + $list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray(); + if (empty($list)) $this->error('无效的商品信息,请稍候再试!'); + [$this->vo] = GoodsService::instance()->buildItemData($list); + $this->fetch(); } else { [$post, $data, $batch] = [$this->request->post(), [], CodeExtend::uniqidDate(12, 'B')]; if (isset($post['goods_code']) && is_array($post['goods_code'])) { @@ -102,7 +101,7 @@ class ShopGoods extends Controller } if (!empty($data)) { $this->app->db->name('ShopGoodsStock')->insertAll($data); - GoodsService::instance()->syncStock($input['code']); + GoodsService::instance()->syncStock($map['code']); $this->success('商品信息入库成功!'); } } diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index 44c25db1d..25fb5f847 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -99,22 +99,21 @@ class GoodsService extends Service /** * 商品数据绑定 - * @param array $list 商品主数据 + * @param array $data 商品主数据 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function buildItemData(array &$list = []): array + public function buildItemData(array &$data = []): array { $cates = $this->app->db->name('ShopGoodsCate')->column('id,pid,name', 'id'); foreach ($cates as $cate) if (isset($cates[$cate['pid']])) { $cates[$cate['id']]['parent'] =& $cates[$cate['pid']]; } - $codes = array_unique(array_column($list, 'code')); - $where = [['goods_code', 'in', $codes], ['status', '=', 1]]; - $items = $this->app->db->name('ShopGoodsItem')->withoutField('id,status,create_at')->where($where)->select()->toArray(); - foreach ($list as &$vo) { + $map = [['goods_code', 'in', array_unique(array_column($data, 'code'))], ['status', '=', 1]]; + $items = $this->app->db->name('ShopGoodsItem')->withoutField('id,status,create_at')->where($map)->select()->toArray(); + foreach ($data as &$vo) { $vo['marks'] = think_string_to_array($vo['mark']); $vo['cates'] = $cates[$vo['cate']] ?? []; $vo['slider'] = explode('|', $vo['slider']); @@ -123,9 +122,7 @@ class GoodsService extends Service foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item; unset($vo['mark'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs']); } - dump($list); - exit; - return $list; + return $data; } diff --git a/app/data/view/shop_goods/index.html b/app/data/view/shop_goods/index.html index ada3126ec..fbe12900c 100644 --- a/app/data/view/shop_goods/index.html +++ b/app/data/view/shop_goods/index.html @@ -78,14 +78,14 @@ {if isset($type) and $type eq 'index'} {if isset($vo.status) and $vo.status eq 1} - - 下 架 + + 下 架 下 架 {else} - - 上 架 + + 上 架 上 架 diff --git a/app/data/view/shop_goods/stock.html b/app/data/view/shop_goods/stock.html index e917995d6..9fed7c770 100644 --- a/app/data/view/shop_goods/stock.html +++ b/app/data/view/shop_goods/stock.html @@ -2,46 +2,34 @@
商品名称 - Goods name -
{$vo.name}
+ Goods Name +
{$vo.name|default=''}
规格数据 - Specification data - + Specification Data +
- + - - - - - - + + + + + + - {foreach $vo.list as $goods} + {foreach $vo.items as $goods} - - - - - - + + + + + +
商品规格市场价格销售价格库存统计总销统计库存剩余入库数量市场价格销售价格库存统计总销统计库存剩余入库数量
- {$goods.goods_spec|think_show_goods_spec} - - - - - - - - - - - {$goods.goods_spec|think_show_goods_spec}¥{$goods.price_market+0}¥{$goods.price_selling+0}{$goods.stock_total|default=0}{$goods.stock_sales|default=0}{$goods.stock_total-$goods.stock_sales} @@ -59,5 +47,4 @@ -