mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]微商城库存管理
This commit is contained in:
parent
de920ca7d8
commit
a099bb6e70
@ -223,6 +223,45 @@ class Goods extends BasicAdmin
|
||||
return ['main' => $main, 'list' => $list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品库存信息更新
|
||||
* @return string
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public function stock()
|
||||
{
|
||||
if (!$this->request->post()) {
|
||||
$goods_id = $this->request->get('id');
|
||||
$goods = Db::name('StoreGoods')->where(['id' => $goods_id, 'is_deleted' => '0'])->find();
|
||||
empty($goods) && $this->error('该商品无法操作入库操作!');
|
||||
$where = ['goods_id' => $goods_id, 'status' => '1', 'is_deleted' => '0'];
|
||||
$goods['list'] = Db::name('StoreGoodsList')->where($where)->select();
|
||||
return $this->fetch('', ['vo' => $goods]);
|
||||
}
|
||||
// 入库保存
|
||||
$goods_id = $this->request->post('id');
|
||||
list($post, $data) = [$this->request->post(), []];
|
||||
foreach ($post['spec'] as $key => $spec) {
|
||||
if ($post['stock'][$key] > 0) {
|
||||
$data[] = [
|
||||
'goods_stock' => $post['stock'][$key],
|
||||
'stock_desc' => $this->request->post('desc'),
|
||||
'goods_spec' => $spec, 'goods_id' => $goods_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
empty($data) && $this->error('无需入库的数据哦!');
|
||||
if (Db::name('StoreGoodsStock')->insertAll($data) !== false) {
|
||||
GoodsService::syncGoodsStock($goods_id);
|
||||
$this->success('商品入库成功!', '');
|
||||
}
|
||||
$this->error('商品入库失败,请稍候再试!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @throws \think\Exception
|
||||
|
@ -99,7 +99,7 @@ class GoodsService
|
||||
{
|
||||
// 检查商品是否需要更新库存
|
||||
$map = ['id' => $goods_id, 'is_deleted' => '0'];
|
||||
if (!($goods = Db::name('Goods')->where($map)->find())) {
|
||||
if (!($goods = Db::name('StoreGoods')->where($map)->find())) {
|
||||
return ['code' => 0, 'msg' => '指定商品信息无法同步库存!'];
|
||||
}
|
||||
// 统计入库信息
|
||||
@ -109,7 +109,7 @@ class GoodsService
|
||||
// 统计销售信息
|
||||
$saleField = 'goods_id,goods_spec,ifnull(sum(number), 0) goods_sale';
|
||||
$saleWhere = ['status' => '1', 'is_deleted' => '0', 'goods_id' => $goods_id];
|
||||
$saleList = (array)Db::name('StoreOrderList')->field($saleField)->where($saleWhere)->group('goods_id,goods_spec')->select();
|
||||
$saleList = (array)Db::name('StoreOrderGoods')->field($saleField)->where($saleWhere)->group('goods_id,goods_spec')->select();
|
||||
// 库存置零
|
||||
list($where, $total_sale) = [['goods_id' => $goods_id], 0];
|
||||
Db::name('StoreGoodsList')->where($where)->update(['goods_stock' => 0, 'goods_sale' => 0]);
|
||||
|
@ -159,6 +159,11 @@
|
||||
<a data-open='{:url("$classuri/edit")}?id={$vo.id}'>编辑</a>
|
||||
<!--{/if}-->
|
||||
|
||||
<!--{if auth("$classuri/stock")}-->
|
||||
<span class="text-explode">|</span>
|
||||
<a data-title="商品入库" data-modal='{:url("$classuri/stock")}?id={$vo.id}'>入库</a>
|
||||
<!--{/if}-->
|
||||
|
||||
<!--{if $vo.status eq 1 and auth("$classuri/forbid")}-->
|
||||
<span class="text-explode">|</span>
|
||||
<a data-update="{$vo.id}" data-field='status' data-value='0' data-action='{:url("$classuri/forbid")}'>下架</a>
|
||||
|
52
application/store/view/goods/stock.html
Normal file
52
application/store/view/goods/stock.html
Normal file
@ -0,0 +1,52 @@
|
||||
<form class="layui-form layui-box modal-form-box" action="{:request()->url()}" data-auto="true" method="post">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商品名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input value='{$vo.goods_title|default=""}' disabled="disabled" class="layui-input layui-bg-gray">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label label-required">商品库存</label>
|
||||
<div class="layui-input-block">
|
||||
<table class="layui-table" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>商品规格</th>
|
||||
<th class="text-right">入库数量</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{foreach $vo.list as $spec}
|
||||
<tr>
|
||||
<td>
|
||||
{$spec.goods_spec|str_replace=['default:default',',',':'],['默认规格',',',':'],###}
|
||||
</td>
|
||||
<td style="padding:0">
|
||||
<input name="spec[]" value="{$spec.goods_spec}" type="hidden">
|
||||
<input name="stock[]" value="0" onblur="this.value=parseInt(this.value)||0"
|
||||
class="layui-input text-right padding-right-10 border-none">
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">入库描述</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea placeholder="请输入入库描述" title="请输入入库描述" class="layui-textarea" name="desc"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="layui-form-item text-center">
|
||||
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
|
||||
<button class="layui-btn" type='submit'>保存数据</button>
|
||||
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
|
||||
</div>
|
||||
|
||||
<script>window.form.render();</script>
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user