spacecp_credit_base.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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: spacecp_credit_base.php 33663 2013-07-30 05:06:43Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(empty($_GET['op'])) $_GET['op'] = 'base';
  12. if(in_array($_GET['op'], array('transfer', 'exchange'))) {
  13. $taxpercent = sprintf('%1.2f', $_G['setting']['creditstax'] * 100).'%';
  14. }
  15. if($_GET['op'] == 'base') {
  16. $loglist = $extcredits_exchange = array();
  17. if(!empty($_G['setting']['extcredits'])) {
  18. foreach($_G['setting']['extcredits'] as $key => $value) {
  19. if($value['allowexchangein'] || $value['allowexchangeout']) {
  20. $extcredits_exchange['extcredits'.$key] = array('title' => $value['title'], 'unit' => $value['unit']);
  21. }
  22. }
  23. }
  24. $count = C::t('common_credit_log')->count_by_uid($_G['uid']);
  25. if($count) {
  26. loadcache(array('magics'));
  27. foreach(C::t('common_credit_log')->fetch_all_by_uid($_G['uid'], 0, 10) as $log) {
  28. $credits = array();
  29. $havecredit = false;
  30. $maxid = $minid = 0;
  31. foreach($_G['setting']['extcredits'] as $id => $credit) {
  32. if($log['extcredits'.$id]) {
  33. $havecredit = true;
  34. if($log['operation'] == 'RPZ') {
  35. $credits[] = $credit['title'].lang('spacecp', 'credit_update_reward_clean');
  36. } else {
  37. $credits[] = $credit['title'].' <span class="'.($log['extcredits'.$id] > 0 ? 'xi1' : 'xg1').'">'.($log['extcredits'.$id] > 0 ? '+' : '').$log['extcredits'.$id].'</span>';
  38. }
  39. if($log['operation'] == 'CEC' && !empty($log['extcredits'.$id])) {
  40. if($log['extcredits'.$id] > 0) {
  41. $log['maxid'] = $id;
  42. } elseif($log['extcredits'.$id] < 0) {
  43. $log['minid'] = $id;
  44. }
  45. }
  46. }
  47. }
  48. if(!$havecredit) {
  49. continue;
  50. }
  51. $log['credit'] = implode('<br/>', $credits);
  52. if(in_array($log['operation'], array('RTC', 'RAC', 'STC', 'BTC', 'ACC', 'RCT', 'RCA', 'RCB'))) {
  53. $tids[$log['relatedid']] = $log['relatedid'];
  54. } elseif(in_array($log['operation'], array('SAC', 'BAC'))) {
  55. $aids[$log['relatedid']] = $log['relatedid'];
  56. } elseif(in_array($log['operation'], array('PRC', 'RSC'))) {
  57. $pids[$log['relatedid']] = $log['relatedid'];
  58. } elseif(in_array($log['operation'], array('TFR', 'RCV'))) {
  59. $uids[$log['relatedid']] = $log['relatedid'];
  60. } elseif($log['operation'] == 'TRC') {
  61. $taskids[$log['relatedid']] = $log['relatedid'];
  62. }
  63. $loglist[] = $log;
  64. }
  65. $otherinfo = getotherinfo($aids, $pids, $tids, $taskids, $uids);
  66. }
  67. $navtitle = lang('core', 'title_credit');
  68. $creditsformulaexp = str_replace('*', 'X', $_G['setting']['creditsformulaexp']);
  69. } elseif ($_GET['op'] == 'buy') {
  70. if((!$_G['setting']['ec_ratio'] || (!$_G['setting']['ec_tenpay_opentrans_chnid'] && !$_G['setting']['ec_tenpay_bargainor'] && !$_G['setting']['ec_account'])) && !$_G['setting']['card']['open'] ) {
  71. showmessage('action_closed', NULL);
  72. }
  73. if(submitcheck('addfundssubmit')) {
  74. if(!isset($_GET['bank_type'])) {
  75. showmessage('memcp_credits_addfunds_msg_notype', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  76. }
  77. $apitype = is_numeric($_GET['bank_type']) ? 'tenpay' : $_GET['bank_type'];
  78. if($apitype == 'card') {
  79. list($seccodecheck) = seccheck('card');
  80. if($seccodecheck) {
  81. if(!check_seccode($_GET['seccodeverify'], $_GET['seccodehash'])) {
  82. showmessage('submit_seccode_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  83. }
  84. }
  85. if(!$_POST['cardid']) {
  86. showmessage('memcp_credits_card_msg_cardid_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  87. }
  88. if(!($card = C::t('common_card')->fetch($_POST['cardid']))) {
  89. showmessage('memcp_credits_card_msg_card_unfined', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true, 'extrajs' => '<script type="text/javascript">updateseccode("'.$_GET['sechash'].'");</script>'));
  90. } else {
  91. if($card['status'] == 2) {
  92. showmessage('memcp_credits_card_msg_used', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  93. }
  94. if($card['cleardateline'] < TIMESTAMP) {
  95. showmessage('memcp_credits_card_msg_cleardateline_early', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  96. }
  97. C::t('common_card')->update($card['id'], array('status' => 2, 'uid' => $_G['uid'], 'useddateline' => $_G['timestamp']));
  98. updatemembercount($_G[uid], array($card['extcreditskey'] => $card['extcreditsval']), true, 'CDC', 1);
  99. showmessage('memcp_credits_card_msg_succeed', 'home.php?mod=spacecp&ac=credit&op=base', array('extcreditstitle' => $_G['setting']['extcredits'][$card['extcreditskey']]['title'], 'extcreditsval' => $card['extcreditsval']), array('showdialog' => 1, 'alert' => 'right', 'showmsg' => true, 'locationtime' => true));
  100. }
  101. } else {
  102. $amount = intval($_GET['addfundamount']);
  103. if(!$amount) {
  104. showmessage('memcp_credits_addfunds_msg_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  105. }
  106. $language = lang('forum/misc');
  107. if(($_G['setting']['ec_mincredits'] && $amount < $_G['setting']['ec_mincredits']) || ($_G['setting']['ec_maxcredits'] && $amount > $_G['setting']['ec_maxcredits'])) {
  108. showmessage('credits_addfunds_amount_invalid', '', array('ec_maxcredits' => $_G['setting']['ec_maxcredits'], 'ec_mincredits' => $_G['setting']['ec_mincredits']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  109. }
  110. if($apitype == 'card' && C::t('forum_order')->count_by_search($_G['uid'], null, null, null, null, null, null, $_G['timestamp'] - 180)) {
  111. showmessage('credits_addfunds_ctrl', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  112. }
  113. if($_G['setting']['ec_maxcreditspermonth']) {
  114. if(C::t('forum_order')->sum_amount_by_uid_submitdate_status($_G['uid'], $_G['timestamp'] - 2592000, array(2, 3)) + $amount > $_G['setting']['ec_maxcreditspermonth']) {
  115. showmessage('credits_addfunds_toomuch', '', array('ec_maxcreditspermonth' => $_G['setting']['ec_maxcreditspermonth']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  116. }
  117. }
  118. $price = round(($amount / $_G['setting']['ec_ratio'] * 100) / 100, 2);
  119. $orderid = '';
  120. require_once libfile('function/trade');
  121. $requesturl = credit_payurl($price, $orderid, $_GET['bank_type']);
  122. if(C::t('forum_order')->fetch($orderid)) {
  123. showmessage('credits_addfunds_order_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  124. }
  125. C::t('forum_order')->insert(array(
  126. 'orderid' => $orderid,
  127. 'status' => '1',
  128. 'uid' => $_G['uid'],
  129. 'amount' => $amount,
  130. 'price' => $price,
  131. 'submitdate' => $_G['timestamp'],
  132. ));
  133. include template('common/header_ajax');
  134. echo '<form id="payform" action="'.$requesturl.'" method="post"></form><script type="text/javascript" reload="1">$(\'payform\').submit();</script>';
  135. include template('common/footer_ajax');
  136. dexit();
  137. }
  138. } else {
  139. if($_G['setting']['card']['open'] && $_G['setting']['seccodestatus'] & 16) {
  140. $seccodecheck = 1;
  141. $secqaacheck = 0;
  142. }
  143. }
  144. } elseif ($_GET['op'] == 'transfer') {
  145. if(!($_G['setting']['transferstatus'] && $_G['group']['allowtransfer'])) {
  146. showmessage('action_closed', NULL);
  147. }
  148. if(submitcheck('transfersubmit')) {
  149. if($_GET['to'] == $_G['username']) {
  150. showmessage('memcp_credits_transfer_msg_self_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  151. }
  152. $amount = intval($_GET['transferamount']);
  153. if($amount <= 0) {
  154. showmessage('credits_transaction_amount_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  155. } elseif(getuserprofile('extcredits'.$_G['setting']['creditstransextra'][9]) - $amount < ($minbalance = $_G['setting']['transfermincredits'])) {
  156. showmessage('credits_transfer_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][9]]['title'], 'minbalance' => $minbalance), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  157. } elseif(!($netamount = floor($amount * (1 - $_G['setting']['creditstax'])))) {
  158. showmessage('credits_net_amount_iszero', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  159. }
  160. $to = C::t('common_member')->fetch_by_username($_GET['to']);
  161. if(!$to) {
  162. showmessage('memcp_credits_transfer_msg_user_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  163. }
  164. loaducenter();
  165. $ucresult = uc_user_login(addslashes($_G['username']), $_GET['password']);
  166. list($tmp['uid']) = $ucresult;
  167. if($tmp['uid'] <= 0) {
  168. showmessage('credits_password_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  169. }
  170. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][9] => -$amount), 1, 'TFR', $to['uid']);
  171. updatemembercount($to['uid'], array($_G['setting']['creditstransextra'][9] => $netamount), 1, 'RCV', $_G['uid']);
  172. if(!empty($_GET['transfermessage'])) {
  173. $transfermessage = dhtmlspecialchars($_GET['transfermessage']);
  174. notification_add($to['uid'], 'credit', 'transfer', array('credit' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][9]]['title'].' '.$netamount.' '.$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][9]]['unit'], 'transfermessage' => $transfermessage));
  175. }
  176. showmessage('credits_transfer_succeed', 'home.php?mod=spacecp&ac=credit&op=transfer', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  177. }
  178. } elseif ($_GET['op'] == 'exchange') {
  179. if(!$_G['setting']['exchangestatus']) {
  180. showmessage('action_closed', NULL);
  181. }
  182. $_CACHE['creditsettings'] = array();
  183. if(file_exists(DISCUZ_ROOT.'/uc_client/data/cache/creditsettings.php')) {
  184. include_once(DISCUZ_ROOT.'/uc_client/data/cache/creditsettings.php');
  185. }
  186. if(submitcheck('exchangesubmit')) {
  187. $tocredits = $_GET['tocredits'];
  188. $fromcredits = $_GET['fromcredits'];
  189. $exchangeamount = $_GET['exchangeamount'];
  190. $outexange = strexists($tocredits, '|');
  191. if($outexange && !empty($_GET['outi'])) {
  192. $fromcredits = $_GET['fromcredits_'.$_GET['outi']];
  193. }
  194. if($fromcredits == $tocredits) {
  195. showmessage('memcp_credits_exchange_msg_num_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  196. }
  197. if($outexange) {
  198. $netamount = floor($exchangeamount * $_CACHE['creditsettings'][$tocredits]['ratiosrc'][$fromcredits] / $_CACHE['creditsettings'][$tocredits]['ratiodesc'][$fromcredits]);
  199. } else {
  200. if($_G['setting']['extcredits'][$tocredits]['ratio'] < $_G['setting']['extcredits'][$fromcredits]['ratio']) {
  201. $netamount = ceil($exchangeamount * $_G['setting']['extcredits'][$tocredits]['ratio'] / $_G['setting']['extcredits'][$fromcredits]['ratio'] * (1 + $_G['setting']['creditstax']));
  202. } else {
  203. $netamount = floor($exchangeamount * $_G['setting']['extcredits'][$tocredits]['ratio'] / $_G['setting']['extcredits'][$fromcredits]['ratio'] * (1 + $_G['setting']['creditstax']));
  204. }
  205. }
  206. if(!$outexange && !$_G['setting']['extcredits'][$tocredits]['ratio']) {
  207. showmessage('credits_exchange_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  208. }
  209. if(!$outexange && !$_G['setting']['extcredits'][$fromcredits]['allowexchangeout']) {
  210. showmessage('extcredits_disallowexchangeout', '', array('credittitle' => $_G['setting']['extcredits'][$fromcredits]['title']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  211. }
  212. if(!$outexange && !$_G['setting']['extcredits'][$tocredits]['allowexchangein']) {
  213. showmessage('extcredits_disallowexchangein', '', array('credittitle' => $_G['setting']['extcredits'][$tocredits]['title']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  214. }
  215. if(!$netamount) {
  216. showmessage('memcp_credits_exchange_msg_balance_insufficient', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  217. } elseif($exchangeamount <= 0) {
  218. showmessage('credits_transaction_amount_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  219. } elseif(getuserprofile('extcredits'.$fromcredits) - $netamount < ($minbalance = $_G['setting']['exchangemincredits'])) {
  220. showmessage('credits_exchange_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$fromcredits]['title'], 'minbalance' => $minbalance), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  221. }
  222. loaducenter();
  223. $ucresult = uc_user_login(addslashes($_G['username']), $_GET['password']);
  224. list($tmp['uid']) = $ucresult;
  225. if($tmp['uid'] <= 0) {
  226. showmessage('credits_password_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  227. }
  228. if(!$outexange) {
  229. updatemembercount($_G['uid'], array($fromcredits => -$netamount, $tocredits => $exchangeamount), 1, 'CEC', $_G['uid']);
  230. } else {
  231. if(!array_key_exists($fromcredits, $_CACHE['creditsettings'][$tocredits]['creditsrc'])) {
  232. showmessage('extcredits_dataerror', NULL);
  233. }
  234. list($toappid, $tocredits) = explode('|', $tocredits);
  235. $ucresult = uc_credit_exchange_request($_G['uid'], $fromcredits, $tocredits, $toappid, $exchangeamount);
  236. if(!$ucresult) {
  237. showmessage('extcredits_dataerror', NULL);
  238. }
  239. updatemembercount($_G['uid'], array($fromcredits => -$netamount), 1, 'ECU', $_G['uid']);
  240. $netamount = $amount;
  241. $amount = $tocredits = 0;
  242. }
  243. showmessage('credits_transaction_succeed', 'home.php?mod=spacecp&ac=credit&op=exchange', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  244. }
  245. } else {
  246. $wheresql = '';
  247. $list = array();
  248. $rid = intval($_GET['rid']);
  249. if($_GET['rid']) {
  250. $wheresql = " AND rid='$rid'";
  251. }
  252. require_once libfile('function/forumlist');
  253. $select = forumselect(false, 0, $_GET['fid']);
  254. $keys = array_keys($_G['setting']['extcredits']);
  255. foreach(C::t('common_credit_rule')->fetch_all_by_rid($rid) as $value) {
  256. if(!helper_access::check_module('doing') && $value['action'] == 'doing') {
  257. continue;
  258. } elseif(!helper_access::check_module('blog') && $value['action'] == 'publishblog') {
  259. continue;
  260. } elseif(!helper_access::check_module('wall') && in_array($value['action'], array('guestbook', 'getguestbook'))) {
  261. continue;
  262. }
  263. if(empty($_GET['fid']) || in_array($value['action'], array('digest', 'post', 'reply', 'getattach', 'postattach'))) {
  264. if(checkvalue($value, $keys)) {
  265. $list[$value['action']] = $value;
  266. }
  267. }
  268. }
  269. if(!empty($_GET['fid'])) {
  270. $_GET['fid'] = intval($_GET['fid']);
  271. $foruminfo = C::t('forum_forumfield')->fetch($_GET['fid']);
  272. $flist = dunserialize($foruminfo['creditspolicy']);
  273. foreach($flist as $action => $value) {
  274. $list[$value['action']] = $value;
  275. }
  276. }
  277. }
  278. include_once template("home/spacecp_credit_base");
  279. function checkvalue($value, $creditids) {
  280. $havevalue = false;
  281. foreach($creditids as $key) {
  282. if($value['extcredits'.$key]) {
  283. $havevalue = true;
  284. break;
  285. }
  286. }
  287. return $havevalue;
  288. }
  289. ?>