thinkPHP商城公告功能開發問題分析_php實例

WBOY
發布: 2023-03-03 06:38:01
原創
1540 人瀏覽過

本文實例分析了thinkPHP商城公告功能開發問題。分享給大家參考,具體如下:

效果如下

1.定在頭部

position: fixed;
z-index: 999;
top: 0;
opacity:1;

登入後複製

2.ajax處理json資料

// 获取商城公告
function getNotice() { // 获取公告函数
  var res;
  $.ajax({
    type: "POST",
    url: "{sh::U('Store/Mall/ajaxGetNotice',array('mid'=>$mid))}",
    dataType:'json', // 设为json之后,就能够很好的处理获取的json数据,json.status
    async: false,
    success: function(json){
      res = json;
    }
  });
  return res;
}

登入後複製

設定dataType:'json'之後,json資料就直接可以透過json.的方式處理了。

3.最後加載,頁面更好看。

$(document).ready(function(e) { // 主函数
  // 获取公告
  var action_name = "{sh::ACTION_NAME}"; // 页面使用thinkphp常量
  var json = getNotice();
  if ( action_name == 'index' && json.status == 1) { // 首页并且公告存在
    $(".top").css("margin-top", "70px"); // jquery设置css
    $(".main-sidebar").css("top" ,"70px");
    var html = '';
    $.each(json.info, function(i, n){ // n为文本内容
      html += "<li><strong>"+n.content+"</strong></li>"
    });
    $(".top-notice").show();
    $('#notice ul').html(""+html);
    $('#notice').unslider(); // 轮播
  }
});

登入後複製

4.取得sql語句的thinkphp處理

// 获取公告
function ajaxGetNotice() {
    if (IS_AJAX) {
      $this->mid;
      // 获取有效的,且结束时间大于当前时间的,或者日期等于0的公告
      $mallNoticeModel = M('Mall_notice');
      $where['mall_id'] = $this->mid;
      $where['status'] = 1;
      $where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;
      //SELECT * from sh_mall_notice where mall_id = 9 and status = 1 and (endtime = 0 or endtime>1458354366);
      $notice = $mallNoticeModel->where($where)->order('sort desc')->select();
      if (!empty($notice)) {
        $this->ajaxReturn(array('status'=>'1','info'=>$notice,'msg'=>"获取成功"),'JSON');
      } else {
        $this->ajaxReturn(array('status'=>'2','info'=>$notice,'msg'=>"公告不存在"),'JSON');
      }
    }
}

登入後複製
$where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;

登入後複製

巧妙的處理了這種邏輯關係。

更多關於thinkPHP相關內容有興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教學》、《Zend FrameWork框架入門教學》、《smarty模板入門基礎教學》及《PHP模板技術總結》。

希望本文所述對大家以ThinkPHP架構為基礎的PHP程式設計有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!