فهرست منبع

add answer list

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

+ 44 - 0
data/model/ugc_answer.model.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/8/16
+ * Time: 下午8:17
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class ugc_answerModel extends Model
+{
+    public function __construct()
+    {
+        parent::__construct('special_answer');
+    }
+    public function counts($special_id)
+    {
+        return $this->where("special_id={$special_id}")->count();
+    }
+
+    public function answer_list($special_id,$field='*',$page_size = 0,$total_count = 0,$lock = false)
+    {
+        return $this->field($field)->where(['special_id' => $special_id])->order('correct_num desc')->page($page_size, $total_count)->lock($lock)->select();
+    }
+    public function lt_count($special_id,$correct_num)
+    {
+        return $this->where(array('special_id' => $special_id, 'correct_num' =>['lt', $correct_num]))->count();
+    }
+
+    public function getAnswer($specialid,$memberid)
+    {
+        $items = $this->field('*')->where(['special_id' => $specialid,'member_id' => $memberid])->select();
+        if(empty($items)) {
+            $items = $this->field('*')->where(['special_id' => $specialid,'member_id' => $memberid])->lock(true)->select();
+        }
+
+        if(!empty($items)) {
+            return $items[0];
+        }
+
+        return $items;
+    }
+}

+ 1 - 2
helper/ugc/answer.php

@@ -124,7 +124,6 @@ class special_submitor extends storage
 
         parent::__construct();
     }
-
     public function limit_type()
     {
         return $this->vote_single;
@@ -261,7 +260,7 @@ class special_answer
             $answer_id = Model()->table('special_answer')->insert(['special_id' => $spid,'member_id' => $member_id,'answer' => serialize($sub_answers),
                 'total_num' => count($this->correct_answers),'correct_num' => $correct_num,'answer_time' => time()]);
         } else {
-            $answer_id = -1;
+            $answer_id = false;
         }
 
         return $correct_num;

+ 9 - 9
helper/ugc/special.php

@@ -16,7 +16,6 @@ class submit_rule
     private $bonus;
     private $type_sn;
     private $per_amount;
-    private $bonus_rate;
 
     public function __construct($content)
     {
@@ -33,10 +32,8 @@ class submit_rule
     public function per_amount() {
         return $this->per_amount;
     }
-    public function bonus_rate() {
-        return $this->bonus_rate;
-    }
-    public function make_bonus($num)
+
+    public function make_bonus($num,&$amount,&$bonus_rate)
     {
         if($this->support_bonus() == false) return false;
         if($this->has_bonus() == true) return $this->type_sn();
@@ -45,7 +42,7 @@ class submit_rule
         {
             $trans = new trans_wapper(null,'submit_rule make_bonus');
             $type = bonus\type::create_by_sn($this->type_sn());
-            $this->bonus_rate = $type->bonus_rate();
+            $bonus_rate = $type->bonus_rate();
 
             $bonus_value = intval(floatval($this->per_amount()) * $num * 100 + 0.5);
 
@@ -82,17 +79,20 @@ class submit_rule
                 if(session_helper::isLogin()) {
                     Model('bonus_type')->edit(['type_id' => $type->getType_id()],
                         array('grabed_num' => array('exp', 'grabed_num+1'),
-                            'binded_num' => array('exp', 'binded_num+1'),
-                            'remain_amount' => array('exp', "remain_amount-{$bonus_value}")));
+                            'binded_num'   => array('exp', 'binded_num+1'),
+                            'total_num'    => array('exp', 'total_num+1'),
+                            'remain_amount'=> array('exp', "remain_amount-{$bonus_value}")));
                 }
                 else {
                     Model('bonus_type')->edit(['type_id' => $type->getType_id()],
-                        array('grabed_num' => array('exp', 'grabed_num+1')));
+                        array('grabed_num' => array('exp', 'grabed_num+1'),
+                              'total_num'  => array('exp', 'total_num+1')));
 
                 }
             }
             $trans->commit();
 
