修改订单

This commit is contained in:
邹景立 2021-03-20 15:04:54 +08:00
parent 2b30e333a1
commit 27c3b80481
6 changed files with 24 additions and 23 deletions

View File

@ -80,7 +80,7 @@ class ShopGoods extends Controller
{ {
$this->marks = GoodsService::instance()->getMarkData(); $this->marks = GoodsService::instance()->getMarkData();
$this->cates = GoodsService::instance()->getCateData(); $this->cates = GoodsService::instance()->getCateData();
GoodsService::instance()->buildData($data, false); GoodsService::instance()->bindData($data, false);
} }
/** /**
@ -201,7 +201,7 @@ class ShopGoods extends Controller
protected function _form_result(bool $result) protected function _form_result(bool $result)
{ {
if ($result && $this->request->isPost()) { if ($result && $this->request->isPost()) {
GoodsService::instance()->syncStock(input('code')); GoodsService::instance()->stock(input('code'));
$this->success('商品编辑成功!', 'javascript:history.back()'); $this->success('商品编辑成功!', 'javascript:history.back()');
} }
} }
@ -219,7 +219,7 @@ class ShopGoods extends Controller
if ($this->request->isGet()) { if ($this->request->isGet()) {
$list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray(); $list = $this->app->db->name('ShopGoods')->where($map)->select()->toArray();
if (empty($list)) $this->error('无效的商品数据,请稍候再试!'); if (empty($list)) $this->error('无效的商品数据,请稍候再试!');
[$this->vo] = GoodsService::instance()->buildData($list); [$this->vo] = GoodsService::instance()->bindData($list);
$this->fetch(); $this->fetch();
} else { } else {
[$data, $post, $batch] = [[], $this->request->post(), CodeExtend::uniqidDate(12, 'B')]; [$data, $post, $batch] = [[], $this->request->post(), CodeExtend::uniqidDate(12, 'B')];
@ -234,7 +234,7 @@ class ShopGoods extends Controller
} }
if (!empty($data)) { if (!empty($data)) {
$this->app->db->name('ShopGoodsStock')->insertAll($data); $this->app->db->name('ShopGoodsStock')->insertAll($data);
GoodsService::instance()->syncStock($map['code']); GoodsService::instance()->stock($map['code']);
$this->success('商品数据入库成功!'); $this->success('商品数据入库成功!');
} }
} }

View File

@ -47,7 +47,7 @@ class Goods extends Controller
} }
$query = $this->_query('ShopGoods')->like('name,cateids,marks,payment')->equal('code'); $query = $this->_query('ShopGoods')->like('name,cateids,marks,payment')->equal('code');
$result = $query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc')->page(true, false, false, 10); $result = $query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc')->page(true, false, false, 10);
if (count($result['list']) > 0) GoodsService::instance()->buildData($result['list']); if (count($result['list']) > 0) GoodsService::instance()->bindData($result['list']);
$this->success('获取商品数据', $result); $this->success('获取商品数据', $result);
} }

View File

@ -177,7 +177,7 @@ class Order extends Auth
}); });
// 同步商品库存销量 // 同步商品库存销量
foreach (array_unique(array_column($items, 'goods_code')) as $code) { foreach (array_unique(array_column($items, 'goods_code')) as $code) {
GoodsService::instance()->syncStock($code); GoodsService::instance()->stock($code);
} }
// 触发订单创建事件 // 触发订单创建事件
$this->app->event->trigger('ShopOrderCreate', $order['order_no']); $this->app->event->trigger('ShopOrderCreate', $order['order_no']);

View File

@ -13,6 +13,15 @@ use think\admin\Service;
class GoodsService extends Service class GoodsService extends Service
{ {
/**
* 最大分类级别
* @return integer
*/
public function getCateMax(): int
{
return 3;
}
/** /**
* 获取分类数据 * 获取分类数据
* @return array * @return array
@ -65,15 +74,6 @@ class GoodsService extends Service
return $query->where($map)->order('sort desc,id desc')->column('name'); return $query->where($map)->order('sort desc,id desc')->column('name');
} }
/**
* 最大分类级别
* @return integer
*/
public function getCateMax(): int
{
return 3;
}
/** /**
* 更新商品库存数据 * 更新商品库存数据
* @param string $code * @param string $code
@ -82,7 +82,7 @@ class GoodsService extends Service
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function syncStock(string $code): bool public function stock(string $code): bool
{ {
// 商品入库统计 // 商品入库统计
$query = $this->app->db->name('ShopGoodsStock'); $query = $this->app->db->name('ShopGoodsStock');
@ -125,7 +125,7 @@ class GoodsService extends Service
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function buildData(array &$data = [], $simple = true): array public function bindData(array &$data = [], $simple = true): array
{ {
[$cates, $codes] = [$this->getCateData(), array_unique(array_column($data, 'code'))]; [$cates, $codes] = [$this->getCateData(), array_unique(array_column($data, 'code'))];
$marks = $this->app->db->name('ShopGoodsMark')->where(['status' => 1])->column('name'); $marks = $this->app->db->name('ShopGoodsMark')->where(['status' => 1])->column('name');

View File

@ -32,7 +32,7 @@ class OrderService extends Service
{ {
$map = ['order_no' => $orderNo]; $map = ['order_no' => $orderNo];
$codes = $this->app->db->name('ShopOrderItem')->where($map)->column('goods_code'); $codes = $this->app->db->name('ShopOrderItem')->where($map)->column('goods_code');
foreach (array_unique($codes) as $code) GoodsService::instance()->syncStock($code); foreach (array_unique($codes) as $code) GoodsService::instance()->stock($code);
return true; return true;
} }

View File

@ -6,11 +6,12 @@
<div class="layui-form-item"> <div class="layui-form-item">
<span class="color-green font-w7 label-required-prev">支付方式图标</span> <span class="color-green font-w7 label-required-prev">支付方式图标</span>
<span class="color-desc margin-left-5">Payment Cover</span> <span class="color-desc margin-left-5">Payment Image</span>
<div class="margin-top-10"> <label class="relative block label-required-null">
<input type="hidden" required name="cover" value="{$vo.cover|default=''}"/> <input required name="cover" value='{$vo.cover|default=""}' placeholder="请上传支付方式图标 &nbsp;&nbsp;&nbsp;&nbsp;" class="layui-input">
<script>$('[name=cover]').uploadOneImage()</script> <a data-file data-type="png,jpg,gif" data-field="cover" class="layui-icon layui-icon-upload input-right-icon"></a>
</div> <script>$('[name="cover"]').uploadOneImage()</script>
</label>
</div> </div>
<label class="layui-form-item relative block"> <label class="layui-form-item relative block">