Index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['info'];
  11. protected $noNeedRight = ['*'];
  12. //进行中的唯一一个投票活动
  13. public function info(){
  14. $find = Db::name('vote_subject')->where('id',1)->find();
  15. if(!$find){
  16. $this->error('没有进行中的投票活动');
  17. }
  18. $find = info_domain_image($find,['image','paihang_image']);
  19. $this->success(1,$find);
  20. }
  21. //结束后的首页
  22. public function index(){
  23. //活动详情
  24. $find = Db::name('vote_subject')->where('id',1)->find();
  25. if(!$find){
  26. $this->error('没有进行中的投票活动');
  27. }
  28. $find = info_domain_image($find,['image','paihang_image']);
  29. //中奖信息
  30. $zhongjiang = [
  31. 'zhongjiang_status' => 0,
  32. 'finish_title' => config('site.finish_title'),
  33. 'finish_info' => config('site.finish_info'),
  34. 'finish_iqiyi' => config('site.finish_iqiyi'),
  35. 'user_kami' => '',
  36. 'finish_content' => config('site.finish_content'),
  37. ];
  38. if($this->auth->isLogin()){
  39. $exam_user_top = Db::name('exam_user_top')->where('user_id',$this->auth->id)->order('id asc')->find();
  40. if(!empty($exam_user_top) && !empty($exam_user_top['info'])){
  41. $zhongjiang['zhongjiang_status'] = 1;
  42. $zhongjiang['user_kami'] = $exam_user_top['info'];
  43. }
  44. }
  45. $result = [
  46. 'subject' => $find,
  47. 'zhongjiang' => $zhongjiang,
  48. ];
  49. $this->success(1,$result);
  50. }
  51. //领取
  52. public function lingqu(){
  53. $exam_user_top = Db::name('exam_user_top')->where('user_id',$this->auth->id)->order('id asc')->find();
  54. if(!empty($exam_user_top) && !empty($exam_user_top['info'])){
  55. if($exam_user_top['status'] == 0){
  56. $update = [
  57. 'status' => 1,
  58. 'gettime' => time(),
  59. ];
  60. Db::name('exam_user_top')->where('id',$exam_user_top['id'])->update($update);
  61. }
  62. }
  63. $this->success('领取成功');
  64. }
  65. }