示例#1
0
 /**
  * 改变中国好产品 状态,并添加进投票项
  * @param int $id 活动产品id
  * @param int $status 活动产品状态
  *
  * @return json
  * */
 public function actionStatus()
 {
     $admin = Yii::$app->util->isAdminLogin();
     if (!$admin && !Yii::$app->util->isAjax()) {
         echo Yii::$app->util->formatResEncode('1001', 'login error');
         exit;
     }
     $params = Yii::$app->request->post();
     $rel_id = isset($params['id']) ? intval($params['id']) : '';
     $status = isset($params['status']) ? intval($params['status']) : '';
     if (empty($rel_id) || empty($status)) {
         echo Yii::$app->util->formatResEncode('1002', 'param error');
         exit;
     }
     $mActivityProduct = new ActivityProduct();
     $actproduct = $mActivityProduct->getDetailBypk($rel_id);
     $product = $actproduct['product']['name'];
     if ($mActivityProduct->changeStatus($rel_id, $status)) {
         $msg = '产品:' . $product . '状态更改成功!';
         //审核通过 增加投票项
         if ($status == ActivityProduct::STATUS_VERIFY_THROUGH) {
             $mapattrval = new ActivityProductAttrVal();
             $attrval = $mapattrval->getRealAttrVals($rel_id, ActivityBase::GOOD_PRODUCT);
             $city = $attrval['division']['val'];
             $poll_type_id = PollType::GOODPRODUCT_TYPE;
             $mpoll = new poll();
             $pollone = $mpoll->getPollByCity($city, $poll_type_id);
             if ($pollone) {
                 $option = ['poll_id' => $pollone['poll_id'], 'owner_id' => $rel_id, 'option_name' => $product, 'option_type_id' => ActivityBase::GOOD_PRODUCT];
                 $mpolloption = new PollOption();
                 //判断该活动产品 是否已经添加进去投票项
                 $isoption = $mpolloption->isOptionRel($option);
                 if (!$isoption) {
                     $option_id = $mpolloption->storeSave($option);
                     if ($option_id) {
                         if (!strpos($pollone['poll_option_ids'], $rel_id)) {
                             $mpoll = new poll();
                             $ids = empty($pollone['poll_option_ids']) ? $rel_id : $pollone['poll_option_ids'] . ',' . $rel_id;
                             $mpoll->storeSave(['poll_id' => $pollone['poll_id'], 'poll_option_ids' => $ids]);
                         }
                         $option_id ? $msg .= ',添加成为投票项' : '';
                     }
                 }
             }
         }
         echo Yii::$app->util->formatResEncode('0', $msg);
     } else {
         echo Yii::$app->util->formatResEncode('1003', '更改失败!');
     }
 }
 /**
  * 中国好产品详情列表页
  * @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]);
 }
示例#3
0
 /**
  * 保存选项数据
  *
  * @return void
  * @author
  **/
 public function saveOptionData($model, $poll_id = null)
 {
     $poll_id = $poll_id ? $poll_id : $model->poll_id;
     if (!empty($model->poll_option_ids)) {
         $ids_arr = explode(',', $model->poll_option_ids);
         // 获取原有的rel_id
         $result['options'] = PollOption::find()->select('owner_id')->where(['poll_id' => $poll_id, 'option_active' => 0])->indexBy('owner_id')->all();
         $option_ids = array_keys($result['options']);
         if ($option_ids != $ids_arr) {
             $del_ids = array_diff($option_ids, $ids_arr);
             $save_ids = array_diff($ids_arr, $option_ids);
             // 写入操作
             if ($save_ids) {
                 foreach ($save_ids as $save_rel_id) {
                     $option_model = new PollOption();
                     $option = $option_model->find()->select('option_id')->where(['poll_id' => $poll_id, 'owner_id' => $save_rel_id])->one();
                     // 判断是否创建或者更新
                     if ($option) {
                         $option->option_active = 0;
                         $option->save();
                     } else {
                         $option_model->isNewRecord = true;
                         $option_model->poll_id = $poll_id;
                         $option_model->owner_id = $save_rel_id;
                         $option_model->created_at = time();
                         $option_model->updated_at = time();
                         $option_model->save();
                     }
                 }
             }
             // 删除操作
             if ($del_ids) {
                 foreach ($del_ids as $del_rel_id) {
                     $option_model = new PollOption();
                     $option = $option_model->find()->select('option_id')->where(['poll_id' => $poll_id, 'owner_id' => $del_rel_id])->one();
                     if ($option) {
                         $option->option_active = 1;
                         $option->save();
                     }
                 }
             }
         }
     }
 }
示例#4
0
 /**
  * 投票项列表页
  * @author
  * @param int $poll_id 投票id
  *
  * @return
  **/
 public function actionView()
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $id = Yii::$app->request->get('poll_id', false);
     $id = intval($id);
     if (!$id) {
         Yii::$app->util->msg('参数错误');
     }
     //获取投票项id数组
     $mPollOption = new PollOption();
     $ids = $mPollOption->getOptionIds($id) ? $mPollOption->getOptionIds($id) : [];
     $searchModel = new OptionSearch();
     $dataProvider = $searchModel->search($ids, Yii::$app->request->queryParams);
     return $this->render('view', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }