修改商品库存管理

This commit is contained in:
Anyon 2020-09-09 12:19:59 +08:00
parent 320d132425
commit d7f7994ce3
4 changed files with 38 additions and 27 deletions

View File

@ -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('商品信息入库成功!');
}
}

View File

@ -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');

11
app/data/sys.php Normal file
View File

@ -0,0 +1,11 @@
<?php
if (!function_exists('show_goods_spec')) {
function show_goods_spec($spec)
{
$specs = [];
foreach (explode(';;', $spec) as $sp) {
$specs[] = explode('::', $sp)[1];
}
return join(' ', $specs);
}
}

View File

@ -1,13 +1,10 @@
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
<div class="layui-card-body padding-left-40">
<div class="layui-form-item relative block">
<span class="color-green font-w7">商品名称</span>
<span class="color-desc margin-left-5">Goods name</span>
<div class="layui-input layui-bg-gray">{$vo.title}</div>
<div class="layui-input layui-bg-gray">{$vo.name}</div>
</div>
<div class="layui-form-item">
<div class="relative block">
<span class="color-green font-w7">规格数据</span>
@ -16,6 +13,7 @@
<thead>
<tr>
<th class="text-left">商品规格</th>
<th class="text-center">市场价格</th>
<th class="text-center">销售价格</th>
<th class="text-center">库存统计</th>
<th class="text-center">总销统计</th>
@ -26,25 +24,28 @@
<tbody>
{foreach $vo.list as $goods}
<tr>
<td class="padding-0" width="40%">
<input class="layui-input layui-bg-gray border-0" disabled value="{$goods.goods_spec|show_goods_spec}">
<td width="28%" class="layui-bg-gray">
{$goods.goods_spec|show_goods_spec}
</td>
<td class="padding-0" width="12%">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.price_market}">
</td>
<td class="padding-0" width="12%">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.number_stock}">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.price_selling}">
</td>
<td class="padding-0" width="12%">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.number_sales} ">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.stock_total}">
</td>
<td class="padding-0" width="12%">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.number_stock-$goods.number_sales} ">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.stock_sales} ">
</td>
<td class="padding-0" width="12%">
<input type="hidden" name="goods_id[]" value="{$goods.goods_id|default=''}">
<input class="layui-input text-center layui-bg-gray border-0 padding-left-0" disabled value="{$goods.stock_total-$goods.stock_sales} ">
</td>
<td class="padding-0" width="12%">
<input type="hidden" name="goods_code[]" value="{$goods.goods_code|default=''}">
<input type="hidden" name="goods_spec[]" value="{$goods.goods_spec|default=''}">
<input class="layui-input text-center border-0 padding-left-0" onblur="this.value=parseInt(this.value)||0" name="goods_number[]" value="0">
<input class="layui-input text-center border-0 padding-left-0" onblur="this.value=parseInt(this.value)||0" name="goods_stock[]" value="0">
</td>
</tr>
{/foreach}
@ -52,12 +53,8 @@
</table>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
{notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
<div class="layui-form-item text-center">
<button class="layui-btn" type='submit'>确定入库</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消入库吗?" data-close>取消入库</button>