/** * @param $startDate int msTimetamp * @param $endDate int msTimetamp * @return array (eg: ['560399d6475df4c7378b4572'=>-200, ...] ) */ public static function getExchangeGoodsScore($startDate, $endDate, $accountId) { $startDate = MongodbUtil::msTimetamp2MongoDate($startDate); $endDate = MongodbUtil::msTimetamp2MongoDate($endDate); $condition = ['brief' => ScoreHistory::ASSIGNER_EXCHAGE_GOODS, 'createdAt' => ['$gte' => $startDate, '$lte' => $endDate], 'accountId' => $accountId]; $memberIds = ScoreHistory::distinct('memberId', $condition); $histories = ScoreHistory::find()->where($condition)->all(); $scores = array(); try { if (!empty($histories) && !empty($memberIds)) { foreach ($memberIds as $memberId) { $scores[(string) $memberId] = 0; foreach ($histories as $history) { if ($memberId == $history->memberId) { $scores[(string) $memberId] += $history->increment; } } } } } catch (Exception $e) { LogUtil::error(['message' => 'Fail to getExchangeGoodsScore', 'exception' => $e], 'earlybird'); throw new ServerErrorHttpException('Fail to getExchangeGoodsScore'); } unset($condition, $memberIds, $histories); return $scores; }