function syn_deal_status($id) { $deals_time = TIME_UTC; $deal_info = $GLOBALS['db']->getRow("select *,(start_time + enddate*24*3600 - " . $deals_time . ") as remain_time,(load_money/borrow_amount*100) as progress_point from " . DB_PREFIX . "deal where id = " . $id); if ($deal_info['deal_status'] == 5) { return true; } if ($deal_info['deal_status'] != 3) { if ($deal_info['progress_point'] < 100) { $data['load_money'] = $GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "deal_load WHERE deal_id={$id} "); $data['progress_point'] = $deal_info['progress_point'] = round($data['load_money'] / $deal_info['borrow_amount'] * 100, 2); } if (($deal_info['progress_point'] >= 100 || $data['progress_point'] >= 100) && floatval($deal_info['load_money']) >= floatval($deal_info['borrow_amount'])) { if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_inrepay_repay WHERE deal_id={$id}") > 0) { $data['deal_status'] = 5; $repay_info = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) As all_repay_money FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay = 1 AND deal_id={$id}"); if ($repay_info) { $data['repay_money'] = $repay_info['all_repay_money']; } $data['last_repay_time'] = $GLOBALS['db']->getOne("SELECT true_repay_time FROM " . DB_PREFIX . "deal_inrepay_repay WHERE deal_id={$id}"); } elseif ($deal_info['deal_status'] == 4 && $deal_info['repay_start_time'] > 0 || $deal_info['deal_status'] == 2 && $deal_info['repay_start_time'] > 0 && $deal_info['repay_start_time'] <= $deals_time) { $repay_info = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) As all_repay_money FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay=1 AND deal_id={$id}"); if (!empty($repay_info['all_repay_money'])) { $data['repay_money'] = $repay_info['all_repay_money']; $last_repay_time = $GLOBALS['db']->getOne("SELECT MAX(repay_time) FROM " . DB_PREFIX . "deal_repay WHERE has_repay=1 AND deal_id={$id}"); $data['last_repay_time'] = $last_repay_time; $data['next_repay_time'] = next_replay_month($last_repay_time); } elseif ($deal_info['deal_status'] == 4) { if ($deal_info['repay_time_type'] == 0) { $data['next_repay_time'] = $deal_info['repay_start_time'] + $deal_info['repay_time'] * 24 * 3600; } else { if (is_last_repay($deal_info['loantype'])) { $data['next_repay_time'] = next_replay_month($deal_info['repay_start_time'], $deal_info['repay_time']); } else { $data['next_repay_time'] = next_replay_month($deal_info['repay_start_time']); } } } //判断是否完成还款 if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay<>1 AND deal_id={$id} ") == 0) { $data['deal_status'] = 5; } else { $data['deal_status'] = 4; } } else { //获取最后一次的投标记录 if ($deal_info['success_time'] == 0) { $data['success_time'] = $deal_info['success_time'] = $GLOBALS['db']->getOne("SELECT max(create_time) FROM " . DB_PREFIX . "deal_load WHERE deal_id={$id} "); } $data['deal_status'] = 2; } } elseif ($deal_info['remain_time'] <= 0 && $deal_info['deal_status'] == 1) { //投标时间超出 更新为流标 $data['deal_status'] = 1; //$data['bad_time'] = $deal_info['start_time'] + $deal_info['enddate']*24*3600; $data['bad_time'] = TIME_UTC; $data['bad_date'] = to_date(TIME_UTC, "Y-m-d"); } /*elseif($deal_info['remain_time'] > 0 && $deal_info['deal_status']==0){ $data['deal_status'] = 1; }*/ } //投标人数 $sdata = $GLOBALS['db']->getRow("SELECT count(*) as buy_count,sum(money) as load_money FROM " . DB_PREFIX . "deal_load WHERE deal_id={$id}"); $data['buy_count'] = $sdata['buy_count']; $data['load_money'] = floatval($sdata['load_money']); //流标 移入后台手动操作 /*if($deal_info['deal_status'] ==3 || $data['deal_status']==3){ //流标时返还 require_once APP_ROOT_PATH."system/libs/user.php"; $r_load_list = $GLOBALS['db']->getAll("SELECT id,user_id,money FROM ".DB_PREFIX."deal_load WHERE is_repay=0 AND deal_id=$id"); foreach($r_load_list as $k=>$v){ modify_account(array("money"=>$v['money']),$v['user_id'],"标:".$deal_info['id'].",流标返还"); $GLOBALS['db']->query("UPDATE ".DB_PREFIX."deal_load SET is_repay=1 WHERE id=".$v['id']); } //发送流标通知 if($deal_info['is_send_bad_msg']==0){ $data['is_send_bad_msg'] = 1; //发邮件 send_deal_faild_mail_sms($id,$deal_info,$deal_info['user_id']); //站内信 send_deal_faild_site_sms($id,$deal_info,$deal_info['user_id']); //添加到动态 insert_topic("deal_bad",$id,$deal_info['user_id'],get_user_name($deal_info['user_id'],false),0); } }*/ //发送流标通知 if (($deal_info['deal_status'] == 3 || $data['deal_status'] == 3) && $deal_info['is_send_bad_msg'] == 0) { $data['is_send_bad_msg'] = 1; //发邮件 send_deal_faild_mail_sms($id, $deal_info, $deal_info['user_id']); //站内信 send_deal_faild_site_sms($id, $deal_info, $deal_info['user_id']); //添加到动态 insert_topic("deal_bad", $id, $deal_info['user_id'], get_user_name($deal_info['user_id'], false), 0); } //放款给用户 移入后台手动操作 /*if($deal_info['is_has_loans']==0 && $data['deal_status']==4){ $data['is_has_loans'] = 1; require_once APP_ROOT_PATH."system/libs/user.php"; modify_account(array("money"=>$deal_info['borrow_amount']),$deal_info['user_id'],"标:".$deal_info['id'].",招标成功"); //扣除服务费 $services_fee = $deal_info['borrow_amount']*floatval(trim($deal_info['services_fee']))/100; modify_account(array("money"=>-$services_fee),$deal_info['user_id'],"服务费"); //发借款成功邮件 send_deal_success_mail_sms($id,$deal_info); //发借款成功站内信 send_deal_success_site_sms($id,$deal_info); //返利给用户 if(floatval(app_conf("USER_BID_REBATE"))!=0){ $load_list = $GLOBALS['db']->getAll("SELECT id,user_id,`money` FROM ".DB_PREFIX."deal_load where deal_id=".$id." and is_rebate = 0 "); foreach($load_list as $lk=>$lv){ $GLOBALS['db']->query("UPDATE ".DB_PREFIX."deal_load SET is_rebate =1 WHERE id=".$lv['id']." AND is_rebate = 0 AND user_id=".$lv['user_id']); if($GLOBALS['db']->affected_rows()){ modify_account(array("money"=>$lv['money']*floatval(app_conf("USER_BID_REBATE"))/100),$lv['user_id'],"标:".$id.",返利"); } } } }*/ $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $data, "UPDATE", "id=" . $id); //自动投标功能 //2013-8-15 排除了 借贷者在外 and usa.user_id <>'".$deal_info['user_id']."' if (app_conf("OPEN_AUTOBID") == 1 && $deal_info['ips_bill_no'] == "") { if (($deal_info['deal_status'] == 1 || $data['deal_status'] == 1) && $deal_info['remain_time'] > 0 && $deals_time - $deal_info['start_time'] >= 1800 && $deal_info['progress_point'] <= 95 && $deal_info['repay_time_type'] == 1) { $sql = "SELECT u.id,u.user_name,usa.fixed_amount FROM " . DB_PREFIX . "user_autobid usa " . "LEFT JOIN " . DB_PREFIX . "user u ON u.id=usa.user_id " . "LEFT JOIN " . DB_PREFIX . "deal d ON d.id=" . $deal_info['id'] . " " . "LEFT JOIN " . DB_PREFIX . "user du ON du.id = d.user_id " . "WHERE (usa.fixed_amount >=d.min_loan_money or d.min_loan_money = 0) AND (usa.fixed_amount <= d.max_loan_money or d.max_loan_money = 0) " . "AND usa.fixed_amount <= d.borrow_amount*0.2 AND usa.is_effect = 1 " . "AND (d.rate between usa.min_rate AND usa.max_rate) " . "AND (d.repay_time between usa.min_period AND usa.max_period) " . "AND usa.user_id not in (SELECT user_id FROM " . DB_PREFIX . "deal_load WHERE deal_id={$id}) and usa.user_id <>d.user_id " . "AND (du.level_id between usa.min_level AND usa.max_level) " . "AND usa.fixed_amount < (d.borrow_amount - d.load_money) " . "AND u.money-usa.retain_amount >= usa.fixed_amount " . "AND FIND_IN_SET(d.cate_id,usa.deal_cates) " . "GROUP BY usa.user_id ORDER BY usa.last_bid_time ASC"; $autobid_user = $GLOBALS['db']->getRow($sql); //开始投标 if ($autobid_user && $deal_info['borrow_amount'] > $GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $deal_info['id']) + $autobid_user['fixed_amount']) { $biddata['deal_id'] = $id; $biddata['money'] = $autobid_user['fixed_amount']; $biddata['is_auto'] = 1; $insertbiddata = return_deal_load_data($biddata, $autobid_user, $deal_info); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", $insertbiddata, "INSERT"); $load_id = $GLOBALS['db']->insert_id(); if ($load_id > 0) { $msg = '[<a href="' . url("index", "deal", array("id" => $deal_info['id'])) . '" target="_blank">' . $deal_info['name'] . '</a>]的投标,付款单号' . $load_id; require_once APP_ROOT_PATH . "system/libs/user.php"; modify_account(array("money" => -$autobid_user['fixed_amount'], 'lock_money' => $autobid_user['fixed_amount']), $autobid_user['id'], $msg, 2); $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "user_autobid SET last_bid_time=" . TIME_UTC . " WHERE user_id=" . $autobid_user['id']); } } } } return $data; }
function dobid2($deal_id, $bid_money, $bid_paypassword, $is_pc = 0) { $root = check_dobid2($deal_id, $bid_money, $bid_paypassword, $is_pc); if ($root["status"] == 0) { return $root; } elseif ($root["status"] == 2) { $root['jump'] = APP_ROOT . "/index.php?ctl=collocation&act=RegisterCreditor&deal_id={$deal_id}&user_id=" . $GLOBALS['user_info']['id'] . "&bid_money=" . $root['bid_money'] . "&bid_paypassword={$bid_paypassword}" . "&from=" . $GLOBALS['request']['from']; $root['jump'] = str_replace("/mapi", "", SITE_DOMAIN . $root['jump']); return $root; } $root["status"] = 0; $bid_money = floatval($root['bid_money']); $bid_paypassword = strim($bid_paypassword); if ($bid_money > $GLOBALS['user_info']['money']) { $root["show_err"] = $GLOBALS['lang']['MONEY_NOT_ENOUGHT']; return $root; } $data['user_id'] = $GLOBALS['user_info']['id']; $data['user_name'] = $GLOBALS['user_info']['user_name']; $data['deal_id'] = $deal_id; $data['money'] = $bid_money; $insertdata = return_deal_load_data($data, $GLOBALS['user_info'], $root['deal']); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", $insertdata, "INSERT"); $load_id = $GLOBALS['db']->insert_id(); if ($load_id > 0) { //更改资金记录 $msg = '[<a href="' . $root['deal']['url'] . '" target="_blank">' . $root['deal']['name'] . '</a>]的投标,付款单号' . $load_id; require_once APP_ROOT_PATH . "system/libs/user.php"; modify_account(array('money' => -$bid_money, 'lock_money' => $bid_money), $GLOBALS['user_info']['id'], $msg, 2); dobid2_ok($deal_id, $GLOBALS['user_info']['id']); //$root["show_err"] = $GLOBALS['lang']['ERROR_TITLE']; $root["status"] = 1; //0:出错;1:正确; return $root; //showSuccess($GLOBALS['lang']['DEAL_BID_SUCCESS'],$ajax,url("index","deal",array("id"=>$id))); } else { $root["show_err"] = $GLOBALS['lang']['ERROR_TITLE']; return $root; } }
function RegisterCreditorCallBack($pMerCode, $pErrCode, $pErrMsg, $str3Req) { //print_r($str3XmlParaInfo); $pMerBillNo = $str3Req["pMerBillNo"]; $where = " pMerBillNo = '" . $pMerBillNo . "'"; $sql = "update " . DB_PREFIX . "ips_register_creditor set is_callback = 1 where is_callback = 0 and " . $where; $GLOBALS['db']->query($sql); if ($GLOBALS['db']->affected_rows()) { //操作成功 $data = array(); $data['pAccountDealNo'] = $str3Req["pAccountDealNo"]; //投资人编号 否 IPS返回的投资人编号 $data['pBidDealNo'] = $str3Req["pBidDealNo"]; //标的编号 否 IPS返回的标的编号 $data['pBusiType'] = $str3Req["pBusiType"]; //业务类型 否 返回1,代表投标 $data['pTransferAmt'] = $str3Req["pTransferAmt"]; //实际冻结金额 否 实际冻结金额 $data['pStatus'] = $str3Req["pStatus"]; //债权人状态 否 0:新增 1:迚行中 10:结束 $data['pP2PBillNo'] = $str3Req["pP2PBillNo"]; //IPS P2P订单号 否 由IPS系统生成的唯一流水号 $data['pIpsTime'] = $str3Req["pIpsTime"]; //IPS处理时间 否 格式为:yyyyMMddHHmmss $data['pErrCode'] = $pErrCode; $data['pErrMsg'] = $pErrMsg; $GLOBALS['db']->autoExecute(DB_PREFIX . "ips_register_creditor", $data, 'UPDATE', $where); if ($pErrCode == 'MG00000F') { $ipsdata = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "ips_register_creditor where " . $where); $user_id = intval($ipsdata['user_id']); $user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id); $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . (int) $ipsdata['deal_id']); $data['pMerBillNo'] = $pMerBillNo; $data['pContractNo'] = $str3Req["pContractNo"]; $data['pP2PBillNo'] = $data['pP2PBillNo']; $data['user_id'] = $user_id; $data['user_name'] = $user['user_name']; $data['deal_id'] = $ipsdata['deal_id']; $data['money'] = $data['pTransferAmt']; $insertdata = return_deal_load_data($data, $user, $deal); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", $insertdata, "INSERT"); $load_id = $GLOBALS['db']->insert_id(); if ($load_id > 0) { require APP_ROOT_PATH . 'app/Lib/deal_func.php'; dobid2_ok($ipsdata['deal_id'], $user_id); return $ipsdata; } //$user_id = intval($GLOBALS['db']->getOne("select user_id from ".DB_PREFIX."ips_register_creditor where ".$where)); //$GLOBALS['db']->query("update ".DB_PREFIX."user set ips_acct_no = '".$data['pIpsAcctNo']."' where id = ".$user_id); } } else { $ipsdata = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "ips_register_creditor where " . $where); return $ipsdata; } }
function RegisterCreditorCallBack($str3Req) { //print_r($str3XmlParaInfo); $order_id = $str3Req["order_id"]; $where = " order_id = '" . $order_id . "'"; $sql = "update " . DB_PREFIX . "baofoo_business set is_callback = 1 where is_callback = 0 and " . $where; $GLOBALS['db']->query($sql); if ($GLOBALS['db']->affected_rows()) { //操作成功 $data = array(); $GLOBALS['db']->autoExecute(DB_PREFIX . "baofoo_business", $str3Req, 'UPDATE', $where); if ($str3Req['code'] == 'CSD000') { $ipsdata = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "baofoo_business where " . $where); $user_id = intval($ipsdata['load_user_id']); $user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id); $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . (int) $ipsdata['cus_id']); $data['pMerBillNo'] = $order_id; $data['pContractNo'] = $order_id; $data['pP2PBillNo'] = $order_id; $data['user_id'] = $user_id; $data['user_name'] = $user['user_name']; $data['deal_id'] = $ipsdata['cus_id']; $data['money'] = $ipsdata['load_amount']; $insertdata = return_deal_load_data($data, $user, $deal); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", $insertdata, "INSERT"); $load_id = $GLOBALS['db']->insert_id(); if ($load_id > 0) { require APP_ROOT_PATH . 'app/Lib/deal_func.php'; dobid2_ok($ipsdata['cus_id'], $user_id); return $ipsdata; } } } else { return 1; } }
function RegisterCreditorCallBack($str3Req) { $requestNo = $str3Req["requestNo"]; $where = " requestNo = '" . $requestNo . "'"; $sql = "update " . DB_PREFIX . "yeepay_cp_transaction set is_callback = 1 where is_callback = 0 and " . $where; $GLOBALS['db']->query($sql); //操作成功 if ($str3Req["code"] == "1") { //print_r($str3XmlParaInfo); $data = array(); $GLOBALS['db']->autoExecute(DB_PREFIX . "yeepay_cp_transaction", $str3Req, 'UPDATE', $where); if ($str3Req['code'] == '1') { $ipsdata = $GLOBALS['db']->getRow("select *,tenderOrderNo as deal_id from " . DB_PREFIX . "yeepay_cp_transaction where " . $where); $user_id = intval($ipsdata['platformUserNo']); $user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id); $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $ipsdata['tenderOrderNo']); $data['pMerBillNo'] = $requestNo; $data['pContractNo'] = $requestNo; $data['pP2PBillNo'] = $requestNo; $data['user_id'] = $user_id; $data['user_name'] = $user['user_name']; $data['deal_id'] = $ipsdata['tenderOrderNo']; $data['money'] = $ipsdata['paymentAmount']; $insertdata = return_deal_load_data($data, $user, $deal); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", $insertdata, "INSERT"); $load_id = $GLOBALS['db']->insert_id(); if ($load_id > 0) { require APP_ROOT_PATH . 'app/Lib/deal_func.php'; dobid2_ok($ipsdata['orderNo'], $user_id); return $ipsdata; } } } else { $ipsdata = $GLOBALS['db']->getRow("select *,tenderOrderNo as deal_id from " . DB_PREFIX . "yeepay_cp_transaction where " . $where); return $ipsdata; } }