Example #1
0
 public function init()
 {
     if (!$GLOBALS['user_info']) {
         if ($_REQUEST['ajax'] == 1) {
             ajax_return(array("status" => 0, "info" => "请先登录"));
         } else {
             es_session::set('before_login', $_SERVER['REQUEST_URI']);
             app_redirect(url("index", "user#login"));
         }
     }
     $id = intval($_REQUEST['id']);
     $this->space_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $id . " and is_effect=  1 and is_delete = 0");
     $user_id = intval($GLOBALS['user_info']['id']);
     if (!$this->space_user) {
         showErr($GLOBALS['lang']['USER_NOT_EXISTS']);
     }
     $focus_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_focus where focus_user_id = " . $user_id . " and focused_user_id = " . $this->space_user['id']);
     if ($focus_data) {
         $this->space_user['focused'] = 1;
     }
     $province_str = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "region_conf where id = " . $this->space_user['province_id']);
     $city_str = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "region_conf where id = " . $this->space_user['city_id']);
     if ($province_str . $city_str == '') {
         $user_location = $GLOBALS['lang']['LOCATION_NULL'];
     } else {
         $user_location = $province_str . " " . $city_str;
     }
     $this->space_user['fav_count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "topic where user_id = " . $this->space_user['id'] . " and fav_id <> 0");
     $this->space_user['user_location'] = $user_location;
     $this->space_user['group_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "user_group where id = " . $this->space_user['group_id'] . " ");
     $GLOBALS['tmpl']->assign("space_user", $this->space_user);
     $GLOBALS['tmpl']->assign('user_statics', sys_user_status($id, true));
 }
 public function index()
 {
     $root = array();
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     $id = intval($GLOBALS['request']['id']);
     //$user_id = intval($GLOBALS['user_info']['id']);
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     if ($user_id > 0) {
         require APP_ROOT_PATH . 'app/Lib/deal.php';
         $root['user_login_status'] = 1;
         $root['response_code'] = 1;
         //充值已支付
         $root['incharge_count'] = $GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "payment_notice where  is_paid = 1 and user_id = " . $user_id . " ");
         $root['incharge_count'] = format_price($root['incharge_count']);
         //提现成功
         $root['carry_money'] = $GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "user_carry where  status = 1 and user_id = " . $user_id . " ");
         $root['carry_money'] = format_price($root['carry_money']);
         //已付管理费
         $root['true_repay_manage_money'] = $GLOBALS['db']->getOne("SELECT sum(true_repay_manage_money) FROM " . DB_PREFIX . "deal_load_repay where  has_repay = 1 and user_id = " . $user_id . " ");
         $root['true_repay_manage_money'] = format_price($root['true_repay_manage_money']);
         $user_statistics = sys_user_status($user_id);
         $root['user_statistics'] = $user_statistics;
     } else {
         $root['response_code'] = 0;
         $root['show_err'] = "未登录";
         $root['user_login_status'] = 0;
     }
     $root['program_title'] = "理财统计";
     output($root);
 }
