public function attributes() { // add related fields to searchable attributes return array_merge(parent::attributes(), ['type.poll_type_name']); }
<span class="sr-only">Toggle Dropdown</span> </button> <ul class="dropdown-menu" role="menu"> <li><a href="<?php echo Url::toRoute(['poll/create?type=product']); ?> ">商品投票</a></li> <li><a href="<?php echo Url::toRoute(['poll/create?type=goodproduct']); ?> ">中国好产品投票</a></li> </ul> </div> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'formatter' => ['class' => 'yii\\i18n\\Formatter', 'booleanFormat' => ['×', '√'], 'nullDisplay' => ''], 'columns' => ['poll_id', ['attribute' => 'poll_name', 'format' => 'raw', 'value' => function ($data) { $poll_name = $data->poll_name; if ($data->poll_type_id == 3) { $parent_poll = Poll::findOne($data->parent_id); $poll_name = $parent_poll ? "[{$parent_poll->poll_city}赛区]{$parent_poll->poll_name}" . '<i style="margin:0 6px;" class="fa fa-angle-double-right"></i>' . $data->poll_name : "[{$data->poll_city}赛区]{$data->poll_name}"; } return $poll_name; }], ['attribute' => 'type.poll_type_name'], ['attribute' => 'poll_start_date'], ['attribute' => 'poll_expire_date'], ['attribute' => 'created_at', 'format' => ['date', 'php:Y-m-d H:i:s']], ['header' => "操作", 'class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'headerOptions' => ['width' => '80'], 'buttons' => ['view' => function ($url, $model, $key) { return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['poll/view?poll_id=' . $model->poll_id], ['title' => '查看']); }]]], 'layout' => "{items}\n{summary}\n{pager}", 'pager' => ['options' => ['class' => "pagination pull-right"]], 'summary' => '总计:<b>{totalCount}</b>']); ?> </div> </div> </div>
/** * 中国好产品详情列表页 * @author shimeixia (1796573650@qq.com) * @param city 上海 赛区 * @param poll_type int 投票类型ID * @return json * 访问接口:http://www.idaiyan-website.cn/goodproduct/g-list?city=上海 */ public function actionGList() { $data = Yii::$app->request->get(); $poll_city = isset($data['city']) ? $data['city'] : ""; $pos_type_id = PollType::GOODPRODUCT_TYPE; $mPoll = new Poll(); $PollMessage = $mPoll->getPollParentid($poll_city, $pos_type_id); if ($PollMessage) { $Poll = $mPoll->getByPollParentid($PollMessage->poll_id); } if (empty($Poll)) { return $this->redirect(['product/index']); //跳转到产品列表页面 exit; } // var_dump($PollMessage);die; // var_dump($Poll); foreach ($Poll as $key => $value) { if (time() < $value['poll_expire_date']) { $ids = explode(',', $value['poll_option_ids']); $conditions = ['poll_id' => $value['poll_id'], 'owner_id' => $ids]; $mPollOption = new PollOption(); $Productlist[] = $mPollOption->TopNum($conditions, 40); $Poll_data[] = $mPoll->getByPollid($value['poll_id']); } } //判断poll表数据完整度 // if (!$PollMessage || empty($PollMessage->poll_option_ids)) { // Yii::$app->util->msg('投票数据不成熟'); // } // $ids = explode(',', $PollMessage->poll_option_ids); // $conditions = [ // 'poll_id' => $PollMessage['poll_id'], // 'owner_id' => $ids, // ]; // $mPollOption = new PollOption(); // $Productlist = $mPollOption->TopNum($conditions, 40); $this->layout = false; return $this->render('g_list', ['poll' => isset($Poll_data[0][0]) ? $Poll_data[0][0] : '', 'Productlist' => isset($Productlist[0]) ? $Productlist[0] : '', 'goodproduct_city' => ActivityBase::GOODPRODUCT_CITY]); }
/** * 删除投票 * * @return void * @author **/ public function actionDelete($id) { // 删除投票 $poll = Poll::findOne($id); if ($poll) { $poll->poll_active = 1; $poll->save(); // 删除子投票 Poll::updateAll(['poll_active' => 1], ['parent_id' => $poll->poll_id]); } Yii::$app->session->setFlash('success', '删除成功!'); return $this->redirect(['index']); }