function_ec_credit.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_ec_credit.php 26205 2011-12-05 10:09:32Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function updatecreditcache($uid, $type, $return = 0) {
  12. $all = countcredit($uid, $type);
  13. $halfyear = countcredit($uid, $type, 180);
  14. $thismonth = countcredit($uid, $type, 30);
  15. $thisweek = countcredit($uid, $type, 7);
  16. $before = array(
  17. 'good' => $all['good'] - $halfyear['good'],
  18. 'soso' => $all['soso'] - $halfyear['soso'],
  19. 'bad' => $all['bad'] - $halfyear['bad'],
  20. 'total' => $all['total'] - $halfyear['total']
  21. );
  22. $data = array('all' => $all, 'before' => $before, 'halfyear' => $halfyear, 'thismonth' => $thismonth, 'thisweek' => $thisweek);
  23. C::t('forum_spacecache')->insert(array(
  24. 'uid' => $uid,
  25. 'variable' => $type,
  26. 'value' => serialize($data),
  27. 'expiration' => getexpiration(),
  28. ), false, true);
  29. if($return) {
  30. return $data;
  31. }
  32. }
  33. function countcredit($uid, $type, $days = 0) {
  34. $type = $type == 'buyercredit' ? 1 : 0;
  35. $good = $soso = $bad = 0;
  36. foreach(C::t('forum_tradecomment')->fetch_all_by_rateeid($uid, $type, $days ? TIMESTAMP - $days * 86400 : 0) as $credit) {
  37. if($credit['score'] == 1) {
  38. $good++;
  39. } elseif($credit['score'] == 0) {
  40. $soso++;
  41. } else {
  42. $bad++;
  43. }
  44. }
  45. return array('good' => $good, 'soso' => $soso, 'bad' => $bad, 'total' => $good + $soso + $bad);
  46. }
  47. function updateusercredit($uid, $type, $level) {
  48. $uid = intval($uid);
  49. if(!$uid || !in_array($type, array('buyercredit', 'sellercredit')) || !in_array($level, array('good', 'soso', 'bad'))) {
  50. return;
  51. }
  52. if($cache = C::t('forum_spacecache')->fetch($uid, $type)) {
  53. $expiration = $cache['expiration'];
  54. $cache = dunserialize($cache['value']);
  55. } else {
  56. $init = array('good' => 0, 'soso' => 0, 'bad' => 0, 'total' => 0);
  57. $cache = array('all' => $init, 'before' => $init, 'halfyear' => $init, 'thismonth' => $init, 'thisweek' => $init);
  58. $expiration = getexpiration();
  59. }
  60. foreach(array('all', 'before', 'halfyear', 'thismonth', 'thisweek') as $key) {
  61. $cache[$key][$level]++;
  62. $cache[$key]['total']++;
  63. }
  64. C::t('forum_spacecache')->insert(array(
  65. 'uid' => $uid,
  66. 'variable' => $type,
  67. 'value' => serialize($cache),
  68. 'expiration' => $expiration,
  69. ), false, true);
  70. $score = $level == 'good' ? 1 : ($level == 'soso' ? 0 : -1);
  71. C::t('common_member_status')->increase($uid, array($type=>$score));
  72. }
  73. ?>