예제 #1
0
파일: buy.php 프로젝트: wuwenhan/huoqiwang
<?php

use frontend\actions\Invest;
use yii\base\ErrorException;
$uid = Yii::$app->user->id;
$pid = $_POST['pid'];
$money = $_POST['money'];
try {
    $result = Invest::invest($uid, $pid, $money);
    if ($result) {
        echo '购买成功';
        exit;
    }
} catch (ErrorException $e) {
    echo $e->getMessage();
    exit;
}
예제 #2
0
 public function actionBuy()
 {
     if (\yii::$app->user->isGuest) {
         $this->redirect(['site/login']);
     }
     $isAuthentic = member::isAuthentic(yii::$app->user->id);
     if (!$isAuthentic) {
         header("Content-type: text/html; charset=utf-8");
         echo "<script>alert('您还没有实名制认证')</script>";
         echo "<script>window.location.href='" . \yii\helpers\Url::to(['setting/setting']) . "'</script>";
         exit;
     }
     $model_asset = Info::find()->where('member_id=' . Yii::$app->user->id)->one();
     if (!isset($model_asset)) {
         //转到绑定银行卡页面
         header("Content-type: text/html; charset=utf-8");
         echo "<script>alert('请先绑定银行卡')</script>";
         echo "<script>window.location.href='" . \yii\helpers\Url::to(['money/bindcard']) . "'</script>";
         exit;
     }
     if (isset($_POST['pid']) && isset($_POST['money'])) {
         $uid = Yii::$app->user->id;
         $pid = $_POST['pid'];
         $money = $_POST['money'];
         try {
             $result = Invest::invest($uid, $pid, $money);
             if ($result) {
                 Invest::gold($uid, $money);
                 echo '购买成功';
                 exit;
             }
         } catch (ErrorException $e) {
             echo $e->getMessage();
             exit;
         }
     }
     return $this->render('buy');
 }