public function indexAction()
 {
     $customerInfo = get_customer_info(get_openid());
     $this->assign('customerType', $customerInfo['subscribe_state']);
     $this->assign('config_buy_max', $this->config_buy_max);
     $this->assign('config_buy_min', $this->config_buy_min);
     $this->assign('payNowUrl', U('OrderForm/Submit/index'));
     $addGoodsToCartUrl = U('Goods/GoodsDetail/add');
     $this->assign('addGoodsToCartUrl', $addGoodsToCartUrl);
     $this->assign('footer', '');
     $goods = new GoodsModel();
     $goodsId = I('get.goodsId');
     $goods->setGoodsId($goodsId);
     $res = $goods->getGoodsInf();
     if ($res == false || $res['state'] != 1) {
         $this->assign('js', $this->fetch('indexJs'));
         $this->assign('css', $this->fetch('indexCss'));
         $detail2 = $this->fetch('error');
         $this->assign('YZBody', $detail2);
         $this->display(YZ_TEMPLATE);
         return;
     }
     //计算运费
     //        if($res['logistics_mode'] == 0)
     //        {
     //            $logistic = new ConfigModel(); //运费配置
     //            $res['internation_transportation_expenses'] = $logistic->getFee($weightTotal);
     //        }
     //
     //获取来源国信息
     $source = new SourceModel();
     $map['id'] = $res['source'];
     $res['source'] = $source->getSource($map);
     $res['source']['icon_url'] = __ROOT__ . "/" . $res['source']['icon_url'];
     $logistic = new LogisticsModel();
     $key = 'logistics_mode';
     $data[0] = $res;
     $data = $logistic->getLogisticInfo($data, $key);
     $res = $data[0];
     $detail = $res;
     //        var_dump($detail);
     $this->assign('goods', $detail);
     $this->assign('js', $this->fetch('indexJs'));
     $this->assign('css', $this->fetch('indexCss'));
     $detail2 = $this->fetch('index');
     $this->assign('YZBody', $detail2);
     $this->display(YZ_TEMPLATE);
 }
 public function runtimeError()
 {
     $solutionId = I('get.sid', 0, 'intval');
     $type = SourceModel::RUNTIMEERROR;
     $error = SourceModel::instance()->getErrorBySolutionId($solutionId, $type);
     dbg($error);
 }
 public function plist()
 {
     $page = I('get.page', 0, 'intval');
     $title = I('get.title', '');
     $source = I('get.source', '');
     if (empty($this->userInfo)) {
         $isAdministrator = false;
         $userId = '';
     } else {
         $userId = $this->userInfo['user_id'];
         $isAdministrator = PrivilegeModel::instance()->isAdministrator($userId);
         if ($page == 0) {
             $_res = UserModel::instance()->getUserByUid($userId, array('volume'));
             $page = $_res['volume'];
         } else {
             $where = array('user_id' => $this->userInfo['user_id']);
             $option = array('volume' => $page);
             UserModel::instance()->updateUserInfo($where, $option);
         }
     }
     $offset = 1000;
     $pageSize = 100;
     $page = $page > 0 ? $page : 1;
     $offsetStart = $offset + ($page - 1) * $pageSize;
     $offsetEnd = $offsetStart + $pageSize;
     if (!empty($title)) {
         $query['title'] = array('like', '%' . $title . '%');
     } else {
         if (!empty($source)) {
             $query['source'] = array('like', '%' . $source . '%');
         } else {
             $query = array('problem_id' => array(array('egt', $offsetStart), array('lt', $offsetEnd)), 'order' => array('problem_id'));
         }
     }
     $field = array('problem_id', 'title', 'defunct', 'submit', 'accepted', 'in_date', 'author');
     $problems = ProblemModel::instance()->getProblemByQuery($query, $field);
     if ($isAdministrator === false) {
         $contests = ContestModel::instance()->getNotEndedContests(array('contest_id'));
         $contestIds = array();
         foreach ($contests as $_contest) {
             $contestIds[] = $_contest['contest_id'];
         }
         $contestProblemIds = ContestModel::instance()->getProblemIdsInContests($contestIds);
         $isInContest = array();
         foreach ($contestProblemIds as $cpId) {
             $isInContest[$cpId] = true;
         }
         unset($contestProblemIds);
     }
     if (!empty($userId)) {
         // 找到该userId对应的该页提交的记录
         $isSubmit = array();
         $where = array('problem_id' => array(array('egt', $offsetStart), array('lt', $offsetEnd)), 'user_id' => $userId);
         $field = array('problem_id', 'result');
         $solutions = SourceModel::instance()->getSolutionsByQuery($where, $field);
         foreach ($solutions as $solution) {
             $_pid = $solution['problem_id'];
             $_re = $solution['result'];
             if (!isset($isSubmit[$_pid])) {
                 $isSubmit[$_pid] = $_re;
             } else {
                 $isSubmit[$_pid] = $_re == 4 ? $_re : $isSubmit[$_pid];
             }
         }
         unset($solutions);
     } else {
         $isSubmit = array();
     }
     foreach ($problems['data'] as $key => $_problem) {
         $_pid = $_problem['problem_id'];
         if (isset($isSubmit[$_pid])) {
             if ($isSubmit[$_pid] == 4) {
                 $problems['data'][$key]['isSubmit'] = 1;
             } else {
                 $problems['data'][$key]['isSubmit'] = -1;
             }
         } else {
             $problems['data'][$key]['isSubmit'] = 0;
         }
         if ($isAdministrator === false) {
             if (empty($isInContest[$_pid])) {
                 if ($_problem['defunct'] == 'Y') {
                     if (empty($userId) || strcmp($_problem['author'], $userId) != 0) {
                         unset($problems['data'][$key]);
                         continue;
                     }
                 }
             } else {
                 unset($problems['data'][$key]);
                 continue;
             }
         }
         unset($problems['data'][$key]['defunct']);
         unset($problems['data'][$key]['author']);
     }
     $this->auto_display();
 }