public static function preProcessEarlyBirdWinnerData($condition) { $winners = self::find()->where($condition)->orderBy(['exchangeGoodsScore' => SORT_DESC])->all(); $rows = []; foreach ($winners as $winner) { $createdAt = MongodbUtil::MongoDate2String($winner->createdAt, 'Y-m-d H:i', null); switch ($winner->prizeLevel) { case 'one': $prizeLevel = '一等獎'; break; case 'two': $prizeLevel = '二等獎'; break; case 'three': $prizeLevel = '三等獎'; break; default: break; } $row = ['prizeLevel' => $prizeLevel, 'mobile' => "'" . $winner->mobile, 'name' => $winner->name, 'prizeName' => $winner->prizeName, 'exchangeGoodsScore' => $winner->exchangeGoodsScore, 'createdAt' => $createdAt]; $rows[] = $row; unset($createdAt, $prizeLevel, $row); } return $rows; }
public function handle($data) { parent::handle($data); # handle the wechat message LogUtil::info(['channel weconnect event' => $data], 'channel-webhook'); if (empty($data)) { throw new BadRequestHttpException(Yii::t('channel', 'parameter_format_error')); } $data = $data['data']; $requiredParameters = ['outTradeNo', 'tradeNo', 'tradeStatus']; ValidatorUtil::fieldsRequired($data, $requiredParameters); $tradePayment = TradePayment::findOne(['orderNumber' => $data['outTradeNo']]); LogUtil::info(['tradePayment' => $tradePayment->toArray()], 'channel-webhook'); if (empty($tradePayment)) { throw new InvalidParameterException(Yii::t('common', 'data_error')); } $memberId = $tradePayment['user']['memberId']; $couponId = $tradePayment['couponId']; LogUtil::info(['memberId' => $memberId, 'couponId' => $couponId], 'channel-webhook'); if ($data['tradeStatus'] == 'PAY_SUCCESS') { $tradePayment->status = TradePayment::STATUS_PAID; $tradePayment->realAmount = intval($data['totalFee']) / 100; // Make coupon used if (!empty($couponId)) { Yii::$app->service->coupon->makeUsed($memberId, $couponId); } } else { if ($data['tradeStatus'] == 'PAY_ERROR') { $tradePayment->status = TradePayment::STATUS_FAILED; } } $tradePayment->paymentTime = MongodbUtil::msTimetamp2MongoDate($data['paymentTime']); $tradePayment->transactionId = $data['tradeNo']; return $tradePayment->save(true, ['paymentTime', 'status', 'transactionId', 'realAmount']); }
/** * This method is used to valide the user's authority with token in help desk chat system. * This method is invoked right before an action is executed. * * The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method * will determine whether the action should continue to run. * * If you override this method, your code should look like the following: * * ```php * public function beforeAction($action) * { * if (parent::beforeAction($action)) { * // your custom code here * return true; // or false if needed * } else { * return false; * } * } * ``` * @param Action $action the action to be executed. * @return boolean whether the action should continue to run. * @author Harry Sun */ public function beforeAction($action) { $route = $this->id . '/' . $action->id; //init i18n configuration from user agent Yii::$app->language = LanguageUtil::getBrowserLanguage(); // the action ids without auth $noAuth = ['site/login', 'site/logout', 'conversation/state', 'conversation/message', 'setting/index', 'setting/self-helpdesk', 'site/send-reset-password-email', 'site/reset-password', 'help-desk/check-auth', 'conversation/user-state', 'issue/create-from-js-sdk', 'issue/remove-attachment']; if (in_array($route, $noAuth)) { return true; } else { $accessToken = $this->getQuery('accesstoken'); $info = Token::getToken($accessToken); if (!empty($info) && isset($info->expireTime) && !MongodbUtil::isExpired($info->expireTime)) { Yii::$app->language = empty($info->language) ? LanguageUtil::DEFAULT_LANGUAGE : $info->language; $expireTime = new \MongoDate(time() + Token::EXPIRE_TIME); if ($info->expireTime < $expireTime) { $info->expireTime = $expireTime; } $updateResult = $info->update(); return true; } LogUtil::error(['accessToken' => $accessToken, 'message' => 'You have not logined']); throw new \yii\web\UnauthorizedHttpException('You have not logined'); } }
public function actionStats() { $memberId = $this->getQuery('memberId'); if (empty($memberId)) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $accountId = $this->getAccountId(); $memberOrderStats = StatsMemberOrder::getByConsumerId($accountId, $memberId); $order = Order::getLastByConsumerId($accountId, $memberId); if (empty($order)) { $result = ['lastOperateTime' => '', 'operateInterval' => null]; } else { $lastDate = MongodbUtil::MongoDate2String($order->operateTime, 'Y-m-d'); $result = ['lastOperateTime' => $lastDate, 'operateInterval' => abs((strtotime(date('Y-m-d')) - strtotime($lastDate)) / 86400)]; } if (empty($memberOrderStats)) { $result['consumptionAmount'] = $result['recentConsumption'] = $result['consumption'] = $result['memberMaxConsumption'] = 0; } else { $result['consumptionAmount'] = round($memberOrderStats->consumptionAmount); $result['recentConsumption'] = $memberOrderStats->recentTransactionCount; $result['consumption'] = round($memberOrderStats->consumptionAmount / $memberOrderStats->transactionCount); $result['memberMaxConsumption'] = round($memberOrderStats->maxConsumption); } $orderStats = StatsOrder::getLatestByAccount($accountId); if (empty($orderStats)) { $result['consumptionAmountAvg'] = $result['recentConsumptionAvg'] = $result['consumptionAvg'] = $result['maxConsumption'] = 0; } else { $result['consumptionAmountAvg'] = round($orderStats->consumptionAmount / $orderStats->consumerCount); $result['recentConsumptionAvg'] = round($orderStats->recentTransactionTotal / $orderStats->consumerCount); $result['consumptionAvg'] = round($orderStats->consumptionAmount / $orderStats->transactionCount); $result['maxConsumption'] = round($orderStats->maxConsumptionTotal / $orderStats->consumerCount); } return $result; }
public static function preProcessCnyWinnerData($condition) { // TODO refine smsContent $smsTemplate = BulkSmsUtil::CNY_WINNERS_SMS_TEMPLATE; $winners = LuckyDrawWinner::find()->where($condition)->all(); $rows = array(); foreach ($winners as $winner) { $smsContent = str_replace("%username%", $winner->name, $smsTemplate); $smsContent = str_replace("%awardName%", $winner->awardName, $smsContent); $member = Member::getByMobile($winner->mobile, $condition['accountId']); if ($member != null) { $city = null; $site = null; foreach ($member->properties as $property) { if ($property['name'] == '縣市') { $city = $property['value']; } if ($property['name'] == '地址') { $site = $property['value']; } } $row = ['mobile' => " " . $winner->mobile, 'name' => $winner->name, 'city' => $city, 'site' => $site, 'awardName' => $winner->awardName, 'scoreAdded' => $winner->winInfo['scoreAdded'], 'createdAt' => MongodbUtil::MongoDate2String($winner->createdAt, 'Y-m-d H:i', null), 'remark' => $winner->winInfo['boughtAllProducts'] ? '已包含全部3支品項' : '', 'smsContent' => $smsContent]; $rows[] = $row; unset($row, $smsContent, $member, $city, $site); } } return $rows; }
public function actionGetList() { $currentPage = Yii::$app->request->get("currentPage", 1); $pageSize = Yii::$app->request->get("pageSize", 10); $offset = ($currentPage - 1) * $pageSize; $sortName = "_id"; $sortDesc = Yii::$app->request->get('sortDesc', 'ASC'); $sort = $sortName . ' ' . $sortDesc; $keyword = Yii::$app->request->get("keyword", ''); $query = new Query(); $accountId = $this->getAccountId(); if ($keyword == '') { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->orderBy($sort)->offset($offset)->limit($pageSize)->all(); } else { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->orderBy($sort)->offset($offset)->limit($pageSize)->all(); } for ($i = 0; $i < count($records); $i++) { $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null); $records[$i]['_id'] = (string) $records[$i]['_id']; } $query = new Query(); if ($keyword == '') { $totalPageCount = $query->from('uhkklpOrder')->where(['accountId' => $accountId])->count(); } else { $totalPageCount = $query->from('uhkklpOrder')->where(['accountId' => $accountId])->andWhere(['like', 'name', $keyword])->count(); } // LogUtil::error(date('Y-m-d h:i:s') . ' $totalPageCount: ' . $totalPageCount); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['code' => 200, 'list' => $records, 'totalPageCount' => $totalPageCount]; }
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'] . ''; }]); }
/** * The default implementation returns the names of the columns whose values have been populated into Product. */ public function fields() { return array_merge(parent::fields(), ['order', 'name', 'type', 'options', 'defaultValue', 'isRequired', 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); }, 'updatedAt' => function () { return MongodbUtil::MongoDate2String($this->updatedAt, 'Y-m-d H:i:s'); }]); }
/** * The default implementation returns the names of the columns whose values have been populated into MessageTemplate. */ public function fields() { return array_merge(parent::fields(), ['id' => function ($model) { return (string) $model->_id; }, 'name', 'weChat', 'email', 'mobile', 'useWebhook', 'updatedAt' => function ($model) { return MongodbUtil::MongoDate2String($model->updatedAt); }]); }
/** * The default implementation returns the names of the columns whose values have been populated into memberLogs. */ public function fields() { return array_merge(parent::fields(), ['memberId', 'operation', 'operationAt' => function ($model) { return MongodbUtil::MongoDate2String($model->operationAt); }, 'createdAt' => function ($model) { return MongodbUtil::MongoDate2String($model->createdAt); }]); }
/** * The default implementation returns the names of the columns whose values have been populated into question. */ public function fields() { return array_merge(parent::fields(), ['title', 'type', 'options' => function () { return empty($this->options) ? [] : $this->options; }, 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); }, 'order']); }
/** * The default implementation returns the names of the columns whose values have been populated into statsCouponLogDaily. */ public function fields() { return array_merge(parent::fields(), ['couponId', 'recievedNum', 'redeemedNum', 'date' => function () { return MongodbUtil::MongoDate2String($this->date); }, 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt); }]); }
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; }
/** * The default implementation returns the names of the columns whose values have been populated into MemberShipCard. */ public function fields() { return array_merge(parent::fields(), ['name', 'poster', 'fontColor', 'privilege', 'condition', 'usageGuide', 'isEnabled', 'isDefault', 'isAutoUpgrade', 'scoreResetDate', 'provideCount' => function () { return Member::count(['cardId' => $this->_id]); }, 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); }, 'updatedAt' => function () { return MongodbUtil::MongoDate2String($this->updatedAt, 'Y-m-d H:i:s'); }]); }
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; }]); }
public static function findList($currentPage = 1, $pageSize = 10, $condition = []) { $offset = ($currentPage - 1) * $pageSize; $query = new Query(); $records = $query->from('uhkklpLuckyDrawRecord')->select(['_id', 'createdAt', 'remark'])->where($condition)->orderBy(['createdAt' => SORT_DESC])->offset($offset)->limit($pageSize)->all(); for ($i = 0; $i < count($records); $i++) { $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null); $records[$i]['_id'] = (string) $records[$i]['_id']; } return $records; }
public static function updateActivityByName($name, $params) { $accountId = Token::getAccountId(); $params['startDate'] = MongodbUtil::msTimetamp2MongoDate($params['startDate']); $params['endDate'] = MongodbUtil::msTimetamp2MongoDate($params['endDate']); $activity = Activity::findOne(['name' => $name, 'accountId' => $accountId]); if (!empty($activity)) { $activity->attributes = $params; $activity->save(); } return $activity; }
public static function preProcessBulkSmsRecordData($smsRecordId, $accountId) { $logs = BulkSmsLog::find()->where(['smsRecordId' => $smsRecordId, 'accountId' => $accountId])->orderBy(['createdAt' => SORT_ASC])->all(); $rows = array(); if (!empty($logs)) { foreach ($logs as $log) { $row = ['mobile' => "'" . $log->mobile, 'smsContent' => $log->smsContent, 'status' => $log->status ? '成功' : '失敗', 'createdAt' => MongodbUtil::MongoDate2String($log->createdAt, 'Y-m-d H:i:s', null)]; $rows[] = $row; unset($row); } } return $rows; }
/** * The default implementation returns the names of the columns whose values have been populated into tradeRefund. */ public function fields() { return array_merge(parent::fields(), ['refundNumber', 'subject', 'transactionId', 'user', 'refundAccount', 'admin' => function () { $admin = $this->admin; if (isset($admin['id'])) { $admin['id'] = (string) $admin['id']; } return $admin; }, 'expectedAmount', 'realAmount', 'refundMode', 'comments', 'orderNumber', 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); }, 'refundAt' => function () { return MongodbUtil::MongoDate2String($this->refundAt, 'Y-m-d H:i:s'); }]); }
public static function preProcessEarlyBirdSmsDetails($smsName, $accountId) { $query = new Query(); $query = $query->from('uhkklpEarlyBirdSmsRecord')->select(['_id']); $record = $query->where(['smsName' => $smsName, 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one(); $rows = array(); $details = self::find()->where(['smsRecordId' => $record['_id']])->orderBy(['createdAt' => SORT_ASC])->all(); foreach ($details as $detail) { $createdAt = MongodbUtil::MongoDate2String($detail->createdAt, 'Y-m-d H:i:s', null); $row = ['createdAt' => $createdAt, 'mobile' => "'" . $detail->mobile, 'smsContent' => $detail->smsContent, 'status' => $detail->status == false ? '失敗' : '成功']; $rows[] = $row; unset($createdAt, $row); } return $rows; }
public static function preProcessSendFailedData($smsName, $accountId) { $query = new Query(); $query = $query->from('uhkklpEarlyBirdSmsRecord')->select(['_id', 'failed']); $record = $query->where(['smsName' => $smsName, 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one(); $rows = array(); if ($record['failed'] > 0) { $failedAll = EarlyBirdSmsFailed::find()->where(['smsRecordId' => $record['_id']])->orderBy(['createdAt' => SORT_ASC])->all(); foreach ($failedAll as $smsFailed) { $createdAt = MongodbUtil::MongoDate2String($smsFailed->createdAt, 'Y-m-d H:i:s', null); $row = ['createdAt' => $createdAt, 'mobile' => "'" . $smsFailed->mobile, 'smsContent' => $smsFailed->smsContent, 'status' => '失敗']; $rows[] = $row; unset($createdAt, $row); } } return $rows; }
/** * 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'); } }
/** * when crate a staff successful,and send sms fail,we need to delete the staff */ public function actionCreate() { $params = $this->getParams(); if (empty($params['phone']) || empty($params['channel']['channelId']) || empty($params['badge']) || empty($params['storeId'])) { throw new BadRequestHttpException('params missing'); } $accountId = $this->getAccountId(); $params['accountId'] = $accountId; $existsEmpID = Staff::checkUnique($params['badge'], $accountId); if ($existsEmpID) { throw new InvalidParameterException(['badge' => Yii::t("store", "badge_exists")]); } $storeId = $params['storeId']; $params['storeId'] = new \MongoId($storeId); if (false === Staff::checkPhone($params['storeId'], $params['phone'])) { throw new InvalidParameterException(['phone' => Yii::t("store", 'phone_exists')]); } $data = Staff::setQrcodeParam($params['channel']['channelId']); $params = array_merge($params, $data); $params['salt'] = StringUtil::rndString(6, 1); $staff = new Staff(); $staff->load($params, ''); $result = 'success'; if ($staff->save()) { if (!empty($params['useWebhook'])) { $eventData = ['type' => Webhook::EVENT_STAFF_CREATED, 'store_id' => $storeId, 'staff_id' => (string) $staff->_id, 'phone' => $params['phone'], 'badge' => $params['badge'], 'channel' => ['id' => $params['channel']['channelId'], 'name' => $params['channel']['channelName'], 'type' => $params['channel']['channelType']], 'origin' => Member::PORTAL, 'account_id' => (string) $accountId, 'created_at' => MongodbUtil::MongoDate2String($staff->createdAt, \DateTime::ATOM)]; Yii::$app->webhook->triggerEvent($eventData); } else { //send mobile message $template = Staff::getMobileTemplate($accountId); $status = MessageUtil::sendMobileMessage($params['phone'], $template); if (false === $status) { $result = 'fail'; //delete the staff Staff::getCollection()->remove(['_id' => $staff->_id]); LogUtil::error(['message' => 'Faild to send message', 'template' => $template, 'params' => $params], 'staff'); } } } else { throw new ServerErrorHttpException(Yii::t('store', 'fail_to_create')); } return ['result' => $result]; }
/** * The default implementation returns the names of the columns whose values have been populated into campaignLog. */ public function fields() { return array_merge(parent::fields(), ['code', 'member' => function () { $member = $this->member; if ($member) { $member['id'] .= ''; } return $member; }, 'product' => function () { return ['id' => (string) $this->productId, 'name' => $this->productName, 'sku' => $this->sku]; }, 'usedFrom', 'redeemTime' => function () { if (!empty($this->redeemTime)) { return MongodbUtil::MongoDate2String($this->redeemTime, 'Y-m-d H:i:s'); } else { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); } }, 'createdAt' => function () { return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s'); }]); }
/** * @args {"description": "Delay: stats of member orders", "runNextJob": true} * @author Rex Chen */ public function perform() { $dateStr = date('Y-m-d'); $operateTimeTo = new MongoDate(strtotime($dateStr)); $accounts = Account::findAll([]); foreach ($accounts as $account) { $modelStatsOrder = StatsOrder::getLatestByAccount($account->_id); if (empty($modelStatsOrder)) { $operateTimeFrom = null; } else { //ensure Y-m-d mongodate $operateDate = MongodbUtil::MongoDate2String($modelStatsOrder->createdAt, 'Y-m-d'); if ($dateStr === $operateDate) { return true; } $operateTimeFrom = new MongoDate(strtotime($operateDate)); } $this->statsMemberOrder($account->_id, $operateTimeFrom, $operateTimeTo); $this->updateMemberRecentTransactionCount($account->_id); } }
public function perform() { $args = $this->args; if (empty($args['key']) || empty($args['header']) || empty($args['accountId'])) { ResqueUtil::log(['status' => 'fail to export goods record', 'message' => 'missing params', 'args' => $args]); return false; } $keyword = $args['keyword']; $header = $args['header']; $fileName = $args['key']; $accountId = unserialize($args['accountId']); $filePath = ExcelUtil::getFile($fileName, 'csv'); $query = new Query(); if ($keyword == '') { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->all(); } else { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->all(); } for ($i = 0; $i < count($records); $i++) { $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null); $records[$i]['_id'] = (string) $records[$i]['_id']; $pro = ""; for ($j = 0; $j < count($records[$i]['product']); $j++) { $pro .= " " . $records[$i]['product'][$j]; } $records[$i]['product'] = $pro; } $rows = $records; 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]); return true; } else { ResqueUtil::log(['status' => 'fail to export order', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
/** * The default implementation returns the names of the columns whose values have been populated into storeGoods. */ public function fields() { return array_merge(parent::fields(), ['storeId' => function () { return (string) $this->storeId; }, 'productId' => function () { return (string) $this->productId; }, 'pictures', 'status', 'onSaleTime' => function () { return empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->onSaleTime, 'Y-m-d H:i'); }, 'offShelfTime' => function () { return empty($this->offShelfTime) || !empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->offShelfTime, 'Y-m-d H:i'); }, 'categoryName' => function () { $category = ProductCategory::findByPk($this->categoryId); if ($category) { return $category['name']; } else { return ''; } }, 'productName', 'sku', 'price' => function () { return self::formatPrice($this->price); }, 'createdAt' => function () { return empty($this->createdAt) ? '' : MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i'); }]); }
/** * The default implementation returns the names of the columns whose values have been populated into Member. */ public function fields() { return array_merge(parent::fields(), ['name', 'type', 'score', 'triggerTime', 'description', 'isEnabled', 'times', 'memberCount', 'couponId' => function () { return (string) $this->couponId; }, 'rewardType', 'properties' => function () { $properties = []; if (!empty($this->properties)) { foreach ($this->properties as $property) { $properties[] = (string) $property; } } return $properties; }, 'startTime' => function () { return MongodbUtil::MongoDate2String($this->startTime); }, 'endTime' => function () { return MongodbUtil::MongoDate2String($this->endTime); }]); }
/** * The default implementation returns the names of the columns whose values have been populated into campaign. */ public function fields() { return array_merge(parent::fields(), ['name', 'startTime' => function () { return MongodbUtil::MongoDate2String($this->startTime, 'Y-m-d H:i:00'); }, 'endTime' => function () { return MongodbUtil::MongoDate2String($this->endTime, 'Y-m-d H:i:00'); }, 'participantCount', 'limitTimes', 'promotion' => function () { $promotion = $this->promotion; $data = []; if (!empty($promotion['data'])) { $products = Product::getByIds($promotion['data']); foreach ($products as $product) { $data[] = ['id' => $product->_id . '', 'name' => $product->name]; } $promotion['data'] = $data; } if (is_array($promotion['products'])) { foreach ($promotion['products'] as &$products) { $products .= ''; } } return $promotion; }, 'isActivated', 'isExpired' => function () { $nextMinute = strtotime('+ 1 minute - ' . date('s') . 'seconds'); return MongodbUtil::MongoDate2TimeStamp($this->endTime) < $nextMinute; }]); }
/** * Activate * * <b>Request Type </b>: GET<br/> * <b>Request Endpoint </b>: http://{server-domain}/api/old-site/activate?code=abcd1234abcd1234<br/> * **/ public function actionActivate() { $code = $this->getQuery('code'); if (empty($code)) { $this->_activateFail(0); //此链接无效,请联系管理员 } $validation = Validation::findOne(['code' => $code]); if (empty($validation)) { $this->_activateFail(0); //此链接无效,请联系管理员 } if (empty($validation->expire) || MongodbUtil::isExpired($validation->expire)) { $this->_activateFail(1); //'此链接已过期,请联系管理员' } $userId = $validation->userId; if (User::updateAll(['isActivated' => User::ACTIVATED], ['_id' => $userId])) { $validation->delete(); $this->redirect('/old/activate?type=0&link=' . urlencode('/site/login')); Yii::$app->end(); } $this->_activateFail(1); //'此链接已过期,请联系管理员' }