ugc_answer.model.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/8/16
  6. * Time: 下午8:17
  7. */
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class ugc_answerModel extends Model
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct('special_answer');
  14. }
  15. public function counts($special_id)
  16. {
  17. $ret = $this->where("special_id={$special_id}")->count();
  18. return intval($ret);
  19. }
  20. public function answer_list($special_id,$field='*',$page_size = 0,$total_count = 0,$lock = false)
  21. {
  22. return $this->field($field)->where(['special_id' => $special_id])->order('correct_num desc')->page($page_size, $total_count)->lock($lock)->select();
  23. }
  24. public function lt_count($special_id,$correct_num)
  25. {
  26. return $this->where(array('special_id' => $special_id, 'correct_num' =>['lt', $correct_num]))->count();
  27. }
  28. public function getAnswer($specialid,$memberid)
  29. {
  30. $items = $this->field('*')->where(['special_id' => $specialid,'member_id' => $memberid])->select();
  31. if(empty($items)) {
  32. $items = $this->field('*')->where(['special_id' => $specialid,'member_id' => $memberid])->lock(true)->select();
  33. }
  34. if(!empty($items)) {
  35. return $items[0];
  36. }
  37. return $items;
  38. }
  39. }