Gift.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 礼物接口
  7. */
  8. class Gift extends Api
  9. {
  10. protected $noNeedLogin = ['getGiftList','getGiftType'];
  11. protected $noNeedRight = '*';
  12. public $giftModel;
  13. public $gifttypeModel;
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->giftModel = new \app\common\model\Gift();
  18. $this->gifttypeModel = new \app\common\model\GiftType();
  19. }
  20. /**
  21. * 获取礼物列表
  22. */
  23. public function getGiftList() {
  24. $type = $this->request->request("type"); // 礼物类型:0=活动,1=常规,2=人气,3=浪漫,4=豪华
  25. $page = $this->request->request('page',1); // 分页
  26. $pageNum = $this->request->request('pageNum',100); // 分页
  27. // 分页搜索构建
  28. $pageStart = ($page-1)*$pageNum;
  29. // 获取基本信息
  30. $where = [];
  31. $type != '' && $where["type"] = $type;
  32. // $giftList = $this->giftModel->where($where)->limit($pageStart,$pageNum)->select();
  33. $giftList = $this->giftModel->where($where)->order("value","asc")->select();
  34. $this->success("获取成功!",$giftList);
  35. }
  36. /**
  37. * 获取礼物类型
  38. */
  39. public function getGiftType() {
  40. // 获取基本信息
  41. $where = [];
  42. $where["is_show"] = 1;
  43. $giftList = $this->gifttypeModel->field("id,name")->where($where)->order("weight","desc")->select();
  44. $this->success("获取成功!",$giftList);
  45. }
  46. /**
  47. * 获取我的背包礼物
  48. */
  49. public function getMyBackGift() {
  50. $userid = $this->auth->id;
  51. $page = $this->request->request('page',1); // 分页
  52. $pageNum = $this->request->request('pageNum',10); // 分页
  53. // 分页搜索构建
  54. $pageStart = ($page-1)*$pageNum;
  55. $list = \app\common\model\GiftBack::field("id,name,image,gif_image,value,sum(number) as number")
  56. ->where(["user_id"=>$userid,"is_use"=>0])
  57. ->limit($pageStart,$pageNum)
  58. ->order('value', 'asc')
  59. ->group("name")
  60. ->select();
  61. $this->success("获取成功!",$list);
  62. }
  63. /**
  64. * 获取我的礼物墙
  65. */
  66. public function getMyGiftWall() {
  67. $user_id = $this->request->request("user_id", 0);
  68. $userid = $user_id ? $user_id : $this->auth->id;
  69. $list = \app\common\model\GiftUserParty::alias('a')->join("hx_gift g", "g.id = a.gift_id", "inner")->field("gift_id,g.name,g.image,sum(number) as number")
  70. ->where(["user_to_id" => $userid, 'g.type' => ['<>', 6]])
  71. ->group("gift_id")
  72. ->order('g.value desc')
  73. ->select();
  74. $this->success("获取成功!", $list);
  75. }
  76. }