takecash.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace WY\app\controller\mobile;
  3. use WY\app\libs\Controller;
  4. use WY\app\model\Bill;
  5. if (!defined('WY_ROOT')) {
  6. exit;
  7. }
  8. class takecash extends CheckUser
  9. {
  10. function __construct()
  11. {
  12. parent::__construct();
  13. $this->bill = new Bill();
  14. if ($this->userData['is_verify_phone']==0)
  15. {
  16. $this->put('woodyapp.php', array('msg' => '请绑定手机号码后操作提现'));
  17. exit;
  18. }
  19. if (!$this->config['tx_state']) {
  20. $this->put('woodyapp.php', array('msg' => '平台提现功能暂时关闭'));
  21. exit;
  22. }
  23. if (!$this->userData['is_takecash']) {
  24. $this->put('woodyapp.php', array('msg' => '您的账号未开通提现功能'));
  25. exit;
  26. }
  27. if (date('H') < $this->config['tx_ftime'] || date('H') > $this->config['tx_etime']) {
  28. $this->put('woodyapp.php', array('msg' => $this->config['tx_closetip']));
  29. exit;
  30. }
  31. // if ($this->model()->select()->from('payments')->where(array('fields' => 'userid=? and ship_type=? and addtime>=? and addtime<?', 'values' => array($_SESSION['login_userid'], 1, strtotime(date('Y-m-d')), time())))->count() >= $this->config['tx_timelimit']) {
  32. // $this->put('woodyapp.php', array('msg' => $this->config['tx_limittip']));
  33. // exit;
  34. // }
  35. if ($this->userData['ship_cycle'] > 0) {
  36. $fromTime = strtotime(date('Y-m-d') . ' 23:59:59') - 60 * 60 * 24 * $this->userData['ship_cycle'];
  37. } else {
  38. $fromTime = strtotime(date('Y-m-d H:i'));
  39. }
  40. $income = $this->bill->getUserIncome($_SESSION['login_userid'], $fromTime);
  41. $newMoney = $this->userData['unpaid'];
  42. if ($income > 0) {
  43. $newMoney += $income;
  44. $data = array('unpaid' => $newMoney);
  45. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($_SESSION['login_userid'])))->update()) {
  46. $where = array('fields' => 'userid=? and is_state=? and is_ship=? and addtime<=?', 'values' => array($_SESSION['login_userid'], 1, 0, $fromTime));
  47. $this->model()->from('orders')->updateSet(array('is_ship' => 1))->where($where)->update();
  48. $data = array('userid' => $_SESSION['login_userid'], 'is_agent' => 0, 'before_money' => $this->userData['unpaid'], 'money' => $income, 'after_money' => $newMoney, 'ctype' => '提现', 'addtime' => time());
  49. $this->model()->from('paylogs')->insertData($data)->insert();
  50. }
  51. }
  52. $this->unpaid = $newMoney;
  53. if ($newMoney < $this->config['tx_minmoney']) {
  54. $this->put('woodyapp.php', array('msg' => '您的账号余额不足,暂无法使用提现。当前系统最低提现额为:' . $this->config['tx_minmoney'] . '元'));
  55. exit;
  56. }
  57. }
  58. public function index()
  59. {
  60. $newMoney = $this->unpaid;
  61. $today_income = $this->bill->todayUserIncome($_SESSION['login_userid'], 0);
  62. $income = $this->bill->beforeUserIncome($_SESSION['login_userid'], 0);
  63. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($this->userData['id'])))->fetchRow();
  64. $usercfo = $this->model()->select()->from('cfo')->where(array('fields' => 'userid=?', 'values' => array($this->userData['id'])))->fetchAll();
  65. $data = array('title' => '申请提现', 'income' => $today_income + $income, 'money' => $newMoney, 'fee' => $this->bill->fee($newMoney), 'userinfo' => $userinfo, 'usercfo' => $usercfo);
  66. $this->put('takecash.php', $data);
  67. }
  68. public function submit()
  69. {
  70. $txmoney = $this->req->post('txmoney');
  71. $ptype = $this->req->post('ptype');
  72. $cfoid = $this->req->post('cfoid');
  73. $Code= $this->req->post('verifycode'); //add
  74. if(strlen($Code)>1 and $Code!=$_SESSION["code"]){ //add
  75. echo json_encode(array('status' => 0, 'msg' => '验证码不正确!'));
  76. exit;
  77. }else{
  78. }
  79. if ($txmoney <= 0) {
  80. echo json_encode(array('status' => 0, 'msg' => '参数错误'));
  81. exit;
  82. }
  83. if ($txmoney < $this->config['tx_minmoney']) {
  84. $this->put('woodyapp.php', array('msg' => '当前系统最低提现额为:' . $this->config['tx_minmoney'] . '元'));
  85. exit;
  86. }
  87. if ($ptype == '1' and $cfoid == '') {
  88. echo json_encode(array('status' => 0, 'msg' => '代收银行信息不能为空'));
  89. exit;
  90. }
  91. if ($txmoney > $this->userData['unpaid']) {
  92. echo json_encode(array('status' => 0, 'msg' => '账户余额不足'));
  93. exit;
  94. }
  95. if ($cfoid && !($cfo = $this->model()->select()->from('cfo')->where(array('fields' => 'userid=? and id=?', 'values' => array($this->userData['id'], $cfoid)))->fetchRow())) {
  96. echo json_encode(array('status' => 0, 'msg' => '代收银行信息不存在'));
  97. exit;
  98. }
  99. $newMoney = $this->userData['unpaid'] - $txmoney;
  100. $data = array('paid' => $this->userData['paid'] + $txmoney, 'unpaid' => $newMoney);
  101. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($this->userData['id'])))->update()) {
  102. $data = array('userid' => $this->userData['id'], 'is_agent' => 0, 'before_money' => $this->userData['unpaid'], 'money' => $txmoney, 'after_money' => $newMoney, 'ctype' => '提现', 'addtime' => time());
  103. $this->model()->from('paylogs')->insertData($data)->insert();
  104. if ($ptype == '0') {
  105. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($this->userData['id'])))->fetchRow();
  106. $realname = $userinfo['realname'];
  107. $batype = $userinfo['batype'];
  108. $baname = $userinfo['baname'];
  109. $baaddr = $userinfo['baaddr'];
  110. } else {
  111. $realname = $cfo['accountname'];
  112. $batype = $cfo['bankname'];
  113. // $batype = $this->setConfig->cfoBank($cfo['bankname']);
  114. $baname = $cfo['cardno'];
  115. $baaddr =$cfo['provice'].$cfo['city'].$cfo['branchname'];
  116. }
  117. $data = array('userid' => $this->userData['id'], 'money' => $txmoney, 'addtime' => time(), 'lastime' => time(), 'sn' => 'b' . time(), 'fee' => $this->bill->fee($txmoney), 'ptype' => $ptype, 'cfoid' => $ptype ? $cfoid : 0, 'ship_type' => 1, 'realname' => $realname, 'batype' => $batype, 'baname' => $baname, 'baaddr' => $baaddr);
  118. $this->model()->from('payments')->insertData($data)->insert();
  119. echo json_encode(array('status' => 1, 'msg' => '申请提现成功', 'url' => '/member/payments'));
  120. $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
  121. $phone='18676665154';
  122. $smsConf = array(
  123. 'key' => 'eb776c91955412a128177b0e06490438', //您申请的APPKEY
  124. 'mobile' => $phone, //接受短信的用户手机号码
  125. 'tpl_id' => '37792', //您申请的短信模板ID,根据实际情况修改
  126. 'tpl_value' =>'#username#='.$realname.'&#userid#='.$this->userData['id'].'&#money#='. $txmoney,//您设置的模板变量,根据实际情况修改
  127. //'tpl_value' =>'#username#=123&#userid#=10000&#money#=123',//您设置的模板变量,根据实际情况修改
  128. );
  129. $this->juhecurl($sendUrl,$smsConf,1); //请求发送短信
  130. unset($_SESSION['code']);
  131. exit;
  132. }
  133. echo json_encode(array('status' => 0, 'msg' => '申请提现失败'));
  134. }
  135. public function getFee()
  136. {
  137. $money = $this->req->post('money');
  138. echo $this->bill->fee($money);
  139. }
  140. public function submit1(){
  141. $cfoid=$this->req->post('bankid');
  142. $txmoney=$this->req->post('txmoney');
  143. $ptype='1';
  144. if ($txmoney <= 0) {
  145. echo json_encode(array('status' => 0, 'msg' => '参数错误'));
  146. exit;
  147. }
  148. if ($txmoney < $this->config['tx_minmoney']) {
  149. $this->put('woodyapp.php', array('msg' => '当前系统最低提现额为:' . $this->config['tx_minmoney'] . '元'));
  150. exit;
  151. }
  152. if ($ptype == '1' and $cfoid == '') {
  153. echo json_encode(array('status' => 0, 'msg' => '代收银行信息不能为空'));
  154. exit;
  155. }
  156. if ($txmoney > $this->userData['unpaid']) {
  157. echo json_encode(array('status' => 0, 'msg' => '账户余额不足'));
  158. exit;
  159. }
  160. if ($cfoid && !($cfo = $this->model()->select()->from('cfo')->where(array('fields' => 'userid=? and id=?', 'values' => array($this->userData['id'], $cfoid)))->fetchRow())) {
  161. echo json_encode(array('status' => 0, 'msg' => '代收银行信息不存在'));
  162. exit;
  163. }
  164. if ($cfoid && !($cfo = $this->model()->select()->from('cfo')->where(array('fields' => 'userid=? and id=?', 'values' => array($this->userData['id'], $cfoid)))->fetchRow())) {
  165. echo json_encode(array('status' => 0, 'msg' => '代收银行信息不存在'));
  166. exit;
  167. }
  168. $newMoney = $this->userData['unpaid'] - $txmoney;
  169. $data = array('paid' => $this->userData['paid'] + $txmoney, 'unpaid' => $newMoney);
  170. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($this->userData['id'])))->update()) {
  171. $data = array('userid' => $this->userData['id'], 'is_agent' => 0, 'before_money' => $this->userData['unpaid'], 'money' => $txmoney, 'after_money' => $newMoney, 'ctype' => '提现', 'addtime' => time());
  172. $this->model()->from('paylogs')->insertData($data)->insert();
  173. if ($ptype == '0') {
  174. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($this->userData['id'])))->fetchRow();
  175. $realname = $userinfo['realname'];
  176. $batype = $userinfo['batype'];
  177. $baname = $userinfo['baname'];
  178. $baaddr = $userinfo['baaddr'];
  179. } else {
  180. $realname = $cfo['accountname'];
  181. $batype = $cfo['bankname'];
  182. // $batype = $this->setConfig->cfoBank($cfo['bankname']);
  183. $baname = $cfo['cardno'];
  184. $baaddr =$cfo['provice'].$cfo['city'].$cfo['branchname'];
  185. }
  186. $data = array('userid' => $this->userData['id'], 'money' => $txmoney, 'addtime' => time(), 'lastime' => time(), 'sn' => 'b' . time(), 'fee' => $this->bill->fee($txmoney), 'ptype' => $ptype, 'cfoid' => $ptype ? $cfoid : 0, 'ship_type' => 1, 'realname' => $realname, 'batype' => $batype, 'baname' => $baname, 'baaddr' => $baaddr);
  187. $this->model()->from('payments')->insertData($data)->insert();
  188. echo json_encode(array('status' => 1, 'msg' => '申请提现成功', 'url' => '/mobile/takecash'));
  189. exit;
  190. }
  191. echo json_encode(array('status' => 0, 'msg' => '申请提现失败'));
  192. }
  193. public function juhecurl($url,$params=false,$ispost=0){
  194. $httpInfo = array();
  195. $ch = curl_init();
  196. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  197. curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
  198. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
  199. curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
  200. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  201. if( $ispost )
  202. {
  203. curl_setopt( $ch , CURLOPT_POST , true );
  204. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  205. curl_setopt( $ch , CURLOPT_URL , $url );
  206. }
  207. else
  208. {
  209. if($params){
  210. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  211. }else{
  212. curl_setopt( $ch , CURLOPT_URL , $url);
  213. }
  214. }
  215. $response = curl_exec( $ch );
  216. if ($response === FALSE) {
  217. //echo "cURL Error: " . curl_error($ch);
  218. return false;
  219. }
  220. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  221. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  222. curl_close( $ch );
  223. return $response;
  224. }
  225. }