Example #3
0
 public function index()
 {
     $root = array();
     $id = intval($GLOBALS['request']['id']);
     $deal = get_deal($id);
     //send_deal_contract_email($id,$deal,$deal['user_id']);  //发送电子协议邮件
     $root['deal'] = $deal;
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $id);
     $u_info = get_user("*", $deal['user_id']);
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $root['can_use_quota'] = $can_use_quota;
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     /*
     		if($GLOBALS['user_info']){
     			$deal['is_faved'] = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."deal_collect WHERE deal_id = ".$id." AND user_id=".intval($GLOBALS['user_info']['id']));
     				
     			if($deal['deal_status'] >=4){
     				//还款列表
     				$loan_repay_list = get_deal_load_list($deal);
     				
     				$root['loan_repay_list']= $loan_repay_list;
     				
     				
     				foreach($load_list as $k=>$v){
     					$load_list[$k]['remain_money'] = $v['money'] - $GLOBALS['db']->getOne("SELECT sum(self_money) FROM ".DB_PREFIX."deal_load_repay WHERE user_id=".$v['user_id']." AND deal_id=".$id);
     					if($load_list[$k]['remain_money'] <=0){
     						$load_list[$k]['remain_money'] = 0;
     						$load_list[$k]['status'] = 1;
     					}
     				}
     			}
     			
     		}*/
     $user_statics = sys_user_status($deal['user_id'], true);
     $root['user_statics'] = $user_statics;
     //借款笔数
     $root['load_list'] = $load_list;
     $root['credit_file'] = $credit_file;
     $root['u_info'] = $u_info;
     //工作认证是否过期
     $root['expire'] = user_info_expire($u_info);
     //留言
     $message_list = $GLOBALS['db']->getAll("SELECT title,content,a.create_time,rel_id,a.user_id,a.is_effect,b.user_name FROM " . DB_PREFIX . "message as a left join " . DB_PREFIX . "user as b on  a.user_id = b.id WHERE rel_id = " . $id);
     $root['message'] = $message_list;
     //seo
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $root['page_title'] = $seo_title;
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $root['page_keyword'] = $seo_keyword;
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $root['seo_description'] = $seo_description;
     output($root);
 }
 function index()
 {
     $user_statics = sys_user_status($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_EARNINGS']);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_earnings.html");
     $GLOBALS['tmpl']->display("page/uc.html");
 }
 function index()
 {
     $user_statics = sys_user_status($GLOBALS['user_info']['id']);
     $user_statics['all_load_money'] = $user_statics['load_earnings'] + $user_statics['reward_money'] + $user_statics['load_tq_impose'] + $user_statics['load_yq_impose'] + $user_statics['rebate_money'] + $user_statics['referrals_money'] - $user_statics['carry_fee_money'] - $user_statics['incharge_fee_money'];
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_EARNINGS']);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_earnings.html");
     $GLOBALS['tmpl']->display("page/uc.html");
 }
 function index()
 {
     $user_statics = sys_user_status($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_EARNINGS']);
     $load = $GLOBALS['db']->getRow("SELECT sum(money) as total_money FROM " . DB_PREFIX . "deal_load WHERE user_id=" . intval($GLOBALS['user_info']['id']));
     $GLOBALS['tmpl']->assign("load", $load);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_earnings.html");
     $GLOBALS['tmpl']->display("page/uc.html");
 }
Example #7
0
 function stepone()
 {
     //检查是否有发布的但是未确认投标的标
     if ($GLOBALS['db']->getOne("SELECT * FROM " . DB_PREFIX . "deal WHERE is_delete=0 and publish_wait=1 and user_id=" . $GLOBALS['user_info']['id']) > 0) {
         app_redirect(url("index", "borrow#steptwo"));
     }
     //判断账户信用是否足够
     if ($GLOBALS['user_info']['point'] < 0) {
         showErr("信用太低,无法借款");
     }
     $GLOBALS['tmpl']->assign('page_title', $GLOBALS['lang']['APPLY_BORROW']);
     $user_statics = sys_user_status($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $typeid = intval($_REQUEST['typeid']);
     $GLOBALS['tmpl']->assign("typeid", $typeid);
     $agreement = app_conf('BORROW_AGREEMENT');
     $GLOBALS['tmpl']->assign("agreement", $agreement);
     $loan_type_list = load_auto_cache("deal_loan_type_list");
     $GLOBALS['tmpl']->assign("loan_type_list", $loan_type_list);
     $level = $GLOBALS['db']->getOneCached("SELECT name FROM " . DB_PREFIX . "user_level WHERE id=" . intval($GLOBALS['user_info']['level_id']));
     $GLOBALS['tmpl']->assign("level", $level);
     $level_list = load_auto_cache("level");
     $GLOBALS['tmpl']->assign("level_list", $level_list);
     //可用额度
     $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal WHERE (is_delete=2 or is_delete=3) AND user_id=" . $GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("deal", $deal);
     $user_view_infos = $GLOBALS['user_info']['view_info'];
     $user_view_infos = unserialize($user_view_infos);
     $user_view_infoss = array();
     $deal_view_info = unserialize($deal['view_info']);
     foreach ($user_view_infos as $k => $v) {
         //会员自己传的或者管理员勾选的 才会显示
         if (intval($v['is_user']) == 1 || isset($deal_view_info[$k])) {
             $user_view_infoss[$k] = $v;
             $user_view_infoss[$k]['key'] = $k;
             if (isset($deal_view_info[$k])) {
                 $user_view_infoss[$k]['is_selected'] = 1;
             }
         }
     }
     $GLOBALS['tmpl']->assign("user_view_info", $user_view_infoss);
     //担保机构
     $agency_list = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "deal_agency WHERE is_effect = 1");
     $GLOBALS['tmpl']->assign("agency_list", $agency_list);
     $inc_file = "inc/borrow/stepone.html";
     $GLOBALS['tmpl']->assign('inc_file', $inc_file);
     $GLOBALS['tmpl']->display("page/borrow_step.html");
 }
 public function init_user()
 {
     $this->user_data = $GLOBALS['user_info'];
     $province_str = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "region_conf where id = " . $this->user_data['province_id']);
     $city_str = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "region_conf where id = " . $this->user_data['city_id']);
     if ($province_str . $city_str == '') {
         $user_location = $GLOBALS['lang']['LOCATION_NULL'];
     } else {
         $user_location = $province_str . " " . $city_str;
     }
     $this->user_data['fav_count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "topic where user_id = " . $this->user_data['id'] . " and fav_id <> 0");
     $this->user_data['user_location'] = $user_location;
     $this->user_data['group_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "user_group where id = " . $this->user_data['group_id'] . " ");
     $this->user_data['user_statics'] = sys_user_status($GLOBALS['user_info']['id'], false);
     $GLOBALS['tmpl']->assign('user_statics', $this->user_data['user_statics']);
 }
Example #9
0
 public function index()
 {
     $root = array();
     $id = intval($GLOBALS['request']['id']);
     $deal = get_deal($id);
     //send_deal_contract_email($id,$deal,$deal['user_id']);  //发送电子协议邮件
     $root['deal'] = $deal;
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $id);
     $u_info = get_user("*", $deal['user_id']);
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $root['can_use_quota'] = $can_use_quota;
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     $user_statics = sys_user_status($deal['user_id'], true);
     $root['user_statics'] = $user_statics;
     //借款笔数
     $root['load_list'] = $load_list;
     $root['credit_file'] = $credit_file;
     $root['u_info'] = $u_info;
     //工作认证是否过期
     $root['expire'] = user_info_expire($u_info);
     //留言
     $message_list = $GLOBALS['db']->getAll("SELECT a.title,a.content,a.create_time,a.rel_id,a.user_id,a.is_effect,b.user_name FROM " . DB_PREFIX . "message as a left join " . DB_PREFIX . "user as b on  a.user_id = b.id WHERE a.rel_id = " . $id);
     $root['message'] = $message_list;
     //seo
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $root['page_title'] = $seo_title;
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $root['page_keyword'] = $seo_keyword;
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $root['seo_description'] = $seo_description;
     $root['program_title'] = "详细信息";
     output($root);
 }
 function preview()
 {
     $deal['id'] = 'XXX';
     $deal_loan_type_list = load_auto_cache("deal_loan_type_list");
     if (intval($_REQUEST['quota']) == 1) {
         $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_quota_submit WHERE status=1 and user_id = " . $GLOBALS['user_info']['id'] . " ORDER BY id DESC");
         $type_id = intval($deal['type_id']);
         $deal['rate_foramt'] = number_format($deal['rate'], 2);
         $data['view_info'] = unserialize($deal['view_info']);
         if ($deal['cate_id'] > 0) {
             $deal['cate_info'] = $GLOBALS['db']->getRowCached("select id,name,brief,uname,icon from " . DB_PREFIX . "deal_cate where id = " . $deal['cate_id'] . " and is_effect = 1 and is_delete = 0");
         }
         $deal['repay_time'] = strim($_REQUEST['repay_time']);
         $deal['repay_time_type'] = 1;
     } else {
         $deal['name'] = strim($_REQUEST['borrowtitle']);
         $type_id = intval($_REQUEST['borrowtype']);
         $deal['repay_time_type'] = intval($_REQUEST['repaytime_type']);
         $deal['rate_foramt'] = number_format(strim($_REQUEST['apr']), 2);
         $deal['repay_time'] = strim($_REQUEST['repaytime']);
         $icon_type = strim($_REQUEST['imgtype']);
         $icon_type_arr = array('upload' => 1, 'userImg' => 2, 'systemImg' => 3);
         $data['icon_type'] = $icon_type_arr[$icon_type];
         switch ($data['icon_type']) {
             case 1:
                 $deal['icon'] = replace_public(strim($_REQUEST['icon']));
                 break;
             case 2:
                 $deal['icon'] = replace_public(get_user_avatar($GLOBALS['user_info']['id'], 'big'));
                 break;
             case 3:
                 $deal['icon'] = $GLOBALS['db']->getOneCached("SELECT icon FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . intval($_REQUEST['systemimgpath']));
         }
         $deal['description'] = replace_public(valid_str(bstrim($_REQUEST['borrowdesc'])));
         $user_view_info = $GLOBALS['user_info']['view_info'];
         $user_view_info = unserialize($user_view_info);
         $new_view_info_arr = array();
         for ($i = 1; $i <= intval($_REQUEST['file_upload_count']); $i++) {
             $img_info = array();
             $img = replace_public(strim($_REQUEST['file_' . $i]));
             if ($img != "") {
                 $img_info['name'] = strim($_REQUEST['file_name_' . $i]);
                 $img_info['img'] = $img;
                 $img_info['is_user'] = 1;
                 $user_view_info[] = $img_info;
                 $ss = $user_view_info;
                 end($ss);
                 $key = key($ss);
                 $new_view_info_arr[$key] = $img_info;
             }
         }
         $data['view_info'] = array();
         foreach ($_REQUEST['file_key'] as $k => $v) {
             if (isset($user_view_info[$v])) {
                 $data['view_info'][$v] = $user_view_info[$v];
             }
         }
         foreach ($new_view_info_arr as $k => $v) {
             $data['view_info'][$k] = $v;
         }
         if ($deal['cate_id'] > 0) {
             $deal['cate_info']['name'] = "借款预览标";
         }
     }
     $deal['borrow_amount'] = strim($_REQUEST['borrowamount']);
     $deal['borrow_amount_format'] = format_price($deal['borrow_amount'] / 10000) . "万";
     $GLOBALS['tmpl']->assign('view_info_list', $data['view_info']);
     unset($data['view_info']);
     foreach ($deal_loan_type_list as $k => $v) {
         if ($v['id'] == $type_id) {
             $deal['type_info'] = $v;
         }
     }
     $deal['min_loan_money'] = 50;
     $deal['need_money'] = $deal['borrow_amount_format'];
     //本息还款金额
     $deal['month_repay_money'] = format_price(pl_it_formula($deal['borrow_amount'], strim($deal['rate']) / 12 / 100, $deal['repay_time']));
     if ($deal['agency_id'] > 0) {
         $deal['agency_info'] = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "deal_agency where id = " . $deal['agency_id'] . " and is_effect = 1");
     }
     $deal['progress_point'] = 0;
     $deal['buy_count'] = 0;
     $deal['voffice'] = 1;
     $deal['vjobtype'] = 1;
     $deal['is_delete'] = 2;
     $u_info = get_user("*", $GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("u_info", $u_info);
     $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $credit_file = get_user_credit_file($GLOBALS['user_info']['id'], $u_info);
     $GLOBALS['tmpl']->assign("credit_file", $credit_file);
     $user_statics = sys_user_status($GLOBALS['user_info']['id'], true);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     $GLOBALS['tmpl']->assign("page_title", $seo_title);
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ",");
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $GLOBALS['tmpl']->assign("seo_description", $seo_description . ",");
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->display("page/deal.html");
 }
 public function detail()
 {
     /*if(!$GLOBALS['user_info']){
     			
     			app_redirect(url("index","user#login")); 
     		}*/
     set_gopreview();
     $id = intval($_REQUEST['id']);
     $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load_transfer WHERE id=" . $id);
     if ($deal_id == 0) {
         echo "不存在的债权";
         die;
     }
     $deal = get_deal($deal_id);
     syn_transfer_status($id);
     $deal['yq_count'] = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay = 1 and deal_id=" . $deal_id . " AND status >= 2");
     $GLOBALS['tmpl']->assign('deal', $deal);
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $deal_id);
     $u_info = get_user("*", $deal['user_id']);
     if ($deal['view_info'] != "") {
         $view_info_list = unserialize($deal['view_info']);
         $GLOBALS['tmpl']->assign('view_info_list', $view_info_list);
     }
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     if ($GLOBALS['user_info']) {
         if ($u_info['user_type'] == 1) {
             $company = $GLOBALS['db']->getRowCached("SELECT * FROM " . DB_PREFIX . "user_company WHERE user_id=" . $u_info['id']);
         }
         if ($deal['deal_status'] >= 4) {
             //还款列表
             $loan_repay_list = get_deal_load_list($deal);
             $GLOBALS['tmpl']->assign("loan_repay_list", $loan_repay_list);
             if ($loan_repay_list) {
                 $temp_self_money_list = $GLOBALS['db']->getAllCached("SELECT sum(self_money) as total_money,u_key FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay=1 AND deal_id=" . $id . " group by u_key ");
                 $self_money_list = array();
                 foreach ($temp_self_money_list as $k => $v) {
                     $self_money_list[$v['u_key']] = $v['total_money'];
                 }
                 foreach ($load_list as $k => $v) {
                     $load_list[$k]['remain_money'] = $v['money'] - $self_money_list[$k];
                     if ($load_list[$k]['remain_money'] <= 0) {
                         $load_list[$k]['remain_money'] = 0;
                         $load_list[$k]['status'] = 1;
                     }
                 }
             }
         }
         $user_statics = sys_user_status($deal['user_id'], true);
         $GLOBALS['tmpl']->assign("user_statics", $user_statics);
         $GLOBALS['tmpl']->assign("company", $company);
     }
     $GLOBALS['tmpl']->assign("load_list", $load_list);
     $GLOBALS['tmpl']->assign("credit_file", $credit_file);
     $GLOBALS['tmpl']->assign("u_info", $u_info);
     //工作认证是否过期
     $GLOBALS['tmpl']->assign('expire', user_info_expire($u_info));
     //留言
     require APP_ROOT_PATH . 'app/Lib/message.php';
     require APP_ROOT_PATH . 'app/Lib/page.php';
     $rel_table = 'transfer';
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "'");
     $condition = "rel_table = '" . $rel_table . "' and rel_id = " . $id;
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
     } else {
         if ($message_type['is_effect'] == 0) {
             $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
         }
     }
     //message_form 变量输出
     $GLOBALS['tmpl']->assign('rel_id', $id);
     $GLOBALS['tmpl']->assign('rel_table', $rel_table);
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
     $msg_condition = $condition . " AND is_effect = 1 ";
     $message = get_message_list($limit, $msg_condition);
     $page = new Page($message['count'], app_conf("PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     foreach ($message['list'] as $k => $v) {
         $msg_sub = get_message_list("", "pid=" . $v['id'], false);
         $message['list'][$k]["sub"] = $msg_sub["list"];
     }
     $GLOBALS['tmpl']->assign("message_list", $message['list']);
     //==================================================
     $condition = ' AND dlt.id=' . $id . ' AND d.deal_status >= 4 and d.is_effect=1 and d.is_delete=0  and d.repay_time_type =1 and  d.publish_wait=0 ';
     $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
     $transfer = get_transfer($union_sql, $condition);
     $GLOBALS['tmpl']->assign('transfer', $transfer);
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['TRANSFER'] . " - " . $seo_title);
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $GLOBALS['tmpl']->assign("page_keyword", $GLOBALS['lang']['TRANSFER'] . "," . $seo_keyword . ",");
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $GLOBALS['tmpl']->assign("seo_description", $GLOBALS['lang']['TRANSFER'] . "," . $seo_description . ",");
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->display("page/transfer.html");
 }
 public function index()
 {
     $this->init_user();
     $user_info = $this->user_data;
     $user_info["total_money"] = number_format(floatval($user_info["money"]) + floatval($user_info["lock_money"]), 2);
     $user_info["lock_money"] = number_format(floatval($user_info["lock_money"]), 2);
     $ajax = intval($_REQUEST['ajax']);
     if ($ajax == 0) {
         $this->init_main();
     }
     $user_id = intval($GLOBALS['user_info']['id']);
     /***统计***/
     $user_statics = sys_user_status($GLOBALS['user_info']['id'], true);
     $user_statics["load_earnings"] = number_format(floatval($user_statics["load_earnings"]), 2);
     //$user_info["load_wait_repay_amount"] = 0;
     $user_statics["need_repay_amount"] = floatval($user_statics["need_repay_amount"]) + floatval($user_statics["need_manage_amount"]);
     //待收本金
     $user_statics["load_wait_self_money"] = number_format(floatval($user_statics["load_wait_self_money"]), 2);
     //待收收益
     $user_statics["load_wait_earnings"] = number_format(floatval($user_statics["load_wait_earnings"]), 2);
     $user_statics["ltotal_money"] = number_format(floatval($user_statics["load_wait_repay_money"]) + floatval($user_statics["load_repay_money"]), 2);
     $user_statics["money"] = number_format(floatval($user_info["money"]), 2);
     $user_statics["load_repay_money"] = number_format(floatval($user_statics["load_repay_money"]), 2);
     $user_statics["load_wait_repay_money"] = number_format(floatval($user_statics["load_wait_repay_money"]), 2);
     $user_statics["need_repay_amount"] = number_format(floatval($user_statics["need_repay_amount"]), 2);
     //投标中的
     $invest_sql = "SELECT count(*) as l_count,sum(money) as l_money FROM " . DB_PREFIX . "deal_load dl LEFT JOIN " . DB_PREFIX . "deal d ON dl.deal_id = d.id WHERE dl.user_id=" . $user_id . " and d.deal_status in(1,2) group by dl.user_id";
     $invest = $GLOBALS['db']->getRowCached($invest_sql);
     $user_statics["invest_count"] = $invest["l_count"];
     $user_statics["invest_money"] = number_format($invest["l_money"], 2);
     $user_statics["total_money"] = number_format(round($invest_sql["money"], 2) + round($user_statics["load_wait_repay_money"], 2) + round($user_statics["load_repay_money"], 2), 2);
     //本月
     $this_wait_deals = $this->get_loadlist($user_id, " AND DATE_FORMAT(FROM_UNIXTIME(repay_time),'%Y年%m月')  = date_format(curdate(),'%Y年%m月')");
     $user_statics["this_month_money"] = 0.0;
     $user_statics["this_month_count"] = 0;
     foreach ($this_wait_deals as $k => $v) {
         $user_statics["this_month_money"] += $v["repay_money"];
         $user_statics["this_month_count"]++;
     }
     //下月
     $next_wait_deals = $this->get_loadlist($user_id, " AND DATE_FORMAT(FROM_UNIXTIME(repay_time),'%Y年%m月')  = date_format(DATE_ADD(curdate(), INTERVAL 1 MONTH),'%Y年%m月')");
     $user_statics["next_month_money"] = 0.0;
     $user_statics["next_month_count"] = 0;
     foreach ($next_wait_deals as $k => $v) {
         $user_statics["next_month_money"] += $v["repay_money"];
         $user_statics["next_month_count"]++;
     }
     //本年
     $year_wait_deals = $this->get_loadlist($user_id, " AND DATE_FORMAT(FROM_UNIXTIME(repay_time),'%Y')  =  DATE_FORMAT(curdate(),'%Y')");
     $user_statics["year_money"] = 0.0;
     $user_statics["year_count"] = 0;
     foreach ($year_wait_deals as $k => $v) {
         $user_statics["year_money"] += $v["repay_money"];
         $user_statics["year_count"]++;
     }
     //$user_statics["total_invest_money"] = number_format($user_statics["this_month_money"]+$user_statics["next_month_money"]+$user_statics["year_money"],2);
     $user_statics["year_money"] = number_format(round($user_statics["year_money"], 2), 2);
     $user_statics["this_month_money"] = number_format(round($user_statics["this_month_money"], 2), 2);
     $user_statics["next_month_money"] = number_format(round($user_statics["next_month_money"], 2), 2);
     //总计
     $all_wait_deals = $this->get_loadlist($user_id, '');
     $user_statics["total_invest_money"] = 0.0;
     $user_statics["total_invest_count"] = 0;
     foreach ($all_wait_deals as $k => $v) {
         $user_statics["total_invest_money"] += $v["repay_money"];
         $user_statics["total_invest_count"]++;
     }
     $user_statics["total_invest_money"] = number_format($user_statics["total_invest_money"], 2);
     //$user_statics["total_invest_count"] = $user_statics["this_month_count"]+$user_statics["next_month_count"]+$user_statics["year_count"];
     $load_list_sql = "SELECT * FROM " . DB_PREFIX . "deal_load WHERE user_id = " . $GLOBALS['user_info']['id'] . " ORDER BY id DESC limit 0,4";
     //最近交易
     $load_list = $GLOBALS['db']->getAllCached($load_list_sql);
     $GLOBALS['tmpl']->assign("load_list", $load_list);
     //$user_statics["total_money"] =  number_format(floatval($user_info["load_wait_repay_money"]) - floatval($user_info["need_repay_amount"]));
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     //最近六个月投资记录
     $month = array();
     //select month(FROM_UNIXTIME(time)) from table_name group by month(FROM_UNIXTIME(time))
     $result['lend'] = $GLOBALS['db']->getAllCached("SELECT count(*) as l_count,sum(money) as l_money,DATE_FORMAT(FROM_UNIXTIME(dl.create_time),'%Y年%m月') as l_month FROM " . DB_PREFIX . "deal_load dl LEFT JOIN " . DB_PREFIX . "deal d ON dl.deal_id = d.id WHERE dl.is_repay = 0 AND dl.user_id=" . $user_id . " and d.deal_status in(1,2,4,5) group by DATE_FORMAT(FROM_UNIXTIME(dl.create_time),'%Y年%m月')");
     $months[0]["time"] = to_date(next_replay_month(TIME_UTC, -5), 'Y年m月');
     $months[1]["time"] = to_date(next_replay_month(TIME_UTC, -4), 'Y年m月');
     $months[2]["time"] = to_date(next_replay_month(TIME_UTC, -3), 'Y年m月');
     $months[3]["time"] = to_date(next_replay_month(TIME_UTC, -2), 'Y年m月');
     $months[4]["time"] = to_date(next_replay_month(TIME_UTC, -1), 'Y年m月');
     $months[5]["time"] = to_date(TIME_UTC, 'Y年m月');
     $max_money = 100;
     foreach ($result['lend'] as $k => $v) {
         if (round($max_money) < round($v["l_money"])) {
             $max_money = $v["l_money"];
         }
         foreach ($months as $kk => $vv) {
             if ($vv["time"] == $v["l_month"]) {
                 $months[$kk]["l_money"] = $v["l_money"];
                 $months[$kk]["show_money"] = number_format(floatval($v["l_money"]), 2);
             }
         }
     }
     foreach ($months as $k => $v) {
         $months[$k]["height"] = $v["l_money"] / $max_money * 325;
         $months[$k]["bottom"] = $v["l_money"] / $max_money * 325 + 35;
     }
     $GLOBALS['tmpl']->assign("max_money", $max_money);
     $GLOBALS['tmpl']->assign("months", $months);
     /***右侧统计结束***/
     $GLOBALS['tmpl']->assign("user_data", $user_info);
     if ($ajax == 0) {
         $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_CENTER_INDEX']);
         $GLOBALS['tmpl']->assign("post_title", $GLOBALS['lang']['UC_CENTER_INDEX']);
         $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_center_index.html");
         $GLOBALS['tmpl']->display("page/uc.html");
     } else {
         header("Content-Type:text/html; charset=utf-8");
         echo $GLOBALS['tmpl']->fetch("inc/topic_col_list.html");
     }
 }
