From d7f7994ce3b3ecf1b7b6aede8a22f266c1985320 Mon Sep 17 00:00:00 2001 From: Anyon Date: Wed, 9 Sep 2020 12:19:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/ShopGoods.php | 25 ++++++++++++++----------- app/data/service/GoodsService.php | 2 +- app/data/sys.php | 11 +++++++++++ app/data/view/shop_goods/stock.html | 27 ++++++++++++--------------- 4 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 app/data/sys.php diff --git a/app/data/controller/ShopGoods.php b/app/data/controller/ShopGoods.php index fdb84b409..4e6fb7af9 100644 --- a/app/data/controller/ShopGoods.php +++ b/app/data/controller/ShopGoods.php @@ -78,24 +78,27 @@ class ShopGoods extends Controller */ public function stock() { + $input = $this->_vali(['code.require' => '商品编号不能为空哦!']); if ($this->request->isGet()) { - $code = $this->request->get('code'); - $goods = $this->app->db->name('ShopGoods')->where(['code' => $code])->find(); + $goods = $this->app->db->name('ShopGoods')->where($input)->find(); empty($goods) && $this->error('无效的商品信息,请稍候再试!'); - $map = ['goods_code' => $code, 'status' => 1]; + $map = ['goods_code' => $input['code'], 'status' => 1]; $goods['list'] = $this->app->db->name('ShopGoodsItem')->where($map)->select()->toArray(); $this->fetch('', ['vo' => $goods]); } else { - [$post, $data] = [$this->request->post(), []]; - if (isset($post['id']) && isset($post['goods_code']) && is_array($post['goods_code'])) { - foreach (array_keys($post['goods_id']) as $key) if ($post['goods_number'][$key] > 0) array_push($data, [ - 'goods_code' => $post['goods_code'][$key], - 'goods_spec' => $post['goods_spec'][$key], - 'stock_total' => $post['goods_number'][$key], - ]); + [$post, $data, $batch] = [$this->request->post(), [], CodeExtend::uniqidDate(12, 'B')]; + if (isset($post['goods_code']) && is_array($post['goods_code'])) { + foreach (array_keys($post['goods_code']) as $key) { + if ($post['goods_stock'][$key] > 0) $data[] = [ + 'batch_no' => $batch, + 'goods_code' => $post['goods_code'][$key], + 'goods_spec' => $post['goods_spec'][$key], + 'goods_stock' => $post['goods_stock'][$key], + ]; + } if (!empty($data)) { $this->app->db->name('ShopGoodsStock')->insertAll($data); - GoodsService::instance()->syncStock($post['code']); + GoodsService::instance()->syncStock($input['code']); $this->success('商品信息入库成功!'); } } diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index 2ca149f4b..121eac854 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -25,7 +25,7 @@ class GoodsService extends Service { // 商品入库统计 $query = $this->app->db->name('ShopGoodsStock'); - $query->field('goods_code,goods_spec,ifnull(sum(number_stock),0) number_stock'); + $query->field('goods_code,goods_spec,ifnull(sum(goods_stock),0) stock_total'); $stockList = $query->where(['goods_code' => $code])->group('goods_code,goods_spec')->select()->toArray(); // 商品销量统计 $query = $this->app->db->table('shop_order a')->field('b.goods_code,b.goods_spec,ifnull(sum(b.stock_sales),0) stock_sales'); diff --git a/app/data/sys.php b/app/data/sys.php new file mode 100644 index 000000000..a9a037072 --- /dev/null +++ b/app/data/sys.php @@ -0,0 +1,11 @@ +url()}" data-auto="true" method="post" autocomplete="off"> -
-
商品名称 Goods name -
{$vo.title}
+
{$vo.name}
-
规格数据 @@ -16,6 +13,7 @@ 商品规格 + 市场价格 销售价格 库存统计 总销统计 @@ -26,25 +24,28 @@ {foreach $vo.list as $goods} - - + + {$goods.goods_spec|show_goods_spec} - + - + - + - + + + + - + {/foreach} @@ -52,12 +53,8 @@
-
-
- {notempty name='vo.id'}{/notempty} -