function_credit.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_credit.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function _checklowerlimit($action, $uid = 0, $coef = 1, $fid = 0, $returnonly = 0) {
  12. global $_G;
  13. include_once libfile('class/credit');
  14. $credit = & credit::instance();
  15. $limit = $credit->lowerlimit($action, $uid, $coef, $fid);
  16. if($returnonly) return $limit;
  17. if($limit !== true) {
  18. $GLOBALS['id'] = $limit;
  19. $lowerlimit = is_array($action) && $action['extcredits'.$limit] ? abs($action['extcredits'.$limit]) + $_G['setting']['creditspolicy']['lowerlimit'][$limit] : $_G['setting']['creditspolicy']['lowerlimit'][$limit];
  20. $rulecredit = array();
  21. if(!is_array($action)) {
  22. $rule = $credit->getrule($action, $fid);
  23. foreach($_G['setting']['extcredits'] as $extcreditid => $extcredit) {
  24. if($rule['extcredits'.$extcreditid]) {
  25. $rulecredit[] = $extcredit['title'].($rule['extcredits'.$extcreditid] > 0 ? '+'.$rule['extcredits'.$extcreditid] : $rule['extcredits'.$extcreditid]);
  26. }
  27. }
  28. } else {
  29. $rule = array();
  30. }
  31. $values = array(
  32. 'title' => $_G['setting']['extcredits'][$limit]['title'],
  33. 'lowerlimit' => $lowerlimit,
  34. 'unit' => $_G['setting']['extcredits'][$limit]['unit'],
  35. 'ruletext' => $rule['rulename'],
  36. 'rulecredit' => implode(', ', $rulecredit)
  37. );
  38. if(!is_array($action)) {
  39. if(!$fid) {
  40. showmessage('credits_policy_lowerlimit', '', $values);
  41. } else {
  42. showmessage('credits_policy_lowerlimit_fid', '', $values);
  43. }
  44. } else {
  45. showmessage('credits_policy_lowerlimit_norule', '', $values);
  46. }
  47. }
  48. }
  49. function _updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '', $customtitle = '', $custommemo = '') {
  50. if(empty($uids)) return;
  51. if(!is_array($dataarr) || empty($dataarr)) return;
  52. if($operation && $relatedid || $customtitle) {
  53. $writelog = true;
  54. } else {
  55. $writelog = false;
  56. }
  57. $data = $log = array();
  58. foreach($dataarr as $key => $val) {
  59. if(empty($val)) continue;
  60. $val = intval($val);
  61. $id = intval($key);
  62. $id = !$id && substr($key, 0, -1) == 'extcredits' ? intval(substr($key, -1, 1)) : $id;
  63. if(0 < $id && $id < 9) {
  64. $data['extcredits'.$id] = $val;
  65. if($writelog) {
  66. $log['extcredits'.$id] = $val;
  67. }
  68. } else {
  69. $data[$key] = $val;
  70. }
  71. }
  72. if($writelog) {
  73. credit_log($uids, $operation, $relatedid, $log, $customtitle, $custommemo);
  74. }
  75. if($data) {
  76. include_once libfile('class/credit');
  77. $credit = & credit::instance();
  78. $credit->updatemembercount($data, $uids, $checkgroup, $ruletxt);
  79. }
  80. }
  81. function credit_log($uids, $operation, $relatedid, $data, $customtitle = '', $custommemo = '') {
  82. if((!$operation || empty($relatedid)) && !strlen($customtitle) || empty($uids) || empty($data)) {
  83. return;
  84. }
  85. $log = array(
  86. 'uid' => $uids,
  87. 'operation' => $operation,
  88. 'relatedid' => $relatedid,
  89. 'dateline' => TIMESTAMP,
  90. );
  91. foreach($data as $k => $v) {
  92. $log[$k] = $v;
  93. }
  94. if(is_array($uids)) {
  95. foreach($uids as $k => $uid) {
  96. $log['uid'] = $uid;
  97. $log['relatedid'] = is_array($relatedid) ? $relatedid[$k] : $relatedid;
  98. $insertid = C::t('common_credit_log')->insert($log, true);
  99. C::t('common_credit_log_field')->insert(array('logid' => $insertid, 'title' => $customtitle, 'text' => $custommemo));
  100. }
  101. } else {
  102. $insertid = C::t('common_credit_log')->insert($log, true);
  103. C::t('common_credit_log_field')->insert(array('logid' => $insertid, 'title' => $customtitle, 'text' => $custommemo));
  104. }
  105. }
  106. ?>