ThinkPHP mall announcement function development problem analysis, thinkphp mall
This article analyzes thinkPHP mall announcement function development issues. We will share this with you for your reference. The details are as follows:
The effect is as follows:
1. Set it to the header
position: fixed;z-index: 999;top: 0;opacity:1;
2. ajax processing json data
// Obtain the mall announcement function getNotice () {// obtain the announcement function var res; $. ajax ({type: "POST", url: "{sh: U ('store/Mall/ajaxGetNotice ', array ('mid' => $ mid ))}", dataType: 'json', // after it is set to json, It can well process the obtained json data, json. status async: false, success: function (json) {res = json ;}}); return res ;}
After dataType: 'json' is set, json data can be processed directly in json. mode.
3. Finally, load the file to make the page look better.
$ (Document ). ready (function (e) {// main function // obtain the announcement var action_name = "{sh: ACTION_NAME}"; // use the thinkphp constant var json = getNotice () on the page (); if (action_name = 'index' & json. status = 1) {// The homepage with the announcement $ (". top ").css (" margin-top "," 70px "); // set css $ (". main-sidebar ").css (" top "," 70px "); var html =''; $. each (json.info, function (I, n) {// n is the text content html + = "<li> <strong>" + n. content + "</strong> </li>"}); $ (". top-notice "). show (); $ ('# notice ul'{.html ("" + html); $ (' # notice '). unslider (); // carousel }});
4. Obtain thinkphp processing of SQL statements
// Obtain the announcement function ajaxGetNotice () {if (IS_AJAX) {$ this-> mid; // obtain valid and end time greater than the current time, or an announcement with a date equal to 0 $ mallNoticeModel = M ('mall _ notice '); $ where ['mall _ id'] = $ this-> mid; $ where ['status'] = 1; $ where ['endtime'] = 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 '=> "obtained successfully"), 'json');} else {$ this-> ajaxReturn (array ('status' => '2 ', 'info' => $ notice, 'msg '=> "announcement does not exist"), 'json ');}}}
$where['endtime'] = array(array('eq',0),array('gt',time()), 'or') ;
It cleverly handles this logical relationship.