+            $amount = $bonus_value;
             if($ret == false) {
                 return false;
             } else {

+ 10 - 9
helper/ugc_helper.php

@@ -132,6 +132,10 @@ class ugc_helper
             {
                 $answor = new special_answer($special);
                 $correct_num = $answor->answer($answers,$answor_id);
+                if($answor_id == false) {
+                    $err = ['code' => errcode::ErrSpecial,'msg' => "您已经答过题了,不能再答"];
+                    return false;
+                }
                 $num += $correct_num;
                 $answer_diff = $answor->diff();
                 $bonus_type = 1;
@@ -142,20 +146,17 @@ class ugc_helper
             $bonus_type = 2;
         }
 
+        $type_sn = "";
+        $amount = 0.0;
+
         $rule = $special->submit_rule();
         if($rule != false && $num > 0)
         {
-            $type_sn = $rule->make_bonus($num);
-            $amount = intval($rule->per_amount() * $num * 100 + 0.5) / 100;
-            $bonus_rate = $rule->bonus_rate();
-            if(isset($answor_id)) {
-                Model()->table('special_answer')->update(['amount' => $amount,'bonus_rate' => $bonus_rate],['spanswer_id' => $answor_id]);
+            $type_sn = $rule->make_bonus($num,$amount,$bonus_rate);
+            if(isset($answor_id) && $type_sn != false) {
+                Model()->table('special_answer')->where(['spanswer_id' => $answor_id])->update(['amount' => $amount,'bonus_rate' => $bonus_rate]);
             }
         }
-        else {
-            $type_sn = "";
-            $amount = 0.0;
-        }
 
         return ['vote_result' => $vote_result,'answer_diff' => $answer_diff,'type_sn' => $type_sn,'num' => $num,'amount' => $amount,'bonus_type' => $bonus_type];
     }

+ 2 - 2
mobile/control/control.php

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

+ 85 - 0
mobile/control/member_ugc.php

@@ -494,4 +494,89 @@ class member_ugcControl extends specialControl
 
         return self::outsuccess(['appreciate' => $result,'members' => $members,'mobile_page' => mobile_page($pages)]);
     }
+
+    public function answer_pageOp()
+    {
+        $special_id = intval($_GET['special_id']);
+        if($special_id < 0) {
+            return self::outerr(errcode::ErrParamter,"该专题不存在");
+        }
+        $memberid = session_helper::memberid();
+        $mod_answer = Model('ugc_answer');
+        $answer = $mod_answer->getAnswer($special_id,$memberid);
+        if(empty($answer)) {
+            return self::outerr(errcode::ErrDB,"抱歉,服务器内部发生错误,研发人员会尽快修复");
+        }
+        else {
+            $result = $this->format_answer($answer,'','');
+            $correct_num = $answer['correct_num'];
+            if($correct_num > 0)
+            {
+                $lt_count = $mod_answer->lt_count($special_id,$correct_num);
+                $counts   = $mod_answer->counts($special_id);
+                if($lt_count > 0 && $counts > 0) {
+                    $scale = intval($lt_count * 100 / $counts + 0.5);
+                } else {
+                    $scale = false;
+                }
+
+            } else {
+                $scale = false;
+            }
+
+            return self::outsuccess(['answer' => $result,'scale' => $scale],'ugc/answer.list');
+        }
+    }
+
+    private function format_answer($answer,$nickname,$avatar)
+    {
+        $result['correct_num'] = intval($answer['correct_num']);
+        $result['total_num']   = intval($answer['total_num']);
+        if($result['total_num'] == 0) {
+            $result['score'] = 0;
+        }
+        else {
+            $result['score']  = intval($result['correct_num'] * 100 / $result['total_num'] + 0.5);
+        }
+        $result['bonus_rate'] = intval($answer['bonus_rate']);
+        $result['amount']     = doubleval($answer['amount']);
+        $result['answer_time']= intval($answer['answer_time']);
+        $result['nickname']   = $nickname;
+        $result['avatar']     = $avatar;
+
+        return $result;
+    }
+
+    public function answersOp()
+    {
+        $special_id = intval($_GET['special_id']);
+        if($special_id < 0) {
+            return self::outerr(errcode::ErrParamter,"该专题不存在");
+        }
+        $mod_answer = Model('ugc_answer');
+        $count = $mod_answer->counts($special_id);
+        $items = $mod_answer->answer_list($special_id,'*',$this->page_size(),$count);
+
+        $uids = [];
+        foreach ($items as $val) {
+            $user_id = intval($val['member_id']);
+            $uids[] = $user_id;
+        }
+        $minfos = $this->users($uids);
+        $members = [];
+        foreach ($minfos as $val) {
+            $mid = intval($val['member_id']);
+            $members[$mid] = $val;
+        }
+
+        $answers = [];
+        foreach ($items as $item) {
+            $mid = intval($item['member_id']);
+            $member = $members[$mid];
+            $value = $this->format_answer($item,$member['nickname'],$member['avatar']);
+            $answers[] = $value;
+        }
+        $pages = $mod_answer->gettotalpage();
+        return self::outsuccess(['answers' => $answers,'mobile_page' => mobile_page($pages)]);
+    }
 }

