/**
  * [中国好产品活动宣传主题页 查询该用户的可以参加中国好产品活动的产品的接口]
  * @param  [int] $uid [用户id]
  * @return [json_encode]
  * 本地地址:http://www.idaiyan-website.cn/index.php?r=special-topic/applygoodproduct
  * 线上地址:http://test.idaiyan.cn/special-topic/applygoodproduct
  */
 public function actionApplygoodproduct()
 {
     $user = Yii::$app->util->isLogin();
     //判断是否登陆
     if (!$user) {
         echo Yii::$app->util->formatResEncode('1000', 'no login!');
         exit;
     }
     $uid = $user['uid'];
     $models = new IProductBase();
     $res = $models->myProducts($uid);
     //创建一个新数组$new,新数组以元素组的 id 为索引
     $new = array();
     foreach ($res as $key => $value) {
         $new[$value['id']]['id'] = $value['id'];
         $new[$value['id']]['name'] = $value['name'];
         if ($value['album']) {
             $new[$value['id']]['album'] = $value['album'] . ProductImage::THUMB_POSTFIX;
         } else {
             $new[$value['id']]['album'] = '';
         }
     }
     $mactivitypdt = new ActivityProduct();
     foreach ($new as $key => $value) {
         $res2 = $mactivitypdt->getActivityProduct($value['id']);
         $status = 1;
         foreach ($res2 as $key => $val) {
             // if (($val['status'] == ActivityProduct::STATUS_SAVE && $val['acti_id'] != ActivityBase::GOOD_PRODUCT) ||
             //     ($val['status'] == ActivityProduct::STATUS_VERIFYING && $val['acti_id'] != ActivityBase::GOOD_PRODUCT)) {
             //     if ($status == 1) {
             //         $status = false;
             //     }
             //     if ($status == true) {
             //         $status = true;
             //     } else {
             //        $status = false;
             //     }
             // }
             // if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT && $val['status'] != ActivityProduct::STATUS_VERIFYING) {
             //     $status = true;
             // } else if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT){
             //     var_dump($val['status']);
             //     $status = false;
             // }
             if ($val['acti_id'] != ActivityBase::GOOD_PRODUCT) {
                 if ($val['status'] == ActivityProduct::STATUS_SAVE || $val['status'] == ActivityProduct::STATUS_VERIFYING || $val['status'] == ActivityProduct::STATUS_VERIFY_NOTTHROUGH) {
                     if ($status == 1) {
                         $status = false;
                     }
                     if ($status == true) {
                         $status = true;
                     } else {
                         $status = false;
                     }
                 } else {
                     if ($status == 1) {
                         $status = true;
                     }
                     if ($status == false) {
                         $status = false;
                     } else {
                         $status = true;
                     }
                 }
             } else {
                 if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT && $val['status'] != ActivityProduct::STATUS_VERIFYING) {
                     $status = true;
                 } else {
                     $status = false;
                 }
             }
         }
         if ($status == 1) {
             $status = true;
         }
         if ($status == false) {
             unset($new[$val['product_id']]);
         }
     }
     if ($new) {
         //成功返回产品信息 <!--如果有产品-->
         $str = '<div class="activity-product-choose">';
         $str .= '<div class="title">选择一款产品参与<span>中国好产品</span>活动</div>';
         $str .= '<form action="/goodproduct/good-product" method="GET">';
         $str .= '<div class="input-wrap">';
         $str .= '<select name="pid" class="product" id="product_id">';
         foreach ($new as $key => $val) {
             $str .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>';
         }
         $str .= '</select>';
         $str .= '<input type="hidden" name = "aid" value = "9">';
         $str .= '<button class="continue bluebtn">继续</button>';
         $str .= '</div>';
         $str .= '</form>';
         $str .= '<div class="tips">无法确认这款产品?可以去<a href="#">产品详情页</a>确认详细内容。</div>';
         $str .= '</div>';
         echo '{"code":"1001","msg":"applygoodproduct!","data":"' . addslashes($str) . '"}';
         // echo "{code:'1001','apply365days!',$str}";
         exit;
     } else {
         $str = '<div class="activity-product-choose no-product">';
         $str .= '<div class="title">您没有能参加此活动的产品,现在就去发布吧</div>';
         $str .= '<a class="publish bluebtn" href="/product/create">发布代言</a>';
         $str .= '</div>';
         echo '{"code":"1002","msg":"applygoodproduct!","data":"' . addslashes($str) . '"}';
         // echo "{code:'1001','apply365days!',$str}";
         exit;
     }
 }