修改商城代码

This commit is contained in:
Anyon 2020-09-10 15:26:49 +08:00
parent 62b1134d61
commit 3bc3f96f26
4 changed files with 34 additions and 51 deletions

View File

@ -82,13 +82,12 @@ class ShopGoods extends Controller
*/
public function stock()
{
$input = $this->_vali(['code.require' => '商品编号不能为空哦!']);
$map = $this->_vali(['code.require' => '商品编号不能为空哦!']);
if ($this->request->isGet()) {
$goods = $this->app->db->name('ShopGoods')->where($input)->find();
empty($goods) && $this->error('无效的商品信息,请稍候再试!');
$map = ['goods_code' => $input['code'], 'status' => 1];
$goods['list'] = $this->app->db->name('ShopGoodsItem')->where($map)->select()->toArray();
$this->fetch('', ['vo' => $goods]);
$list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray();
if (empty($list)) $this->error('无效的商品信息,请稍候再试!');
[$this->vo] = GoodsService::instance()->buildItemData($list);
$this->fetch();
} else {
[$post, $data, $batch] = [$this->request->post(), [], CodeExtend::uniqidDate(12, 'B')];
if (isset($post['goods_code']) && is_array($post['goods_code'])) {
@ -102,7 +101,7 @@ class ShopGoods extends Controller
}
if (!empty($data)) {
$this->app->db->name('ShopGoodsStock')->insertAll($data);
GoodsService::instance()->syncStock($input['code']);
GoodsService::instance()->syncStock($map['code']);
$this->success('商品信息入库成功!');
}
}

View File

@ -99,22 +99,21 @@ class GoodsService extends Service
/**
* 商品数据绑定
* @param array $list 商品主数据
* @param array $data 商品主数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function buildItemData(array &$list = []): array
public function buildItemData(array &$data = []): array
{
$cates = $this->app->db->name('ShopGoodsCate')->column('id,pid,name', 'id');
foreach ($cates as $cate) if (isset($cates[$cate['pid']])) {
$cates[$cate['id']]['parent'] =& $cates[$cate['pid']];
}
$codes = array_unique(array_column($list, 'code'));
$where = [['goods_code', 'in', $codes], ['status', '=', 1]];
$items = $this->app->db->name('ShopGoodsItem')->withoutField('id,status,create_at')->where($where)->select()->toArray();
foreach ($list as &$vo) {
$map = [['goods_code', 'in', array_unique(array_column($data, 'code'))], ['status', '=', 1]];
$items = $this->app->db->name('ShopGoodsItem')->withoutField('id,status,create_at')->where($map)->select()->toArray();
foreach ($data as &$vo) {
$vo['marks'] = think_string_to_array($vo['mark']);
$vo['cates'] = $cates[$vo['cate']] ?? [];
$vo['slider'] = explode('|', $vo['slider']);
@ -123,9 +122,7 @@ class GoodsService extends Service
foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item;
unset($vo['mark'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs']);
}
dump($list);
exit;
return $list;
return $data;
}

View File

@ -78,14 +78,14 @@
<!--{/if}-->
{if isset($type) and $type eq 'index'}
{if isset($vo.status) and $vo.status eq 1}
<!--{if auth("forbid")}-->
<a class="layui-btn layui-btn-xs layui-btn-warm" data-action="{:url('forbid')}" data-value="code#{$vo.code};status#0"> </a>
<!--{if auth("state")}-->
<a class="layui-btn layui-btn-xs layui-btn-warm" data-action="{:url('state')}" data-value="code#{$vo.code};status#0"> </a>
<!--{else}-->
<a data-tips-text="您没有下架商品的权限哦!" class="layui-btn layui-btn-xs layui-btn-primary layui-disabled"> </a>
<!--{/if}-->
{else}
<!--{if auth("resume")}-->
<a class="layui-btn layui-btn-xs layui-btn-warm" data-action="{:url('resume')}" data-value="code#{$vo.code};status#1"> </a>
<!--{if auth("state")}-->
<a class="layui-btn layui-btn-xs layui-btn-warm" data-action="{:url('state')}" data-value="code#{$vo.code};status#1"> </a>
<!--{else}-->
<a data-tips-text="您没有上架商品的权限哦!" class="layui-btn layui-btn-xs layui-btn-primary layui-disabled"> </a>
<!--{/if}-->

View File

@ -2,46 +2,34 @@
<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.name}</div>
<span class="color-desc margin-left-5">Goods Name</span>
<div class="layui-input layui-bg-gray">{$vo.name|default=''}</div>
</div>
<div class="layui-form-item">
<div class="relative block">
<span class="color-green font-w7">规格数据</span>
<span class="color-desc margin-left-5">Specification data</span>
<table class="layui-table">
<span class="color-desc margin-left-5">Specification Data</span>
<table class="layui-table" lay-skin="line">
<thead>
<tr>
<tr class="layui-bg-cyan">
<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>
<th class="text-center">库存剩余</th>
<th class="text-center">入库数量</th>
<th class="text-center nowrap">市场价格</th>
<th class="text-center nowrap">销售价格</th>
<th class="text-center nowrap">库存统计</th>
<th class="text-center nowrap">总销统计</th>
<th class="text-center nowrap">库存剩余</th>
<th class="text-center nowrap">入库数量</th>
</tr>
</thead>
<tbody>
{foreach $vo.list as $goods}
{foreach $vo.items as $goods}
<tr>
<td width="28%" class="layui-bg-gray">
{$goods.goods_spec|think_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.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.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.stock_sales} ">
</td>
<td class="padding-0" width="12%">
<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="layui-bg-gray" width="28%">{$goods.goods_spec|think_show_goods_spec}</td>
<td class="layui-bg-gray text-center" width="12%">{$goods.price_market+0}</td>
<td class="layui-bg-gray text-center" width="12%">{$goods.price_selling+0}</td>
<td class="layui-bg-gray text-center" width="12%">{$goods.stock_total|default=0}</td>
<td class="layui-bg-gray text-center" width="12%">{$goods.stock_sales|default=0}</td>
<td class="layui-bg-gray text-center" width="12%">{$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=''}">
@ -59,5 +47,4 @@
<button class="layui-btn" type='submit'>确定入库</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消入库吗?" data-close>取消入库</button>
</div>
</form>