Пример #1
0
 public function perform()
 {
     $args = $this->args;
     if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) {
         ResqueUtil::log(['status' => 'fail to export slotgame useRecord', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     $condition = unserialize($args['condition']);
     $activityId = $condition['activityId'];
     $condition = ['activityId' => $activityId];
     $accountId = new \MongoId($args['accountId']);
     $header = $args['header'];
     $fileName = $args['key'];
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $object = ActivityUser::find();
     if (empty($object)) {
         ResqueUtil::log(['status' => 'fail to export slotgame useRecord', 'message' => 'no data found in DB', 'args' => $args]);
         return false;
     }
     $classFunction = '\\backend\\modules\\uhkklp\\models\\ActivityUser::preProcessBarUseRecordData';
     ExcelUtil::processMultiData($header, $filePath, $args, $condition, $object, $classFunction);
     $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName);
     if ($hashKey) {
         //notice frontend the job is finished
         Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]);
         return true;
     } else {
         ResqueUtil::log(['status' => 'fail to export slotgame useRecord', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]);
         return false;
     }
 }
 public function perform()
 {
     $args = $this->args;
     if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) {
         ResqueUtil::log(['status' => 'fail to export slotgame prize statistic', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     $accountId = new \MongoId($args['accountId']);
     $header = $args['header'];
     $condition = unserialize($args['condition']);
     $fileName = $args['key'];
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $rows = ActivityUser::preProcessPrizeStatisticData($condition);
     ExcelUtil::exportCsv($header, $rows, $filePath, 1);
     $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName);
     if ($hashKey) {
         //notice frontend the job is finished
         Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]);
         return true;
     } else {
         ResqueUtil::log(['status' => 'fail to export slotgame prize statistic', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]);
         return false;
     }
 }
Пример #3
0
 /**
  * deal with the data before export
  * @param $condition,array. (activityId:MongoId, accountId:MongoId)
  */
 public static function preProcessUserPlayCountData($condition)
 {
     $activityId = $condition['activityId'];
     $users = ActivityUser::find()->where(['activityId' => $activityId])->orderBy(['createdAt' => SORT_ASC])->all();
     $userCountArr = array();
     if (!empty($users)) {
         foreach ($users as $user) {
             if (!empty($userCountArr[$user->mobile])) {
                 $userCountArr[$user->mobile] += 1;
             } else {
                 $userCountArr[$user->mobile] = 1;
             }
         }
     }
     $rows = array();
     if (!empty($userCountArr) and is_array($userCountArr)) {
         foreach ($userCountArr as $key => $value) {
             $row = ['mobile' => "'" . $key, 'count' => $value];
             $rows[] = $row;
             unset($row);
         }
         unset($userCountArr);
     }
     return $rows;
 }
 private function _prizeDraw($activityId, $mobile, $deviceId)
 {
     $bar = ActivityBar::findOne($activityId);
     $probalility = $bar->probability;
     //未中奖几率
     $drawArr = array();
     //抽奖阵列
     // 加入中奖的比率
     $i = 100 - (int) $probalility;
     while ($i > 0) {
         $drawArr[] = 'Y';
         $i--;
     }
     // 加入沒中奖的比率
     $i = (int) $probalility;
     while ($i > 0) {
         $drawArr[] = 'N';
         $i--;
     }
     shuffle($drawArr);
     // 抽奖 (随机打乱阵列)
     $hasPrize = $drawArr[0];
     // 抽出其中一个看是否中奖
     $resultPrize = null;
     $thankPrize = array('name' => "銘謝惠顧", 'prizeImgUrl' => "", '_id' => 'thanks');
     //给中奖用户抽奖品
     if ($hasPrize == 'Y') {
         $prizeList = ActivityPrize::getValidPrizesByActivityId($activityId);
         if (!empty($prizeList)) {
             $prizeArr = array();
             //奖品阵列
             $today = strtotime(date('Y-m-d H:i:s'));
             $todayMstime = MongodbUtil::MongoDate2msTimeStamp(new \MongoDate($today));
             foreach ($prizeList as $prize) {
                 if ($prize['type'] == 'topPrize') {
                     if ($prize['startDate'] <= $todayMstime and $todayMstime < $prize['endDate']) {
                         $prizeArr[] = $prize;
                     }
                 } else {
                     $prizeArr[] = $prize;
                 }
             }
             unset($prizeList);
             shuffle($prizeArr);
             $resultPrize = $prizeArr[0];
         } else {
             //奖项列表为空,改发鸣谢惠顾
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
         }
     } else {
         $resultPrize = $thankPrize;
     }
     //判断奖品数量是否足够
     $activityPrize = ActivityPrize::findOne($resultPrize['_id']);
     if (!empty($activityPrize)) {
         $quantity = $activityPrize->quantity - 1;
         $activityPrize->quantity = $quantity;
         if ($quantity >= 0) {
             if (!$activityPrize->save()) {
                 //更新奖品数量(减1), 失敗,改发鸣谢惠顾
                 $hasPrize = 'N';
                 $resultPrize = $thankPrize;
             }
         } else {
             //奖品不够,改发鸣谢惠顾
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
         }
     }
     if ($resultPrize['_id'] != 'thanks' and $resultPrize['isPoint'] == 'Y') {
         //add points
         try {
             $service = Yii::$app->service;
             $service->accountId = $this->getAccountId();
             $member = Member::getByMobile($mobile, $this->getAccountId());
             $rewardResult = $service->member->rewardScore([$member['_id']], $resultPrize['points'], '拉霸活動中獎');
             if (is_bool($rewardResult) && $rewardResult) {
                 $resultPrize['name'] = $resultPrize['name'] . '(已發獎' . $resultPrize['points'] . '積分)';
             } else {
                 $hasPrize = 'N';
                 $resultPrize = $thankPrize;
                 //Failed,改发鸣谢惠顾
             }
             unset($service, $member, $rewardResult);
         } catch (Exception $e) {
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
             LogUtil::error(['message' => '获奖者加积分捕获未知错误', 'result' => '改发鸣谢惠顾', 'mobile' => $mobile, 'exception' => $e], 'activitybar');
         }
     }
     //save in DB
     $params = array('activityId' => $activityId, 'prizeId' => $resultPrize['_id'], 'deviceId' => $deviceId, 'mobile' => $mobile, 'prizeContent' => $resultPrize['name']);
     $isOK = ActivityUser::createUser($params);
     if (!$isOK) {
         $hasPrize = 'N';
         $resultPrize = $thankPrize;
     }
     $result = ['hasPrize' => $hasPrize, 'prizeName' => $resultPrize['name'], 'prizeImage' => $resultPrize['prizeImgUrl']];
     unset($thankPrize, $resultPrize, $params);
     return ['code' => 200, 'msg' => 'ok', 'result' => $result];
 }