+ 8 - 0
mobile/control/special.php

@@ -302,6 +302,7 @@ class tpl_ugc
             $str = "<button class=\"button_vote button_null\" disabled>您已经提交过</button>";
         }
         echo $str;
+        $this->show_answer_page();
     }
 
     private function show_comment_header()
@@ -729,4 +730,11 @@ class tpl_ugc
 
         return $avatars;
     }
+    private function show_answer_page()
+    {
+        $specialid = $this->special_id();
+        $url = BASE_SITE_URL . "/mobile/index.php?act=member_ugc&op=answer_page&client_type=wap&special_id={$specialid}";
+        $str = "<p class=\"look_question_result\" style=\"color: #FF4E4E; text-align: center;font-size: 24px;\"><a href=\"{$url}\">查看答题情况>></a></p >";
+        echo $str;
+    }
 }

+ 163 - 0
mobile/templates/default/ugc/answer.list.php

@@ -0,0 +1,163 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>答题结果</title>
+    <meta name="viewport" content="width=750,user-scalable=no,target-densitydpi=device-dpi">
+    <meta name="format-detection" content="telephone=no">
+    <link rel="stylesheet" href="<?php echo RESOURCE_SITE_URL; ?>/mobile/ugc/css/main.css?<?php echo bonus_version(); ?>">
+</head>
+<body>
+<div class="result_list">
+    <div class="my_result">
+        <div class="answer_collect">
+            <p class="all_question_num">本次答题总计<span class="letter_pro"><?php $answer = $output['answer']; echo $answer['total_num'];?></span>题</p>
+            <p class="right_question_num">您答对了<span class="letter_pro"><?php $answer = $output['answer']; echo $answer['correct_num'];?></span>题</p>
+        </div>
+        <div class="my_score">
+            <p><span class="letter_pro"><?php $answer = $output['answer']; echo $answer['score'];?></span>分</p>
+        </div>
+        <div class="rank">
+            <?php $scale = $output['scale'];
+                if($scale != false) {
+                    echo "<p>您的智慧已经远远超过了<span class=\"letter_pro\">{$scale}%</span>的人</p>";
+                } else {
+                    echo "<p>为了彰显您的智慧,邀请好友一起答题吧~</p>";
+                }
+            ?>
+        </div>
+    </div>
+
+    <div class="br"></div>
+    <div class="other_bonus_reslut">
+
+    </div>
+</div>
+<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/bonus/js/zepto.min.js?<?php echo bonus_version(); ?>"></script>
+<script type="text/javascript">
+    $(function ()
+    {
+        var getTime = function (time)
+        {
+            var date = '';
+            var location = parseInt(new Date().getTime() / 1000);
+            var diffHour = parseInt((location - time) / 60 / 60);
+            var diffMinutes = parseInt((location - time) / 60);
+            if (diffHour <= 0) {
+                if (diffMinutes >= 0 && diffMinutes < 5) {
+                    date = "刚刚";
+                }
+                else {
+                    date = diffMinutes + "分钟前";
+                }
+            }
+            if (diffHour < 24 && diffHour > 0) {
+                date = diffHour + '小时前';
+            }
+            if (diffHour >= 24) {
+                var milliseconds = time * 1000;//秒变微秒
+                var dat = new Date(milliseconds);//生成日期
+                var month = dat.getMonth() + 1;    //取得月
+                var date1 = dat.getDate(); //取得天
+                var hour = dat.getHours();//取得小时
+                var minutes = dat.getMinutes();//取得分钟
+                if (hour < 10) {
+                    hour = '0' + dat.getHours();
+                }
+                if (minutes < 10) {
+                    minutes = '0' + dat.getMinutes();
+                }
+                date = month + '月' + date1 + '日' + hour + ':' + minutes;
+            }
+            return date;
+        };
+
+        var Item = function (obj, index, datas, is_king)
+        {
+            var king = '';
+            if (is_king) {
+                king = '<span class="king_icon"></span>';
+            }
+            var result = datas;
+            var exHtml = function (item)
+            {
+                var html = '<div class="item">' +
+                                '<div class="user_index">' +
+                                    +index + '.' +
+                                '</div>' +
+                                '<div class="user_msg">' +
+                                    '<div class="user_img">' +
+                                        '<img src="' + result.avatar + '">' + king +
+                                    '</div>' +
+                                    '<div class="user_pro">' +
+                                        '<p class="user_name">' + result.nickname + '</p>' +
+                                        '<p class="answer_time">' + getTime(result.answer_time) + '</p>' +
+                                    '</div>' +
+                                '</div>' +
+                                '<div class="score">' +
+                                    '<span class="letter_pro">' + result.score + '</span>分' +
+                                '</div>' +
+                                '<div class="bonus_label">' +
+                                    '<p>' + result.amount + '元</p>' +
+                                    '<div class="scale"><span class="border">' + result.bonus_rate + '<i class="ratio_icon"></i></span></div>' +
+                                '</div>' +
+                            '</div>';
+                return html;
+            };
+            this.exportHTML = function () {
+                obj.append(exHtml(result));
+            }
+        };
+
+        var host = (function () {
+            return window.location.protocol + "//" + window.location.host;
+        })();
+
+        var page = 1;
+        var isLoad = false;
+        var index = 1;
+        var getData = function ()
+        {
+            isLoad = true;
+            var url = host + '/mobile/index.php?act=member_ugc&op=answers&client_type=ajax&special_id=258&curpage=' + page;
+            $.ajax({
+                type: "get",
+                async: false,
+                url: url,
+                dataType: "jsonp",
+                jsonp: "callback",
+                jsonpCallback: "flightHandler",
+                success: function (data)
+                {
+                    var datas = data.datas;
+                    isLoad = false;
+                    if (data.code !== 200) {
+                        alert(data.message);
+                    }
+                    for (var i = 0; i < datas.answers.length; i++)
+                    {
+                        if (index < 4) {
+                            new Item($('.other_bonus_reslut'), index, datas.answers[i], true).exportHTML();
+                        }
+                        else {
+                            new Item($('.other_bonus_reslut'), index, datas.answers[i]).exportHTML();
+                        }
+                        index++;
+                    }
+
+                    if (datas['mobile_page'].hasmore && isLoad == false) {
+                        $(window).on('scroll', getData);
+                        page++;
+                    }
+                    else {
+                        $(window).unbind('scroll');
+                    }
+                }
+            });
+        };
+
+        getData();
+    })
+</script>
+</body>
+</html>