From e006d1461d6aec77235ff26648be25e162acaf39 Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 15 Sep 2020 16:35:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/ShopGoods.php | 109 +++++++++++++++++----------- app/data/view/shop_goods/form.html | 4 +- app/data/view/shop_goods/index.html | 3 + 3 files changed, 72 insertions(+), 44 deletions(-) diff --git a/app/data/controller/ShopGoods.php b/app/data/controller/ShopGoods.php index eb9110616..1019a4880 100644 --- a/app/data/controller/ShopGoods.php +++ b/app/data/controller/ShopGoods.php @@ -87,43 +87,7 @@ class ShopGoods extends Controller } /** - * 商品库存入库 - * @auth true - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function stock() - { - $map = $this->_vali(['code.require' => '商品编号不能为空哦!']); - if ($this->request->isGet()) { - $list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray(); - if (empty($list)) $this->error('无效的商品信息,请稍候再试!'); - [$this->vo] = GoodsService::instance()->buildItemData($list); - $this->fetch(); - } else { - [$data, $post, $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($map['code']); - $this->success('商品信息入库成功!'); - } - } - $this->error('没有需要商品入库的数据!'); - } - } - - /** - * 添加商品信息 + * 添加商品数据 * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException @@ -132,12 +96,12 @@ class ShopGoods extends Controller public function add() { $this->mode = 'add'; - $this->title = '添加商品信息'; + $this->title = '添加商品数据'; $this->_form($this->table, 'form', 'code'); } /** - * 编辑商品信息 + * 编辑商品数据 * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException @@ -146,10 +110,35 @@ class ShopGoods extends Controller public function edit() { $this->mode = 'edit'; - $this->title = '编辑商品信息'; + $this->title = '编辑商品数据'; $this->_form($this->table, 'form', 'code'); } + /** + * 复制编辑商品 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function copy() + { + $this->mode = 'copy'; + $this->title = '复制编辑商品'; + $this->_form($this->table, 'form', 'code'); + } + + /** + * 表单数据处理 + * @param array $data + */ + protected function _copy_form_filter(&$data) + { + if ($this->request->isPost()) { + $data['code'] = CodeExtend::uniqidNumber(12, 'G'); + } + } + /** * 表单数据处理 * @param array $data @@ -209,7 +198,43 @@ class ShopGoods extends Controller } /** - * 上下架商品管理 + * 商品库存入库 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function stock() + { + $map = $this->_vali(['code.require' => '商品编号不能为空哦!']); + if ($this->request->isGet()) { + $list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray(); + if (empty($list)) $this->error('无效的商品数据,请稍候再试!'); + [$this->vo] = GoodsService::instance()->buildItemData($list); + $this->fetch(); + } else { + [$data, $post, $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($map['code']); + $this->success('商品数据入库成功!'); + } + } + $this->error('没有需要商品入库的数据!'); + } + } + + /** + * 商品上下架管理 * @auth true * @throws \think\db\exception\DbException */ @@ -222,7 +247,7 @@ class ShopGoods extends Controller } /** - * 删除商品信息 + * 删除商品数据 * @auth true * @throws \think\db\exception\DbException */ diff --git a/app/data/view/shop_goods/form.html b/app/data/view/shop_goods/form.html index c646b8da4..c99dd21db 100644 --- a/app/data/view/shop_goods/form.html +++ b/app/data/view/shop_goods/form.html @@ -20,9 +20,9 @@ Category Name diff --git a/app/data/view/shop_goods/index.html b/app/data/view/shop_goods/index.html index 26ef115f2..e599ce5c9 100644 --- a/app/data/view/shop_goods/index.html +++ b/app/data/view/shop_goods/index.html @@ -71,6 +71,9 @@
剩余库存 {$vo.stock_total-$vo.stock_sales} 件 ( 已销售 {$vo.stock_sales} 件 )
+ {if auth('copy')} + 复 制 + {/if} 编 辑