Commit 2f6a03bd authored by wxl's avatar wxl

自动添加商品编码

parent 405e5ffb
...@@ -585,4 +585,25 @@ class GoodsController extends AbstractActionController ...@@ -585,4 +585,25 @@ class GoodsController extends AbstractActionController
exit; exit;
return; return;
} }
/**
* 分类id检索,ajax输出
* @return JsonModel
*/
public function goodsCategoryIdSearchAction(): JsonModel
{
$array = ['state' => 'false'];
$goodsCategoryId = (int) $this->params()->fromPost('goodsCategoryId', 0);
if($goodsCategoryId > 0) {
$goodsInfo = $this->entityManager->getRepository(Goods::class)->findOneBy(['goodsCategoryId' => $goodsCategoryId],["goodsId"=>"DESC"]);
if($goodsInfo) {
$array['state'] = 'ok';
$array['goods_number'] = $goodsInfo->getgoodsNumber() +1;
}
}
return new JsonModel($array);
}
} }
\ No newline at end of file
...@@ -242,4 +242,15 @@ ...@@ -242,4 +242,15 @@
} }
}); });
}); });
</script>
<script type="text/javascript">
$("#goodsCategoryId").change( function() {
// 这里可以写些验证代码
var goodsCategoryId=$("#goodsCategoryId").val();
$.post("<?php echo $this->url('goods', ['action' => 'goodsCategoryIdSearch']); ?>", {goodsCategoryId: goodsCategoryId}, function (data) {
if(data.state == 'ok') {
$('#goodsNumber').val(data.goods_number);
}
})
});
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment