国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
5.9KB

  1. <?php
  2. /**
  3. * @version $id:buy_action.php 8:38 2023年02月13日 tianya $
  4. * @package DedeBIZ.User
  5. * @copyright Copyright (c) 2022 DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. require_once(dirname(__FILE__)."/config.php");
  10. CheckRank(0, 0);
  11. $menutype = 'mydede';
  12. $menutype_son = 'op';
  13. require_once DEDEINC.'/dedetemplate.class.php';
  14. $product = isset($product) ? trim(HtmlReplace($product, 1)) : '';
  15. $mid = $cfg_ml->M_ID;
  16. $ptype = '';
  17. $pname = '';
  18. $price = '';
  19. $mtime = time();
  20. $paytype = isset($paytype)? intval($paytype) : 0;
  21. if (isset($pd_encode) && isset($pd_verify) && md5("payment".$pd_encode.$cfg_cookie_encode) == $pd_verify) {
  22. $result = json_decode(mchStrCode($pd_encode, 'DECODE'));
  23. $product = preg_replace("#[^0-9a-z]#i", "", $result->product);
  24. $pid = preg_replace("#[^0-9a-z]#i", "", $result->pid);
  25. $row = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  26. if (!isset($row['buyid'])) {
  27. ShowMsg("请不要重复提交表单", 'javascript:;');
  28. exit();
  29. }
  30. if ($paytype === 0) {
  31. ShowMsg("请选择支付方式", 'javascript:;');
  32. exit();
  33. }
  34. $buyid = $row['buyid'];
  35. } else {
  36. $buyid = 'M'.$mid.'T'.$mtime.'RN'.mt_rand(100, 999);
  37. //删除用户旧的未付款的同类记录
  38. if (!empty($product)) {
  39. $dsql->ExecuteNoneQuery("DELETE FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  40. }
  41. }
  42. if (empty($product)) {
  43. ShowMsg("请选择一个产品", 'javascript:;');
  44. exit();
  45. }
  46. $pid = isset($pid) && is_numeric($pid) ? $pid : 0;
  47. if ($product == 'member') {
  48. $ptype = "会员升级";
  49. $row = $dsql->GetOne("SELECT * FROM `#@__member_type` WHERE aid='{$pid}'");
  50. if (!is_array($row)) {
  51. ShowMsg("无法识别您的订单", 'javascript:;');
  52. exit();
  53. }
  54. $pname = $row['pname'];
  55. $price = $row['money'];
  56. } else if ($product == 'card') {
  57. $ptype = "积分购买";
  58. $row = $dsql->GetOne("SELECT * FROM `#@__moneycard_type` WHERE tid='{$pid}'");
  59. if (!is_array($row)) {
  60. ShowMsg("无法识别您的订单", 'javascript:;');
  61. exit();
  62. }
  63. $pname = $row['pname'];
  64. $price = $row['money'];
  65. }
  66. if ($paytype === 0) {
  67. $inquery = "INSERT INTO `#@__member_operation` (`buyid`,`pname`,`product`,`money`,`mtime`,`pid`,`mid`,`sta`,`oldinfo`) VALUES ('$buyid','$pname','$product','$price','$mtime','$pid','$mid','0','$ptype');";
  68. $isok = $dsql->ExecuteNoneQuery($inquery);
  69. if (!$isok) {
  70. echo "数据库出错,请重新尝试".$dsql->GetError();
  71. exit();
  72. }
  73. if ($price == '') {
  74. echo "无法识别您的订单";
  75. exit();
  76. }
  77. //获取支付接口设置
  78. $payment_list = array();
  79. $dsql->SetQuery("SELECT * FROM `#@__sys_payment` WHERE `status`=1 ORDER BY sortrank ASC");
  80. $dsql->Execute();
  81. $i = 0;
  82. while ($row = $dsql->GetArray()) {
  83. $payment_list[] = $row;
  84. $i++;
  85. }
  86. $pr_encode = array();
  87. foreach ($_REQUEST as $key => $val) {
  88. if (!in_array($key, array('product', 'pid'))) {
  89. continue;
  90. }
  91. $val = preg_replace("#[^0-9a-z]#i", "", $val);
  92. $pr_encode[$key] = $val;
  93. }
  94. $pr_encode = str_replace('=', '', mchStrCode(json_encode($pr_encode)));
  95. $pr_verify = md5("payment".$pr_encode.$cfg_cookie_encode);
  96. $tpl = new DedeTemplate();
  97. $tpl->LoadTemplate(DEDEMEMBER.'/templets/buy_action_payment.htm');
  98. $tpl->Display();
  99. } else {
  100. $moRow = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE buyid='$buyid'");
  101. if ($moRow['sta'] == 2) {
  102. ShowMsg("已完成支付,无需重复付款", "javascript:;");
  103. exit;
  104. }
  105. if($paytype === 4) {
  106. if ($cfg_ml->M_UserMoney < $row['money']) {
  107. ShowMsg("余额不足,请确保当前账户有足够金币支付", "javascript:;");
  108. exit;
  109. }
  110. $query = "UPDATE `#@__member_operation` SET sta = '2' WHERE buyid = '$buyid'";
  111. $dsql->ExecuteNoneQuery($query);
  112. $query = "UPDATE `#@__member` SET money = money+{$row['num']} WHERE mid = '$mid'";
  113. $dsql->ExecuteNoneQuery($query);
  114. $query = "UPDATE `#@__member` SET user_money = user_money-{$row['money']} WHERE mid = '$mid'";
  115. $dsql->ExecuteNoneQuery($query);
  116. ShowMsg("成功使用余额付款", "javascript:;");
  117. exit;
  118. }
  119. }
  120. /**
  121. * 加密函数
  122. *
  123. * @access public
  124. * @param string $string 字符串
  125. * @param string $operation 操作
  126. * @return string
  127. */
  128. function mchStrCode($string, $operation = 'ENCODE')
  129. {
  130. $key_length = 4;
  131. $expiry = 0;
  132. $key = md5($GLOBALS['cfg_cookie_encode']);
  133. $fixedkey = md5($key);
  134. $egiskeys = md5(substr($fixedkey, 16, 16));
  135. $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  136. $keys = md5(substr($runtokey, 0, 16).substr($fixedkey, 0, 16).substr($runtokey, 16).substr($fixedkey, 16));
  137. $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16).$string : base64_decode(substr($string, $key_length));
  138. $i = 0;
  139. $result = '';
  140. $string_length = strlen($string);
  141. for ($i = 0; $i < $string_length; $i++) {
  142. $result .= chr(ord($string[$i]) ^ ord($keys[$i % 32]));
  143. }
  144. if ($operation == 'ENCODE') {
  145. return $runtokey.str_replace('=', '', base64_encode($result));
  146. } else {
  147. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
  148. return substr($result, 26);
  149. } else {
  150. return '';
  151. }
  152. }
  153. }
  154. ?>