Beispiel #1
0
 public function loansreturn()
 {
     file_put_contents('/tmp/debugwhh', date('m-d H:i:s') . "\$_POST:" . print_r($_POST, true) . "\n", FILE_APPEND);
     if (strcmp($_POST['RespCode'], "000") == 0) {
         $mem = new Memcache();
         $mem->connect("127.0.0.1", 11211);
         $key = 'loansreturn-' . $_POST['CmdId'] . '-' . $_POST['OutCustId'];
         $has = $mem->get($key);
         if ($has) {
             sleep(1);
             //return ;
         } else {
             //设置4秒
             $mem->set($key, 1, 0, 1);
         }
         unset($mem, $has, $key);
     }
     $usrid = $_POST['OutCustId'];
     $info = M("huifulog")->distinct(true)->field("uid,username")->where("usrid=" . $usrid)->find();
     $data = array();
     $data['uid'] = $info['uid'];
     //用户UID
     $data['username'] = $info['username'];
     //用户名
     $data['rescode'] = $_POST['RespCode'];
     //返回码
     $data['cmdid'] = $_POST['CmdId'];
     //消息类型
     $data['usrid'] = $_POST['OutCustId'];
     //用户客户号(出账人客户号)
     $data['ordid'] = $_POST['OrdId'];
     //订单号
     $data['orddate'] = $_POST['OrdDate'];
     //订单日期
     $data['trxid'] = "";
     $data['merpriv'] = $_POST['MerPriv'];
     $data['addtime'] = time();
     //记录时间
     //解冻金额是否减掉
     $reqext = 0;
     $reqext = $_POST['RespExt'];
     //代金券的内容json字符串
     $reqext = json_decode(urldecode($reqext), 1);
     $reqext = $reqext['LoansVocherAmt'];
     file_put_contents('/tmp/debugwhh', date('m-d H:i:s') . "reqext:" . print_r($reqext, true) . "\n", FILE_APPEND);
     $condition['uid'] = $data['uid'];
     $condition['ordid'] = $data['ordid'];
     $num = M("huifulog")->where($condition)->count();
     $md = M()->getLastSql();
     file_put_contents('/tmp/debugwhh', date('m-d H:i:s') . "\\md:" . print_r($md, true) . "\n", FILE_APPEND);
     if ($num == 0) {
         M("huifulog")->add($data);
         if (strcmp($_POST['RespCode'], "000") == 0) {
             $temp = base64_decode($data['merpriv']);
             $pos1 = strpos($temp, '{');
             $pos2 = strpos($temp, '}');
             $len = $pos2 - $pos1 + 1;
             $merpriv = substr($temp, $pos1, $len);
             $merpriv = json_decode($merpriv, true);
             $borrowid = $merpriv['borrowid'];
             //标ID
             $investid = $merpriv['investid'];
             //投资ID
             $binfo = M("borrow_info")->field("borrow_type,reward_type,reward_num,borrow_fee,borrow_money,borrow_uid,borrow_duration,repayment_type,manage_rate")->find($borrowid);
             //还款时间
             $endTime = strtotime(date("Y-m-d", time()) . " 23:59:59");
             //逾期时刻
             if ($binfo['borrow_type'] == 3 || $binfo['repayment_type'] == 1) {
                 $deadline = strtotime("+{$binfo['borrow_duration']} day", $endTime);
                 //天标或秒标
             } else {
                 $deadline = strtotime("+{$binfo['borrow_duration']} month", $endTime);
                 //月标
             }
             //更新投资信息
             $investinfo = array();
             $investinfo['deadline'] = $deadline;
             $investinfo['status'] = 4;
             //复审通过,还款中
             M("borrow_investor")->where("id=" . $investid)->save($investinfo);
             //更新还款信息
             switch ($binfo['repayment_type']) {
                 case 2:
                     //每月还款
                 //每月还款
                 case 3:
                     //每季还本
                 //每季还本
                 case 4:
                     //期未还本
                     for ($i = 1; $i <= $binfo['borrow_duration']; $i++) {
                         $repaymentinfo = array();
                         $deadlines = strtotime("+{$i} month", $endTime);
                         //月还款时间
                         $repaymentinfo['deadline'] = $deadlines;
                         $repaymentinfo['status'] = 7;
                         //复审通过,还款中
                         M("investor_detail")->where("invest_id={$investid} AND  `sort_order` ={$i}")->save($repaymentinfo);
                     }
                     break;
                 case 1:
                     //按天一次性还款
                 //按天一次性还款
                 case 5:
                     //一次性还款
                     $repaymentinfo = array();
                     $repaymentinfo['deadline'] = $deadline;
                     //一次性还款时间
                     $repaymentinfo['status'] = 7;
                     //复审通过,还款中
                     M("investor_detail")->where("invest_id=" . $investid)->save($repaymentinfo);
                     break;
             }
             //解冻保证金要减去代金券 20150831
             if ($reqext) {
                 $investor_capital = str2val_money($_POST['TransAmt'] - $reqext);
                 $tip = "第{$borrowid}号标复审通过,冻结本金成为待收金额.使用代金券{$reqext}元";
             } else {
                 $investor_capital = str2val_money($_POST['TransAmt']);
                 $tip = "第{$borrowid}号标复审通过,冻结本金成为待收金额.";
             }
             //因为要给代收金额加上代金券的钱 所以要添加一个变量。20150831 by lj
             memberMoneyLog($data['uid'], 15, $investor_capital, $tip, $binfo['borrow_uid'], '', 0, $reqext);
             file_put_contents('/tmp/debugwhh', date('m-d H:i:s') . "is_null_req:" . print_r($reqext, true) . "\n", FILE_APPEND);
             $daishou = M('investor_detail')->field('interest')->where("investor_uid = {$data['uid']} and borrow_id = {$borrowid} and invest_id ={$investid}")->sum('interest');
             memberMoneyLog($data['uid'], 28, $daishou, "第{$borrowid}号标复审通过,应收利息成为待收利息", $binfo['borrow_uid']);
             //memberMoneyLog($vo['recommend_id'],13,$jiangli,$vo['user_name']."对{$borrow_id}号标投资成功,你获得推广奖励".$jiangli."元。",$v['investor_uid']);
             $id = M("borrow_investor")->field('id')->where("borrow_id=" . $borrowid)->order('id desc')->find();
             if ($id['id'] == $investid) {
                 $borrowinfo = array();
                 $borrowinfo['deadline'] = $deadline;
                 $borrowinfo['borrow_status'] = 6;
                 M("borrow_info")->where("id=" . $borrowid)->save($borrowinfo);
                 //更新借款信息
                 //投标代金券放入客户代收金额*/
                 memberMoneyLog($binfo['borrow_uid'], 17, $binfo['borrow_money'], "第{$borrowid}号标复审通过,借款金额入帐");
                 //投标代金券放入客户代收金额结束*/
                 $total = M("borrow_info")->field("danbao,borrow_money")->where("id=" . $borrowid)->find();
                 //如果担保公司存在
                 if ($total['danbao'] != 0) {
                     $Guar = M('members')->field("usrid,id")->where("id = " . $total['danbao'])->find();
                     $guar_rate = M('member_guarrate')->where("uid = " . $total['danbao'])->find();
                     //担保费率
                     $rates_fee = $guar_rate['guarrate'] * $binfo['borrow_money'] / 100;
                     memberMoneyLog($binfo['borrow_uid'], 104, -$rates_fee, "第{$borrowid}号标借款成功,扣除担保费");
                     //借款者付出担保费
                     memberMoneyLog($Guar['id'], 105, $rates_fee, "第{$borrowid}号标借款成功,获得担保费");
                     //担保者获得担保费
                 }
                 memberMoneyLog($binfo['borrow_uid'], 18, -$binfo['borrow_fee'], "第{$borrowid}号标借款成功,扣除借款管理费");
                 //借款保证金
                 $_P_fee = get_global_setting();
                 $info1 = M("members")->field("usrid")->find($binfo['borrow_uid']);
                 $usrid = $info1['usrid'];
                 $transamt = $_P_fee['money_deposit'] * $total['borrow_money'] / 100;
                 import("ORG.Huifu.Huifu");
                 $huifu = new Huifu();
                 $huifu->usrFreezeBg($usrid, $transamt, $borrowid);
             }
         }
         echo "RECV_ORD_ID_" . $_POST['OrdId'];
     }
 }