/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MOfficeCampaignPicCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'sort_order' => $this->sort_order]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public static function getScore($office_id, $date = null) { $pic_categories = MOfficeCampaignPicCategory::find()->all(); $office = \app\models\MOffice::findOne(['office_id' => $office_id]); $total = 0; foreach ($pic_categories as $pic_category) { if (!$office->is_selfOperated && $pic_category->sort_order == 6) { continue; } $scores = self::getScoreByPicCategory($office_id, $pic_category->id, $date); if ($scores['count'] == 0) { return false; } $total += $scores['count'] == 1 ? $scores['total'] : $scores['total'] / $scores['count']; } return $total; }
public function actionCsmdzltj3() { //$this->layout = 'wap'; $this->layout = false; $office_id = $_GET['office_id']; $model_office = MOffice::findOne(['office_id' => $office_id]); //$campaign_pic_categories = MOfficeCampaignPicCategory::find()->orderBy('sort_order')->all(); $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); //$model = MUser::findOne(['gh_id'=>$gh_id, 'openid'=>$openid]); Yii::$app->wx->setGhId($gh_id); $gh = Yii::$app->wx->getGh(); $jssdk = new JSSDK($gh['appid'], $gh['appsecret']); $model_category_id = $_GET['model_category_id']; $model_ocpc = MOfficeCampaignPicCategory::findOne(['id' => $model_category_id]); return $this->render('csmdzltj3', ['gh_id' => $gh_id, 'openid' => $openid, 'model_office' => $model_office, 'model_ocpc' => $model_ocpc, 'jssdk' => $jssdk]); }
/** * Finds the MOfficeCampaignPicCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MOfficeCampaignPicCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MOfficeCampaignPicCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getDetailReadyStatus($office_id, $date = null) { $start_date = \app\models\utils\OfficeCampaignUtils::getOfficeCampaignBeginDate($date); $end_date = \app\models\utils\OfficeCampaignUtils::getOfficeCampaignEndDate($date); $pic_categories = MOfficeCampaignPicCategory::find()->all(); $office = \app\models\MOffice::findOne(['office_id' => $office_id]); $category_count = 0; $detail_count = 0; foreach ($pic_categories as $pic_category) { if (!$office->is_selfOperated && $pic_category->sort_order == 6) { continue; } $category_count++; $detail = self::find()->andWhere(['office_id' => $office_id, 'pic_category' => $pic_category->id])->andWhere('created_time >= :start_time', [':start_time' => $start_date->format("Y-m-d H:i:s")])->andWhere('created_time < :end_time', [':end_time' => $end_date->format("Y-m-d H:i:s")])->one(); if (!empty($detail)) { $detail_count++; } } if ($category_count == $detail_count) { return self::DETAIL_COMPLETE; } if ($detail_count == 0) { return self::DETAIL_IMCOMPLETE; } else { return self::DETAIL_PARTIALLY; } }