Collection.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Collection
  5. {
  6. # 保存信息 收费
  7. public function up($ticket_id, $uid, $source_uid, $info_id, $cate_id, $num = 1)
  8. {
  9. $ticket = Dever::db('user/ticket')->one($ticket_id);
  10. if (!$ticket) {
  11. return false;
  12. }
  13. if ($ticket['num'] > 0 && $ticket['num'] >= $num) {
  14. $state = $this->upAct($uid, $info_id, $cate_id, $num, $source_uid, $ticket_id);
  15. if ($state) {
  16. Dever::score($uid, 'use_ticket', '使用门票', false, false, false, 'collection', $info_id);
  17. if ($source_uid && $source_uid != $uid) {
  18. # 添加积分
  19. Dever::score($source_uid, 'give_ticket', '赠送门票', false, false, false, 'collection', $info_id);
  20. }
  21. # 减少门票
  22. Dever::db('user/ticket')->des(array('where_id' => $ticket_id, 'num' => $num));
  23. }
  24. return true;
  25. } else {
  26. return false;
  27. }
  28. }
  29. # 保存信息 免费
  30. public function upAct($uid, $info_id, $cate_id, $num = 1, $source_uid = false, $ticket_id = false)
  31. {
  32. $where['uid'] = $uid;
  33. $where['info_id'] = $info_id;
  34. //$where['ticket_id'] = $ticket_id;
  35. $info = Dever::db('user/collection')->one($where);
  36. if (!$info) {
  37. $where['num'] = $num;
  38. if ($source_uid) {
  39. $where['source_uid'] = $source_uid;
  40. # 更新邀请榜单
  41. Dever::load('collection/lib/ranking')->up($source_uid, $info_id, 3, 1);
  42. }
  43. if ($ticket_id) {
  44. $where['ticket_id'] = $ticket_id;
  45. }
  46. $where['cate_id'] = $cate_id;
  47. return Dever::db('user/collection')->insert($where);
  48. }
  49. return false;
  50. }
  51. # 获取信息
  52. public function check($uid, $info_id)
  53. {
  54. $where['uid'] = $uid;
  55. $where['info_id'] = $info_id;
  56. $info = Dever::db('user/collection')->one($where);
  57. return $info;
  58. }
  59. # 获取用户拥有的合集
  60. public function getList($uid, $cate_id = false)
  61. {
  62. $where['uid'] = $uid;
  63. if ($cate_id) {
  64. $where['cate_id'] = $cate_id;
  65. }
  66. $info = Dever::db('user/collection')->getAll($where);
  67. return $info;
  68. }
  69. # 获取用户拥有的合集分类
  70. public function getCateList($uid)
  71. {
  72. $where['uid'] = $uid;
  73. $info = Dever::db('user/collection')->getCateAll($where);
  74. return $info;
  75. }
  76. # 获取某个合集的拥有数量
  77. public function getNum($info_id)
  78. {
  79. $where['info_id'] = $info_id;
  80. $info = Dever::db('user/collection')->num($where);
  81. if (!$info) {
  82. $info['num'] = 0;
  83. }
  84. return $info['num'];
  85. }
  86. }