|
@@ -0,0 +1,97 @@
|
|
|
+<?php
|
|
|
+namespace app\user\model;
|
|
|
+
|
|
|
+use think\Db;
|
|
|
+use think\Model;
|
|
|
+
|
|
|
+class UserShow extends Model {
|
|
|
+ public function initialize(){
|
|
|
+ parent::initialize();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据信息
|
|
|
+ * @param int $page 页码
|
|
|
+ * @param array $where 查询条件
|
|
|
+ */
|
|
|
+ public function getInfo($page = 0, $where = array()){
|
|
|
+ return $this->db()
|
|
|
+ ->where($where)
|
|
|
+ ->page($page, config('paginate.list_rows'))
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateInfo($show_id, $title, $content)
|
|
|
+ {
|
|
|
+ return $this->db()->where('id', $show_id)->update(['title'=>$title, 'content'=>$content]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addScore($show_id, $score1, $score2, $score3, $score4, $score5)
|
|
|
+ {
|
|
|
+ $score_total = $score1 + $score2 + $score3 + $score4 + $score5;
|
|
|
+
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score1', $score1);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score2', $score2);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score3', $score3);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score4', $score4);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score5', $score5);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('score_total', $score_total);
|
|
|
+ $this->db()->where('id', $show_id)->setInc('num_scored');
|
|
|
+
|
|
|
+ $show = $this->db()->where('id', $show_id)->find();
|
|
|
+ $data = array();
|
|
|
+ $data['sa1'] = round($show['score1'] / $show['num_scored'],5);
|
|
|
+ $data['sa2'] = round($show['score2'] / $show['num_scored'],5);
|
|
|
+ $data['sa3'] = round($show['score2'] / $show['num_scored'],5);
|
|
|
+ $data['sa4'] = round($show['score3'] / $show['num_scored'],5);
|
|
|
+ $data['sa5'] = round($show['score4'] / $show['num_scored'],5);
|
|
|
+ $data['sat'] = round($show['score_total'] / $show['num_scored'],5);
|
|
|
+ $this->db()->where('id', $show_id)->update($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function infoList($sort, $page)
|
|
|
+ {
|
|
|
+ $page = max($page, 1);
|
|
|
+ $num_pre_page = 10;
|
|
|
+ $start = ($page-1) * $num_pre_page;
|
|
|
+
|
|
|
+ $db = Db::name("user_show");
|
|
|
+
|
|
|
+ $list = array();
|
|
|
+ switch ($sort)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ $list = $db->where("del", 0)->order('sat DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ $list = $db->where("del", 0)->order('sa1 DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $list = $db->where("del", 0)->order('sa2 DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $list = $db->where("del", 0)->order('sa3 DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $list = $db->where("del", 0)->order('sa4 DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $list = $db->where("del", 0)->order('sa5 DESC, id DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function infoListByUser($user_id, $page)
|
|
|
+ {
|
|
|
+ $page = max($page, 1);
|
|
|
+ $num_pre_page = 10;
|
|
|
+ $start = ($page-1) * $num_pre_page;
|
|
|
+
|
|
|
+ $db = Db::name("user_show");
|
|
|
+ $list = $db->where("user_id=$user_id AND del=0")->order('score_total DESC')->limit("$start, $num_pre_page")->select();
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+}
|