Pay.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Pay
  5. {
  6. /**
  7. * 支付成功后,调取的接口
  8. *
  9. * @return mixed
  10. */
  11. public function act_api($param = array())
  12. {
  13. $send = Dever::preInput('pay_');
  14. $key = md5('jmss_2018');
  15. ksort($send);
  16. $send['signature'] = md5($key . '&' . http_build_query($send));
  17. $signature = Dever::input('signature');
  18. if ($send['signature'] == $signature) {
  19. $product_id = $send['pay_product_id'];
  20. $uid = $send['pay_uid'];
  21. $cash = $send['pay_cash'];
  22. $order_id = $send['pay_order_id'];
  23. $status = $send['pay_status'];
  24. $msg = $send['pay_msg'];
  25. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  26. if ($send['pay_status'] == 2 && $order) {
  27. $update = array();
  28. $update['where_id'] = $order['id'];
  29. $update['status'] = 2;
  30. if ($order['type'] == 3) {
  31. # 购买兑换码
  32. $product_num = 1;
  33. $code_num = 1;
  34. if ($order['buy_id'] > 0) {
  35. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  36. $product_num = $buy['num'];
  37. $code_num = $buy['code'];
  38. }
  39. if ($code_num > 1) {
  40. $product_num = intval($product_num/$code_num);
  41. for ($i = 0; $i < $code_num; $i++) {
  42. $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid, $order['order_id']);
  43. }
  44. } else {
  45. $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid, $order['order_id']);
  46. }
  47. }
  48. Dever::db('journal/order')->update($update);
  49. if ($order['type'] != 1) {
  50. return;
  51. }
  52. # 订阅
  53. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  54. $score = false;
  55. $num = false;
  56. if ($order['buy_id'] > 0) {
  57. $info = Dever::db('journal/info')->one($order['product_id']);
  58. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  59. if ($info && $buy && $info['score'] > 0) {
  60. $score = $buy['num'] * $info['score'];
  61. } elseif ($info && $buy) {
  62. $num = $buy['num'];
  63. }
  64. }
  65. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  66. # 发消息
  67. $journal = Dever::db('journal/info')->one($order['product_id']);
  68. if (Dever::project('message')) {
  69. Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', 11, $order['cate_id']);
  70. }
  71. $user = Dever::db('passport/user')->one($uid);
  72. # 发短信
  73. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  74. $send = array();
  75. $send['name'] = $journal['name'];
  76. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  77. }
  78. # 发模板消息
  79. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  80. if ($wechat && Dever::project('wechat_applet')) {
  81. $send['key'] = 'buy_journal';
  82. $send['project_id'] = $order['cate_id'];
  83. $send['touser'] = $wechat['openid'];
  84. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  85. $send['data'] = array
  86. (
  87. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  88. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  89. );
  90. $send['data'] = json_encode($send['data']);
  91. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  92. if ($send['form_id']) {
  93. Dever::load('wechat_applet/msg.send', $send);
  94. }
  95. }
  96. } else {
  97. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  98. }
  99. }
  100. }
  101. public function send_api()
  102. {
  103. $uid = Dever::input('uid', 8);
  104. # 发模板消息
  105. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  106. if ($wechat && Dever::project('wechat_applet')) {
  107. $send['key'] = 'buy_journal';
  108. $send['project_id'] = 2;
  109. $send['touser'] = $wechat['openid'];
  110. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  111. $send['data'] = array
  112. (
  113. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  114. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  115. );
  116. $send['data'] = json_encode($send['data']);
  117. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  118. if ($send['form_id']) {
  119. Dever::load('wechat_applet/msg.send', $send);
  120. }
  121. }
  122. }
  123. }