增加商品复制功能

This commit is contained in:
Anyon 2020-09-15 16:35:41 +08:00
parent 194bd33cdc
commit e006d1461d
3 changed files with 72 additions and 44 deletions

View File

@ -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
*/

View File

@ -20,9 +20,9 @@
<span class="color-desc margin-left-5">Category Name</span>
<select class="layui-select" name="cate" lay-search>
{foreach $cates as $cate}{if isset($vo.cate) and $vo.cate eq $cate.id}
<option {$cate.sat} disabled selected value="{$cate.id}">{$cate.spl}{$cate.name|default=''}</option>
<option {$cate.sat} selected value="{$cate.id}">{$cate.spl}{$cate.name|default=''}</option>
{else}
<option {$cate.sat} disabled value="{$cate.id}">{$cate.spl}{$cate.name|default=''}</option>
<option {$cate.sat} value="{$cate.id}">{$cate.spl}{$cate.name|default=''}</option>
{/if}{/foreach}
</select>
</label>

View File

@ -71,6 +71,9 @@
</td>
<td class='nowrap sub-span-blue'>
<div class="margin-bottom-5">剩余库存 <span>{$vo.stock_total-$vo.stock_sales}</span> ( 已销售 <span>{$vo.stock_sales}</span> )</div>
{if auth('copy')}
<a class="layui-btn layui-btn-xs layui-btn-normal" data-open='{:url("copy")}?code={$vo.code}'> </a>
{/if}
<!--{if auth("edit")}-->
<a class="layui-btn layui-btn-xs" data-open='{:url("edit")}?code={$vo.code}'> </a>
<!--{else}-->