iwebshop模擬秒殺

//秒殺模擬練習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>";    }}
相關文章
相關標籤/搜索