Gift.php 2.7 KB

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