notify_trade.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: notify_trade.php 34251 2013-11-25 03:10:11Z nemohou $
  7. */
  8. define('IN_API', true);
  9. define('CURSCRIPT', 'api');
  10. define('DISABLEXSSCHECK', true);
  11. require '../../source/class/class_core.php';
  12. require '../../source/function/function_forum.php';
  13. $discuz = C::app();
  14. $discuz->init();
  15. $apitype = empty($_GET['attach']) || !preg_match('/^[a-z0-9]+$/i', $_GET['attach']) ? 'alipay' : $_GET['attach'];
  16. require_once DISCUZ_ROOT.'./api/trade/api_' . $apitype . '.php';
  17. $PHP_SELF = $_SERVER['PHP_SELF'];
  18. $_G['siteurl'] = dhtmlspecialchars('http://'.$_SERVER['HTTP_HOST'].preg_replace("/\/+(api\/trade)?\/*$/i", '', substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'))).'/');
  19. $notifydata = trade_notifycheck('trade');
  20. if($notifydata['validator']) {
  21. $orderid = $notifydata['order_no'];
  22. if($orderid) {
  23. $tradelog = C::t('forum_tradelog')->fetch($orderid);
  24. if($tradelog && $tradelog['status'] != STATUS_TRADE_SUCCESS && $tradelog['status'] != STATUS_REFUND_CLOSE && ($apitype == 'tenpay' || $tradelog['selleraccount'] == $_REQUEST['seller_email'])) {
  25. $status = $notifydata['status'];
  26. C::t('forum_tradelog')->update($orderid, array(
  27. 'status' => $status,
  28. 'lastupdate' => $_G['timestamp'],
  29. 'tradeno' => $notifydata['trade_no']
  30. ));
  31. if($status != $tradelog['status']) {
  32. if($status == STATUS_SELLER_SEND) {
  33. notification_add($tradelog['sellerid'], 'goods', 'trade_seller_send', array(
  34. 'buyerid' => $tradelog['buyerid'],
  35. 'buyer' => $tradelog['buyer'],
  36. 'orderid' => $orderid,
  37. 'subject' => $tradelog['subject']
  38. ));
  39. } elseif($status == STATUS_WAIT_BUYER) {
  40. notification_add($tradelog['buyerid'], 'goods', 'trade_buyer_confirm', array(
  41. 'sellerid' => $tradelog['sellerid'],
  42. 'seller' => $tradelog['seller'],
  43. 'orderid' => $orderid,
  44. 'subject' => $tradelog['subject']
  45. ));
  46. } elseif($status == STATUS_TRADE_SUCCESS) {
  47. if($_G['setting']['creditstransextra'][5] != -1 && $tradelog['basecredit']) {
  48. $netcredit = round($tradelog['number'] * $tradelog['basecredit'] * (1 - $_G['setting']['creditstax']));
  49. updatemembercount($tradelog['sellerid'], array($_G['setting']['creditstransextra'][5] => $netcredit));
  50. } else {
  51. $netcredit = 0;
  52. }
  53. C::t('forum_trade')->update($tradelog['tid'], $tradelog['pid'], array('lastbuyer' => $tradelog['buyer'], 'lastupdate' => $_G['timestamp']));
  54. C::t('forum_trade')->update_counter($tradelog['tid'], $tradelog['pid'], $tradelog['number'], $tradelog['price'], $netcredit);
  55. updatecreditbyaction('tradefinished', $tradelog['sellerid']);
  56. updatecreditbyaction('tradefinished', $tradelog['buyerid']);
  57. notification_add($tradelog['sellerid'], 'goods', 'trade_success', array(
  58. 'orderid' => $orderid,
  59. 'subject' => $tradelog['subject']
  60. ));
  61. notification_add($tradelog['buyerid'], 'goods', 'trade_success', array(
  62. 'orderid' => $orderid,
  63. 'subject' => $tradelog['subject']
  64. ));
  65. } elseif($status == STATUS_REFUND_CLOSE) {
  66. C::t('forum_trade')->update_counter($tradelog['tid'], $tradelog['pid'], 0, 0, 0, $tradelog['number']);
  67. notification_add($tradelog['sellerid'], 'goods', 'trade_fefund_success', array(
  68. 'orderid' => $orderid,
  69. 'subject' => $tradelog['subject']
  70. ));
  71. notification_add($tradelog['buyerid'], 'goods', 'trade_fefund_success', array(
  72. 'orderid' => $orderid,
  73. 'subject' => $tradelog['subject']
  74. ));
  75. if($_G['setting']['creditstrans'] && $tradelog['buyerid']) {
  76. updatemembercount($tradelog['buyerid'], array($_G['setting']['creditstrans'] => $tradelog['buyercredits']));
  77. }
  78. if($_G['setting']['creditstransextra'][5] != -1 && $tradelog['basecredit'] && $tradelog['buyerid']) {
  79. $credit = $tradelog['number'] * $tradelog['basecredit'];
  80. updatemembercount($tradelog['buyerid'], array($_G['setting']['creditstransextra'][5] => $credit));
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. if($notifydata['location']) {
  88. dheader('location: '.$_G['siteurl'].'forum.php?mod=misc&action=paysucceed&orderid='.$orderid);
  89. } else {
  90. exit($notifydata['notify']);
  91. }
  92. ?>