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 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 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 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];
 }
 /**
  * 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);
     }]);
 }
Beispiel #7
0
 /**
  * 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);
     }]);
 }
Beispiel #8
0
 /**
  * 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);
     }]);
 }
 /**
  * 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 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;
 }
Beispiel #12
0
 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;
 }
 public function actionGetOrderSetting()
 {
     $resultCondition = ['accountId' => $this->getAccountId(), 'name' => 'orderSetting'];
     $result = Registration::findOne($resultCondition);
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if (!empty($result)) {
         $result['startDate'] = MongodbUtil::MongoDate2String($result['startDate'], 'Y-m-d H:i:s', null);
         $result['endDate'] = MongodbUtil::MongoDate2String($result['endDate'], 'Y-m-d H:i:s', null);
         return ['result' => 'success', 'data' => $result];
     } else {
         return ['result' => 'failed'];
     }
 }
Beispiel #14
0
 /**
  * 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;
 }
Beispiel #16
0
 /**
  * The default implementation returns the names of the columns whose values have been populated into questionnaire.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['name', 'startTime' => function () {
         return MongodbUtil::MongoDate2String($this->startTime, 'Y-m-d H:i:s');
     }, 'endTime' => function () {
         return MongodbUtil::MongoDate2String($this->endTime, 'Y-m-d H:i:s');
     }, 'creator' => function ($model) {
         $creator = $model->creator;
         $creator['id'] .= '';
         return $creator;
     }, 'description', 'questions' => function () {
         return self::getByOrder($this->questions);
     }, 'isPublished', 'createdAt' => function () {
         return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i:s');
     }]);
 }
Beispiel #17
0
 /**
  * The default implementation returns the names of the columns whose values have been populated into couponLog.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['couponId' => function () {
         $couponId = (string) $this->couponId;
         return $couponId;
     }, 'membershipDiscountId' => function () {
         return (string) $this->membershipDiscountId;
     }, 'type', 'title', 'status', 'member' => function () {
         $member = $this->member;
         $member['id'] .= '';
         return $member;
     }, 'store', 'total', 'operationTime' => function () {
         return MongodbUtil::MongoDate2String($this->operationTime);
     }, 'createdAt' => function () {
         return MongodbUtil::MongoDate2String($this->createdAt);
     }]);
 }
 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;
 }
 /**
  * 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];
 }
Beispiel #20
0
 /**
  * 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;
     }
 }
Beispiel #23
0
 /**
  * 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');
     }]);
 }
Beispiel #24
0
 /**
  * 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);
     }]);
 }
Beispiel #25
0
 /**
  * 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;
     }]);
 }
 /**
  * The default implementation returns the names of the columns whose values have been populated into statsMemberGrowthQuarterly.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['totalNew', 'totalActive', 'totalInactive', 'year', 'quarter', 'createdAt' => function ($model) {
         return MongodbUtil::MongoDate2String($model->createdAt);
     }]);
 }
 /**
  * View Questionnaire by questionnaire.
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/questionnaire/{questionnaireId}&channelId={channelId}&openId={openId}br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for viewing questionnaire.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *    id, string<br/>
  *    channelId, string<br/>
  *    openId, string<br/>
  *
  * <b>Response Example:</b><br/>
  *     {
  *           "_id": "55d6cb8be9c2fb022c8b4579",
  *           "name": "name",
  *           "startTime": "1429000112193",
  *           "endTime": "1429000116193",
  *           "description": "good",
  *           "question": [
  *               {
  *                   "id": "55d6cb8be9c2fb022c8b4577",
  *                   "title": "math",
  *                   "type": "radio",
  *                   "order": 0,
  *                   "options": [
  *                       {
  *                           "icon": "support",
  *                           "content": "A option"
  *                       },
  *                       {
  *                           "icon": "support",
  *                           "content": "B option"
  *                       }
  *                   ]
  *               },
  *               {
  *                   "id": "55d6cb8be9c2fb022c8b4577",
  *                   "type": "input",
  *                   "title": "This is a problem",
  *                   "order": 1
  *               }
  *           ],
  *           "isPublished": false,
  *           "answerTime": "2015-08-26 10:28:55",
  *           "isAnswered": false
  *     }
  * <pre>
  * </pre>
  */
 public function actionView($id)
 {
     $channelId = $this->getQuery('channelId');
     $openId = $this->getQuery('openId');
     $isAnswered = false;
     $question = [];
     $answerTime = '';
     $questionnaire = [];
     $user = ["channelId" => $channelId, "openId" => $openId];
     $questionnaireInfo = Questionnaire::getById(new MongoId($id));
     if (empty($questionnaireInfo)) {
         throw new InvalidParameterException(Yii::t('content', 'questionnaire_no_exist'));
     }
     if (!empty($channelId) && !empty($openId)) {
         $questionnaireLogInfo = QuestionnaireLog::getByQuestionnaireAndUser(new MongoId($id), $user);
         if (!empty($questionnaireLogInfo)) {
             $answerTime = MongodbUtil::MongoDate2String($questionnaireLogInfo->createdAt, 'Y-m-d H:i:s');
             $isAnswered = true;
         }
     }
     $questionnaire = $questionnaireInfo->toArray();
     $questionnaire['answerTime'] = $answerTime;
     $questionnaire['isAnswered'] = $isAnswered;
     return $questionnaire;
 }
Beispiel #28
0
 public static function webhookEvent($member)
 {
     $property = MemberProperty::findOne(['name' => Member::DEFAULT_PROPERTIES_MOBILE, 'accountId' => $member->accountId]);
     $phone = '';
     if (!empty($property) && !empty($member->properties)) {
         foreach ($member->properties as $memberProperty) {
             if ((string) $memberProperty['id'] === (string) $property->_id) {
                 $phone = $memberProperty['value'];
                 break;
             }
         }
     }
     $triggerData = ['type' => Webhook::EVENT_MEMBER_CREATED, 'account_id' => (string) $member->accountId, 'member_id' => (string) $member->_id, 'phone' => $phone, 'origin' => Member::PORTAL, 'created_at' => MongodbUtil::MongoDate2String($member->createdAt, \DateTime::ATOM)];
     Yii::$app->webhook->triggerEvent($triggerData);
 }
Beispiel #29
0
 /**
  * The default implementation returns the names of the columns whose values have been populated into Goods.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['productId' => function () {
         return $this->productId . '';
     }, 'pictures', 'score', 'total', 'usedCount', 'status', 'onSaleTime' => function () {
         if ($this->onSaleTime) {
             return MongodbUtil::MongoDate2String($this->onSaleTime, 'Y-m-d H:i');
         } else {
             return '';
         }
     }, 'offShelfTime' => function () {
         return empty($this->offShelfTime) || !empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->offShelfTime, 'Y-m-d H:i');
     }, 'url', 'order', 'categoryName' => function () {
         $category = ProductCategory::findByPk($this->categoryId);
         if ($category) {
             return $category['name'];
         } else {
             return '';
         }
     }, 'productName', 'sku', 'clicks', 'description', 'receiveModes', 'addresses' => function () {
         $addresses = [];
         if (!empty($this->addresses)) {
             foreach ($this->addresses as $address) {
                 $addresses[] = (string) $address;
             }
         }
         return $addresses;
     }, 'createdAt' => function () {
         return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i');
     }]);
 }
 /**
  * The default implementation returns the names of the columns whose values have been populated into statsMemberMonthly.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['month', 'origin', 'originName', 'total', 'createdAt' => function ($model) {
         return MongodbUtil::MongoDate2String($model->createdAt);
     }]);
 }