人人商城

refund.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php error_reporting(0);
  2. require("../../../../../framework/bootstrap.inc.php");
  3. require("../../../../../addons/ewei_shopv2/defines.php");
  4. require("../../../../../addons/ewei_shopv2/core/inc/functions.php");
  5. global $_W;
  6. global $_GPC;
  7. ignore_user_abort();
  8. set_time_limit(0);
  9. $sets = pdo_fetchall("select uniacid,refund from " . tablename("ewei_shop_groups_set"));
  10. foreach( $sets as $key => $value )
  11. {
  12. global $_W;
  13. global $_GPC;
  14. global $_S;
  15. $_W["uniacid"] = $value["uniacid"];
  16. $shopset = $_S["shop"];
  17. $_W["uniacid"] = $value["uniacid"];
  18. if( empty($_W["uniacid"]) )
  19. {
  20. continue;
  21. }
  22. $hours = intval($value["refund"]);
  23. if( $hours <= 0 )
  24. {
  25. continue;
  26. }
  27. $times = $hours * 60 * 60;
  28. $orders = pdo_fetchall("select id,orderno,refundid,openid,credit,creditmoney,price,freight,status,pay_type,teamid,apppay,isborrow,borrowopenid,more_spec from " . tablename("ewei_shop_groups_order") . "\r\n where uniacid=" . $_W["uniacid"] . " and status = 1 and pay_type !='other' and success = -1 and refundtime = 0 and canceltime + " . $times . " <= " . time() . " order by id desc ");
  29. foreach( $orders as $k => $val )
  30. {
  31. $realprice = $val["price"] - $val["creditmoney"] + $val["freight"];
  32. $credits = $val["credit"];
  33. if( $val["pay_type"] == "credit" )
  34. {
  35. $result = m("member")->setCredit($val["openid"], "credit2", $realprice, array( 0, $shopset["name"] . "退款: " . $realprice . "元 订单号: " . $val["orderno"] ));
  36. }
  37. else
  38. {
  39. if( $val["pay_type"] == "wechat" )
  40. {
  41. $realprice = round($realprice, 2);
  42. if( empty($val["isborrow"]) )
  43. {
  44. $result = m("finance")->refund($val["openid"], $val["orderno"], $val["orderno"], $realprice * 100, $realprice * 100, (!empty($val["apppay"]) ? true : false));
  45. }
  46. else
  47. {
  48. $result = m("finance")->refundBorrow($val["borrowopenid"], $val["orderno"], $val["orderno"], $realprice * 100, $realprice * 100, (!empty($val["apppay"]) ? true : false));
  49. }
  50. $refundtype = 2;
  51. }
  52. else
  53. {
  54. if( $val["pay_type"] == "wxapp" )
  55. {
  56. $realprice = round($realprice, 2);
  57. $result = m("finance")->wxapp_refund($val["openid"], $val["orderno"], $val["orderno"], $realprice * 100, $realprice * 100);
  58. }
  59. else
  60. {
  61. if( $realprice < 1 )
  62. {
  63. show_json(0, "退款金额必须大于1元,才能使用微信企业付款退款!");
  64. }
  65. $result = m("finance")->pay($val["openid"], 1, $realprice * 100, $val["orderno"], $shopset["name"] . "退款: " . $realprice . "元 订单号: " . $val["orderno"]);
  66. $refundtype = 1;
  67. }
  68. }
  69. }
  70. if( is_error($result) && $result["message"] != "OK | 订单已全额退款" && $result["message"] != "Refund exists|退款已存在" )
  71. {
  72. continue;
  73. }
  74. if( 0 < $credits )
  75. {
  76. m("member")->setCredit($val["openid"], "credit1", $credits, array( "0", $shopset["name"] . "购物返还抵扣积分 积分: " . $val["credit"] . " 抵扣金额: " . $val["creditmoney"] . " 订单号: " . $val["orderno"] ));
  77. }
  78. $refund = pdo_fetch("select * from " . tablename("ewei_shop_groups_order_refund") . " where id=:id limit 1", array( ":id" => $val["refundid"] ));
  79. if( empty($refund) != true && $refund["refundstatus"] == 0 )
  80. {
  81. $change_refund["refundstatus"] = 1;
  82. $change_refund["refundtype"] = $refundtype;
  83. $change_refund["refundtime"] = time();
  84. if( empty($refund["operatetime"]) )
  85. {
  86. $change_refund["operatetime"] = time();
  87. }
  88. pdo_update("ewei_shop_groups_order_refund", $change_refund, array( "id" => $val["refundid"] ));
  89. }
  90. pdo_update("ewei_shop_groups_order", array( "refundstate" => 0, "status" => -1, "refundtime" => time() ), array( "id" => $val["id"], "uniacid" => $_W["uniacid"] ));
  91. $sales = pdo_fetch("select id,sales,stock from " . tablename("ewei_shop_groups_goods") . " where id = :id and uniacid = :uniacid ", array( ":id" => $val["goodid"], ":uniacid" => $uniacid ));
  92. pdo_update("ewei_shop_groups_goods", array( "sales" => $sales["sales"] - 1, "stock" => $sales["stock"] + 1 ), array( "id" => $sales["id"], "uniacid" => $uniacid ));
  93. if( $val["more_spec"] == 1 )
  94. {
  95. $option = pdo_get("ewei_shop_groups_order_goods", array( "uniacid" => $_W["uniacid"], "groups_order_id" => $val["id"] ));
  96. pdo_update("ewei_shop_groups_goods_option", array( "stock" => "stock+1" ), array( "id" => $option["groups_goods_option_id"] ));
  97. }
  98. plog("groups.task.refund", "订单退款 ID: " . $val["id"] . " 订单号: " . $val["orderno"]);
  99. }
  100. }
  101. ?>