Collection.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, $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, $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, $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. return Dever::db('user/collection')->insert($where);
  47. }
  48. return false;
  49. }
  50. # 获取信息
  51. public function check($uid, $info_id)
  52. {
  53. $where['uid'] = $uid;
  54. $where['info_id'] = $info_id;
  55. $info = Dever::db('user/collection')->one($where);
  56. return $info;
  57. }
  58. # 获取用户拥有的合集
  59. public function getList($uid)
  60. {
  61. $where['uid'] = $uid;
  62. $info = Dever::db('user/collection')->getAll($where);
  63. return $info;
  64. }
  65. # 获取某个合集的拥有数量
  66. public function getNum($info_id)
  67. {
  68. $where['info_id'] = $info_id;
  69. $info = Dever::db('user/collection')->num($where);
  70. if (!$info) {
  71. $info['num'] = 0;
  72. }
  73. return $info['num'];
  74. }
  75. }