本文整理汇总了PHP中Inventory::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Inventory::validate方法的具体用法?PHP Inventory::validate怎么用?PHP Inventory::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory::validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCategory
public function actionCategory($name)
{
if (Yii::app()->user->isGuest) {
$this->redirect(Yii::app()->homeUrl);
}
$id = WebshopCategory::model()->find('alt_name = "' . $name . '"');
$this->pageTitle = Yii::t('title', 'Webshop') . ': ' . $id->name;
$criteria = new CDbCriteria();
$criteria->select = '*';
$criteria->condition = 'category_id = ' . $id->category_id;
$pages = new CPagination(Webshop::model()->count($criteria));
$pages->pageSize = Config::get('page_shop');
$pages->applyLimit($criteria);
$model = Webshop::model()->findAll($criteria);
$form = new Inventory();
$form->scenario = 'buy';
if (isset($_POST['Inventory'])) {
$form->attributes = $_POST['Inventory'];
if ($form->validate()) {
$criteria = new CDbCriteria();
$criteria->select = '*';
$criteria->condition = 'item_id = ' . $form->item_id;
$item = Webshop::model()->find($criteria);
$real_price = ceil($form->new_amount * ($item->price / $item->amount));
$account = AccountData::model()->findByPk(Yii::app()->user->id);
if ($account[Yii::app()->params->money] < $real_price) {
Yii::app()->user->setFlash('message', '<div class="flash_error">' . Yii::t('webshop', 'Insufficient funds.') . '</div>');
$this->refresh();
}
$criteria = new CDbCriteria();
$criteria->condition = 'id = ' . $form->item_owner . ' AND online = 1';
$online = Players::model()->count($criteria);
if ($online == 1) {
Yii::app()->user->setFlash('message', '<div class="flash_error">' . Yii::t('webshop', 'Log-out') . '</div>');
$this->refresh();
}
$criteria = new CDbCriteria();
$criteria->select = 'MAX(mail_unique_id) as mail_unique_id';
$last_mail_id = Mail::model()->find($criteria);
$mail = new Mail();
$mail->mail_unique_id = $last_mail_id->mail_unique_id + 1;
$mail->mail_recipient_id = $form->item_owner;
$mail->sender_name = 'Admin';
$mail->mail_title = Yii::t('webshop', 'Delivery');
$mail->mail_message = Yii::t('webshop', 'Your purchase has been successful. Thank you, and we hope you enjoy the game!');
$mail->unread = 1;
if ($form->item_id == 182400001) {
$mail->attached_item_id = 0;
$mail->attached_kinah_count = $form->new_amount;
} else {
$mail->attached_item_id = $this->add_item($form->item_id, $form->item_owner, $form->new_amount);
$mail->attached_kinah_count = 0;
}
$mail->express = 1;
$mail->save(false);
$account[Yii::app()->params->money] = $account[Yii::app()->params->money] - $real_price;
$account->save(false);
$log = new LogWebshop();
$log->player_id = $form->item_owner;
$log->item = $form->item_id;
$log->amount = $form->new_amount;
$log->price = $real_price;
$log->save(false);
Yii::app()->user->setFlash('message', '<div class="flash_success">' . Yii::t('webshop', 'Purchase successful!') . '</div>');
$this->refresh();
}
}
$this->render('category', array('model' => $model, 'id' => $id, 'form' => $form, 'players' => Players::getPlayers(), 'pages' => $pages));
}