Pay.php 9.3 KB

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