stanley-king 7 سال پیش
والد
کامیت
026d76bbf0

+ 4 - 0
data/model/appreciate.model.php

@@ -22,4 +22,8 @@ class appreciateModel extends Model
     {
         return $this->field($field)->where(['special_id' => $special_id])->order('appreciate_id desc')->page($page_size, $total_count)->lock($lock)->select();
     }
+    public function getTopAppreciate($special_id,$field='*',$limit = 20,$lock = false)
+    {
+        return $this->field($field)->where(['special_id' => $special_id])->order('appreciate_id desc')->limit($limit)->lock($lock)->select();
+    }
 }

+ 36 - 29
data/resource/mobile/ugc/js/main.js

@@ -1,5 +1,5 @@
 $('html').css('height','100%');
-// $('body').css('height','100%');
+
 $.fn.autoTextarea = function(options) {
     var defaults={
         maxHeight:null,
@@ -30,7 +30,6 @@ $("#comments").autoTextarea({
 
 var host = (function(){
     return window.location.protocol + "//" + window.location.host;
-    // return 'http://192.168.0.200';
 })();
 
 $('.thumbnail img').picLazyLoad();
@@ -48,7 +47,8 @@ var event = function (obj, eventType, callback) {
     obj.live(eventType, callback);
 };
 
-var ajax = function (url, callback, error) {
+var get_ajax = function (url, callback)
+{
     $.ajax({
         type: "get",
         async: false,
@@ -56,11 +56,7 @@ var ajax = function (url, callback, error) {
         dataType: "jsonp",
         jsonp: "callback",
         jsonpCallback: "flightHandler",
-        success: callback,
-        error: error || function () {
-            $('.loader').hide();
-            alert('网络错误');
-        }
+        success: callback
     });
 };
 
@@ -339,7 +335,7 @@ var ReplyItem = function (comment, members) {
     };
     var commentdata = comment;
     var sub = '';
-    var subnum = 4;
+    var subnum = 10;
     if(comment) {
         var defaultSubNum = comment['sub_count'];
     }
@@ -459,8 +455,9 @@ var ReplyList = function () {
     var getDate = function () {
         isLoad = true;
         $('.loader').show();
-        ajax(host +'/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&curpage=' + curpage, function (data) {
-            console.log(data);
+        var url = host +'/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&curpage=' + curpage;
+        get_ajax(url,function (data)
+        {
             $('.loader').hide();
             isLoad = false;
             if (data.code !== 200) {
@@ -485,10 +482,11 @@ var ReplyList = function () {
                     document.getElementsByClassName('wrapper')[0].removeEventListener('scroll',loadEvent);
                 }
             }
-        }, function () {
-            $('.loader').hide();
-            $('.comment_list').append(new ReplyItem().empty());
-        })
+        });
+        // , function () {
+        //     $('.loader').hide();
+        //     $('.comment_list').append(new ReplyItem().empty());
+        // })
     };
     var loadEvent = function () {
         var scrollTop = $(this).scrollTop();
@@ -509,9 +507,11 @@ var ReplyList = function () {
 };
 
 
-var CommentsBox = function () {
+var CommentsBox = function ()
+{
     var maxSize = 150;
-    var show = function () {
+    var show = function ()
+    {
         $('.pop').show();
         $('.answer_comments').show();
         $('#comments').focus();
@@ -519,6 +519,7 @@ var CommentsBox = function () {
             event.preventDefault();
         });
     };
+
     var inputFocus = function(){
         $('#comments').focus(function(){
             interval = setInterval(function() {
@@ -584,7 +585,8 @@ var CommentsBox = function () {
             var textVal = $('#comments').val();
             if (Comment_type == 'special_id') {
                 url = host +'/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal);
-                ajax(url, function (data) {
+                get_ajax(url, function (data)
+                {
                     $('.loader').hide();
                     if (data.code !== 200) {
                         alert(data.message);
@@ -605,7 +607,7 @@ var CommentsBox = function () {
                 else {
                     url = host +'/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal) + '&comment_id=' + res.comment_id;
                 }
-                ajax(url, function (data) {
+                get_ajax(url, function (data) {
                     $('.loader').hide();
                     if (data.code !== 200) {
                         alert(data.message);
@@ -727,7 +729,7 @@ event($('.btn_appreciate'),'click',function(){
             else {
                 logined = true;
                 var url = host + '/mobile/index.php?act=member_ugc&op=mine_bonus&client_type=ajax';
-                ajax(url,function(data){
+                get_ajax(url,function(data){
                     $('.loader').hide();
                     if (data.code !== 200) {
                         alert(data.message);
@@ -746,7 +748,7 @@ event($('.btn_appreciate'),'click',function(){
     }
     else {
         var url = host + '/mobile/index.php?act=member_ugc&op=mine_bonus&client_type=ajax';
-        ajax(url,function(data){
+        get_ajax(url,function(data){
             $('.loader').hide();
             if (data.code !== 200) {
                 alert(data.message);
@@ -777,7 +779,7 @@ event($('#submit_appreciate'),'click',function(){
     var money = $('.bonus_item.active .money').text();
     var content = $('#live_msg').val();
     var url = host + '/mobile/index.php?act=member_ugc&op=appreciate&client_type=ajax&rate='+rate+'&money=' + money + '&content=' + encodeURI(content) + '&special_id=' + specialId ;
-    ajax(url,function(data){
+    get_ajax(url,function(data){
         console.log(data);
         if (data.code !== 200) {
             alert(data.message);
@@ -837,7 +839,7 @@ $('#submit_btn').on('click', function () {
         allAnswers.question = resAnswers;
     }
     var url = host + "/mobile/index.php?act=special&op=submit&client_type=ajax&special_id=" + specialId + '&content=' + encodeURI(JSON.stringify(allAnswers));
-    ajax(url, function (data) {
+    get_ajax(url, function (data) {
         $('.loader').hide();
         if (data.code !== 200) {
             alert(data.message);
@@ -846,6 +848,14 @@ $('#submit_btn').on('click', function () {
         }
         _self.css('display', 'none');
 
+        if($('.vote').length <= 0 && $('.question_list').length <= 0) {
+            if (data.datas['bonus_url'] !== "") {
+                $('.pop').show();
+                $('.bonus_page').attr('href', data.datas["bonus_url"]).addClass('fade-in').show();
+                $('.close_icon').addClass('rotate').show();
+                $('.bonus_page img').attr('src',data.datas["sender_avatar"]);
+            }
+        }
 
         if ($('.vote').length > 0 && $('.question_list').length <= 0) {
             $('.vote_options').css('display', 'none');
@@ -907,7 +917,7 @@ event($('.like_btn'), 'click', function () {
     if ($(this).attr('data-comment_id')) {
         var comment_id = $(this).attr('data-comment_id');
         url = host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id;
-        ajax(url, function (data) {
+        get_ajax(url, function (data) {
             $('.loader').hide();
             if (data.code !== 200) {
                 alert(data.message);
@@ -927,7 +937,7 @@ event($('.like_btn'), 'click', function () {
     }
     else {
         url = host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId;
-        ajax(url, function (data) {
+        get_ajax(url, function (data) {
             $('.loader').hide();
             if (data.code !== 200) {
                 alert(data.message);
@@ -952,7 +962,7 @@ event($('.button_load_more'), 'click', function () {
     var comment_id = $(this).parent('.comment_item').attr('data-comment_id');
     var curpage = $(this).attr('data-page');
     var url = host + '/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id + '&curpage=' + curpage +'&page=4';
-    ajax(url, function (data) {
+    get_ajax(url, function (data) {
         $('.loader').hide();
         if (data.code !== 200) {
             alert(data.message);
@@ -994,9 +1004,6 @@ register_js_hander('onKeyboardClose',function(data,callback) {
     commentsBox.close();
 });
 
-
-
-
 function app()
 {
     var app=navigator.userAgent.toLowerCase(),//判断设备

+ 1 - 1
helper/ugc/comments.php

@@ -12,7 +12,7 @@ use algorithm;
 
 class comments
 {
-    const max_response = 5;
+    const max_response = 11;
 
     private $counter;
     private $users;

+ 4 - 0
helper/ugc/setting.php

@@ -152,11 +152,15 @@ class setting
         $type = $this->mSetting['ispub'] ? 0 : 1;
         return $type;
     }
+    public function appreciate() {
+        return $this->mSetting['appreciate'] == true ? true : false;
+    }
 
     public function format()
     {
         $result['submit_rule'] = $this->submit_rule();
         $result['reader_type'] = $this->reader_type();
+//        $result['appreciate']  = $this->appreciate();
 
         return $result;
     }

+ 2 - 2
mobile/control/control.php

@@ -289,9 +289,9 @@ class mbMemberControl extends mobileControl
 
 function bonus_version()
 {
-    return "v=2017081005";
+    return "v=2017081108";
 }
 function shop_version()
 {
-    return "v=2017081005";
+    return "v=2017081106";
 }

+ 1 - 1
mobile/control/member_ugc.php

@@ -396,7 +396,7 @@ class member_ugcControl extends specialControl
         {
             $mod = Model('ugc_comment');
             $comments = $mod->getCommentList(['comment_id' => $ret],'*',0);
-            $comments_obj =new ugc\comments($comments,$special_id);
+            $comments_obj =new ugc\comments($comments,$special_id,[]);
             $comments = $comments_obj->comments();
             $uids = $comments_obj->users();
             $members = $this->users($uids);

+ 68 - 1
mobile/control/special.php

@@ -248,6 +248,8 @@ class tpl_ugc
         }
 
         $this->show_submit();
+        $this->show_appreciate();
+        $this->show_comment_header();
     }
     private function show_submit()
     {
@@ -284,7 +286,12 @@ class tpl_ugc
                 $str = "<button class=\"button_vote\" id=\"submit_btn\">{$content}</button>";
             }
         }
+        echo $str;
+    }
 
+    private function show_comment_header()
+    {
+        $str = '';
         if(!$this->preview())
         {
             $str .= '<div class="comment">
@@ -292,7 +299,7 @@ class tpl_ugc
                             <div class="pro_title">评论</div>
                         </div>
                         <div class="comment_list"></div>
-                    </div>';
+                      </div>';
         }
 
         echo $str;
@@ -641,4 +648,64 @@ class tpl_ugc
 
         echo $str;
     }
+    private function show_appreciate()
+    {
+        $nums = $this->special->appreciates();
+        $header = "<div class=\"appreciate\">
+                        <p class=\"appreciate_pro\">如果你喜欢该文章,请随意打赏。</p >
+                        <div class=\"appreciate_box\">
+                            <div class=\"btn_appreciate\">";
+        if($nums > 0)
+        {
+            $header .=          "赞赏<span class=\"appreciate_num\">|已有{$nums}人打赏</span>";
+            $header .=      "</div>
+                        </div>
+                        <div class=\"appreciate_users\">";
+
+            $avatars = $this->appreciate_avatars($this->special_id(),20);
+
+            $sAvatars = '';
+            foreach ($avatars as $avatar) {
+                $sAvatars .= "<img src=\"{$avatar}\">";
+            }
+            $header .= $sAvatars;
+            $header .= '</div>';
+            if($nums > 20) {
+                $header .= '<div class="appreciate_label">....超20人赞赏</div>';
+            }
+        }
+        else {
+            $header .= "赞赏";
+            $header .= "</div>";
+        }
+        $header .= '</div>';
+        echo $header;
+    }
+
+    private function appreciate_avatars($special_id,$count)
+    {
+        $mod = Model('appreciate');
+        $items = $mod->getTopAppreciate($special_id,'*',$count);
+
+        $uids = [];
+        foreach ($items as $item) {
+            $uid = intval($item['member_id']);
+            $uids[] = $uid;
+        }
+
+        $avatars = [];
+        if(!empty($uids))
+        {
+            $mod_member = Model('member');
+            $mInfos = $mod_member->getMemberList(array('member_id' => ['in',$uids]));
+
+            foreach ($mInfos as $info) {
+                $minfo = new member_info($info);
+                $avatar = $minfo->avatar();
+                $avatars[] = $avatar;
+            }
+        }
+
+        return $avatars;
+    }
 }

+ 1 - 0
mobile/templates/default/ugc/content.php

@@ -12,6 +12,7 @@
     <link rel="stylesheet" href="<?php echo RESOURCE_SITE_URL; ?>/mobile/ugc/css/main.css?<?php echo bonus_version(); ?>">
 </head>
 <body data-special_id="<?php $tpl_obj = $output['tpl_obj']; echo $tpl_obj->special_id();?>">
+
 <div class="wrapper">
     <div class="content">
         <?php $tpl_obj = $output['tpl_obj']; $tpl_obj->show_title();?>

+ 1 - 1
test/TestUGC.php

@@ -120,7 +120,7 @@ class TestUGC extends PHPUnit_Framework_TestCase
         $commentids = $this->commentids($items);
         $comments = $mod->getCommentList(array('top_id' => ['in',$commentids]),'*',0);
 
-        $comments_obj =new ugc\comments($comments,$special_id);
+        $comments_obj =new ugc\comments($comments,$special_id,[]);
         $comments = $comments_obj->comments();
         $users = $comments_obj->users();
     }