Pay.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. $code = Dever::load('code/lib/core')->createCodeByOrder($order);
  89. if ($code) {
  90. $update['code'] = $code;
  91. }
  92. }
  93. /*
  94. if ($order['type'] == 3 && !$order['code']) {
  95. # 购买兑换码
  96. $product_num = 1;
  97. $code_num = 1;
  98. if ($order['buy_id'] > 0) {
  99. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  100. $product_num = $buy['num'];
  101. $code_num = $buy['code'];
  102. }
  103. if ($code_num > 1) {
  104. $product_num = intval($product_num/$code_num);
  105. for ($i = 0; $i < $code_num; $i++) {
  106. $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']);
  107. }
  108. } else {
  109. $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']);
  110. }
  111. }
  112. */
  113. Dever::db('journal/order')->update($update);
  114. if ($order['type'] != 1) {
  115. return;
  116. }
  117. # 订阅
  118. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  119. $score = false;
  120. $num = false;
  121. if ($order['buy_id'] > 0) {
  122. $info = Dever::db('journal/info')->one($order['product_id']);
  123. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  124. if ($info && $buy && $info['score'] > 0) {
  125. $score = $buy['num'] * $info['score'];
  126. } elseif ($info && $buy) {
  127. $num = $buy['num'];
  128. }
  129. }
  130. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  131. # 发消息
  132. $journal = Dever::db('journal/info')->one($order['product_id']);
  133. if (Dever::project('message')) {
  134. 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']));
  135. }
  136. $user = Dever::db('passport/user')->one($uid);
  137. # 发短信
  138. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  139. $send = array();
  140. $send['name'] = $journal['name'];
  141. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  142. }
  143. # 发模板消息
  144. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  145. if ($wechat && Dever::project('wechat_applet')) {
  146. $send['key'] = 'buy_journal';
  147. $send['project_id'] = $order['cate_id'];
  148. $send['touser'] = $wechat['openid'];
  149. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  150. $send['data'] = array
  151. (
  152. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  153. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  154. );
  155. $send['data'] = json_encode($send['data']);
  156. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  157. if ($send['form_id']) {
  158. Dever::load('wechat_applet/msg.send', $send);
  159. }
  160. }
  161. } else {
  162. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  163. }
  164. }
  165. }
  166. public function send_api()
  167. {
  168. $uid = Dever::input('uid', 8);
  169. # 发模板消息
  170. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  171. if ($wechat && Dever::project('wechat_applet')) {
  172. $send['key'] = 'buy_journal';
  173. $send['project_id'] = 2;
  174. $send['touser'] = $wechat['openid'];
  175. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  176. $send['data'] = array
  177. (
  178. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  179. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  180. );
  181. $send['data'] = json_encode($send['data']);
  182. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  183. if ($send['form_id']) {
  184. Dever::load('wechat_applet/msg.send', $send);
  185. }
  186. }
  187. }
  188. }