Pay.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Pay
  5. {
  6. private $key = 'jmss_2018';
  7. public function go_api()
  8. {
  9. $where['code'] = 'null';
  10. $where['type'] = 3;
  11. $where['status'] = 2;
  12. $data = Dever::db('journal/order')->getUnCode($where);
  13. echo Dever::sql();
  14. if ($data) {
  15. print_r($data);die;
  16. foreach ($data as $k => $v) {
  17. # 购买兑换码
  18. $order = $v;
  19. $product_num = 1;
  20. $code_num = 1;
  21. $uid = $order['uid'];
  22. if ($order['buy_id'] > 0) {
  23. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  24. $product_num = $buy['num'];
  25. $code_num = $buy['code'];
  26. }
  27. if ($code_num > 1) {
  28. $product_num = intval($product_num/$code_num);
  29. for ($i = 0; $i < $code_num; $i++) {
  30. $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']);
  31. }
  32. } else {
  33. $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']);
  34. }
  35. $update['where_id'] = $order['id'];
  36. Dever::db('journal/order')->update($update);
  37. }
  38. }
  39. }
  40. public function test_api()
  41. {
  42. $data['status'] = 1;
  43. $this->order(1, 'test', $data);
  44. }
  45. public function order($id, $name, $data)
  46. {
  47. $status = Dever::param('status', $data);
  48. if ($status > 0 && $id > 0) {
  49. $send = array();
  50. $info = Dever::db('journal/order')->one($id);
  51. $send['pay_project_id'] = 1;
  52. $send['pay_uid'] = $info['uid'];
  53. $send['pay_order_id'] = $info['order_id'];
  54. $send['pay_tk_pic'] = Dever::param('tk_pic', $data);
  55. $send['pay_tk_time'] = Dever::param('tk_time', $data);
  56. $send['pay_tk_desc'] = Dever::param('tk_desc', $data);
  57. $send['pay_status'] = $status;
  58. $send['dever_token'] = $this->key;
  59. Dever::load('pay/lib/set.updateStatus', $send);
  60. }
  61. }
  62. /**
  63. * 支付成功后,调取的接口 这里的安全以后再升级吧,升级成和pay/lib/set.updateStatus一样的
  64. *
  65. * @return mixed
  66. */
  67. public function act_api($param = array())
  68. {
  69. $send = Dever::preInput('pay_');
  70. $key = md5($this->key);
  71. ksort($send);
  72. $send['signature'] = md5($key . '&' . http_build_query($send));
  73. $signature = Dever::input('signature');
  74. if ($send['signature'] == $signature) {
  75. $product_id = $send['pay_product_id'];
  76. $uid = $send['pay_uid'];
  77. $cash = $send['pay_cash'];
  78. $order_id = $send['pay_order_id'];
  79. $status = $send['pay_status'];
  80. $msg = $send['pay_msg'];
  81. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  82. if ($send['pay_status'] == 2 && $order) {
  83. $update = array();
  84. $update['where_id'] = $order['id'];
  85. $update['status'] = 2;
  86. if ($order['type'] == 3 && !$order['code']) {
  87. # 购买兑换码
  88. $product_num = 1;
  89. $code_num = 1;
  90. if ($order['buy_id'] > 0) {
  91. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  92. $product_num = $buy['num'];
  93. $code_num = $buy['code'];
  94. }
  95. if ($code_num > 1) {
  96. $product_num = intval($product_num/$code_num);
  97. for ($i = 0; $i < $code_num; $i++) {
  98. $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']);
  99. }
  100. } else {
  101. $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']);
  102. }
  103. }
  104. Dever::db('journal/order')->update($update);
  105. if ($order['type'] != 1) {
  106. return;
  107. }
  108. # 订阅
  109. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  110. $score = false;
  111. $num = false;
  112. if ($order['buy_id'] > 0) {
  113. $info = Dever::db('journal/info')->one($order['product_id']);
  114. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  115. if ($info && $buy && $info['score'] > 0) {
  116. $score = $buy['num'] * $info['score'];
  117. } elseif ($info && $buy) {
  118. $num = $buy['num'];
  119. }
  120. }
  121. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  122. # 发消息
  123. $journal = Dever::db('journal/info')->one($order['product_id']);
  124. if (Dever::project('message')) {
  125. 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']));
  126. }
  127. $user = Dever::db('passport/user')->one($uid);
  128. # 发短信
  129. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  130. $send = array();
  131. $send['name'] = $journal['name'];
  132. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  133. }
  134. # 发模板消息
  135. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  136. if ($wechat && Dever::project('wechat_applet')) {
  137. $send['key'] = 'buy_journal';
  138. $send['project_id'] = $order['cate_id'];
  139. $send['touser'] = $wechat['openid'];
  140. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  141. $send['data'] = array
  142. (
  143. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  144. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  145. );
  146. $send['data'] = json_encode($send['data']);
  147. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  148. if ($send['form_id']) {
  149. Dever::load('wechat_applet/msg.send', $send);
  150. }
  151. }
  152. } else {
  153. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  154. }
  155. }
  156. }
  157. public function send_api()
  158. {
  159. $uid = Dever::input('uid', 8);
  160. # 发模板消息
  161. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  162. if ($wechat && Dever::project('wechat_applet')) {
  163. $send['key'] = 'buy_journal';
  164. $send['project_id'] = 2;
  165. $send['touser'] = $wechat['openid'];
  166. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  167. $send['data'] = array
  168. (
  169. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  170. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  171. );
  172. $send['data'] = json_encode($send['data']);
  173. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  174. if ($send['form_id']) {
  175. Dever::load('wechat_applet/msg.send', $send);
  176. }
  177. }
  178. }
  179. }