Pay.php 8.8 KB

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