Pay.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. #新版本的异步支付
  3. namespace Act\Lib;
  4. use Dever;
  5. class Pay
  6. {
  7. private $key = 'jmss_2018';
  8. # 退款操作
  9. public function order($id, $name, $data)
  10. {
  11. $status = Dever::param('status', $data);
  12. if ($status == 5 && $id > 0) {
  13. $send = array();
  14. $info = Dever::db('act/order')->one($id);
  15. $send['pay_project_id'] = 1;
  16. $send['pay_uid'] = $info['uid'];
  17. $send['pay_order_id'] = $info['order_id'];
  18. $send['pay_tk_pic'] = Dever::param('tk_pic', $data);
  19. $send['pay_tk_time'] = Dever::param('tk_time', $data);
  20. $send['pay_tk_desc'] = Dever::param('tk_desc', $data);
  21. $send['pay_status'] = $status;
  22. $send['dever_token'] = $this->key;
  23. # 减少积分
  24. Dever::load('pay/lib/set.updateStatus', $send);
  25. }
  26. }
  27. /**
  28. * 支付成功后,调取的接口 这里的安全以后再升级吧,升级成和pay/lib/set.updateStatus一样的
  29. *
  30. * @return mixed
  31. */
  32. public function act_api($param = array())
  33. {
  34. $send = Dever::preInput('pay_');
  35. $key = md5($this->key);
  36. ksort($send);
  37. $send['signature'] = md5($key . '&' . http_build_query($send));
  38. $signature = Dever::input('signature');
  39. if ($send['signature'] == $signature) {
  40. $product_id = $send['pay_product_id'];
  41. $uid = $send['pay_uid'];
  42. $cash = $send['pay_cash'];
  43. $order_id = $send['pay_order_id'];
  44. $status = $send['pay_status'];
  45. $msg = $send['pay_msg'];
  46. $order = Dever::db('act/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  47. if ($send['pay_status'] == 2 && $order) {
  48. $update = array();
  49. $update['where_id'] = $order['id'];
  50. $update['status'] = 2;
  51. if ($order['type'] == 3 && !$order['code']) {
  52. $code = Dever::load('code/lib/core')->createCodeByOrder($order, -1);
  53. if ($code) {
  54. $update['code'] = $code;
  55. }
  56. }
  57. Dever::db('act/order')->update($update);
  58. $score = false;
  59. $num = false;
  60. $journal = Dever::load('act/order')->getJournal($order['product_id']);
  61. if ($order['buy_id'] > 0) {
  62. $buy = Dever::load('act/order')->getBuy($order['buy_id']);
  63. if ($buy && $buy['score'] > 0) {
  64. $score = $buy['num'] * $buy['score'];
  65. } else {
  66. if ($order['type'] == 1) {
  67. # 直接购买
  68. $col = 'score';
  69. } elseif ($order['type'] == 3) {
  70. $col = 'dh_score';
  71. }
  72. if ($journal && $buy && $journal[$col] > 0) {
  73. $score = $buy['num'] * $journal[$col];
  74. } elseif ($journal && $buy) {
  75. $num = $buy['num'];
  76. }
  77. }
  78. if ($buy && $buy['num']) {
  79. # 增加本数
  80. Dever::load('act/lib/num')->submit($order['product_id'], $uid, $buy['num']);
  81. }
  82. }
  83. # 积分
  84. Dever::score($uid, 'buy_journal', '购买小刊', '', $score, $num);
  85. # 发消息
  86. $journal['id'] = $order['product_id'];
  87. $journal['name'] = $order['name'];
  88. if (strstr('-', $journal['name'])) {
  89. $name = explode('-', $journal['name']);
  90. $journal['name'] = $name[0];
  91. }
  92. //$journal = Dever::db('journal/info')->one($order['product_id']);
  93. if (Dever::project('message')) {
  94. Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', 11, $order['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  95. }
  96. $user = Dever::db('passport/user')->one($uid);
  97. # 发短信
  98. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  99. $send = array();
  100. $send['name'] = $journal['name'];
  101. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  102. }
  103. # 发模板消息
  104. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  105. if ($wechat && Dever::project('wechat_applet')) {
  106. $send['key'] = 'buy_journal';
  107. $send['project_id'] = $order['cate_id'];
  108. $send['touser'] = $wechat['openid'];
  109. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  110. $send['data'] = array
  111. (
  112. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  113. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  114. );
  115. $send['data'] = json_encode($send['data']);
  116. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  117. if ($send['form_id']) {
  118. Dever::load('wechat_applet/msg.send', $send);
  119. }
  120. }
  121. } else {
  122. Dever::db('act/order')->update(array('where_id' => $order['id'], 'status' => 3));
  123. }
  124. }
  125. return 'ok';
  126. }
  127. public function send_api()
  128. {
  129. $uid = Dever::input('uid', 8);
  130. # 发模板消息
  131. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  132. if ($wechat && Dever::project('wechat_applet')) {
  133. $send['key'] = 'buy_journal';
  134. $send['project_id'] = 2;
  135. $send['touser'] = $wechat['openid'];
  136. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  137. $send['data'] = array
  138. (
  139. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  140. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  141. );
  142. $send['data'] = json_encode($send['data']);
  143. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  144. if ($send['form_id']) {
  145. Dever::load('wechat_applet/msg.send', $send);
  146. }
  147. }
  148. }
  149. }