//秒杀模拟练习
public function sha(){
$testObj = new IModel("goodss");
$arr = $testObj->query();
$this->list = $arr;
$this->redirect('sha');
}
public function miao(){
$id = IReq::get("id");
$testObj = new IModel("goodss");
$arr = $testObj->query("goods_id=$id");
$num = $arr[0]['goods_num'];
if($num>0){ //支持购买
//库存减少
$num-=1;
$data = array(
'goods_num'=>$num
);
$testObj->setData($data);
$a = $testObj->update("goods_id=$id");
if($a){
echo "<script>alert('购买成功');location.href='http://localhost/test/iwebshop4.6/index.php?controller=text&action=sha'</script>";
}else{
echo "<script>alert('购买失败,请稍后重试!');location.href='http://localhost/test/iwebshop4.6/index.php?controller=text&action=sha'</script>";
}
}else{
echo "<script>alert('不好意思,库存不足!');location.href='http://localhost/test/iwebshop4.6/index.php?controller=text&action=sha'</script>";
}
}
如果您觉得本文对您的学习有所帮助,请多关注支持与鼓励。
正在看本人博客的这位童鞋,我看你气度不凡,谈吐间隐隐有王者之气,日后必有一番作为!屏幕右下角有“好文要顶”四字,如果觉得对你有帮助,你就顺手把它点了吧。
浙公网安备 33010602011771号