Exemple #1
0
<?php

$this->pageLabel = Yii::t("admin", "Quản lý Sự Kiện");
$this->menu = array(array('label' => Yii::t('admin', 'Danh sách'), 'url' => array('admin')), array('label' => Yii::t('admin', 'Thêm mới'), 'url' => array('create')), array('label' => Yii::t('admin', 'Tìm kiếm'), 'url' => '#', 'linkOptions' => array('class' => 'search-button')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('admin-event-model-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<div class="search-form" style="display:none">
<?php 
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'admin-event-model-grid', 'dataProvider' => $dataProvider, 'columns' => array(array('name' => 'name', 'header' => EventModel::model()->getAttributeLabel("name"), 'value' => 'CHtml::link($data->name,array("update","id"=>$data->_id))', 'type' => 'raw'), array('name' => 'description', 'header' => EventModel::model()->getAttributeLabel("description")), array('name' => 'group_id', 'header' => EventModel::model()->getAttributeLabel("group_id"), 'value' => 'AdminEventGroupModel::model()->findByPk(new MongoId($data->group_id))->name', 'type' => 'raw'), array('name' => 'point', 'header' => EventModel::model()->getAttributeLabel("point")), 'reset', array('name' => 'status', 'header' => EventModel::model()->getAttributeLabel("status"), 'value' => '($data->status==1)?"<span class=\\"s_label s_1\\">Actived</span>":"<span class=\\"s_label s_2\\">Not Active</span>"', 'type' => 'raw'), array('class' => 'CButtonColumn'))));
 public function wLogEvent($user_id, $user_phone, $eventId, $source, $contentId = '', $contentName = '', $transaction = '', $transactionId = 0, $transaction_name, $log_point)
 {
     try {
         $log = new KLogger('log_event_users_transaction', KLogger::INFO);
         $event = EventModel::model()->findByPk(new MongoId($eventId));
         $point = $event->point;
         if ($log_point == 0) {
             $point = 0;
         }
         $log->LogInfo("{$transaction}|{$user_phone}|{$contentId}|{$point}", false);
         $userSubscribe = true;
         switch ($transaction) {
             case 'play_song':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 break;
             case 'play_video':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 break;
             case 'play_album':
                 $transactionValid = $this->isContent24h($contentId, $eventId, $user_phone, $transaction);
                 $point = $this->getPoint($contentId, $transaction, $point);
                 $pointValid = $this->isPoint24h($point, $user_phone);
                 $userSubscribe = UserSubscribeModel::model()->get($user_phone);
                 break;
             default:
                 $transactionValid = true;
                 $pointValid = true;
                 break;
         }
         if ($transactionValid && $pointValid && $userSubscribe) {
             if ($event && (!empty($user_id) || !empty($user_phone))) {
                 $eventName = $event->name;
                 $groupEventId = $event->group_id;
                 $groupEventName = $event->group_name;
                 $model = new self();
                 $model->user_id = (int) $user_id;
                 $model->user_phone = !empty($user_phone) ? $user_phone : 0;
                 $model->event_id = $eventId;
                 $model->event_name = $eventName;
                 $model->group_id = $groupEventId;
                 $model->group_name = $groupEventName;
                 $model->content_id = $contentId;
                 $model->content_name = $contentName;
                 $model->transaction = $transaction;
                 $model->transaction_name = $transaction_name;
                 $model->transaction_id = (string) $transactionId;
                 $model->point = (int) $point;
                 $model->method = $source;
                 $model->created_time = date('Y-m-d H:i:s');
                 $model->updated_time = date('Y-m-d H:i:s');
                 $res = $model->save();
                 $log->LogInfo('write log ' . $transaction . ' | ' . $user_phone . '|' . $transaction . '|event:' . $eventId . '|' . json_encode($res), false);
                 if (!$res) {
                     $errors = $model->getErrors();
                     $log->LogInfo('update log new:' . json_encode($errors), false);
                 } else {
                     $updatePoint = self::model()->updatePoint($user_id, $user_phone, $point, $event->reset);
                     $log->LogInfo('update point|' . $user_id . '|' . json_encode($user_phone) . ':' . json_encode($updatePoint), false);
                     return $updatePoint;
                 }
                 //return $res;
             }
         }
     } catch (Exception $e) {
         //$e->getMessage();
         $log->LogInfo('update log exception:' . $e->getMessage());
         return false;
     }
     return false;
 }
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }