public function actionStats($chosen_month = false)
 {
     $user = User::model()->findByPk(Yii::app()->user->id);
     //$registration_month = date('n',$user->create_at);
     //$registration_year = date('Y',$user->create_at);
     $tmp = explode('-', $user->create_at);
     $registration_year = $tmp[0];
     $registration_month = $tmp[1];
     $current_month = date('m');
     $current_year = date('Y');
     $months = array();
     for ($year = $registration_year; $year <= $current_year; $year++) {
         $first_month = 1;
         $last_month = 12;
         if ($year == $registration_year) {
             $first_month = $registration_month;
         }
         if ($year == $current_year) {
             $last_month = $current_month;
         }
         for ($month = $first_month; $month <= $last_month; $month++) {
             if ($month < 10) {
                 $month = '0' . $month;
             }
             $months[$year . '-' . $month] = $year . '-' . $month;
         }
     }
     if (!$chosen_month) {
         $chosen_month = $current_year . '-' . $current_month;
     }
     $tmp = explode('-', $chosen_month);
     $days = cal_days_in_month(CAL_GREGORIAN, $tmp[1], $tmp[0]);
     $rawData = WebmasterLog::getLogsSumm($user->id, $chosen_month . '-01', $chosen_month . '-' . $days);
     $arrayDataProvider = new CArrayDataProvider($rawData, array('id' => 'id', 'pagination' => array('pageSize' => 31)));
     $this->render('stats', array('dataProvider' => $arrayDataProvider, 'months' => $months, 'chosen_month' => $chosen_month));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     if (isset($_GET['sid'])) {
         // Меняем статус, ajax
         $sid = $_GET['sid'];
         $model = $this->loadModel($id);
         $model->status = $sid;
         $model->save();
         Yii::app()->end();
     }
     if (Yii::app()->request->isAjaxRequest) {
         //echo 'test';
         $data = Yii::app()->request->getRestParams();
         $field = str_replace('Zakaz_', '', $data['elid']);
         if (is_array($data)) {
             $model = $this->loadModel($data['id']);
             echo json_encode($model->{$field} = $data['data']);
             echo json_encode($model->save());
             echo json_encode($model->errors);
             Yii::app()->end();
         }
         $this->renderPartial('_order_list_update');
         Yii::app()->end();
     }
     Yii::app()->session['project_id'] = $id;
     $model = $this->loadModel($id);
     if (Yii::app()->request->getParam('close') == 'yes') {
         $model->old_status = $model->status;
         $model->status = 5;
         $model->save(false);
         $user = User::model()->findByPk($model->user_id);
         if ($user->pid) {
             $payed = Payment::model()->exists('order_id = :p1 AND payment_type = :p2', array(':p1' => $model->id, ':p2' => Payment::OUTCOMING_WEBMASTER));
             if (!$payed) {
                 // Only first time
                 $webmaster = User::model()->with('profile')->findByPk($user->pid);
                 $openlog = WebmasterLog::model()->findByAttributes(array('order_id' => $model->id), 'action = :p1 OR action = :p2', array(':p1' => WebmasterLog::FIRST_ORDER, ':p2' => WebmasterLog::NON_FIRST_ORDER));
                 $webmasterlog = new WebmasterLog();
                 $webmasterlog->pid = $user->pid;
                 $webmasterlog->uid = $user->id;
                 $webmasterlog->date = date("Y-m-d");
                 $webmasterlog->order_id = $model->id;
                 if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                     $webmasterlog->action = WebmasterLog::FINISH_FIRST_ORDER_SUCCESS;
                 } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                     $webmasterlog->action = WebmasterLog::FINISH_NON_FIRST_ORDER_SUCCESS;
                 }
                 $webmasterlog->save();
                 // Pament for webmaster ~~~~~~~~~~~~~~~~~~~~~~~~~~
                 $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $model->id));
                 $manag = User::model()->findByPk(Yii::app()->user->id);
                 $buh = new Payment();
                 $buh->order_id = $model->id;
                 $buh->receive_date = date('Y-m-d');
                 $buh->theme = $model->title;
                 $buh->user = $webmaster->email;
                 $buh->details_ya = $webmaster->profile->yandex;
                 $buh->details_wm = $webmaster->profile->wmr;
                 $buh->details_bank = $webmaster->profile->bank_account;
                 $buh->payment_type = Payment::OUTCOMING_WEBMASTER;
                 $buh->manager = $manag->email;
                 //$buh->approve = 0;
                 $buh->method = 'Cash or Bank';
                 if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                     $buh->summ = (double) $payment->project_price * Company::getWebmasterFirstOrderRate();
                 } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                     $buh->summ = (double) $payment->project_price * Company::getWebmasterSecondOrderRate();
                 }
                 $buh->save();
             }
         }
         $this->redirect(array('update', 'id' => $model->id));
     } elseif (Yii::app()->request->getParam('open') == 'yes') {
         $model->status = $model->old_status;
         $model->save(false);
         $this->redirect(array('update', 'id' => $model->id));
     } elseif (Yii::app()->request->getParam('refound') == 'yes') {
         $model->old_status = $model->status;
         $model->status = 5;
         $model->save(false);
         $user = User::model()->findByPk($model->user_id);
         // Refound ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         $manag = User::model()->findByPk(Yii::app()->user->id);
         $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $model->id));
         if ($payment && $payment->received > 0) {
             $refound = $payment->received;
             $payment->received = 0;
             $payment->save();
             $buh = new Payment();
             $buh->order_id = $model->id;
             $buh->receive_date = date('Y-m-d');
             $buh->theme = $model->title;
             $buh->user = $user->email;
             $buh->summ = (double) $refound;
             $buh->payment_type = Payment::OUTCOMING_CUSTOMER;
             $buh->manager = $manag->email;
             //$buh->approve = 0;
             $buh->method = 'Cash or Bank';
             $buh->save();
         }
         if ($user->pid) {
             $webmasterlog = new WebmasterLog();
             $webmasterlog->pid = $user->pid;
             $webmasterlog->uid = $user->id;
             $webmasterlog->date = date("Y-m-d");
             $webmasterlog->order_id = $model->id;
             $openlog = WebmasterLog::model()->findByAttributes(array('order_id' => $model->id), 'action = :p1 OR action = p2', array(':p1' => WebmasterLog::FIRST_ORDER, ':p2' => WebmasterLog::NON_FIRST_ORDER));
             if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                 $webmasterlog->action = WebmasterLog::FINISH_FIRST_ORDER_FAILURE;
             } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                 $webmasterlog->action = WebmasterLog::FINISH_NON_FIRST_ORDER_FAILURE;
             } else {
                 echo 'Somthing wrong...';
                 Yii::app()->end();
             }
             $webmasterlog->save();
         }
         $this->redirect(array('update', 'id' => $model->id));
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Zakaz'])) {
         $model->attributes = $_POST['Zakaz'];
         if (isset($_POST['Zakaz']['dbdate'])) {
             $model->dbdate = $_POST['Zakaz']['dbdate'];
         }
         $projectFields = $model->getFields();
         if ($projectFields) {
             foreach ($projectFields as $field) {
                 if ($field->field_type == "TIMESTAMP") {
                     // ----------------------------------------------------
                     $tmp = $field->varname;
                     if (isset($_POST['Zakaz'][$tmp])) {
                         $model->{$tmp} = $_POST['Zakaz'][$tmp];
                         $model->timestampInput($field);
                     }
                 }
             }
         }
         if ($model->save()) {
             if (Yii::app()->request->getParam('accepted') && User::model()->isCorrector()) {
                 EventHelper::correctorAccepted($model->id);
             }
             $role = User::model()->getUserRole();
             if ($role != 'Manager' && $role != 'Admin') {
                 // где-то есть дублрующий вызов записи события, поэтому этот комментируем
                 // oldbadger 09.10.2015
                 //					EventHelper::editOrder($model->id);
                 //$view = 'orderInModerate';
                 $this->redirect(array("../project/chat?orderId={$id}"));
             } else {
                 //					$this->redirect(array('project/chat','orderId'=>$model->id));
                 $this->redirect(array('update', 'id' => $model->id));
             }
         }
     }
     $managerlog = new ManagerLog();
     $managerlog->uid = Yii::app()->user->id;
     $managerlog->action = ManagerLog::ORDER_PAGE_VIEW;
     $managerlog->datetime = date('Y-m-d H:i:s');
     $managerlog->order_id = $model->id;
     $managerlog->save();
     $hints = Templates::model()->getTemplateList(4);
     $view = 'update';
     $isModified = false;
     $this->render($view, array('model' => $model, 'hints' => $hints, 'isModified' => $isModified));
 }
