Score.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Score
  5. {
  6. # 获取我在这个小刊中的积分
  7. public function get($id, $uid, $type = 4)
  8. {
  9. $where['uid'] = $uid;
  10. $where['type'] = $type;
  11. $where['data_id'] = $id;
  12. $where['state'] = 1;
  13. $data = Dever::db('act/score')->one($where);
  14. if ($data) {
  15. return $data['score'];
  16. } else {
  17. return 0;
  18. }
  19. }
  20. # 获取小刊的积分排行
  21. public function getList($id, $type = 4, $uid = false)
  22. {
  23. $where['type'] = $type;
  24. $where['data_id'] = $id;
  25. if ($uid > 0) {
  26. $where['uid'] = $uid;
  27. }
  28. $data = Dever::db('act/score')->getAll($where);
  29. if ($data) {
  30. foreach ($data as $k => $v) {
  31. $user = Dever::load('passport/api')->info($v['uid']);
  32. $data[$k]['username'] = $user['username'];
  33. $data[$k]['avatar'] = $user['avatar'];
  34. $data[$k]['mobile'] = $user['mobile'];
  35. }
  36. }
  37. return $data;
  38. }
  39. public function submit()
  40. {
  41. $user_log_id = Dever::input('user_log_id');
  42. $type = Dever::input('type', 4);
  43. $id = Dever::input('id');
  44. $method = Dever::input('method');
  45. $user_log = Dever::db('score/user_log')->one($user_log_id);
  46. if ($user_log) {
  47. if ($method == 'share' || $method == 'pay' || $method == 'code') {
  48. # 活动结束后,无法增加当前小刊积分
  49. if ($type == 4) {
  50. $journal = Dever::db('journal/active')->one(array('info_id' => $id, 'state' => 1));
  51. if (!$journal) {
  52. return;
  53. }
  54. if ($journal && $journal['status'] == 2) {
  55. return;
  56. }
  57. if ($journal && time() > $journal['end']) {
  58. return;
  59. }
  60. }
  61. }
  62. //$where['user_log_id'] = $user_log_id;
  63. $where['uid'] = $user_log['uid'];
  64. $where['data_id'] = $id;
  65. $where['type'] = $type;
  66. $table = 'act/score';
  67. $info = Dever::db($table)->one($where);
  68. if (!$info) {
  69. $where['score'] = $user_log['num'];
  70. Dever::db($table)->insert($where);
  71. } else {
  72. $where['where_id'] = $info['id'];
  73. $where['score'] = $info['score'] + $user_log['num'];
  74. Dever::db($table)->update($where);
  75. }
  76. }
  77. return true;
  78. }
  79. /**
  80. * 导出成excel
  81. *
  82. * @return mixed
  83. */
  84. public function out_api()
  85. {
  86. $id = Dever::input('id');
  87. $journal = Dever::db('journal/info')->one($id);
  88. if (!$journal) {
  89. return;
  90. }
  91. $score = $this->getList($id);
  92. $header = $data = array();
  93. $name = $journal['name'];
  94. if ($score) {
  95. $i = 0;
  96. foreach ($score as $k => $v) {
  97. $data[$i] = array
  98. (
  99. $i+1,
  100. $v['username'],
  101. $v['mobile'],
  102. $v['score'],
  103. );
  104. $i++;
  105. }
  106. }
  107. $header = array
  108. (
  109. '排序', '用户名', '手机号', '积分'
  110. );
  111. $file = $name . '_邀请积分排行榜';
  112. if (Dever::input('test')) {
  113. print_r($header);
  114. print_r($data);die;
  115. }
  116. Dever::excelExport($data, $header, $file, $sheet = 0, $sheetName = $name);
  117. return;
  118. }
  119. }