Exemple #1
0
 public function actionCreateReport()
 {
     $txt = self::getParam('txt', 'no');
     $start_date = self::getParam('start_date', '');
     $end_date = self::getParam('end_date', '');
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date) + 86400;
     $mon = new PL_Db_Mongo(DbConfig::getMongodb('userlogin'));
     $mon->switchColl('gemorder');
     $condition = array('status' => StatusCode::payment_finished, 'action' => 'recharge_gem', 'finish_t' => array('$gte' => $start_time, '$lt' => $end_time), 'istest' => array('$ne' => 1));
     //die(var_export($condition,1));
     $rows = $mon->find($condition);
     $data = array();
     foreach ($rows as $row) {
         $day = date('Y-m-d', $row['finish_t']);
         if (!isset($data[$day])) {
             $data[$day] = array('day' => $day, 'count' => 0, 'cash' => 0, 'alipay_cash' => 0);
         }
         if ($row['source'] == 'internal') {
             $data[$day]['alipay_cash'] += $row['cash'];
         } else {
             $data[$day]['cash'] += $row['cash'];
         }
         $data[$day]['count'] += 1;
     }
     $mon2 = new PL_Db_Mongo(DbConfig::getMongodb('userlogin'));
     $mon2->switchColl('order_stat');
     foreach ($data as $day => $d) {
         $insert_data = array('_id' => $day, 'value' => $d);
         $mon2->update(array('_id' => $day), $insert_data, array('upsert' => true));
     }
     if ($txt != 'no') {
         header('content-type: text/plain; charset=utf8');
         foreach ($data as $key => $r) {
             echo "{$key}\t{$r['count']}\t{$r['alipay_cash']}\t{$r['cash']}\n";
         }
     } else {
         die(json_encode(array('s' => 'ok', 'data' => $data)));
     }
 }
Exemple #2
0
 /**
  * @author 符璨
  * @desc
  *      从cdkey_task取出待处理的cdkey任务进行处理 
  *      批量生成cdkey
  */
 public static function action_gen_cdkey()
 {
     $redis = DbConfig::getRedis('realtime_stat');
     $process_id = getmypid();
     //从cdkey中取出一条状态为0(未处理cdkey生成记录),并更新为1(正在处理)
     $mc = new PL_Db_Mongo(DbConfig::getMongodb('userlogin'));
     $mc->switchColl('cdkey_task');
     $cdkey_task = $mc->findOne(array('status' => 0));
     //没有待处理的任务
     if ($cdkey_task == NULL) {
         return;
     }
     glog::info("[{$process_id}] gen cdkey worker started", 'cdkey');
     $task_id = $cdkey_task['_id'];
     $mc->update(array('_id' => $task_id), array('$set' => array('status' => 1)));
     $pa = $cdkey_task;
     unset($pa['status']);
     $num = $pa['num'];
     $task_id = $cdkey_task['_id'];
     //根据cdkey_task的内容生成cdkey
     $mc->switchColl('cdkey');
     while ($num--) {
         $pa['_id'] = model_Cdkey::genCdkey(13);
         $pa['task_id'] = $task_id->__toString();
         //try以防有重复的cdkey
         try {
             $cdkey = $mc->insert($pa);
             //redis中统计当前已生成的cdkey数目
             $redis->hIncrBy('cdkey_task', $task_id, 1);
             $redis->lpush("cdkey_{$task_id}", $pa['_id']);
         } catch (Exception $ex) {
             $exception_cnt--;
             $num++;
             glog::info("[{$process_id}] gen cdkey worker:Duplicated _id {$pa['_id']}", 'cdkey');
             if (!$exception_cnt) {
                 break;
             }
             continue;
         }
         $exception_cnt = 10;
     }
     $mc->switchColl('cdkey_task');
     $mc->update(array('_id' => $task_id), array('$set' => array('status' => 2)));
     $redis->hDel('cdkey_task', $task_id);
     glog::info("[{$process_id}] gen cdkey worker completed", 'cdkey');
 }