Example #13
0
function getUCInrepayRepayBorrowMoney($id)
{
    $id = intval($id);
    $root = array();
    $root["status"] = 0;
    //0:出错;1:正确;
    if ($id == 0) {
        $root["show_err"] = "操作失败!";
        return $root;
    }
    $deal = get_deal($id);
    if (!$deal) {
        $root["show_err"] = "借款不存在!";
        return $root;
    }
    if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
        $root["show_err"] = "不属于你的借款!";
        return $root;
    }
    if ($deal['deal_status'] != 4) {
        $root["show_err"] = "借款不是还款状态!";
        return $root;
    }
    $time = TIME_UTC;
    $impose_money = 0;
    //还了几期了
    $has_repay_count = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id);
    //计算罚息
    $loan_list = get_deal_load_list($deal);
    $k_repay_time = 0;
    foreach ($loan_list as $k => $v) {
        if ($k > $has_repay_count - 1) {
            if ($k_repay_time == 0) {
                $k_repay_time = $v['repay_day'];
            }
            $impose_money += $v['impose_money'];
        }
    }
    if ($impose_money > 0) {
        $root["show_err"] = "请将逾期未还的借款还完才可以进行此操作!";
        return $root;
    }
    //月利率
    $rate = $deal['rate'] / 12 / 100;
    $impose_money = 0;
    //计算剩多少本金
    $benjin = $deal['borrow_amount'];
    if ($deal['loantype'] == 0) {
        //等额本息的时候才通过公式计算剩余多少本金
        for ($i = 1; $i <= $has_repay_count; $i++) {
            $benjin = $benjin - ($deal['month_repay_money'] - $benjin * $rate);
        }
        $impose_money = ($benjin - $deal['month_repay_money'] + $benjin * $rate) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $benjin * $rate;
    } elseif ($deal['loantype'] == 1) {
        //每月付息,到期还本
        $impose_money = $benjin * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $deal['month_repay_money'];
    } elseif ($deal['loantype'] == 2) {
        //到期还本息
        $impose_money += $benjin * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $benjin * $rate;
        //计算应缴多罚息 多少管理费
        $now_ym = to_date($time, "Y-m");
        $i = 0;
        foreach ($loan_list as $k => $v) {
            ++$i;
            if ($now_ym == to_date($v['repay_day'], "Y-m")) {
                $deal['month_manage_money'] = $benjin * trim(app_conf('MANAGE_FEE')) / 100 * $i;
            }
        }
    }
    $GLOBALS['tmpl']->assign("impose_money", $impose_money);
    $GLOBALS['tmpl']->assign("total_repay_money", $total_repay_money);
    $true_total_repay_money = $total_repay_money + $impose_money + $deal['month_manage_money'];
    if ($total_repay_money + $impose_money + $deal['month_manage_money'] > $GLOBALS['user_info']['money']) {
        $root["show_err"] = "对不起,您的余额不足!";
        return $root;
    }
    //录入到提前还款列表
    $inrepay_data['deal_id'] = $id;
    $inrepay_data['user_id'] = $GLOBALS['user_info']['id'];
    $inrepay_data['repay_money'] = round($total_repay_money);
    $inrepay_data['impose_money'] = round($impose_money, 2);
    $inrepay_data['manage_money'] = round($deal['month_manage_money']);
    $inrepay_data['repay_time'] = $k_repay_time;
    $inrepay_data['true_repay_time'] = $time;
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_inrepay_repay", $inrepay_data, "INSERT");
    $inrepay_id = $GLOBALS['db']->insert_id();
    if ($inrepay_id == 0) {
        $root["show_err"] = "对不起,数据处理失败,请联系客服!";
        return $root;
    }
    //录入还款列表
    $after_time = $GLOBALS['db']->getOne("SELECT repay_time FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id . " ORDER BY repay_time DESC");
    if ($after_time == "") {
        $after_time = $deal['repay_start_time'];
    }
    $temp_ids[] = array();
    for ($i = 0; $i < $deal['repay_time'] - $has_repay_count; $i++) {
        $repay_data['id'] = $v['repay_id'];
        $repay_data['has_repay'] = 1;
        $repay_data['deal_id'] = $id;
        $repay_data['user_id'] = $GLOBALS['user_info']['id'];
        $repay_data['repay_time'] = $after_time = next_replay_month($after_time);
        $repay_data['true_repay_time'] = $time;
        $repay_data['status'] = 0;
        if ($i == 0) {
            $repay_data['repay_money'] = round($deal['month_repay_money'], 2);
            $repay_data['impose_money'] = round($impose_money, 2);
            $repay_data['manage_money'] = round($deal['month_manage_money']);
        } else {
            if ($deal['loantype'] == 0) {
                //等额本息
                $repay_data['repay_money'] = $benjin / ($deal['repay_time'] - $has_repay_count);
            } elseif ($deal['loantype'] == 1) {
                //每月还息
                if ($i + 1 == $deal['repay_time'] - $has_repay_count) {
                    $repay_data['repay_money'] = $benjin;
                } else {
                    $repay_data['repay_money'] = 0;
                }
            } elseif ($deal['loantype'] == 2) {
                //每月还息
                if ($i + 1 == $deal['repay_time'] - $has_repay_count) {
                    $repay_data['repay_money'] = $benjin;
                } else {
                    $repay_data['repay_money'] = 0;
                }
            }
            $repay_data['impose_money'] = 0;
            $repay_data['manage_money'] = 0;
        }
        $deal_repay_id = $v['repay_id'];
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", "id=" . $deal_repay_id);
        //假如出错 删除掉原来的以插入的数据
        if ($GLOBALS['db']->affected_rows() == 0) {
            if ($temp_ids) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay set has_repay = 0 WHERE id in (" . implode(",", $temp_ids) . ")");
            }
            $root["show_err"] = "对不起,处理数据失败请联系客服!";
            return $root;
        } else {
            $temp_ids[] = $deal_repay_id;
        }
    }
    //更新用户账户资金记录
    require APP_ROOT_PATH . 'system/libs/user.php';
    modify_account(array("money" => -round($impose_money)), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",提前还款违约金");
    modify_account(array("money" => -round($total_repay_money + $deal['month_manage_money'], 2)), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",提前还款");
    //用户获得额度
    modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",还清借款获得额度");
    $content = "您好,您在" . app_conf("SHOP_TITLE") . "的借款 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”成功提前还款" . number_format($true_total_repay_money, 2) . "元,";
    $content .= "其中违约金为:" . number_format($impose_money, 2) . "元,本笔借款已还款完毕!";
    send_user_msg("", $content, 0, $GLOBALS['user_info']['id'], $time, 0, true, 8);
    //短信通知
    if (app_conf("SMS_ON") == 1 && app_conf('SMS_SEND_REPAY') == 1) {
        $sms_content = "尊敬的" . app_conf("SHOP_TITLE") . "用户" . $GLOBALS['user_info']['user_name'] . ",您成功提前还款" . number_format($true_total_repay_money, 2) . "元,其中违约金为:" . number_format($impose_money, 2) . "元,感谢您的关注和支持。【" . app_conf("SHOP_TITLE") . "】";
        $msg_data['dest'] = $GLOBALS['user_info']['mobile'];
        $msg_data['send_type'] = 0;
        $msg_data['title'] = $msg_data['content'] = addslashes($sms_content);
        $msg_data['send_time'] = 0;
        $msg_data['is_send'] = 0;
        $msg_data['create_time'] = $time;
        $msg_data['user_id'] = $GLOBALS['user_info']['id'];
        $msg_data['is_html'] = 0;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    //判断获取的信用是否超过限制
    if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_log WHERE (log_info='标:" . $deal['id'] . ",还清借款' or log_info='还清借款') AND user_id=" . $GLOBALS['user_info']['id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
        //获取上一次还款时间
        $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(log_time) FROM " . DB_PREFIX . "user_log WHERE (log_info='标:" . $deal['id'] . ",还清借款' or log_info='还清借款') AND user_id=" . $GLOBALS['user_info']['id']);
        $day = ceil(($time - $befor_repay_time) / 24 / 3600);
        //当天数大于等于间隔时间 获得信用
        if ($day >= (int) trim(app_conf('REPAY_SUCCESS_DAY'))) {
            modify_account(array("point" => trim(app_conf('REPAY_SUCCESS_POINT'))), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",还清借款");
        }
        //用户获得额度
        modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",还清借款获得额度");
    }
    syn_deal_status($id);
    sys_user_status($GLOBALS['user_info']['id'], false, true);
    //用户回款
    $user_loan_list = get_deal_user_load_list($deal);
    foreach ($user_loan_list as $lllk => $lllv) {
        foreach ($lllv as $kk => $vv) {
            //本金
            $user_self_money = 0;
            //本息
            $user_repay_money = 0;
            //违约金
            $user_impose_money = 0;
            //管理费
            $user_manage_money = 0;
            $in_user_id = $vv['user_id'];
            //判断是否转让了债权
            if ($vv['t_user_id'] > 0) {
                $in_user_id = $vv['t_user_id'];
                $loan_user_info['user_name'] = $vv['user_name'];
                $loan_user_info['t_email'] = $vv['email'];
                $loan_user_info['t_mobile'] = $vv['mobile'];
            } else {
                $loan_user_info['user_name'] = $vv['t_user_name'];
                $loan_user_info['t_email'] = $vv['t_email'];
                $loan_user_info['t_mobile'] = $vv['t_mobile'];
            }
            //借入者已还款,但是没打款到借出用户中心
            if ($vv['has_repay'] == 0) {
                $user_load_data['deal_id'] = $v['deal_id'];
                $user_load_data['user_id'] = $v['user_id'];
                $user_load_data['repay_time'] = $vv['repay_day'];
                $user_load_data['true_repay_time'] = $time;
                $user_load_data['is_site_repay'] = 0;
                $user_load_data['status'] = 0;
                //小于提前还款按正常还款
                if ($vv['repay_day'] < $k_repay_time) {
                    //等额本息的时候才通过公式计算剩余多少本金
                    $user_load_data['self_money'] = $vv['self_money'];
                    $user_load_data['repay_money'] = $vv['month_repay_money'];
                    $user_load_data['manage_money'] = $vv['month_manage_money'];
                    $user_load_data['impose_money'] = $vv['impose_money'];
                    if ($vv['status'] > 0) {
                        $user_load_data['status'] = $vv['status'] - 1;
                    }
                    $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”成功还款" . number_format($vv['month_repay_money'] + $vv['impose_money'], 2) . "元,";
                    $unext_loan = $user_loan_list[$kk + 1];
                    if ($unext_loan) {
                        $content .= "本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需要本息" . number_format($unext_loan['month_repay_money'], 2) . "元。";
                    }
                    $user_self_money += (double) $user_load_data['self_money'];
                    if ($user_load_data['impose_money'] != 0 || $user_load_data['manage_money'] != 0 || $user_load_data['repay_money'] != 0) {
                        //更新用户账户资金记录
                        modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",逾期罚息");
                        modify_account(array("money" => -$user_load_data['manage_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",投标管理费");
                        modify_account(array("money" => $user_load_data['repay_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",回报本息");
                        $msg_conf = get_user_msg_conf($in_user_id);
                        //站内信
                        if ($msg_conf['sms_bidrepaid'] == 1) {
                            send_user_msg("", $content, 0, $in_user_id, $time, 0, true, 9);
                        }
                        //邮件
                        if ($msg_conf['mail_bidrepaid'] == 1) {
                        }
                    }
                } else {
                    if ($vv['repay_day'] == $k_repay_time) {
                        if ($deal['loantype'] == 0) {
                            //等额本息的时候才通过公式计算剩余多少本金
                            $user_load_data['self_money'] = $vv['month_repay_money'] - get_benjin($kk, $deal['repay_time'], $v['money'], $vv['month_repay_money'], $deal['rate']) * $deal['rate'] / 12 / 100;
                            $user_load_data['impose_money'] = ($user_load_data['self_money'] - $vv['month_repay_money'] + $user_load_data['self_money'] * $v['rate']) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
                        } elseif ($deal['loantype'] == 1) {
                            //每月还息,到期还本
                            $user_load_data['self_money'] = $vv['money'];
                            $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                        } elseif ($deal['loantype'] == 2) {
                            //每月还息,到期还本
                            $user_load_data['self_money'] = $vv['money'];
                            $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                        }
                        $user_self_money += (double) $user_load_data['self_money'];
                        if ($deal['loantype'] == 0) {
                            //等额本息的时候才通过公式计算剩余多少本金
                            $user_load_data['repay_money'] = $vv['month_repay_money'];
                            $user_load_data['manage_money'] = $vv['month_manage_money'];
                        } elseif ($deal['loantype'] == 1) {
                            $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                            $user_load_data['manage_money'] = $vv['month_manage_money'];
                        } elseif ($deal['loantype'] == 2) {
                            $user_load_data['repay_money'] = $vv['money'];
                            $user_load_data['manage_money'] = $vv['money'] * floatval(trim($deal['user_loan_manage_fee'])) / 100 * ($kk + 1);
                        }
                        $user_repay_k = $kk + 1;
                    } else {
                        //其他月份
                        //等额本息
                        if ($deal['loantype'] == 0) {
                            if ($user_self_money == 0) {
                                $user_load_data['self_money'] = $vv['month_repay_money'] - get_benjin($kk, $deal['repay_time'], $v['money'], $vv['month_repay_money'], $deal['rate']) * $deal['rate'] / 12 / 100;
                                $user_load_data['impose_money'] = ($user_load_data['self_money'] - $vv['month_repay_money'] + $user_load_data['self_money'] * $v['rate']) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = ($v['money'] - $user_self_money) / ($v['repay_time'] - $user_repay_k);
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        } elseif ($deal['loantype'] == 1) {
                            if ($user_self_money == 0) {
                                $user_self_money = $user_load_data['self_money'] = $v['money'];
                                $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                                $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                                $user_load_data['manage_money'] = $vv['month_manage_money'];
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = 0;
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        } elseif ($deal['loantype'] == 2) {
                            if ($user_self_money == 0) {
                                $user_self_money = $user_load_data['self_money'] = $v['money'];
                                $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                                $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                                $user_load_data['manage_money'] = $vv['money'] * floatval(trim($deal['user_loan_manage_fee'])) / 100 * ($kk + 1);
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = 0;
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        }
                    }
                    $user_repay_money += (double) $user_load_data['repay_money'];
                    $user_impose_money += (double) $user_load_data['impose_money'];
                    $user_manage_money += (double) $user_load_data['manage_money'];
                    $user_load_data['l_key'] = $kk;
                    $user_load_data['u_key'] = $k;
                }
                $user_load_data['has_repay'] = 1;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "INSERT");
            }
            if ($user_repay_money > 0) {
                $all_repay_money = number_format($GLOBALS['db']->getOne("SELECT (sum(repay_money)-sum(self_money) + sum(impose_money)) as shouyi FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
                $all_impose_money = number_format($GLOBALS['db']->getOne("SELECT sum(impose_money) FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
                $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”提前还款,";
                $content .= "本次投标共获得收益:" . $all_repay_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!";
                //更新用户账户资金记录
                modify_account(array("money" => $user_impose_money), $in_user_id, "标:" . $deal['id'] . ",违约金");
                modify_account(array("money" => -$user_manage_money), $in_user_id, "标:" . $deal['id'] . ",投标管理费");
                modify_account(array("money" => $user_repay_money), $in_user_id, "标:" . $deal['id'] . ",回报本息");
                $msg_conf = get_user_msg_conf($in_user_id);
                //短信通知
                if (app_conf("SMS_ON") == 1 && app_conf('SMS_REPAY_TOUSER_ON') == 1) {
                    $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_SMS'");
                    $tmpl_content = $tmpl['content'];
                    $notice['user_name'] = $loan_user_info['user_name'];
                    $notice['deal_name'] = $deal['sub_name'];
                    $notice['deal_url'] = $deal['url'];
                    $notice['site_name'] = app_conf("SHOP_TITLE");
                    $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                    $notice['all_repay_money'] = $all_repay_money;
                    $notice['impose_money'] = $all_impose_money;
                    $GLOBALS['tmpl']->assign("notice", $notice);
                    $sms_content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                    $msg_data['dest'] = $loan_user_info['mobile'];
                    $msg_data['send_type'] = 0;
                    $msg_data['title'] = $msg_data['content'] = addslashes($sms_content);
                    $msg_data['send_time'] = 0;
                    $msg_data['is_send'] = 0;
                    $msg_data['create_time'] = $time;
                    $msg_data['user_id'] = $in_user_id;
                    $msg_data['is_html'] = 0;
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                    //插入
                }
                //站内信
                if ($msg_conf['sms_bidrepaid'] == 1) {
                    send_user_msg("", $content, 0, $in_user_id, $time, 0, true, 9);
                }
                //邮件
                if ($msg_conf['mail_bidrepaid'] == 1 && app_conf('MAIL_ON') == 1) {
                    $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'");
                    $tmpl_content = $tmpl['content'];
                    $notice['user_name'] = $loan_user_info['user_name'];
                    $notice['deal_name'] = $deal['sub_name'];
                    $notice['deal_url'] = $deal['url'];
                    $notice['site_name'] = app_conf("SHOP_TITLE");
                    $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                    $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                    $notice['msg_cof_setting_url'] = SITE_DOMAIN . url("index", "uc_msg#setting");
                    $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                    $notice['all_repay_money'] = $all_repay_money;
                    $notice['impose_money'] = $all_impose_money;
                    $GLOBALS['tmpl']->assign("notice", $notice);
                    $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                    $msg_data['dest'] = $loan_user_info['email'];
                    $msg_data['send_type'] = 1;
                    $msg_data['title'] = "“" . $deal['name'] . "”回款通知";
                    $msg_data['content'] = addslashes($msg);
                    $msg_data['send_time'] = 0;
                    $msg_data['is_send'] = 0;
                    $msg_data['create_time'] = $time;
                    $msg_data['user_id'] = $in_user_id;
                    $msg_data['is_html'] = $tmpl['is_html'];
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                    //插入
                }
            }
        }
    }
    $root["status"] = 1;
    //0:出错;1:正确;
    $root["show_err"] = "操作成功!";
    return $root;
}
Example #14
0
/**
 * 更新 用户回款 计划数据
 * @param unknown_type $deal_id
 * @param unknown_type $deal_repay_id
 */
function syn_deal_repay_status($deal_id, $deal_repay_id)
{
    //has_repay 0未收到还款,1已收到还款
    $deal_id = intval($deal_id);
    $deal_repay_id = intval($deal_repay_id);
    $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal WHERE id=" . $deal_id);
    $deal['url'] = url("index", "deal", array("id" => $deal['id']));
    $deal["user"] = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "user WHERE id=" . $deal['user_id']);
    //未还款记录数
    $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 0 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
    $has_repay_0 = $GLOBALS['db']->getOne($sql);
    //已经还款记录数
    $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 1 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
    $has_repay_1 = $GLOBALS['db']->getOne($sql);
    //第几期
    $kk = $GLOBALS['db']->getOne("select l_key from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id);
    //has_repay 0未还,1已还 2部分还款
    if ($has_repay_0 == 0 && $has_repay_1 == 0 || $has_repay_0 == 0 && $has_repay_1 > 0) {
        $deal_rs_sql = "select sum(true_interest_money) as total_true_interest_money," . "sum(true_self_money) as total_true_self_money," . "sum(true_repay_money) as total_true_repay_money," . "sum(true_repay_manage_money) as total_true_repay_manage_money," . "sum(repay_manage_impose_money) as total_repay_manage_impose_money, " . "sum(impose_money) as total_impose_money " . "from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
        $deal_rs = $GLOBALS['db']->getRow($deal_rs_sql);
        $last_Rs = $GLOBALS['db']->getRow("SELECT `status`,`true_repay_time`,`repay_time` from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id . " ORDER BY `true_repay_time` DESC");
        $deal_repay_data['true_repay_money'] = $deal_rs['total_true_repay_money'];
        $deal_repay_data['true_manage_money'] = $deal_rs['total_true_repay_manage_money'];
        $deal_repay_data['manage_impose_money'] = $deal_rs['total_repay_manage_impose_money'];
        $deal_repay_data['true_self_repay'] = $deal_rs['total_true_self_money'];
        $deal_repay_data['impose_money'] = $deal_rs['total_impose_money'];
        $deal_repay_data['true_interest_money'] = $deal_rs['total_true_interest_money'];
        $deal_repay_data['true_repay_time'] = $last_Rs['true_repay_time'];
        $deal_repay_data['true_repay_date'] = to_date($last_Rs['true_repay_time']);
        $deal_repay_data['status'] = $last_Rs['status'];
        $deal_repay_data['has_repay'] = 1;
        //返佣金额
        $rebate_rs = get_rebate_fee($deal['user_id'], "borrow");
        $deal_repay_data['true_manage_money_rebate'] = floatval($deal_repay_data['true_manage_money']) * floatval($rebate_rs['rebate']) / 100;
        $true_manage_money_rebate = $deal_repay_data['true_manage_money'] * floatval($rebate_rs['rebate']) / 100;
        //借款者返佣
        if ($true_manage_money_rebate != 0) {
            /*ok*/
            $reback_memo = sprintf($GLOBALS['lang']["BORROW_REBATE_LOG"], $deal["url"], $deal["name"], $deal["user"]["user_name"], intval($kk) + 1);
            reback_rebate_money($deal['user_id'], $true_manage_money_rebate, "borrow", $reback_memo);
        }
        require_once APP_ROOT_PATH . "system/libs/user.php";
        if ($last_Rs['status'] > 1) {
            $impose_day = ceil(($last_Rs['true_repay_time'] - $last_Rs['repay_time'] + 24 * 3600 - 1) / 24 / 3600);
            //VIP降级-逾期还款
            $type = 2;
            $type_info = 5;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
            if ($impose_day < app_conf('YZ_IMPSE_DAY')) {
                modify_account(array("point" => trim(app_conf('IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,逾期还款", 11);
                $repay_update_data['status'] = 2;
            } else {
                modify_account(array("point" => trim(app_conf('YZ_IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,严重逾期", 11);
                $repay_update_data['status'] = 3;
            }
        } elseif ($last_Rs['status'] == 1) {
            //VIP升级 -正常还款
            $type = 1;
            $type_info = 3;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
        } elseif ($last_Rs['status'] == 0) {
            //VIP升级 -提前还款
            $type = 1;
            $type_info = 4;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
        }
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $deal_repay_data, "UPDATE", "id = " . $deal_repay_id);
        $last_repay_key = $kk;
        //判断本借款是否还款完毕
        if ($GLOBALS['db']->getOne("SELECT count(*)  FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and l_key=" . $last_repay_key . " AND has_repay <> 1 ") == 0) {
            //全部还完
            if ($GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and has_repay=0 ") == 0) {
                //判断获取的信用是否超过限制
                if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_point_log WHERE  `type`=6 AND user_id=" . $deal['user_id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
                    //获取上一次还款时间
                    $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(create_time) FROM " . DB_PREFIX . "user_point_log WHERE  `type`=6 AND user_id=" . $deal['user_id']);
                    $day = ceil(($last_Rs['true_repay_time'] - $befor_repay_time) / 24 / 3600);
                    //当天数大于等于间隔时间 获得信用
                    if ($day >= (int) trim(app_conf('REPAY_SUCCESS_DAY'))) {
                        modify_account(array("point" => trim(app_conf('REPAY_SUCCESS_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款", 4);
                    }
                }
                //用户获得额度
                modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款获得额度", 4);
            }
        }
        sys_user_status(intval($GLOBALS['user_info']['id']), false, true);
        syn_deal_status($deal_id);
        syn_transfer_status(0, $deal_id);
    } else {
        if ($has_repay_0 > 0 && $has_repay_1 == 0) {
            $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 0 where id = " . $deal_repay_id;
        } else {
            $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 2 where id = " . $deal_repay_id;
        }
    }
    $GLOBALS['db']->query($sql);
}
function getUCInrepayRepayBorrowMoney($id)
{
    $id = intval($id);
    $root = array();
    $root["status"] = 0;
    //0:出错;1:正确;
    if ($id == 0) {
        $root["show_err"] = "操作失败!";
        return $root;
    }
    $deal = get_deal($id);
    if (!$deal) {
        $root["show_err"] = "借款不存在!";
        return $root;
    }
    if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
        $root["show_err"] = "不属于你的借款!";
        return $root;
    }
    if ($deal['deal_status'] != 4) {
        $root["show_err"] = "借款不是还款状态!";
        return $root;
    }
    $time = TIME_UTC;
    $impose_money = 0;
    //是否有部分还款的
    $repay_count_ing = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay=2 and deal_id=" . $id);
    if ($repay_count_ing) {
        $root["show_err"] = "请将部分还款的借款还完才可以进行此操作!";
        return $root;
    }
    //计算罚息
    $loan_list = get_deal_load_list($deal);
    $k_repay_key = -1;
    $k_repay_time = 0;
    foreach ($loan_list as $k => $v) {
        if ($v['has_repay'] == 0) {
            if ($k_repay_key == -1) {
                $k_repay_key = $v['l_key'];
                $k_repay_time = $v['repay_day'];
            }
            $impose_money += $v['impose_money'];
        }
    }
    if ($impose_money > 0) {
        $root["show_err"] = "请将逾期未还的借款还完才可以进行此操作!";
        return $root;
    }
    if ($deal['ips_bill_no'] != "") {
        $root["status"] = 2;
        $root["jump"] = APP_ROOT . '/index.php?ctl=collocation&act=RepaymentNewTrade&deal_id=' . $deal['id'] . '&l_key=all&from=' . $GLOBALS['request']['from'];
        $root['jump'] = str_replace("/mapi", "", SITE_DOMAIN . $root['jump']);
        return $root;
    }
    //还了几期了
    $has_repay_count = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay=1 and deal_id=" . $id);
    $loaninfo['deal'] = $deal;
    $loaninfo['loanlist'] = $loan_list;
    $inrepay_info = inrepay_repay($loaninfo, $has_repay_count);
    $true_repay_money = (double) $inrepay_info['true_repay_money'];
    $true_self_money = (double) $inrepay_info['true_self_money'];
    $impose_money = (double) $inrepay_info['impose_money'];
    $true_manage_money = (double) $inrepay_info['true_manage_money'];
    $true_total_repay_money = $true_repay_money + $impose_money + $true_manage_money;
    if ($true_total_repay_money > $GLOBALS['user_info']['money']) {
        $root["show_err"] = "对不起,您的余额不足!";
        return $root;
    }
    //录入到提前还款列表
    $inrepay_data['deal_id'] = $id;
    $inrepay_data['user_id'] = $GLOBALS['user_info']['id'];
    $inrepay_data['repay_money'] = $true_repay_money;
    $inrepay_data['self_money'] = $true_self_money;
    $inrepay_data['impose_money'] = $impose_money;
    $inrepay_data['manage_money'] = $true_manage_money;
    $inrepay_data['repay_time'] = $k_repay_time;
    $inrepay_data['true_repay_time'] = $time;
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_inrepay_repay", $inrepay_data, "INSERT");
    $inrepay_id = $GLOBALS['db']->insert_id();
    if ($inrepay_id == 0) {
        $root["show_err"] = "对不起,数据处理失败,请联系客服!";
        return $root;
    }
    //录入还款列表
    $wait_repay_list = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id . " and has_repay=0 ORDER BY l_key ASC");
    $temp_ids = array();
    foreach ($wait_repay_list as $k => $v) {
        $repay_data = array();
        $repay_data['has_repay'] = 1;
        $repay_data['true_repay_time'] = $time;
        $repay_data['true_repay_date'] = to_date($time);
        $repay_data['status'] = 0;
        if ($k_repay_key == $v['l_key']) {
            $repay_data['true_repay_money'] = $true_repay_money;
            $repay_data['impose_money'] = $impose_money;
            $repay_data['true_manage_money'] = $true_manage_money;
            $repay_data['true_self_money'] = $true_self_money;
            $repay_data['true_interest_money'] = $true_repay_money - $true_self_money;
        }
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", "id=" . $v['id']);
        //假如出错 删除掉原来的以插入的数据
        if ($GLOBALS['db']->affected_rows() == 0) {
            if (count($temp_ids) > 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay SET has_repay=0 WHERE id in " . implode(",", $temp_ids) . "");
                make_repay_plan($deal);
            }
            $root["show_err"] = "对不起,处理数据失败请联系客服!";
            return $root;
        } else {
            $temp_ids[] = $v['id'];
        }
    }
    if (count($temp_ids) == 0) {
        $root["show_err"] = "对不起,处理数据失败请联系客服!";
        return $root;
    }
    //更新用户账户资金记录
    require APP_ROOT_PATH . 'system/libs/user.php';
    modify_account(array("money" => -round($impose_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款违约金", 6);
    modify_account(array("money" => -round($true_manage_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款管理费", 10);
    modify_account(array("money" => -round($true_repay_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款本息", 6);
    //用户获得额度
    modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款获得额度", 6);
    //判断获取的信用是否超过限制
    if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_point_log WHERE `type`=6 AND user_id=" . $GLOBALS['user_info']['id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
        //获取上一次还款时间
        $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(create_time) FROM " . DB_PREFIX . "user_point_log WHERE `type`=6 AND user_id=" . $GLOBALS['user_info']['id']);
        $day = ceil(($time - $befor_repay_time) / 24 / 3600);
        //当天数大于等于间隔时间 获得信用
        if ($day >= (int) trim(app_conf('REPAY_SUCCESS_DAY'))) {
            modify_account(array("point" => trim(app_conf('REPAY_SUCCESS_POINT'))), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款", 6);
        }
    }
    //用户回款
    /**
     * 获取某一期的用户还款列表
     * array $deal_info 借款信息 
     * int $user_id 用户ID 为0代表全部
     * int $lkey  第几期 -1 全部
     * int $ukey 第几个投标人 -1 全部
     * int $true_time  真实还款时间
     * int $get_type  0 全部 1代表未还的  2 代表已还的
     * int $r_type = 0; 返回类型; 1:只返回一个数组; $result['item']
     * string $limit; 查询限制数量; 0,20  $result['count']
     */
    $user_loan_list = get_deal_user_load_list($deal, 0, -1, -1, $time, 1, 0, '');
    foreach ($user_loan_list as $lllk => $lllv) {
        //循环用户
        //本金
        $user_self_money = 0;
        //本息
        $user_repay_money = 0;
        //违约金
        $user_impose_money = 0;
        //管理费
        $user_manage_money = 0;
        foreach ($lllv as $kk => $vv) {
            //循环期数
            $in_user_id = $vv['user_id'];
            //判断是否转让了债权
            if ((int) $vv['t_user_id'] == 0) {
                $loan_user_info['user_name'] = $vv['user_name'];
                $loan_user_info['email'] = $vv['email'];
                $loan_user_info['mobile'] = $vv['mobile'];
            } else {
                $in_user_id = $vv['t_user_id'];
                $loan_user_info['user_name'] = $vv['t_user_name'];
                $loan_user_info['email'] = $vv['t_email'];
                $loan_user_info['mobile'] = $vv['t_mobile'];
            }
            $user_load_data = array();
            $user_load_data['true_repay_time'] = $time;
            $user_load_data['true_repay_date'] = to_date($time);
            $user_load_data['is_site_repay'] = 0;
            $user_load_data['status'] = 0;
            if ($k_repay_key == $vv['l_key']) {
                $loadinfo['deal']['rate'] = $deal['rate'];
                $loadinfo['deal']['loantype'] = $deal['loantype'];
                $loadinfo['deal']['repay_time'] = $deal['repay_time'];
                $loadinfo['deal']['borrow_amount'] = $vv['money'];
                $loadinfo['deal']['repay_start_time'] = $deal['repay_start_time'];
                $loadinfo['deal']['month_manage_money'] = $vv['manage_money'];
                $loadinfo['deal']['month_repay_money'] = $vv['month_repay_money'];
                $loadinfo['deal']['compensate_fee'] = $deal['compensate_fee'];
                if ($deal['repay_time_type'] == 1) {
                    $loadinfo['deal']['all_manage_money'] = $vv['manage_money'];
                } else {
                    $loadinfo['deal']['all_manage_money'] = $vv['manage_money'] * $deal['repay_time'];
                }
                $loadinfo['deal']['repay_time_type'] = $deal['repay_time_type'];
                $user_load_rs = inrepay_repay($loadinfo, $has_repay_count);
                $user_load_data['true_repay_money'] = $user_load_rs['true_repay_money'];
                $user_load_data['true_self_money'] = $user_load_rs['true_self_money'];
                $user_load_data['impose_money'] = $user_load_rs['impose_money'];
                $user_load_data['true_interest_money'] = $user_load_rs['true_repay_money'] - $user_load_rs['true_self_money'];
                $user_load_data['true_manage_money'] = $user_load_rs['true_manage_money'];
                $user_load_data['true_repay_manage_money'] = $true_manage_money / count($user_loan_list);
                $user_self_money = $user_load_data['true_self_money'];
                $user_repay_money = $user_load_data['true_repay_money'];
                $user_impose_money = $user_load_data['impose_money'];
                $user_manage_money = $user_load_data['true_manage_money'];
            }
            $user_load_data['has_repay'] = 1;
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "UPDATE", "id=" . $vv['id']);
        }
        if ($user_repay_money > 0 || $user_impose_money > 0 || $user_manage_money > 0) {
            $all_repay_money = number_format($GLOBALS['db']->getOne("SELECT (sum(repay_money)-sum(self_money) + sum(impose_money)) as shouyi FROM " . DB_PREFIX . "deal_load_repay WHERE  has_repay = 1 and deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
            $all_impose_money = number_format($GLOBALS['db']->getOne("SELECT sum(impose_money) FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay = 1 and deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
            $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”提前还款,";
            $content .= "本次投标共获得收益:" . $all_repay_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!";
            //更新用户账户资金记录
            modify_account(array("money" => $user_repay_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],回报本息", 5);
            modify_account(array("money" => $user_impose_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前回收违约金", 7);
            modify_account(array("money" => -$user_manage_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],投标管理费", 20);
            $msg_conf = get_user_msg_conf($in_user_id);
            //短信通知
            if (app_conf("SMS_ON") == 1 && app_conf('SMS_REPAY_TOUSER_ON') == 1) {
                $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_SMS'");
                $tmpl_content = $tmpl['content'];
                $notice['user_name'] = $loan_user_info['user_name'];
                $notice['deal_name'] = $deal['sub_name'];
                $notice['deal_url'] = $deal['url'];
                $notice['site_name'] = app_conf("SHOP_TITLE");
                $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                $notice['all_repay_money'] = $all_repay_money;
                $notice['impose_money'] = $all_impose_money;
                $GLOBALS['tmpl']->assign("notice", $notice);
                $sms_content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                $msg_data['dest'] = $loan_user_info['mobile'];
                $msg_data['send_type'] = 0;
                $msg_data['title'] = $msg_data['content'] = addslashes($sms_content);
                $msg_data['send_time'] = 0;
                $msg_data['is_send'] = 0;
                $msg_data['create_time'] = $time;
                $msg_data['user_id'] = $in_user_id;
                $msg_data['is_html'] = 0;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                //插入
            }
            //站内信
            if ($msg_conf['sms_bidrepaid'] == 1) {
                send_user_msg("", $content, 0, $in_user_id, $time, 0, true, 9);
            }
            //邮件
            if ($msg_conf['mail_bidrepaid'] == 1 && app_conf('MAIL_ON') == 1) {
                $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'");
                $tmpl_content = $tmpl['content'];
                $notice['user_name'] = $loan_user_info['user_name'];
                $notice['deal_name'] = $deal['sub_name'];
                $notice['deal_url'] = $deal['url'];
                $notice['site_name'] = app_conf("SHOP_TITLE");
                $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                $notice['msg_cof_setting_url'] = SITE_DOMAIN . url("index", "uc_msg#setting");
                $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                $notice['all_repay_money'] = $all_repay_money;
                $notice['impose_money'] = $all_impose_money;
                $GLOBALS['tmpl']->assign("notice", $notice);
                $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                $msg_data['dest'] = $loan_user_info['email'];
                $msg_data['send_type'] = 1;
                $msg_data['title'] = "“" . $deal['name'] . "”回款通知";
                $msg_data['content'] = addslashes($msg);
                $msg_data['send_time'] = 0;
                $msg_data['is_send'] = 0;
                $msg_data['create_time'] = $time;
                $msg_data['user_id'] = $in_user_id;
                $msg_data['is_html'] = $tmpl['is_html'];
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                //插入
            }
        }
    }
    $content = "您好,您在" . app_conf("SHOP_TITLE") . "的借款 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”成功提前还款" . number_format($true_total_repay_money, 2) . "元,";
    $content .= "其中违约金为:" . number_format($impose_money, 2) . "元,本笔借款已还款完毕!";
    send_user_msg("", $content, 0, $GLOBALS['user_info']['id'], $time, 0, true, 8);
    //短信通知
    if (app_conf("SMS_ON") == 1 && app_conf('SMS_SEND_REPAY') == 1) {
        //$sms_content = "尊敬的".app_conf("SHOP_TITLE")."用户".$GLOBALS['user_info']['user_name'].",您成功提前还款".number_format($true_total_repay_money,2)."元,其中违约金为:".number_format($impose_money,2)."元,感谢您的关注和支持。【".app_conf("SHOP_TITLE")."】";
        $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_REPAY_SUCCESS_MSG'");
        $tmpl_content = $tmpl['content'];
        $notice['user_name'] = $GLOBALS['user_info']['user_name'];
        $notice['deal_name'] = $deal['sub_name'];
        $notice['site_name'] = app_conf("SHOP_TITLE");
        $notice['index'] = $has_repay_count + 1;
        $notice['status'] = "成功提前";
        $notice['all_money'] = number_format($true_total_repay_money, 2);
        $notice['repay_money'] = number_format($true_repay_money, 2);
        $notice['impose_money'] = number_format($impose_money, 2);
        $notice['manage_money'] = number_format($true_manage_money, 2);
        $notice['manage_impose_money'] = 0;
        $GLOBALS['tmpl']->assign("notice", $notice);
        $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
        $msg_data['dest'] = $GLOBALS['user_info']['mobile'];
        $msg_data['send_type'] = 0;
        $msg_data['title'] = "提前还款短信通知";
        $msg_data['content'] = $msg;
        $msg_data['send_time'] = 0;
        $msg_data['is_send'] = 0;
        $msg_data['create_time'] = $time;
        $msg_data['user_id'] = $GLOBALS['user_info']['id'];
        $msg_data['is_html'] = 0;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    syn_deal_status($id);
    sys_user_status($GLOBALS['user_info']['id'], false, true);
    $root["status"] = 1;
    //0:出错;1:正确;
    $root["show_err"] = "操作成功!";
    return $root;
}
Example #16
0
 public function mborrow_stat()
 {
     $user_statics = sys_user_status($GLOBALS['user_info']['id'], false, true);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_DEAL_BORROW_STAT']);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_deal_borrow_stat.html");
     $GLOBALS['tmpl']->display("uc_deal_mborrow_stat.html");
 }
Example #17
0
 function stepone()
 {
     //检查是否有发布的但是未确认投标的标
     if ($GLOBALS['db']->getOne("SELECT * FROM " . DB_PREFIX . "deal WHERE is_delete=0 and publish_wait=1 and user_id=" . $GLOBALS['user_info']['id']) > 0) {
         app_redirect(url("index", "borrow#steptwo"));
     }
     //判断账户信用是否足够
     if ($GLOBALS['user_info']['point'] < 0) {
         showErr("信用太低,无法借款");
     }
     $GLOBALS['tmpl']->assign('page_title', $GLOBALS['lang']['APPLY_BORROW']);
     $user_statics = sys_user_status($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     $typeid = intval($_REQUEST['typeid']);
     $GLOBALS['tmpl']->assign("typeid", $typeid);
     $agreement = app_conf('BORROW_AGREEMENT');
     $GLOBALS['tmpl']->assign("agreement", $agreement);
     $loan_type_list = load_auto_cache("deal_loan_type_list");
     $GLOBALS['tmpl']->assign("loan_type_list", $loan_type_list);
     $loantype_list = load_auto_cache("loantype_list");
     $GLOBALS['tmpl']->assign("loantype_list", $loantype_list);
     $level = $GLOBALS['db']->getOne("SELECT name FROM " . DB_PREFIX . "user_level WHERE id=" . intval($GLOBALS['user_info']['level_id']));
     $GLOBALS['tmpl']->assign("level", $level);
     //VIP会员 借款管理费
     $load_mfee = $GLOBALS['db']->getOne("SELECT v.load_mfee FROM " . DB_PREFIX . "vip_setting v LEFT JOIN " . DB_PREFIX . "user u ON u.vip_id=v.vip_id where u.vip_state=1 and v.is_effect=1 and u.id='" . $GLOBALS['user_info']['id'] . "'");
     if ($load_mfee) {
         $manage_fee = $load_mfee;
     } else {
         $manage_fee = app_conf("MANAGE_FEE");
     }
     $GLOBALS['tmpl']->assign('manage_fee', $manage_fee);
     $level_list = load_auto_cache("level");
     $GLOBALS['tmpl']->assign("level_list", $level_list);
     $has_day_type = 0;
     foreach ($level_list as $k => $v) {
         if ($v[1] == 0) {
             $has_day_type = 1;
         }
     }
     $GLOBALS['tmpl']->assign("has_day_type", $has_day_type);
     //可用额度
     $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal WHERE (is_delete=2 or is_delete=3) AND user_id=" . $GLOBALS['user_info']['id']);
     $GLOBALS['tmpl']->assign("deal", $deal);
     $user_view_infos = $GLOBALS['user_info']['view_info'];
     $user_view_infos = unserialize($user_view_infos);
     $user_view_infoss = array();
     $deal_view_info = unserialize($deal['view_info']);
     foreach ($user_view_infos as $k => $v) {
         //会员自己传的或者管理员勾选的 才会显示
         if (intval($v['is_user']) == 1 || isset($deal_view_info[$k])) {
             $user_view_infoss[$k] = $v;
             $user_view_infoss[$k]['key'] = $k;
             if (isset($deal_view_info[$k])) {
                 $user_view_infoss[$k]['is_selected'] = 1;
             }
         }
     }
     $GLOBALS['tmpl']->assign("user_view_info", $user_view_infoss);
     //担保机构
     $agency_list = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "user WHERE is_effect = 1 AND user_type=2 ");
     $GLOBALS['tmpl']->assign("agency_list", $agency_list);
     $json_data = $level_list['repaytime_list'][$GLOBALS['user_info']['level_id']];
     $GLOBALS['tmpl']->assign('json_data', json_encode($json_data));
     $inc_file = "inc/borrow/stepone.html";
     $GLOBALS['tmpl']->assign('inc_file', $inc_file);
     $GLOBALS['tmpl']->display("page/borrow_step.html");
 }
 public function index()
 {
     $root = array();
     //set_gopreview();
     $deal_id = intval($GLOBALS['request']['id']);
     $root['deal_id'] = $deal_id;
     if ($deal_id == 0) {
         echo "不存在的债权";
         die;
     }
     $deal = get_deal($deal_id);
     //syn_transfer_status($id);
     $deal['yq_count'] = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay = 1 and deal_id=" . $deal_id . " AND status >= 2");
     $root['deal'] = $deal;
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $deal_id);
     $u_info = get_user("*", $deal['user_id']);
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $root['can_use_quota'] = $can_use_quota;
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     $user_statics = sys_user_status($deal['user_id'], true);
     $root['user_statics'] = $user_statics;
     $root['load_list'] = $load_list;
     $root['credit_file'] = $credit_file;
     $root['u_info'] = $u_info;
     //工作认证是否过期
     $root['expire'] = user_info_expire($u_info);
     //留言
     $message_list = $GLOBALS['db']->getAll("SELECT title,content,a.create_time,rel_id,a.user_id,a.is_effect,b.user_name FROM " . DB_PREFIX . "message as a left join " . DB_PREFIX . "user as b on  a.user_id = b.id WHERE rel_id = " . $id);
     $root['message'] = $message_list;
     /*
     //分页
     $page = intval($_REQUEST['p']);
     if($page==0)
     	$page = 1;
     $limit = (($page-1)*app_conf("PAGE_SIZE")).",".app_conf("PAGE_SIZE");
     $msg_condition = $condition." AND is_effect = 1 ";
     $message = get_message_list($limit,$msg_condition);
     $page = new Page($message['count'],app_conf("PAGE_SIZE"));   //初始化分页对象
     $p  =  $page->show();
     $root['pages']= $p;
     */
     foreach ($message['list'] as $k => $v) {
         $msg_sub = get_message_list("", "pid=" . $v['id'], false);
         $message['list'][$k]["sub"] = $msg_sub["list"];
     }
     $root['message_list'] = $message['list'];
     $condition = ' AND dlt.id=' . $id . ' AND d.deal_status >= 4 and d.is_effect=1 and d.is_delete=0  and d.repay_time_type =1 and  d.publish_wait=0 ';
     $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
     $transfer = get_transfer($union_sql, $condition);
     $root['transfer'] = $transfer;
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $root['page_title'] = $seo_title;
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $root['page_keyword'] = $seo_keyword;
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $root['seo_description'] = $seo_description;
     output($root);
 }