Exemplo n.º 3
0
<?php

Yii::app()->getClientScript()->registerCssFile(Yii::app()->theme->baseUrl . '/css/custom.css');
?>
<div id="partner-stats-grid" class="white-block">
<?php 
echo CHtml::dropDownList('month', $chosen_month, $months, array('onchange' => 'js:window.location.search="chosen_month="+this.value;'));
$this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $dataProvider, 'columns' => array(array('name' => WebmasterLog::getLabel('date'), 'type' => 'raw', 'value' => 'CHtml::encode($data["date"])'), array('name' => WebmasterLog::getLabel('unique'), 'type' => 'raw', 'value' => 'CHtml::encode($data["unique"])'), array('name' => WebmasterLog::getLabel('sales_first'), 'type' => 'raw', 'value' => 'CHtml::encode($data["sales_first"])'), array('name' => WebmasterLog::getLabel('sales_repeat'), 'type' => 'raw', 'value' => 'CHtml::encode($data["sales_repeat"])'), array('name' => WebmasterLog::getLabel('completed_first'), 'type' => 'raw', 'value' => 'CHtml::encode($data["completed_first"])'), array('name' => WebmasterLog::getLabel('completed_repeat'), 'type' => 'raw', 'value' => 'CHtml::encode($data["completed_repeat"])'), array('name' => WebmasterLog::getLabel('profit'), 'type' => 'raw', 'value' => 'CHtml::encode($data["profit"])'))));
?>
</div>
 /**
  * Registration user
  */
 public static function register($model, $post, $role = 'Customer')
 {
     $model->attributes = $post;
     if (isset($_COOKIE['partner'])) {
         $model->pid = intval($_COOKIE['partner']);
     }
     if ($model->validate()) {
         $soucePassword = UserModule::generate_password(8);
         $model->password = UserModule::encrypting($soucePassword);
         $model->superuser = 0;
         $model->status = 1;
         if ($model->save()) {
             $AuthAssignment = new AuthAssignment();
             $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id);
             $AuthAssignment->save();
             if ($role == 'Author') {
                 if ($model->profile == null) {
                     $profile = new Profile();
                     $profile->user_id = $model->id;
                     $profile->mailing_for_executors = 1;
                     $profile->save();
                 }
             }
             $webmasterlog = new WebmasterLog();
             $webmasterlog->pid = $model->pid;
             $webmasterlog->uid = $model->id;
             $webmasterlog->date = date("Y-m-d");
             $webmasterlog->action = WebmasterLog::REG;
             $webmasterlog->save();
             // новая служба системных сообщений
             $type_id = Emails::TYPE_11;
             $email = new Emails();
             $criteria = new CDbCriteria();
             $criteria->order = 'id DESC';
             $criteria->limit = 1;
             $user = User::model()->findAll($criteria);
             $user = $user[0];
             $email->from_id = 1;
             $email->to_id = $user->id;
             $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
             $id = Company::getId();
             $email->company = Company::getName();
             $email->name = $model->full_name;
             $email->login = $model->email;
             $email->password = $soucePassword;
             $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit';
             $email->sendTo($user->email, $rec[0]->title, $rec[0]->text, $type_id);
             $identity = new UserIdentity($model->email, $soucePassword);
             $identity->authenticate();
             Yii::app()->user->login($identity, 0);
             //$this->redirect(Yii::app()->controller->module->returnUrl[0]);
             return true;
             //Yii::app()->end();
         } else {
             //Yii::app()->user->setFlash('reg_failed',UserModule::t("Sorry, something wrong... :("));
             //$this->refresh();
             echo 'Cant save';
             Yii::app()->end();
         }
     } else {
         return false;
     }
 }
 public function saveFullPaymentWebmasterLog($order)
 {
     $user = User::model()->findByPk($order->user_id);
     if ($user->pid) {
         $webmasterlog = new WebmasterLog();
         $webmasterlog->pid = $user->pid;
         $webmasterlog->uid = $user->id;
         $webmasterlog->date = date("Y-m-d");
         $webmasterlog->order_id = $order->id;
         $openlog = WebmasterLog::model()->findByAttributes(array('order_id' => $order->id), 'action = :p1 OR action = :p2', array(':p1' => WebmasterLog::FIRST_ORDER, ':p2' => WebmasterLog::NON_FIRST_ORDER));
         if ($openlog->action == WebmasterLog::FIRST_ORDER) {
             $webmasterlog->action = WebmasterLog::FULL_PAYMENT_4_FIRST_ORDER;
         } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
             $webmasterlog->action = WebmasterLog::FULL_PAYMENT_4_NON_FIRST_ORDER;
         }
         $webmasterlog->save();
     }
 }