Pay.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 == 5 && $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. # 减少积分
  60. Dever::load('pay/lib/set.updateStatus', $send);
  61. }
  62. }
  63. /**
  64. * 支付成功后,调取的接口 这里的安全以后再升级吧,升级成和pay/lib/set.updateStatus一样的
  65. *
  66. * @return mixed
  67. */
  68. public function act_api($param = array())
  69. {
  70. $send = Dever::preInput('pay_');
  71. $key = md5($this->key);
  72. ksort($send);
  73. $send['signature'] = md5($key . '&' . http_build_query($send));
  74. $signature = Dever::input('signature');
  75. if ($send['signature'] == $signature) {
  76. $product_id = $send['pay_product_id'];
  77. $uid = $send['pay_uid'];
  78. $cash = $send['pay_cash'];
  79. $order_id = $send['pay_order_id'];
  80. $status = $send['pay_status'];
  81. $msg = $send['pay_msg'];
  82. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  83. if ($send['pay_status'] == 2 && $order) {
  84. $update = array();
  85. $update['where_id'] = $order['id'];
  86. $update['status'] = 2;
  87. if ($order['type'] == 3 && !$order['code']) {
  88. # 购买兑换码
  89. $product_num = 1;
  90. $code_num = 1;
  91. if ($order['buy_id'] > 0) {
  92. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  93. $product_num = $buy['num'];
  94. $code_num = $buy['code'];
  95. }
  96. if ($code_num > 1) {
  97. $product_num = intval($product_num/$code_num);
  98. for ($i = 0; $i < $code_num; $i++) {
  99. $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']);
  100. }
  101. } else {
  102. $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']);
  103. }
  104. }
  105. Dever::db('journal/order')->update($update);
  106. if ($order['type'] != 1) {
  107. return;
  108. }
  109. # 订阅
  110. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  111. $score = false;
  112. $num = false;
  113. if ($order['buy_id'] > 0) {
  114. $info = Dever::db('journal/info')->one($order['product_id']);
  115. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  116. if ($info && $buy && $info['score'] > 0) {
  117. $score = $buy['num'] * $info['score'];
  118. } elseif ($info && $buy) {
  119. $num = $buy['num'];
  120. }
  121. }
  122. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  123. # 发消息
  124. $journal = Dever::db('journal/info')->one($order['product_id']);
  125. if (Dever::project('message')) {
  126. 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']));
  127. }
  128. $user = Dever::db('passport/user')->one($uid);
  129. # 发短信
  130. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  131. $send = array();
  132. $send['name'] = $journal['name'];
  133. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  134. }
  135. # 发模板消息
  136. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  137. if ($wechat && Dever::project('wechat_applet')) {
  138. $send['key'] = 'buy_journal';
  139. $send['project_id'] = $order['cate_id'];
  140. $send['touser'] = $wechat['openid'];
  141. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  142. $send['data'] = array
  143. (
  144. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  145. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  146. );
  147. $send['data'] = json_encode($send['data']);
  148. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  149. if ($send['form_id']) {
  150. Dever::load('wechat_applet/msg.send', $send);
  151. }
  152. }
  153. } else {
  154. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  155. }
  156. }
  157. }
  158. public function send_api()
  159. {
  160. $uid = Dever::input('uid', 8);
  161. # 发模板消息
  162. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  163. if ($wechat && Dever::project('wechat_applet')) {
  164. $send['key'] = 'buy_journal';
  165. $send['project_id'] = 2;
  166. $send['touser'] = $wechat['openid'];
  167. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  168. $send['data'] = array
  169. (
  170. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  171. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  172. );
  173. $send['data'] = json_encode($send['data']);
  174. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  175. if ($send['form_id']) {
  176. Dever::load('wechat_applet/msg.send', $send);
  177. }
  178. }
  179. }
  180. }