public function fields() { return array_merge(parent::fields(), ['creator', 'action', 'description', 'createdAt' => function ($model) { return MongodbUtil::MongoDate2msTimeStamp($model['createdAt']); }, 'issueId' => function ($model) { return $model['issueId'] . ''; }]); }
public static function cmpCreatedAt($firstPageAndArticle, $secondPageAndArticle) { $firstCreatedAt = MongodbUtil::MongoDate2msTimeStamp($firstPageAndArticle['createdAt']); $secondCreatedAt = MongodbUtil::MongoDate2msTimeStamp($secondPageAndArticle['createdAt']); if ($firstCreatedAt == $secondCreatedAt) { return 0; } return $firstCreatedAt < $secondCreatedAt ? 1 : -1; }
public function fields() { return array_merge(parent::fields(), ['title', 'description', 'status', 'creator', 'assignee', 'createdAt' => function ($model) { return MongodbUtil::MongoDate2msTimeStamp($model['createdAt']); }, 'isDeleted', 'origin', 'hasAttachment' => function ($model) { if (isset($model['attachmentIds']) && count($model['attachmentIds']) > 0) { return true; } return false; }]); }
/** * Unified Order, the order must contain `orderNumber`, * `shallCount`, `payMode`, `user`, `timeExpire` * @param ObjectId $accountId * @param array $order the detail of trade order. * @return bool */ public function create($order) { $requiredFields = ['userIp', 'subject', 'orderNumber', 'expectedAmount', 'realAmount', 'payMode', 'timeExpire', 'openId', 'user' => ['memberId']]; ValidatorUtil::fieldsRequired($order, $requiredFields); ModelPayment::avoidDuplicate($order['orderNumber']); if (!ModelPayment::isAlreadyPrepay($order['orderNumber'])) { if (!ModelPayment::create($this->accountId, $order)) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } } $totalFee = round(floatval($order['realAmount']) * 100); try { $reponse = Yii::$app->tradeService->unifiedOrder($order['subject'], $order['orderNumber'], $totalFee, MongodbUtil::MongoDate2msTimeStamp($order['timeExpire']), $order['userIp'], $this->accountId, $order['openId']); return $reponse; } catch (yii\base\Exception $e) { LogUtil::error(['message' => 'Create wechat order occurs a error', 'error' => $e->getMessage()], 'trade'); } }
public static function getValidPrizesByActivityId($activityId) { $list = ActivityPrize::findAll(['activityId' => $activityId, 'isDeleted' => false, 'quantity' => ['$gt' => 0]]); for ($i = 0; $i < count($list); $i++) { if (!empty($list[$i]['startDate'])) { $list[$i]['startDate'] = MongodbUtil::MongoDate2msTimeStamp($list[$i]['startDate']); $list[$i]['endDate'] = MongodbUtil::MongoDate2msTimeStamp($list[$i]['endDate']); } $list[$i] = $list[$i]->attributes; } return $list; }
public function actionCnyPromotion() { $params = $this->getParams('data', null); $accountId = new \MongoId($params['account_id']); if (empty($params) || empty($params['member_id']) || empty($params['type']) || empty($params['score']) || empty($accountId)) { throw new BadRequestHttpException("params are missing."); } if ($params['type'] != 'promotion_code_redeemed') { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['message' => 'Not promotion_code_redeemed']; } //get memberInfo $member = Member::findByPk(new \MongoId($params['member_id'])); $memberInfo = ['addScore' => $params['score'], 'id' => new \MongoId($params['member_id']), 'score' => $member->score]; if (!empty($member->properties)) { foreach ($member->properties as $propertie) { if ($propertie['name'] == 'name') { $memberInfo['name'] = $propertie['value']; } if ($propertie['name'] == 'tel') { $memberInfo['mobile'] = $propertie['value']; } } } unset($member, $params); // get CNY Info $activity = Activity::findOne(['name' => 'cny', 'accountId' => $accountId]); if (empty($activity)) { throw new ServerErrorHttpException("Get CNY information failed or No CNY"); } $needPoints = $activity->luckyDrawInfo['needPoints']; $drawDates = $activity->luckyDrawInfo['drawDate']; $conditionForOdds = ['member.id' => $memberInfo['id'], 'redeemTime' => ['$gte' => $activity->startDate, '$lte' => $activity->endDate]]; unset($activity); // get day // sort($drawDates); // $currentDate = new \mongoDate(); // $targetDate = null; // $day = 0; // foreach ($drawDates as $drawDate) { // if ($drawDate > $currentDate) { // $targetDate = $drawDate; // break; // } // } // if (!empty($targetDate)) { // $offsetTime = MongodbUtil::MongoDate2msTimeStamp($targetDate) - MongodbUtil::MongoDate2msTimeStamp($currentDate); // $day = ceil($offsetTime / (1000 * 60 * 60 * 24)); // unset($drawDates, $currentDate, $targetDate); // } // get odds $oddsCount = 0; $checkDouble = []; $canDouble = false; $redeemRecords = CampaignLog::find()->where($conditionForOdds)->all(); if (!empty($redeemRecords)) { foreach ($redeemRecords as $redeemRecord) { $product = $redeemRecord['productName']; $oddsCount += $redeemRecord['member']['scoreAdded']; if (!$canDouble) { if ($product == '2015 雞粉2.2kg' || $product == '2015 雞粉1.1kg' || $product == '2016 康寶雞粉 1.1KG' || $product == '2016 康寶雞粉 2.2KG') { $checkDouble['chickenPowder'] = true; } if ($product == '2015 鮮雞汁' || $product == '2016 康寶濃縮鮮雞汁') { $checkDouble['chickenJuice'] = true; } if ($product == '2015 鰹魚粉1kg' || $product == '2015 鰹魚粉1.5kg' || $product == '2016 康寶鰹魚粉 1KG' || $product == '2016 康寶鰹魚粉 1.5KG') { $checkDouble['fishmeal'] = true; } if (count($checkDouble) == 3) { $canDouble = true; } } unset($product); } } $oddsCount = intval($oddsCount / $needPoints); if ($canDouble) { $oddsCount = $oddsCount * 2; } unset($checkDouble, $canDouble, $needPoints, $redeemRecords, $conditionForOdds); //$memberInfo:id,name,mobile,addScore,score; $day; $oddsCount $mobile = BulkSmsUtil::processSmsMobile($accountId, $memberInfo['mobile']); $smsContent = null; $currentDate = MongodbUtil::MongoDate2msTimeStamp(new \mongoDate()); $topPrizeDate = MongodbUtil::MongoDate2msTimeStamp(new \MongoDate(strtotime("2016-02-29 00:00:00"))); $offsetDay = ceil(($topPrizeDate - $currentDate) / (1000 * 60 * 60 * 24)); if ($offsetDay > 10) { // 還沒倒計時 $smsContent = $memberInfo['name'] . '您好,您郵寄的點數已入點完成,此次共入點' . $memberInfo['addScore'] . '點,您目前點數為' . $memberInfo['score'] . '點。恭喜您同時累積活動『年年好味不能沒有你』' . $oddsCount . '次抽獎機會,累積點數越多,中獎機會越大,詳細活動辦法請見http://bit.ly/1P4yZEA'; } elseif ($offsetDay > 3 && $offsetDay < 11) { $smsContent = $memberInfo['name'] . '您好,您郵寄的點數已入點完成,此次共入點' . $memberInfo['addScore'] . '點,您目前點數為' . $memberInfo['score'] . '點。恭喜您同時累積活動『年年好味不能沒有你』' . $oddsCount . '次抽獎機會,距離30萬元紅包抽獎,只剩' . $offsetDay . '天,詳細活動辦法請見http://bit.ly/1P4yZEA'; } elseif ($offsetDay >= 0 && $offsetDay <= 3) { $smsContent = $memberInfo['name'] . '您好,您郵寄的點數已入點完成,此次共入點' . $memberInfo['addScore'] . '點,您目前點數為' . $memberInfo['score'] . '點。恭喜您同時累積活動『年年好味不能沒有你』' . $oddsCount . '次抽獎機會,距離30萬元紅包抽獎,倒數' . abs($offsetDay) . '天,詳細活動辦法請見http://bit.ly/1P4yZEA'; } Smslog::createSmsLog($mobile, $smsContent, 'CNY webhook SMS', 'sending', $accountId); MessageUtil::sendMobileMessage($mobile, $smsContent, $accountId); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['mobile' => $mobile, 'smsContent' => $smsContent]; }
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]; }
public function actionGetActivityInfo() { $drawDate = array(); $activity = Activity::getActivityByName('cny'); if (!empty($activity)) { foreach ($activity->luckyDrawInfo['drawDate'] as $key => $value) { $drawDate[] = MongodbUtil::MongoDate2msTimeStamp($value); } Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['startDate' => MongodbUtil::MongoDate2msTimeStamp($activity->startDate), 'endDate' => MongodbUtil::MongoDate2msTimeStamp($activity->endDate), 'drawDate' => $drawDate, 'needPoints' => $activity->luckyDrawInfo['needPoints']]; } }
public static function getById($id) { $bar = self::findOne(new \MongoId($id)); $bar['_id'] = $id; $bar['startDate'] = MongodbUtil::MongoDate2msTimeStamp($bar['startDate']); $bar['endDate'] = MongodbUtil::MongoDate2msTimeStamp($bar['endDate']); return $bar; }
public function actionValidateOrderTime() { $resultCondition = ['accountId' => $this->getAccountId(), 'name' => 'orderSetting']; $result = WestPromotionActivity::findOne($resultCondition); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if (!empty($result)) { $startDate = MongodbUtil::MongoDate2msTimeStamp($result['startDate']); $endDate = MongodbUtil::MongoDate2msTimeStamp($result['endDate']); $time = explode(" ", microtime()); $time = $time[1] . $time[0] * 1000; $time2 = explode(".", $time); $currentDate = $time2[0]; // LogUtil::error(date('Y-m-d h:i:s') . ' $startDate: ' . $result['startDate']); // LogUtil::error(date('Y-m-d h:i:s') . ' $endDate: ' . $endDate); // LogUtil::error(date('Y-m-d h:i:s') . ' $currentDate: ' . $currentDate); if ($currentDate > $endDate) { return ['code' => 1]; } else { if ($currentDate < $startDate) { return ['code' => 2]; } else { if ($currentDate >= $startDate && $currentDate <= $endDate) { return ['code' => 3]; } else { return ['code' => 4]; } } } } else { return ['code' => 5]; } }
/** * The default implementation returns the names of the columns whose values have been populated into user. */ public function fields() { return array_merge(parent::fields(), ['badge', 'email', 'avatar', 'isEnabled', 'isActivated', 'name', 'language', 'clientCount', 'loginDevice', 'tags', 'notificationType', 'lastLoginAt' => function ($model) { return empty($model['lastLoginAt']) ? '' : MongodbUtil::MongoDate2msTimeStamp($model['lastLoginAt']); }, 'isOnline' => function ($model) { $conversations = Yii::$app->cache->get('conversations' . $model->accountId); if (is_array($conversations) && array_key_exists($model->_id . '', $conversations)) { return true; } return false; }, 'conversationCount' => function ($model) { $conversations = Yii::$app->cache->get('conversations' . $model->accountId); if (is_array($conversations) && !empty($conversations)) { if (isset($conversations[$model->_id . ''])) { return count($conversations[$model->_id . '']); } } return 0; }, 'maxClient' => function ($model) { $helpDeskSetting = HelpDeskSetting::getInstance($model->accountId); if (empty($helpDeskSetting['maxClient'])) { throw new ServerErrorHttpException('maxClient error'); } return $helpDeskSetting['maxClient']; }]); }