Active.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Active\Lib;
  3. use Dever;
  4. class Active
  5. {
  6. public function action($uid, $active_id, $num, $path, $remark = false)
  7. {
  8. $user = Dever::db('active/user')->find($uid);
  9. // print_R(json_decode('[{"id":"1","value":"文本"},{"id":"2","value":"文本"},{"id":"3","value":"1"}]'));die;
  10. $data = Dever::db('active/info')->find($active_id);
  11. // if ($data['act_status'] == 1 || (isset($data['act_start']) && $data['act_start'] && time() < $data['sign_start'])) {
  12. // Dever::alert('活动还未开始报名');
  13. // }
  14. if ($data['act_status'] >=3 || (isset($data['sign_end']) && $data['sign_end'] && time()>$data['sign_end'])){
  15. Dever::alert('活动报名已结束');
  16. }
  17. $insert['active_id'] = $active_id;
  18. $insert['num'] = $num;
  19. $insert['price'] = $num * $data['price'];
  20. if ($remark) {
  21. $insert['remark'] = $remark;
  22. }
  23. if ($path) {
  24. $insert['path'] = $path;
  25. }
  26. $insert['uid'] = $user['id'];
  27. $title = array();
  28. if ($data['attr']) {
  29. if ($data['attr_input']) {
  30. $input['num'] = explode(',',$data['attr_input']);
  31. }
  32. $data['attr'] = explode(',',$data['attr']);
  33. foreach ($data['attr'] as $k => $v) {
  34. foreach ($input['num'] as $k1 => $v1) {
  35. if($k == $k1){
  36. $title[$k]['id'] = $v;
  37. $title[$k]['num'] = $v1;
  38. }
  39. }
  40. }
  41. }
  42. $order = Dever::db('active/order')->getNum(array('uid'=>$uid,'active_id'=>$active_id));
  43. $member = Dever::load('active/lib/user')->agent($user);
  44. if ($data['status'] == 2) {
  45. if (!$member) {
  46. Dever::alert('本活动只能是代理商报名');
  47. }
  48. }
  49. if ($title && $member) {
  50. foreach ($title as $k => $v) {
  51. if($v['id'] == $member['role']) {
  52. if ($v['num'] > 0 && $num > $v['num']) {
  53. Dever::alert('您已超过限购数量');
  54. }
  55. if ($order && $order['total'] && $v['num'] > 0 && $order['total'] > $v['num']) {
  56. Dever::alert('您已超过限购数量');
  57. }
  58. }
  59. }
  60. } else {
  61. if ($order && $order['total'] && $order['total'] >= $data['num']) {
  62. Dever::alert('您已超过限购数量');
  63. }
  64. if ($num > $data['num'] ) {
  65. Dever::alert('您已超过限购数量');
  66. }
  67. }
  68. $insert['order_num'] = $this->getOrderId();
  69. $ids = Dever::db('active/order')->insert($insert);
  70. $url = Dever::url();
  71. $refer = 'https://www.churenyiliao.com/';
  72. if (strstr($url, 'uat.')) {
  73. $refer = 'http://guanli.uat.churenyiliao.com/';
  74. }
  75. $refer .= 'data/payback/active.html?order_id=' . $ids;
  76. if ($ids) {
  77. $info = Dever::db('active/order')->find($ids);
  78. $active = Dever::db('active/info')->find($info['active_id']);
  79. $param = array
  80. (
  81. 'project_id' => 6,
  82. 'channel_id' => 1,
  83. 'system_source' => 1,
  84. 'account_id' => 8,
  85. 'uid' => $uid,
  86. 'name' => $active['name'],
  87. //'openid' => $data['openid'],
  88. 'cash' => $info['price'],
  89. 'product_id' => $ids,
  90. 'order_id' => $info['order_num'],
  91. 'h5' => 1,
  92. 'refer' => $refer,
  93. );
  94. $result = Dever::load('pay/api.pay', $param);
  95. if ($result['order']) {
  96. Dever::db('active/order')->update(array('where_id'=>$ids,'url'=>$result['order']));
  97. }
  98. $result['order_num'] = $info['order_num'];
  99. $result['order_id'] = $info['id'];
  100. $jump = Dever::input('jump');
  101. if ($jump == 1) {
  102. Dever::location($result['order']);
  103. }
  104. return $result;
  105. } else {
  106. Dever::alert('提交失败');
  107. }
  108. }
  109. # 支付成功回调 安全加密 设置token
  110. public function success_secure_api_token()
  111. {
  112. $project_id = Dever::input('pay_project_id');
  113. $info = Dever::db('pay/project')->one($project_id);
  114. if ($info) {
  115. return $info['key'];
  116. }
  117. return 'agent_buy_dever_2020';
  118. }
  119. # 支付成功回调 安全加密
  120. public function success_secure_api($param = array())
  121. {
  122. $this->success($param);
  123. }
  124. # 支付成功回调
  125. public function success($param = array())
  126. {
  127. $send = $param ? $param : Dever::preInput('pay_');
  128. $product_id = $send['pay_product_id'];
  129. $order_id = $send['pay_order_id'];
  130. $status = $send['pay_status'];
  131. $cash = $send['pay_cash'];
  132. $msg = $send['pay_msg'];
  133. $order = Dever::db('active/order')->one(array('id' => $product_id, 'clear' => true));
  134. if ($order && $status == 2) {
  135. $update['status'] = 2;
  136. $update['where_id'] = $order['id'];
  137. Dever::db('active/order')->update($update);
  138. }
  139. return 'ok';
  140. }
  141. #生成订单号
  142. public function getOrderId()
  143. {
  144. $where['order_num'] = Dever::order('D');
  145. $where['clear'] = true;
  146. $state = Dever::db('active/order')->one($where);
  147. if (!$state) {
  148. return $where['order_num'];
  149. } else {
  150. return $this->getOrderId();
  151. }
  152. }
  153. }