Gift.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 = ['is_show'=>1];
  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. /**
  74. * 获取我的收送礼明细
  75. */
  76. public function my_gift_log(){
  77. $user_id = $this->auth->id;
  78. $type = input('type',1);
  79. $where = [];
  80. if($type == 1){
  81. $where['user_id'] = $user_id;//我送出
  82. $joinstr = 'gup.user_to_id = user.id';
  83. }else{
  84. $where['user_to_id'] = $user_id;//我收到
  85. $joinstr = 'gup.user_id = user.id';
  86. }
  87. $list = Db::name('gift_user_party')->alias('gup')
  88. ->join('user',$joinstr,'LEFT')->field('gup.*,user.nickname')
  89. ->where($where)->order('id desc')->autopage()->select();
  90. $list = list_domain_image($list,['gift_gif_image']);
  91. $rs = [];
  92. if(empty($list)){
  93. $this->success(1,$rs);
  94. }
  95. foreach($list as $key => $val){
  96. if($type == 1){
  97. $remark = '赠送'.$val['nickname'].','.$val['gift_name'].'*'.$val['number'].',价值'.$val['value'].'钻石';
  98. }else{
  99. $remark = $val['nickname'].'赠送,'.$val['gift_name'].'*'.$val['number'].',价值'.$val['value'].'钻石';
  100. }
  101. $rs[] = [
  102. 'id' => $val['id'],
  103. 'gift_image' => $val['gift_gif_image'],
  104. 'createtime' => $val['createtime'],
  105. 'remark' => $remark
  106. ];
  107. }
  108. $this->success(1,$rs);
  109. }
  110. }