Score.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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)
  22. {
  23. $where['type'] = $type;
  24. $where['data_id'] = $id;
  25. $data = Dever::db('act/score')->getAll($where);
  26. if ($data) {
  27. foreach ($data as $k => $v) {
  28. $user = Dever::load('passport/api')->info($v['uid']);
  29. $data[$k]['username'] = $user['username'];
  30. $data[$k]['avatar'] = $user['avatar'];
  31. }
  32. }
  33. return $data;
  34. }
  35. public function submit()
  36. {
  37. $user_log_id = Dever::input('user_log_id');
  38. $type = Dever::input('type', 4);
  39. $id = Dever::input('id');
  40. $method = Dever::input('method');
  41. $user_log = Dever::db('score/user_log')->one($user_log_id);
  42. if ($user_log) {
  43. if ($method == 'share' || $method == 'pay' || $method == 'code') {
  44. # 活动结束后,无法增加当前小刊积分
  45. if ($type == 4) {
  46. $journal = Dever::db('journal/active')->one(array('info_id' => $id, 'state' => 1));
  47. if (!$journal) {
  48. return;
  49. }
  50. if ($journal && $journal['status'] == 2) {
  51. return;
  52. }
  53. if ($journal && time() > $journal['end']) {
  54. return;
  55. }
  56. }
  57. }
  58. //$where['user_log_id'] = $user_log_id;
  59. $where['uid'] = $user_log['uid'];
  60. $where['data_id'] = $id;
  61. $where['type'] = $type;
  62. $table = 'act/score';
  63. $info = Dever::db($table)->one($where);
  64. if (!$info) {
  65. $where['score'] = $user_log['num'];
  66. Dever::db($table)->insert($where);
  67. } else {
  68. $where['where_id'] = $info['id'];
  69. $where['score'] = $info['score'] + $user_log['num'];
  70. Dever::db($table)->update($where);
  71. }
  72. }
  73. return true;
  74. }
  75. }