Active.php 5.3 KB

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