/** * 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; }]); }
/** * Get by Ids * @param array $ids * @return array */ public function getByIds($ids) { return ModelProduct::getByIds($ids); }