Exemple #1
0
 public function addCredit($weid, $from_user, $credit, $credittype = 1, $tag = '')
 {
     yload()->classs('quick_center', 'creditlog');
     $_creditlog = new CreditLog();
     $_creditlog->logCredit($this, $weid, $from_user, $credittype, $credit, $tag . '前');
     $ret = $this->sysAddCredit($from_user, floatval($credit), $credittype, $tag);
     $_creditlog->logCredit($this, $weid, $from_user, $credittype, $credit, $tag . '后');
     return $ret;
 }
 function afterSave($created)
 {
     if ($created) {
         //		$user_id                 = $this->Auth->user('id');
         $data = array();
         $vlog_id = $this->getInsertID();
         $datas = $this->data['VideoResponse'];
         if ($this->data['VideoLog']['user_id'] == 36) {
         } else {
             foreach ($datas as $key => $val) {
                 $data = $this->VideoResponse->set(array('video_log_id' => $vlog_id, 'video_feedback_id' => $key, 'video_feedback_option_id' => $val['video_feedback_option_id']));
                 $this->VideoResponse->saveAll($data);
             }
             $this->Video->incrementvideoview($this->data['VideoLog']['video_id']);
             $vid = $this->Video->findVideo($this->data['VideoLog']['video_id']);
             $num_views = $vid['Video']['video_views'];
             $max_views = $vid['Video']['max_view'];
             if ($num_views == $max_views || $num_views > $max_views) {
                 $this->Video->disableVideo($this->data['VideoLog']['video_id']);
             }
             App::import('Model', 'Viewer');
             $viewer = new Viewer();
             $trust = $viewer->getTrustScore($this->data['VideoLog']['user_id']);
             $credit = $this->Video->findCreditValue($this->data['VideoLog']['video_id']);
             $this->User->credituser($this->data['VideoLog']['user_id'], $credit, $trust);
             $currentbalance = $this->User->findCurrentBalance($this->data['VideoLog']['user_id']);
             App::import('Model', 'CreditLog');
             $creditLog = new CreditLog();
             $ext_id = $this->data['VideoLog']['video_id'];
             $rate = $trust / 16000;
             //checking trust percentage
             if ($rate == 1) {
                 // check if user has 100% trust
                 $creditLog->addCreditLog($this->data['VideoLog']['user_id'], $credit, $currentbalance, $ext_id);
                 //log entry of the Video View
             } else {
                 $credit_added = $credit * $rate;
                 //eels credited to the users account
                 $credit_left = $credit - $credit_added;
                 // credits left from the video view
                 $currentbalance_flipit = $this->User->findCurrentBalance(18);
                 //current balance ofthe flipit account
                 $creditLog->addCreditLog($this->data['VideoLog']['user_id'], $credit_added, $currentbalance, $ext_id);
                 // log entry of the percentage of credit deposited into user account
                 $creditLog->left_CreditLog(18, $credit_left, $currentbalance_flipit, $ext_id);
                 // Log entry of the remaining crdits from the video to flipit account
             }
         }
     }
 }
Exemple #3
0
 public static function creditLog($uids, $operation, $relatedid, $data)
 {
     if (!$operation || empty($relatedid) || empty($uids) || empty($data)) {
         return null;
     }
     $log = array("uid" => $uids, "operation" => $operation, "relatedid" => $relatedid, "dateline" => TIMESTAMP);
     foreach ($data as $k => $v) {
         $log[$k] = $v;
     }
     if (is_array($uids)) {
         foreach ($uids as $k => $uid) {
             $log["uid"] = $uid;
             $log["relatedid"] = is_array($relatedid) ? $relatedid[$k] : $relatedid;
             CreditLog::model()->add($log);
         }
     } else {
         CreditLog::model()->add($log);
     }
 }
Exemple #4
0
 protected function getCreditLog()
 {
     CacheUtil::load(array("creditrule"));
     $creditRule = CreditRule::model()->fetchAllSortByPk("rid");
     $credits = Ibos::app()->setting->get("setting/extcredits");
     $relateRules = CreditRuleLog::model()->fetchAllByAttributes(array("uid" => $this->getUid()));
     $criteria = array("condition" => "`uid` = :uid", "params" => array(":uid" => $this->getUid()), "order" => "dateline DESC");
     $count = CreditLog::model()->count($criteria);
     $pages = PageUtil::create($count, 20);
     $criteria["limit"] = 20;
     $criteria["offset"] = $pages->getOffset();
     $creditLog = CreditLog::model()->fetchAll($criteria);
     return array("creditLog" => $creditLog, "relateRules" => $relateRules, "credits" => $credits, "creditRule" => $creditRule, "pages" => $pages);
 }