PageRenderTime 136ms CodeModel.GetById 40ms RepoModel.GetById 6ms app.codeStats 0ms

/source/include/spacecp/spacecp_credit_base.php

https://github.com/jinbo51/DiscuzX
PHP | 323 lines | 282 code | 35 blank | 6 comment | 100 complexity | bea49e40b802436198fb3cd0313b6ebf MD5 | raw file
Possible License(s): BSD-3-Clause
  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 32266 2012-12-12 02:49:54Z monkey $
  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. if($_G['setting']['seccodestatus'] & 16) {
  80. if(!check_seccode($_GET['seccodeverify'], $_GET['sechash'])) {
  81. showmessage('submit_seccode_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  82. }
  83. }
  84. if(!$_POST['cardid']) {
  85. showmessage('memcp_credits_card_msg_cardid_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  86. }
  87. if(!($card = C::t('common_card')->fetch($_POST['cardid']))) {
  88. showmessage('memcp_credits_card_msg_card_unfined', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true, 'extrajs' => '<script type="text/javascript">updateseccode("'.$_GET['sechash'].'");</script>'));
  89. } else {
  90. if($card['status'] == 2) {
  91. showmessage('memcp_credits_card_msg_used', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  92. }
  93. if($card['cleardateline'] < TIMESTAMP) {
  94. showmessage('memcp_credits_card_msg_cleardateline_early', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  95. }
  96. C::t('common_card')->update($card['id'], array('status' => 2, 'uid' => $_G['uid'], 'useddateline' => $_G['timestamp']));
  97. updatemembercount($_G[uid], array($card['extcreditskey'] => $card['extcreditsval']), true, 'CDC', 1);
  98. 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));
  99. }
  100. } else {
  101. $amount = intval($_GET['addfundamount']);
  102. if(!$amount) {
  103. showmessage('memcp_credits_addfunds_msg_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  104. }
  105. $language = lang('forum/misc');
  106. if(($_G['setting']['ec_mincredits'] && $amount < $_G['setting']['ec_mincredits']) || ($_G['setting']['ec_maxcredits'] && $amount > $_G['setting']['ec_maxcredits'])) {
  107. 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));
  108. }
  109. if($apitype == 'card' && C::t('forum_order')->count_by_search($_G['uid'], null, null, null, null, null, null, $_G['timestamp'] - 180)) {
  110. showmessage('credits_addfunds_ctrl', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  111. }
  112. if($_G['setting']['ec_maxcreditspermonth']) {
  113. if(C::t('forum_order')->sum_amount_by_uid_submitdate_status($_G['uid'], $_G['timestamp'] - 2592000, array(2, 3)) + $amount > $_G['setting']['ec_maxcreditspermonth']) {
  114. showmessage('credits_addfunds_toomuch', '', array('ec_maxcreditspermonth' => $_G['setting']['ec_maxcreditspermonth']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  115. }
  116. }
  117. $price = round(($amount / $_G['setting']['ec_ratio'] * 100) / 100, 2);
  118. $orderid = '';
  119. require_once libfile('function/trade');
  120. $requesturl = credit_payurl($price, $orderid, $_GET['bank_type']);
  121. if(C::t('forum_order')->fetch($orderid)) {
  122. showmessage('credits_addfunds_order_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  123. }
  124. C::t('forum_order')->insert(array(
  125. 'orderid' => $orderid,
  126. 'status' => '1',
  127. 'uid' => $_G['uid'],
  128. 'amount' => $amount,
  129. 'price' => $price,
  130. 'submitdate' => $_G['timestamp'],
  131. ));
  132. include template('common/header_ajax');
  133. echo '<form id="payform" action="'.$requesturl.'" method="post"></form><script type="text/javascript" reload="1">$(\'payform\').submit();</script>';
  134. include template('common/footer_ajax');
  135. dexit();
  136. }
  137. } else {
  138. if($_G['setting']['card']['open'] && $_G['setting']['seccodestatus'] & 16) {
  139. $seccodecheck = 1;
  140. $secqaacheck = 0;
  141. }
  142. }
  143. } elseif ($_GET['op'] == 'transfer') {
  144. if(!($_G['setting']['transferstatus'] && $_G['group']['allowtransfer'])) {
  145. showmessage('action_closed', NULL);
  146. }
  147. if(submitcheck('transfersubmit')) {
  148. if($_GET['to'] == $_G['username']) {
  149. showmessage('memcp_credits_transfer_msg_self_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  150. }
  151. $amount = intval($_GET['transferamount']);
  152. if($amount <= 0) {
  153. showmessage('credits_transaction_amount_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  154. } elseif(getuserprofile('extcredits'.$_G['setting']['creditstransextra'][9]) - $amount < ($minbalance = $_G['setting']['transfermincredits'])) {
  155. showmessage('credits_transfer_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][9]]['title'], 'minbalance' => $minbalance), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  156. } elseif(!($netamount = floor($amount * (1 - $_G['setting']['creditstax'])))) {
  157. showmessage('credits_net_amount_iszero', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  158. }
  159. $to = C::t('common_member')->fetch_by_username($_GET['to']);
  160. if(!$to) {
  161. showmessage('memcp_credits_transfer_msg_user_incorrect', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  162. }
  163. loaducenter();
  164. $ucresult = uc_user_login(addslashes($_G['username']), $_GET['password']);
  165. list($tmp['uid']) = $ucresult;
  166. if($tmp['uid'] <= 0) {
  167. showmessage('credits_password_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  168. }
  169. updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][9] => -$amount), 1, 'TFR', $to['uid']);
  170. updatemembercount($to['uid'], array($_G['setting']['creditstransextra'][9] => $netamount), 1, 'RCV', $_G['uid']);
  171. if(!empty($_GET['transfermessage'])) {
  172. $transfermessage = dhtmlspecialchars($_GET['transfermessage']);
  173. 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));
  174. }
  175. showmessage('credits_transfer_succeed', 'home.php?mod=spacecp&ac=credit&op=transfer', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  176. }
  177. } elseif ($_GET['op'] == 'exchange') {
  178. if(!$_G['setting']['exchangestatus']) {
  179. showmessage('action_closed', NULL);
  180. }
  181. $_CACHE['creditsettings'] = array();
  182. if(file_exists(DISCUZ_ROOT.'/uc_client/data/cache/creditsettings.php')) {
  183. include_once(DISCUZ_ROOT.'/uc_client/data/cache/creditsettings.php');
  184. }
  185. if(submitcheck('exchangesubmit')) {
  186. $tocredits = $_GET['tocredits'];
  187. $fromcredits = $_GET['fromcredits'];
  188. $exchangeamount = $_GET['exchangeamount'];
  189. $outexange = strexists($tocredits, '|');
  190. if($outexange && !empty($_GET['outi'])) {
  191. $fromcredits = $_GET['fromcredits_'.$_GET['outi']];
  192. }
  193. if($fromcredits == $tocredits) {
  194. showmessage('memcp_credits_exchange_msg_num_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  195. }
  196. if($outexange) {
  197. $netamount = floor($exchangeamount * $_CACHE['creditsettings'][$tocredits]['ratiosrc'][$fromcredits] / $_CACHE['creditsettings'][$tocredits]['ratiodesc'][$fromcredits]);
  198. } else {
  199. if($_G['setting']['extcredits'][$tocredits]['ratio'] < $_G['setting']['extcredits'][$fromcredits]['ratio']) {
  200. $netamount = ceil($exchangeamount * $_G['setting']['extcredits'][$tocredits]['ratio'] / $_G['setting']['extcredits'][$fromcredits]['ratio'] * (1 + $_G['setting']['creditstax']));
  201. } else {
  202. $netamount = floor($exchangeamount * $_G['setting']['extcredits'][$tocredits]['ratio'] / $_G['setting']['extcredits'][$fromcredits]['ratio'] * (1 + $_G['setting']['creditstax']));
  203. }
  204. }
  205. if(!$outexange && !$_G['setting']['extcredits'][$tocredits]['ratio']) {
  206. showmessage('credits_exchange_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  207. }
  208. if(!$outexange && !$_G['setting']['extcredits'][$fromcredits]['allowexchangeout']) {
  209. showmessage('extcredits_disallowexchangeout', '', array('credittitle' => $_G['setting']['extcredits'][$fromcredits]['title']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  210. }
  211. if(!$outexange && !$_G['setting']['extcredits'][$tocredits]['allowexchangein']) {
  212. showmessage('extcredits_disallowexchangein', '', array('credittitle' => $_G['setting']['extcredits'][$tocredits]['title']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  213. }
  214. if(!$netamount) {
  215. showmessage('memcp_credits_exchange_msg_balance_insufficient', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  216. } elseif($exchangeamount <= 0) {
  217. showmessage('credits_transaction_amount_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  218. } elseif(getuserprofile('extcredits'.$fromcredits) - $netamount < ($minbalance = $_G['setting']['exchangemincredits'])) {
  219. showmessage('credits_exchange_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$fromcredits]['title'], 'minbalance' => $minbalance), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  220. }
  221. loaducenter();
  222. $ucresult = uc_user_login(addslashes($_G['username']), $_GET['password']);
  223. list($tmp['uid']) = $ucresult;
  224. if($tmp['uid'] <= 0) {
  225. showmessage('credits_password_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
  226. }
  227. if(!$outexange) {
  228. updatemembercount($_G['uid'], array($fromcredits => -$netamount, $tocredits => $exchangeamount), 1, 'CEC', $_G['uid']);
  229. } else {
  230. if(!array_key_exists($fromcredits, $_CACHE['creditsettings'][$tocredits]['creditsrc'])) {
  231. showmessage('extcredits_dataerror', NULL);
  232. }
  233. list($toappid, $tocredits) = explode('|', $tocredits);
  234. $ucresult = uc_credit_exchange_request($_G['uid'], $fromcredits, $tocredits, $toappid, $exchangeamount);
  235. if(!$ucresult) {
  236. showmessage('extcredits_dataerror', NULL);
  237. }
  238. updatemembercount($_G['uid'], array($fromcredits => -$netamount), 1, 'ECU', $_G['uid']);
  239. $netamount = $amount;
  240. $amount = $tocredits = 0;
  241. }
  242. showmessage('credits_transaction_succeed', 'home.php?mod=spacecp&ac=credit&op=exchange', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  243. }
  244. } else {
  245. $wheresql = '';
  246. $list = array();
  247. $rid = intval($_GET['rid']);
  248. if($_GET['rid']) {
  249. $wheresql = " AND rid='$rid'";
  250. }
  251. require_once libfile('function/forumlist');
  252. $select = forumselect(false, 0, $_GET['fid']);
  253. $keys = array_keys($_G['setting']['extcredits']);
  254. foreach(C::t('common_credit_rule')->fetch_all_by_rid($rid) as $value) {
  255. if(!helper_access::check_module('doing') && $value['action'] == 'doing') {
  256. continue;
  257. } elseif(!helper_access::check_module('blog') && $value['action'] == 'publishblog') {
  258. continue;
  259. } elseif(!helper_access::check_module('wall') && in_array($value['action'], array('guestbook', 'getguestbook'))) {
  260. continue;
  261. }
  262. if(empty($_GET['fid']) || in_array($value['action'], array('digest', 'post', 'reply', 'getattach', 'postattach'))) {
  263. if(checkvalue($value, $keys)) {
  264. $list[$value['action']] = $value;
  265. }
  266. }
  267. }
  268. if(!empty($_GET['fid'])) {
  269. $_GET['fid'] = intval($_GET['fid']);
  270. $foruminfo = C::t('forum_forumfield')->fetch($_GET['fid']);
  271. $flist = dunserialize($foruminfo['creditspolicy']);
  272. foreach($flist as $action => $value) {
  273. $list[$value['action']] = $value;
  274. }
  275. }
  276. }
  277. include_once template("home/spacecp_credit_base");
  278. function checkvalue($value, $creditids) {
  279. $havevalue = false;
  280. foreach($creditids as $key) {
  281. if($value['extcredits'.$key]) {
  282. $havevalue = true;
  283. break;
  284. }
  285. }
  286. return $havevalue;
  287. }
  288. ?>