public function add()
 {
     $user_info = $GLOBALS['user_info'];
     $ajax = intval($_REQUEST['ajax']);
     if (!$user_info) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax);
     }
     if ($_REQUEST['content'] == '') {
         showErr($GLOBALS['lang']['MESSAGE_CONTENT_EMPTY'], $ajax);
     }
     //验证码
     if (app_conf("VERIFY_IMAGE") == 1) {
         $verify = md5(trim($_REQUEST['verify']));
         $session_verify = es_session::get('verify');
         if ($verify != $session_verify) {
             showErr($GLOBALS['lang']['VERIFY_CODE_ERROR'], $ajax);
         }
     }
     if (!check_ipop_limit(get_client_ip(), "message", intval(app_conf("SUBMIT_DELAY")), 0)) {
         showErr($GLOBALS['lang']['MESSAGE_SUBMIT_FAST'], $ajax);
     }
     $rel_table = strim($_REQUEST['rel_table']);
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "'");
     if (!$message_type) {
         showErr($GLOBALS['lang']['INVALID_MESSAGE_TYPE'], $ajax);
     }
     //添加留言
     $message['title'] = $_REQUEST['title'] ? strim($_REQUEST['title']) : btrim(valid_str($_REQUEST['content']));
     $message['content'] = btrim(valid_str($_REQUEST['content']));
     $message['title'] = valid_str($message['title']);
     $message['create_time'] = TIME_UTC;
     $message['rel_table'] = $rel_table;
     $message['rel_id'] = intval($_REQUEST['rel_id']);
     $message['user_id'] = intval($GLOBALS['user_info']['id']);
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $message_effect = 0;
     } else {
         $message_effect = $message_type['is_effect'];
     }
     $message['is_effect'] = $message_effect;
     $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
     $l_user_id = $GLOBALS['db']->getOne("SELECT user_id FROM " . DB_PREFIX . "deal WHERE id=" . $message['rel_id']);
     //添加到动态
     insert_topic($rel_table . "_message", $message['rel_id'], $message['user_id'], $GLOBALS['user_info']['user_name'], $l_user_id);
     if ($rel_table == "deal") {
         require_once APP_ROOT_PATH . 'app/Lib/deal.php';
         $deal = get_deal($message['rel_id']);
         //自己给自己留言不执行操作
         if ($deal['user_id'] != $message['user_id']) {
             $msg_conf = get_user_msg_conf($deal['user_id']);
             //站内信
             if ($msg_conf['sms_asked'] == 1) {
                 $content = "<p>您好,用户 " . get_user_name($message['user_id']) . "对您发布的借款列表 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”进行了以下留言:</p>";
                 $content .= "<p>“" . $message['content'] . "”</p>";
                 send_user_msg("", $content, 0, $deal['user_id'], TIME_UTC, 0, true, 13, $message['rel_id']);
             }
             //邮件
             if ($msg_conf['mail_asked'] == 1 && app_conf('MAIL_ON') == 1) {
                 $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $deal['user_id']);
                 $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_DEAL_MSG'");
                 $tmpl_content = $tmpl['content'];
                 $notice['user_name'] = $user_info['user_name'];
                 $notice['msg_user_name'] = get_user_name($message['user_id'], false);
                 $notice['deal_name'] = $deal['name'];
                 $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $deal['id']));
                 $notice['message'] = $message['content'];
                 $notice['site_name'] = app_conf("SHOP_TITLE");
                 $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                 $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                 $GLOBALS['tmpl']->assign("notice", $notice);
                 $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                 $msg_data['dest'] = $user_info['email'];
                 $msg_data['send_type'] = 1;
                 $msg_data['title'] = get_user_name($message['user_id'], false) . "给您的标留言!";
                 $msg_data['content'] = addslashes($msg);
                 $msg_data['send_time'] = 0;
                 $msg_data['is_send'] = 0;
                 $msg_data['create_time'] = TIME_UTC;
                 $msg_data['user_id'] = $user_info['id'];
                 $msg_data['is_html'] = $tmpl['is_html'];
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                 //插入
             }
         }
     }
     showSuccess($GLOBALS['lang']['MESSAGE_POST_SUCCESS'], $ajax);
 }
Example #2
0
 function savedeal()
 {
     $is_ajax = intval($_REQUEST['is_ajax']);
     if (!$GLOBALS['user_info']) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $is_ajax);
     }
     $t = trim($_REQUEST['t']);
     if (!in_array($t, array("save", "publish"))) {
         showErr($GLOBALS['lang']['ERROR_TITLE'], $is_ajax);
     }
     if ($t == "save") {
         $data['is_delete'] = 2;
     } else {
         $data['is_delete'] = 0;
     }
     $data['name'] = strim($_REQUEST['borrowtitle']);
     if (empty($data['name'])) {
         showErr("请输入借款标题", $is_ajax);
     }
     $data['publish_wait'] = 1;
     $icon_type = strim($_REQUEST['imgtype']);
     if ($icon_type == "") {
         showErr("请选择借款图片类型", $is_ajax);
     }
     $icon_type_arr = array('upload' => 1, 'userImg' => 2, 'systemImg' => 3);
     $data['icon_type'] = $icon_type_arr[$icon_type];
     if (intval($data['icon_type']) == 0) {
         showErr("请选择借款图片类型", $is_ajax);
     }
     switch ($data['icon_type']) {
         case 1:
             if (strim($_REQUEST['icon']) == '') {
                 showErr("请上传图片", $is_ajax);
             } else {
                 $data['icon'] = replace_public(strim($_REQUEST['icon']));
             }
             break;
         case 2:
             $data['icon'] = replace_public(get_user_avatar($GLOBALS['user_info']['id'], 'big'));
             break;
         case 3:
             if (intval($_REQUEST['systemimgpath']) == 0) {
                 showErr("请选择系统图片", $is_ajax);
             } else {
                 $data['icon'] = $GLOBALS['db']->getOne("SELECT icon FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . intval($_REQUEST['systemimgpath']));
             }
             break;
     }
     $data['type_id'] = intval($_REQUEST['borrowtype']);
     if ($data['type_id'] == 0) {
         showErr("请选择借款用途", $is_ajax);
     }
     $data['borrow_amount'] = floatval($_REQUEST['borrowamount']);
     if ($data['borrow_amount'] < (int) trim(app_conf('MIN_BORROW_QUOTA')) || $data['borrow_amount'] > (int) trim(app_conf('MAX_BORROW_QUOTA')) || $data['borrow_amount'] % 50 != 0) {
         showErr("请正确输入借款金额", $is_ajax);
     }
     //判断是否需要额度
     if ($GLOBALS['db']->getOne("SELECT is_quota FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . $data['type_id']) == 1) {
         if (intval($GLOBALS['user_info']['quota']) != 0) {
             $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
             if ($data['borrow_amount'] > intval($can_use_quota)) {
                 showErr("输入借款的借款金额超过您的可用额度<br>您当前可用额度为:" . $can_use_quota, $is_ajax);
             }
         }
     }
     $data['repay_time'] = intval($_REQUEST['repaytime']);
     if ($data['repay_time'] == 0) {
         showErr("借款期限", $is_ajax);
     }
     $data['rate'] = floatval($_REQUEST['apr']);
     $data['repay_time_type'] = intval($_REQUEST['repaytime_type']);
     $level_list = load_auto_cache("level");
     $min_rate = 0;
     $max_rate = 0;
     $is_rate_lock = false;
     foreach ($level_list['repaytime_list'][$GLOBALS['user_info']['level_id']] as $kkk => $vvv) {
         if ($data['repay_time_type'] == 1) {
             if ($data['repay_time'] == intval($vvv[0]) && $vvv[1] == $data['repay_time_type']) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
             }
         } else {
             if ($data['repay_time'] <= intval($vvv[0]) && intval($vvv[1]) == $data['repay_time_type'] && $is_rate_lock == false) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
                 $is_rate_lock = true;
             } elseif ($data['repay_time'] > intval($vvv[0]) && intval($vvv[1]) == $data['repay_time_type']) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
             }
         }
     }
     if (floatval($data['rate']) <= 0 || floatval($data['rate']) > $max_rate || floatval($data['rate']) < $min_rate) {
         showErr("请正确输入借款利率", $is_ajax);
     }
     $data['enddate'] = intval($_REQUEST['enddate']);
     $data['description'] = replace_public(btrim($_REQUEST['borrowdesc']));
     $data['description'] = valid_tag($data['description']);
     if (trim($data['description']) == '') {
         showErr("请输入项目描述", $is_ajax);
     }
     $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;
         }
     }
     $datas['view_info'] = serialize($user_view_info);
     $GLOBALS['db']->autoExecute(DB_PREFIX . "user", $datas, "UPDATE", "id=" . $GLOBALS['user_info']['id']);
     $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;
     }
     $data['view_info'] = serialize($data['view_info']);
     //资金运转
     $data['remark_1'] = strim(replace_public($_REQUEST['remark_1']));
     $data['remark_1'] = valid_tag($data['remark_1']);
     //风险控制措施
     $data['remark_2'] = strim(replace_public($_REQUEST['remark_2']));
     $data['remark_2'] = valid_tag($data['remark_2']);
     //政策及市场分析
     $data['remark_3'] = strim(replace_public($_REQUEST['remark_3']));
     $data['remark_3'] = valid_tag($data['remark_3']);
     //企业背景
     $data['remark_4'] = strim(replace_public($_REQUEST['remark_4']));
     $data['remark_4'] = valid_tag($data['remark_4']);
     //企业信息
     $data['remark_5'] = strim(replace_public($_REQUEST['remark_5']));
     $data['remark_5'] = valid_tag($data['remark_5']);
     //项目相关资料
     $data['remark_6'] = strim(replace_public($_REQUEST['remark_6']));
     $data['remark_6'] = valid_tag($data['remark_6']);
     //$data['voffice'] = intval($_REQUEST['voffice']);
     //$data['vposition'] = intval($_REQUEST['vposition']);
     $data['voffice'] = 1;
     $data['vposition'] = 1;
     $data['is_effect'] = 1;
     $data['deal_status'] = 0;
     $data['agency_id'] = intval($_REQUEST['agency_id']);
     $data['agency_status'] = 1;
     $data['warrant'] = intval($_REQUEST['warrant']);
     $data['guarantor_margin_amt'] = floatval($_REQUEST['guarantor_margin_amt']);
     $data['guarantor_pro_fit_amt'] = floatval($_REQUEST['guarantor_pro_fit_amt']);
     $data['user_id'] = intval($GLOBALS['user_info']['id']);
     $data['loantype'] = intval($_REQUEST['loantype']);
     if ($data['repay_time_type'] == 0) {
         $data['loantype'] = 2;
     }
     //当为天的时候
     if ($data['repay_time_type'] == 0) {
         $true_repay_time = 1;
     } else {
         $true_repay_time = $data['repay_time'];
     }
     //本金担保
     if ($data['warrant'] == 1) {
         $data['guarantor_amt'] = $data['borrow_amount'];
     } elseif ($data['warrant'] == 2) {
         //等额本息
         if ($data['loantype'] == 0) {
             $data['guarantor_amt'] = pl_it_formula($data['borrow_amount'], $data['rate'] / 12 / 100, $true_repay_time) * $true_repay_time;
         } elseif ($data['loantype'] == 1) {
             $data['guarantor_amt'] = av_it_formula($data['borrow_amount'], $data['rate'] / 12 / 100) * $true_repay_time + $data['borrow_amount'];
         } elseif ($data['loantype'] == 2) {
             $data['guarantor_amt'] = $data['borrow_amount'] * $data['rate'] / 12 / 100 * $true_repay_time + $data['borrow_amount'];
         }
     }
     $data['create_time'] = TIME_UTC;
     $module = "INSERT";
     $jumpurl = url("index", "borrow#steptwo");
     $condition = "";
     $deal_id = $GLOBALS['db']->getOne("SELECT id FROM " . DB_PREFIX . "deal WHERE ((is_delete=2 or is_delete=3) or (is_delete=0 and publish_wait=1)) AND user_id=" . $GLOBALS['user_info']['id']);
     if ($deal_id > 0) {
         $module = "UPDATE";
         if ($t == "save") {
             $jumpurl = url("index", "borrow#stepone");
         }
         $condition = "id = {$deal_id}";
     } else {
         if ($t == "save") {
             $jumpurl = url("index", "borrow#stepone");
         }
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $data, $module, $condition);
     if ($module == "INSERT") {
         $deal_id = $GLOBALS['db']->insert_id();
     }
     require_once APP_ROOT_PATH . 'app/Lib/deal.php';
     $deal = get_deal($deal_id);
     //发送验证通知
     if ($t != "save" && trim(app_conf('CUSTOM_SERVICE')) != '' && ($GLOBALS['user_info']['idcardpassed'] == 0 || $GLOBALS['user_info']['incomepassed'] == 0 || $GLOBALS['user_info']['creditpassed'] == 0 || $GLOBALS['user_info']['workpassed'] == 0)) {
         $ulist = explode(",", trim(app_conf('CUSTOM_SERVICE')));
         $ulist = array_filter($ulist);
         if ($ulist) {
             $uuid = $ulist[array_rand($ulist)];
             if ($uuid > 0) {
                 $content = app_conf("SHOP_TITLE") . "用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话 " . app_conf('SHOP_TEL') . " 或给客服邮箱发邮件 " . app_conf("REPLY_ADDRESS") . " 我们会及时给您回复。";
                 require_once APP_ROOT_PATH . 'app/Lib/message.php';
                 //添加留言
                 $message['title'] = $content;
                 $message['content'] = htmlspecialchars(addslashes(valid_str($content)));
                 $message['title'] = valid_str($message['title']);
                 $message['create_time'] = TIME_UTC;
                 $message['rel_table'] = "deal";
                 $message['rel_id'] = $deal_id;
                 $message['user_id'] = $uuid;
                 $message['is_effect'] = 1;
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
                 //添加到动态
                 insert_topic("message", $message['rel_id'], $message['user_id'], get_user_name($message['user_id'], false), $GLOBALS['user_info']['id']);
                 //自己给自己留言不执行操作
                 if ($deal['user_id'] != $message['user_id']) {
                     $msg_conf = get_user_msg_conf($deal['user_id']);
                     //站内信
                     if ($msg_conf['sms_asked'] == 1) {
                         $notices['shop_title'] = app_conf("SHOP_TITLE");
                         $notices['shop_tel'] = app_conf('SHOP_TEL');
                         $notices['shop_address'] = app_conf("REPLY_ADDRESS");
                         /*{$notice.shop_title}用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话{$notice.shop_tel}或给客服邮箱发邮件{$notice.shop_address}我们会及时给您回复。*/
                         $notices['url'] = "“<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”";
                         $notices['user_name'] = get_user_name($message['user_id']);
                         $notices['money'] = $user_load_data['true_repay_money'] + $user_load_data['impose_money'];
                         $tmpl_content = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_WORDS_MSG'", false);
                         $GLOBALS['tmpl']->assign("notice", $notices);
                         $contents = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content['content']);
                         send_user_msg("", $contents, 0, $deal['user_id'], TIME_UTC, 0, true, 13, $message['rel_id']);
                     }
                     //邮件
                     if ($msg_conf['mail_asked'] == 1 && app_conf('MAIL_ON') == 1) {
                         $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_DEAL_MSG'");
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $GLOBALS['user_info']['user_name'];
                         $notice['msg_user_name'] = get_user_name($message['user_id'], false);
                         $notice['deal_name'] = $deal['name'];
                         $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $deal['id']));
                         $notice['message'] = $message['content'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                         $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                         $GLOBALS['tmpl']->assign("notice", $notice);
                         $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                         $msg_data['dest'] = $GLOBALS['user_info']['email'];
                         $msg_data['send_type'] = 1;
                         $msg_data['title'] = get_user_name($message['user_id'], false) . "给您的标留言!";
                         $msg_data['content'] = addslashes($msg);
                         $msg_data['send_time'] = 0;
                         $msg_data['is_send'] = 0;
                         $msg_data['create_time'] = TIME_UTC;
                         $msg_data['user_id'] = $GLOBALS['user_info']['id'];
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($is_ajax == 1) {
         showSuccess($GLOBALS['lang']['SUCCESS_TITLE'], $is_ajax, $jumpurl);
     } else {
         app_redirect($jumpurl);
     }
 }
function send_deal_success_site_sms($deal_id, $deal_info = false)
{
    if (!$deal_info && $deal_id == 0) {
        return false;
    }
    if (!$deal_info) {
        $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $deal_id);
    }
    if (intval($deal_info['is_send_success_msg']) == 1) {
        return false;
    }
    //获取投标列表
    $load_user_list = $GLOBALS['db']->getAll("SELECT user_name,user_id,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $deal_info['id']);
    if ($load_user_list) {
        foreach ($load_user_list as $k => $v) {
            $user_info = $GLOBALS['db']->getRow("select email from " . DB_PREFIX . "user where id = " . $v['user_id']);
            $load_msg_conf = get_user_msg_conf($v['user_id']);
            if ($load_msg_conf['sms_bidsuccess'] == 1 || !$load_msg_conf) {
                $content = "<p>感谢您使用" . app_conf("SHOP_TITLE") . "贷款融资,很高兴的通知您,您于" . to_date($v['create_time'], "Y年m月d日") . "投标的借款列表";
                $content .= "“<a href=\"" . url("index", "deal", array("id" => $deal_info['id'])) . "\">" . $deal_info['name'] . "</a>”满标</p>";
                send_user_msg("", $content, 0, $v['user_id'], TIME_UTC, 0, true, 16);
            }
        }
    }
}
Example #4
0
 public function msg_reply()
 {
     $ajax = 1;
     $user_info = $GLOBALS['user_info'];
     if (!$user_info) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax);
     }
     if ($_REQUEST['content'] == '') {
         showErr($GLOBALS['lang']['MESSAGE_CONTENT_EMPTY'], $ajax);
     }
     if (!check_ipop_limit(CLIENT_IP, "message", intval(app_conf("SUBMIT_DELAY")), 0)) {
         showErr($GLOBALS['lang']['MESSAGE_SUBMIT_FAST'], $ajax);
     }
     $rel_table = strim($_REQUEST['rel_table']);
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "'");
     if (!$message_type) {
         showErr($GLOBALS['lang']['INVALID_MESSAGE_TYPE'], $ajax);
     }
     //添加留言
     $message['title'] = $_REQUEST['title'] ? strim($_REQUEST['title']) : btrim(valid_str($_REQUEST['content']));
     $message['content'] = btrim(valid_str($_REQUEST['content']));
     $message['title'] = valid_str($message['title']);
     $message['create_time'] = TIME_UTC;
     $message['rel_table'] = $rel_table;
     $message['rel_id'] = intval($_REQUEST['rel_id']);
     $message['user_id'] = intval($GLOBALS['user_info']['id']);
     $message['pid'] = intval($_REQUEST['pid']);
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $message_effect = 0;
     } else {
         $message_effect = $message_type['is_effect'];
     }
     $message['is_effect'] = $message_effect;
     $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
     if ($rel_table == "deal") {
         $l_user_id = $GLOBALS['db']->getOne("SELECT user_id FROM " . DB_PREFIX . "deal WHERE id=" . $message['rel_id']);
     } else {
         $l_user_id = $GLOBALS['db']->getOne("SELECT user_id FROM " . DB_PREFIX . "deal_load_transfer WHERE id=" . $message['rel_id']);
     }
     //添加到动态
     insert_topic($rel_table . "_message_reply", $message['rel_id'], $message['user_id'], $GLOBALS['user_info']['user_name'], $l_user_id);
     if ($rel_table == "deal") {
         require_once APP_ROOT_PATH . 'app/Lib/deal.php';
         $deal = get_deal($message['rel_id']);
         $msg_u_id = $GLOBALS['db']->getOne("SELECT user_id FROM " . DB_PREFIX . "message WHERE id=" . $message['pid']);
         if ($message['user_id'] != $msg_u_id) {
             $msg_conf = get_user_msg_conf($deal['user_id']);
             //站内信
             if ($msg_conf['sms_answer'] == 1) {
                 $notices['user_name'] = get_user_name($message['user_id']);
                 $notices['url'] = "“<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”";
                 $notices['msg'] = "“" . $message['content'] . "”";
                 $tmpl_contents = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_REPLY_MSG'", false);
                 $GLOBALS['tmpl']->assign("notice", $notices);
                 $content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_contents['content']);
                 send_user_msg("", $content, 0, $msg_u_id, TIME_UTC, 0, true, 14, $message['rel_id']);
             }
             //邮件
             if ($msg_conf['mail_answer'] == 1 && app_conf('MAIL_ON') == 1) {
                 $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $msg_u_id);
                 $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_DEAL_REPLY_MSG'", false);
                 $tmpl_content = $tmpl['content'];
                 $notice['user_name'] = $user_info['user_name'];
                 $notice['msg_user_name'] = get_user_name($message['user_id'], false);
                 $notice['deal_name'] = $deal['name'];
                 $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $deal['id']));
                 $notice['message'] = $message['content'];
                 $notice['site_name'] = app_conf("SHOP_TITLE");
                 $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                 $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                 $GLOBALS['tmpl']->assign("notice", $notice);
                 $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                 $msg_data['dest'] = $user_info['email'];
                 $msg_data['send_type'] = 1;
                 $msg_data['title'] = "用户" . get_user_name($message['user_id'], false) . "回复了你的留言!";
                 $msg_data['content'] = addslashes($msg);
                 $msg_data['send_time'] = 0;
                 $msg_data['is_send'] = 0;
                 $msg_data['create_time'] = TIME_UTC;
                 $msg_data['user_id'] = $user_info['id'];
                 $msg_data['is_html'] = $tmpl['is_html'];
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                 //插入
             }
         }
     }
     showSuccess($GLOBALS['lang']['REPLY_POST_SUCCESS'], $ajax);
 }
Example #5
0
 /**
  * 代还款
  */
 function do_site_repay($page = 1)
 {
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $id = intval($_REQUEST['id']);
     $l_key = intval($_REQUEST['l_key']);
     $this->assign("jumpUrl", U("Deal/repay_plan", array("id" => $id)));
     if ($id == 0) {
         $this->success("数据错误");
     }
     $deal_info = get_deal($id);
     if (!$deal_info) {
         $this->success("借款不存在");
     }
     if ($deal_info['ips_bill_no'] != "") {
         $this->success("第三方同步暂无法代还款");
     }
     $user_id = $deal_info['user_id'];
     if ($page == 0) {
         $page = 1;
     }
     $page_size = 10;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $user_loan_list = get_deal_user_load_list($deal_info, 0, $l_key, -1, 0, 0, 1, $limit);
     $rs_count = $user_loan_list['count'];
     $page_all = ceil($rs_count / $page_size);
     require_once APP_ROOT_PATH . "system/libs/user.php";
     foreach ($user_loan_list['item'] as $kk => $vv) {
         if ($vv['has_repay'] == 0) {
             //借入者已还款,但是没打款到借出用户中心
             $user_load_data = array();
             $user_load_data['true_repay_time'] = TIME_UTC;
             $user_load_data['true_repay_date'] = to_date(TIME_UTC);
             $user_load_data['is_site_repay'] = 1;
             $user_load_data['status'] = 0;
             $user_load_data['true_repay_money'] = (double) $vv['month_repay_money'];
             $user_load_data['true_self_money'] = (double) $vv['self_money'];
             $user_load_data['true_interest_money'] = (double) $vv['interest_money'];
             $user_load_data['true_manage_money'] = (double) $vv['manage_money'];
             $user_load_data['true_manage_interest_money'] = (double) $vv['manage_interest_money'];
             $user_load_data['true_repay_manage_money'] = (double) $vv['repay_manage_money'];
             $user_load_data['true_manage_interest_money_rebate'] = (double) $vv['manage_interest_money_rebate'];
             $user_load_data['impose_money'] = (double) $vv['impose_money'];
             $user_load_data['repay_manage_impose_money'] = (double) $vv['repay_manage_impose_money'];
             $user_load_data['true_reward_money'] = (double) $vv['reward_money'];
             if ($vv['status'] > 0) {
                 $user_load_data['status'] = $vv['status'] - 1;
             }
             $user_load_data['has_repay'] = 1;
             $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "UPDATE", "id=" . $vv['id'] . " AND has_repay = 0 ", "SILENT");
             if ($GLOBALS['db']->affected_rows() > 0) {
                 //$content = "您好,您在".app_conf("SHOP_TITLE")."的投标 “<a href=\"".$deal_info['url']."\">".$deal_info['name']."</a>”成功还款".($user_load_data['true_repay_money']+$user_load_data['impose_money'])."元,";
                 $unext_loan = $user_loan_list[$vv['u_key']][$kk + 1];
                 if ($unext_loan) {
                     //$content .= "本笔投标的下个还款日为".to_date($unext_loan['repay_day'],"Y年m月d日").",需还本息".number_format($unext_loan['month_repay_money'],2)."元。";
                     $notices['content'] = ",本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需还本息" . number_format($unext_loan['month_repay_money'], 2) . "元。";
                 } else {
                     $load_repay_rs = $GLOBALS['db']->getOne("SELECT (sum(true_interest_money) + sum(impose_money)) as shouyi,sum(impose_money) as total_impose_money FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']);
                     $all_shouyi_money = number_format($load_repay_rs['shouyi'], 2);
                     $all_impose_money = number_format($load_repay_rs['total_impose_money'], 2);
                     //$content .= "本次投标共获得收益:".$all_shouyi_money."元,其中违约金为:".$all_impose_money."元,本次投标已回款完毕!";
                     $notices['content'] = ",本次投标共获得收益:" . $all_shouyi_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!";
                 }
                 if ($user_load_data['impose_money'] != 0 || $user_load_data['true_manage_money'] != 0 || $user_load_data['true_repay_money'] != 0) {
                     $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'];
                     }
                     //更新用户账户资金记录
                     modify_account(array("money" => $user_load_data['true_repay_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,回报本息", 5);
                     if ($user_load_data['true_manage_money'] > 0) {
                         modify_account(array("money" => -$user_load_data['true_manage_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,投标管理费", 20);
                     }
                     //利息管理费
                     modify_account(array("money" => -$user_load_data['true_manage_interest_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,投标利息管理费", 20);
                     if ($user_load_data['impose_money'] != 0) {
                         modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,逾期罚息", 21);
                     }
                     //普通会员邀请返利
                     get_referrals($vv['id']);
                     //投资者返佣金
                     if ($user_load_data['true_manage_interest_money_rebate'] != 0) {
                         /*ok*/
                         $reback_memo = sprintf($GLOBALS['lang']["INVEST_REBATE_LOG"], $deal_info["url"], $deal_info["name"], $loan_user_info["user_name"], intval($vv["l_key"]) + 1);
                         reback_rebate_money($in_user_id, $user_load_data['true_manage_interest_money_rebate'], "invest", $reback_memo);
                     }
                     $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']->getRow("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_info['sub_name'];
                         $notice['deal_url'] = $deal_info['url'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['repay_money'] = number_format($user_load_data['true_repay_money'] + $user_load_data['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $notice['all_repay_money'] = $all_shouyi_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_UTC;
                         $msg_data['user_id'] = $in_user_id;
                         $msg_data['is_html'] = 0;
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                     //站内信
                     $notices['shop_title'] = app_conf("SHOP_TITLE");
                     $notices['url'] = "“<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”";
                     $notices['money'] = $user_load_data['true_repay_money'] + $user_load_data['impose_money'];
                     $tmpl_content = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SITE_REPAY'", false);
                     $GLOBALS['tmpl']->assign("notice", $notices);
                     $content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content['content']);
                     if ($msg_conf['sms_bidrepaid'] == 1) {
                         send_user_msg("", $content, 0, $in_user_id, TIME_UTC, 0, true, 9);
                     }
                     //邮件
                     if ($msg_conf['mail_bidrepaid'] == 1 && app_conf('MAIL_ON') == 1) {
                         $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'", false);
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $loan_user_info['user_name'];
                         $notice['deal_name'] = $deal_info['sub_name'];
                         $notice['deal_url'] = $deal_info['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'] = number_format($vv['month_repay_money'] + $vv['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $notice['all_repay_money'] = $all_shouyi_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_info['name'] . "”回款通知";
                         $msg_data['content'] = addslashes($msg);
                         $msg_data['send_time'] = 0;
                         $msg_data['is_send'] = 0;
                         $msg_data['create_time'] = TIME_UTC;
                         $msg_data['user_id'] = $in_user_id;
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($page >= $page_all) {
         $s_count = $GLOBALS['db']->getOne("SELECT count(*) FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0");
         $adm_session = es_session::get(md5(conf("AUTH_KEY")));
         if ($s_count == 0) {
             $rs_sum = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) as total_repay_money,sum(true_self_money) as total_self_money,sum(true_interest_money) as total_interest_money,sum(true_repay_manage_money) as total_manage_money,sum(impose_money) as total_impose_money,sum(repay_manage_impose_money) as total_repay_manage_impose_money FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . "  and has_repay = 1");
             $deal_load_list = get_deal_load_list($deal_info);
             //统计网站代还款
             $rs_site_sum = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) as total_repay_money,sum(true_self_money) as total_self_money,sum(true_repay_manage_money) as total_manage_money,sum(impose_money) as total_impose_money,sum(repay_manage_impose_money) as total_repay_manage_impose_money FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and is_site_repay=1 and has_repay = 1");
             $repay_data['status'] = (int) $GLOBALS['db']->getOne("SELECT `status` FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 1 AND is_site_repay=1  ORDER BY l_key DESC");
             $repay_data['true_repay_time'] = TIME_UTC;
             $repay_data['true_repay_date'] = to_date(TIME_UTC);
             $repay_data['has_repay'] = 1;
             $repay_data['impose_money'] = floatval($rs_sum['total_impose_money']);
             $repay_data['true_self_money'] = floatval($rs_sum['total_self_money']);
             $repay_data['true_repay_money'] = floatval($rs_sum['total_repay_money']);
             $repay_data['true_manage_money'] = floatval($rs_sum['total_manage_money']);
             $repay_data['true_interest_money'] = floatval($rs_sum['total_interest_money']);
             $repay_data['manage_impose_money'] = floatval($rs_sum['total_repay_manage_impose_money']);
             $rebate_rs = get_rebate_fee($user_id, "borrow");
             $repay_data['true_manage_money_rebate'] = $repay_data['true_manage_money'] * floatval($rebate_rs['rebate']) / 100;
             //借款者返佣
             if ($repay_data['true_manage_money_rebate'] != 0) {
                 /*ok*/
                 $reback_memo = sprintf(L("BORROW_REBATE_LOG"), $deal_info["url"], $deal_info["name"], $deal_info["user"]["user_name"], intval($l_key) + 1);
                 reback_rebate_money($user_id, $repay_data['true_manage_money_rebate'], "borrow", $reback_memo);
             }
             $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", " deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0 ");
             $impose_day = ceil((to_timespan(to_date(TIME_UTC, "Y-m-d"), "Y-m-d") - $deal_load_list[$l_key]['repay_day']) / 24 / 3600);
             if ($impose_day > 0) {
                 //VIP 逾期还款降级
                 $type = 2;
                 $type_info = 5;
                 $resultdate = syn_user_vip($user_id, $type, $type_info);
                 if ($impose_day < app_conf('YZ_IMPSE_DAY')) {
                     modify_account(array("point" => trim(app_conf('IMPOSE_POINT'))), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,逾期还款", 11);
                 } else {
                     modify_account(array("point" => trim(app_conf('YZ_IMPOSE_POINT'))), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,严重逾期", 11);
                 }
             } else {
                 //VIP 代还款降级
                 $type = 2;
                 $type_info = 6;
                 $resultdate = syn_user_vip($user_id, $type, $type_info);
             }
             if ($rs_site_sum) {
                 $r_msg = "网站代还款";
                 if ($rs_site_sum['total_repay_money'] > 0) {
                     $r_msg .= ",本息:" . format_price($rs_site_sum['total_repay_money']);
                 }
                 if ($rs_site_sum['total_impose_money'] > 0) {
                     $r_msg .= ",逾期费用:" . format_price($rs_site_sum['total_impose_money']);
                 }
                 if ($rs_site_sum['total_manage_money'] > 0) {
                     $r_msg .= ",管理费:" . format_price($rs_site_sum['total_manage_money']);
                 }
                 if ($rs_site_sum['total_repay_manage_impose_money'] > 0) {
                     $r_msg .= ",逾期管理费:" . format_price($rs_site_sum['total_repay_manage_impose_money']);
                 }
                 repay_log($deal_load_list[$l_key]['repay_id'], $r_msg, 0, $adm_session['adm_id']);
             }
             if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "generation_repay WHERE deal_id=" . $id . " AND repay_id=" . $deal_load_list[$l_key]['repay_id'] . "") == 0) {
                 $generation_repay['deal_id'] = $id;
                 $generation_repay['repay_id'] = $deal_load_list[$l_key]['repay_id'];
                 $generation_repay['admin_id'] = $adm_session['adm_id'];
                 $generation_repay['agency_id'] = $deal_info['agency_id'];
                 $generation_repay['repay_money'] = $rs_site_sum['total_repay_money'];
                 $generation_repay['self_money'] = $rs_site_sum['total_self_money'];
                 $generation_repay['impose_money'] = $rs_site_sum['total_impose_money'];
                 $generation_repay['manage_money'] = $rs_site_sum['total_manage_money'];
                 $generation_repay['manage_impose_money'] = $rs_site_sum['total_repay_manage_impose_money'];
                 $generation_repay['create_time'] = TIME_UTC;
                 $generation_repay['create_date'] = to_date(TIME_UTC, "Y-m-d");
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "generation_repay", $generation_repay);
                 $site_money_data['user_id'] = $user_id;
                 $site_money_data['create_time'] = TIME_UTC;
                 $site_money_data['create_time_ymd'] = to_date(TIME_UTC, "Y-m-d");
                 $site_money_data['create_time_ym'] = to_date(TIME_UTC, "Ym");
                 $site_money_data['create_time_y'] = to_date(TIME_UTC, "Y");
                 if ($rs_sum['total_manage_money'] != 0) {
                     $site_money_data['memo'] = "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . $l_key . "期,借款管理费";
                     $site_money_data['type'] = 10;
                     $site_money_data['money'] = $rs_sum['total_manage_money'];
                     $GLOBALS['db']->autoExecute(DB_PREFIX . "site_money_log", $site_money_data, "INSERT");
                 }
                 if ($rs_sum['total_repay_manage_impose_money'] != 0) {
                     $site_money_data['memo'] = "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . $l_key . "期,逾期管理费";
                     $site_money_data['type'] = 12;
                     $site_money_data['money'] = $rs_sum['total_repay_manage_impose_money'];
                     $GLOBALS['db']->autoExecute(DB_PREFIX . "site_money_log", $site_money_data, "INSERT");
                 }
             }
         }
         syn_deal_status($deal_info['id']);
         syn_transfer_status(0, $deal_info['id']);
         $this->success("代还款执行完毕!");
     } else {
         register_shutdown_function(array(&$this, 'do_site_repay'), $page + 1);
     }
 }
Example #6
0
/**
 * 满标放款
 * $type 0 普通 1代表 第三方
 * $is_loan 0 不返款, 1 返款
 */
function do_loans($id, $repay_start_time, $type = 0)
{
    $return = array("status" => 0, "info" => "");
    if ($id == 0) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    require_once APP_ROOT_PATH . "app/Lib/deal.php";
    $deal_info = get_deal($id);
    if (!$deal_info) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    if (!in_array($deal_info['deal_status'], array(2, 4, 5))) {
        $return['info'] = "放款失败,借款不是满标状态";
        return $return;
    }
    if ($type == 0) {
        $loan_data['repay_start_time'] = $repay_start_time == '' ? 0 : to_timespan(to_date(to_timespan($repay_start_time), "Y-m-d"), "Y-m-d");
    } else {
        $loan_data['repay_start_time'] = $repay_start_time;
    }
    if ($loan_data['repay_start_time'] == 0) {
        $return['info'] = "放款失败,时间没选择";
        return $return;
    }
    if ($type == 0 && $deal_info['ips_bill_no'] != "") {
        $return['status'] = 2;
        $return['info'] = "";
        $return['jump'] = APP_ROOT . "/index.php?ctl=collocation&act=Transfer&pTransferType=1&deal_id=" . $id . "&ref_data=" . $loan_data['repay_start_time'];
        return $return;
    }
    if ($loan_data['repay_start_time'] > 0) {
        $deal_info['next_repay_time'] = $loan_data['next_repay_time'] = next_replay_month($loan_data['repay_start_time']);
    }
    $deal_info['deal_status'] = $loan_data['deal_status'] = 4;
    $deal_info['is_has_loans'] = $loan_data['is_has_loans'] = 1;
    $loan_data['repay_start_date'] = to_date($loan_data['repay_start_time'], "Y-m-d");
    //放款给用户
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $loan_data, "UPDATE", "id=" . $id . " AND is_has_loans=0 ");
    $deal_info['repay_start_time'] = $loan_data['repay_start_time'];
    if ($GLOBALS['db']->affected_rows() > 0) {
        format_deal_item($deal_info);
        require_once APP_ROOT_PATH . "system/libs/user.php";
        if ($type == 0) {
            modify_account(array("money" => $deal_info['borrow_amount']), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],招标成功", 3);
            //扣除服务费
            $services_fee = $deal_info['borrow_amount'] * floatval(trim($deal_info['services_fee'])) / 100;
            modify_account(array("money" => -$services_fee), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],服务费", 14);
        }
        //积分
        if ($deal_info['score'] != 0) {
            modify_account(array("score" => $deal_info['score']), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],招标成功", 3);
        }
        $load_list = $GLOBALS['db']->getAll("SELECT id,user_id,`money`,`is_old_loan`,`rebate_money`,`bid_score`,`is_winning`,`income_type`,`income_value` FROM " . DB_PREFIX . "deal_load where deal_id=" . $id . " and is_rebate = 0 ");
        foreach ($load_list as $lk => $lv) {
            //扣除冻结资金
            if ($type == 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_has_loans =1 WHERE id=" . $lv['id'] . " AND is_has_loans = 0 AND user_id=" . $lv['user_id']);
                if ($GLOBALS['db']->affected_rows()) {
                    if ($lv['is_old_loan'] == 0) {
                        modify_account(array("lock_money" => -$lv['money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投标成功", 2);
                    }
                }
            }
            //返利给用户
            if (floatval($lv["rebate_money"]) != 0 || intval($lv["bid_score"]) != 0) {
                $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()) {
                    //返利
                    if (floatval($lv["rebate_money"]) != 0) {
                        modify_account(array("money" => $lv['rebate_money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投资返利", 24);
                    }
                    //积分
                    if (intval($lv["bid_score"]) != 0) {
                        modify_account(array("score" => $lv['bid_score']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投资返积分", 2);
                    }
                    //VIP奖励
                    if (((int) $lv['income_type'] == 1 || (int) $lv['income_type'] == 2 || (int) $lv['income_type'] == 3 || (int) $lv['income_type'] == 4) && $lv['is_winning'] == 1) {
                        $user_msg_conf = get_user_msg_conf($lv['user_id']);
                        //发放奖励
                        if ($lv['income_type'] == 1) {
                            //红包记录 增加用户金额与不可提现金额
                            $red_envelope_date['user_id'] = $lv['user_id'];
                            $red_envelope_date['deal_id'] = $id;
                            $red_envelope_date['load_id'] = $lv['id'];
                            $red_envelope_date['reward_name'] = "投标收益奖励";
                            $red_envelope_date['gift_type'] = 1;
                            $redmoney = $GLOBALS['db']->getOne("SELECT money FROM " . DB_PREFIX . "vip_red_envelope WHERE id='" . (int) $lv['income_value'] . "'");
                            $red_envelope_date['gift_value'] = $redmoney;
                            $red_envelope_date['status'] = 1;
                            $red_envelope_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $red_envelope_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $is_send_mail = $user_msg_conf['mail_redenvelope'];
                            $is_send_sms = $user_msg_conf['sms_redenvelope'];
                            $TPL_MAIL_NAME = "TPL_MAIL_RED_ENVELOPE";
                            $TPL_SMS_NAME = "TPL_SMS_RED_ENVELOPE";
                            $gift_value = $redmoney;
                            if ($redmoney != 0 && $redmoney != "") {
                                $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $red_envelope_date);
                                //插入
                                modify_account(array('money' => $redmoney, 'nmc_amount' => $redmoney), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],的投标收益奖励  红包现金", 28);
                            }
                        } elseif ($lv['income_type'] == 2) {
                            //收益率
                            $rate_date['user_id'] = $lv['user_id'];
                            $rate_date['deal_id'] = $id;
                            $rate_date['load_id'] = $lv['id'];
                            $rate_date['reward_name'] = "投标收益奖励";
                            $rate_date['gift_type'] = 2;
                            $loadinfo = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_load_repay WHERE load_id='" . $lv['id'] . "'");
                            $interest_money = $loadinfo['repay_money'] - $loadinfo['self_money'];
                            $gift_value = $interest_money * (double) $lv['income_value'] * 0.01;
                            $rate_date['reward_money'] = $gift_value;
                            $rate_date['gift_value'] = $lv['income_value'];
                            $rate_date['status'] = 1;
                            $rate_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $rate_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $rate_date);
                            //插入
                        } elseif ($lv['income_type'] == 3) {
                            //积分
                            $score = (int) $lv['income_value'];
                            $score_date['user_id'] = $lv['user_id'];
                            $score_date['deal_id'] = $id;
                            $score_date['load_id'] = $lv['id'];
                            $score_date['reward_name'] = "投标收益奖励";
                            $score_date['gift_type'] = 3;
                            $score_date['gift_value'] = (int) $lv['income_value'];
                            $score_date['status'] = 1;
                            $score_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $score_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $score_date);
                            //插入
                            $is_send_mail = $user_msg_conf['mail_integral'];
                            $is_send_sms = $user_msg_conf['sms_integral'];
                            $TPL_MAIL_NAME = "TPL_MAIL_INTEGRAL";
                            $TPL_SMS_NAME = "TPL_SMS_INTEGRAL";
                            $gift_value = (int) $lv['income_value'];
                            if ($score != 0) {
                                modify_account(array("score" => $score), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],的投标收益奖励 积分", 28);
                            }
                        } elseif ($lv['income_type'] == 4) {
                            //礼品记录
                            $gift_date['user_id'] = $lv['user_id'];
                            $gift_date['deal_id'] = $id;
                            $gift_date['load_id'] = $lv['id'];
                            $gift_date['reward_name'] = "投标收益奖励";
                            $gift_date['gift_type'] = 4;
                            $gift_date['gift_value'] = (int) $lv['income_value'];
                            $gift_date['status'] = 1;
                            $gift_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $gift_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $gift_date);
                            //插入
                            $is_send_mail = $user_msg_conf['mail_gift'];
                            $is_send_sms = $user_msg_conf['sms_gift'];
                            $TPL_MAIL_NAME = "TPL_MAIL_GIFT";
                            $TPL_SMS_NAME = "TPL_SMS_GIFT";
                            $gift_value = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "vip_gift where id = " . $gift_date['gift_value']);
                        }
                        $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $lv['user_id']);
                        $deal_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal where id = " . $id);
                        //邮件
                        if ($is_send_mail == 1 && app_conf("MAIL_ON") == 1) {
                            $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = '" . $TPL_MAIL_NAME . "'");
                            $tmpl_content = $tmpl['content'];
                            $notice['user_name'] = $user_info['user_name'];
                            $notice['deal_name'] = $deal_name;
                            $notice['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $notice['site_name'] = app_conf("SHOP_TITLE");
                            $notice['gift_value'] = $gift_value;
                            $GLOBALS['tmpl']->assign("notice", $notice);
                            $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                            $msg_data['dest'] = $user_info['email'];
                            $msg_data['send_type'] = 1;
                            $msg_data['title'] = "投标奖励邮件通知";
                            $msg_data['content'] = addslashes($msg);
                            $msg_data['send_time'] = 0;
                            $msg_data['is_send'] = 0;
                            $msg_data['create_time'] = TIME_UTC;
                            $msg_data['user_id'] = $user_info['id'];
                            $msg_data['is_html'] = $tmpl['is_html'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                            //插入
                        }
                        //短信
                        if ($is_send_sms == 1 && app_conf("SMS_ON") == 1) {
                            $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = '" . $TPL_SMS_NAME . "'");
                            $tmpl_content = $tmpl['content'];
                            $notice['user_name'] = $user_info['user_name'];
                            $notice['deal_name'] = $deal_name;
                            $notice['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $notice['site_name'] = app_conf("SHOP_TITLE");
                            $notice['gift_value'] = $gift_value;
                            $GLOBALS['tmpl']->assign("notice", $notice);
                            $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                            $msg_data['dest'] = $user_info['mobile'];
                            $msg_data['send_type'] = 0;
                            $msg_data['title'] = "投标奖励短信通知";
                            $msg_data['content'] = addslashes($msg);
                            $msg_data['send_time'] = 0;
                            $msg_data['is_send'] = 0;
                            $msg_data['create_time'] = TIME_UTC;
                            $msg_data['user_id'] = $user_info['id'];
                            $msg_data['is_html'] = $tmpl['is_html'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                            //插入
                        }
                    }
                }
            }
        }
        //$GLOBALS['db']->autoExecute(DB_PREFIX."deal_load",array("is_has_loans"=>1),"UPDATE","deal_id=".$id);
        make_repay_plan($deal_info);
        //发借款成功邮件
        send_deal_success_mail_sms($id, $deal_info);
        //发借款成功站内信
        send_deal_success_site_sms($id, $deal_info);
        $return['status'] = 1;
        $return['info'] = "放款成功";
        return $return;
    } else {
        $return['info'] = "放款失败";
        return $return;
    }
}
Example #7
0
function dotrans_ok($transfer_id)
{
    $transfer = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_load_transfer where id = " . $transfer_id);
    //发送消息
    $msg_conf = get_user_msg_conf($transfer['user_id']);
    if ($msg_conf['sms_transfer'] == 1 || $msg_conf['mail_transfer'] == 1) {
        $transfer['tuser'] = get_user("user_name,email", $transfer['t_user_id']);
        $transfer['user'] = get_user("user_name,email", $transfer['user_id']);
    }
    if ($msg_conf['sms_transfer'] == 1) {
        $content = "您好,您在" . app_conf("SHOP_TITLE") . "的债权 “<a href=\"" . url("index", "transfer#detail", array("id" => $transfer['id'])) . "\">Z-" . $transfer['load_id'] . "</a>” 成功转让给:<a href=\"" . $transfer['tuser']['url'] . "\">" . $transfer['tuser']['user_name'] . "</a>";
        send_user_msg("", $content, 0, $transfer['user_id'], TIME_UTC, 0, true, 18);
    }
    //邮件
    if ($msg_conf['mail_transfer'] == 1 && app_conf('MAIL_ON') == 1) {
        $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_TRANSFER_SUCCESS'");
        $tmpl_content = $tmpl['content'];
        $notice['user_name'] = $transfer['user']['user_name'];
        $notice['transfer_time'] = to_date($transfer['create_time'], "Y年m月d日");
        $notice['transfer_id'] = "Z-" . $transfer['load_id'];
        $notice['deal_url'] = SITE_DOMAIN . url("index", "transfer#detail", array("id" => $transfer['id']));
        $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");
        $GLOBALS['tmpl']->assign("notice", $notice);
        $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
        $msg_data['dest'] = $transfer['user']['email'];
        $msg_data['send_type'] = 1;
        $msg_data['title'] = "“债权:Z-" . $transfer['load_id'] . "”转让通知";
        $msg_data['content'] = addslashes($msg);
        $msg_data['send_time'] = 0;
        $msg_data['is_send'] = 0;
        $msg_data['create_time'] = TIME_UTC;
        $msg_data['user_id'] = $transfer['user_id'];
        $msg_data['is_html'] = $tmpl['is_html'];
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    if (app_conf('SMS_ON') == 1) {
        $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_TRANSFER_SUCCESS'");
        $tmpl_content = $tmpl['content'];
        $notice['user_name'] = $transfer['user']['user_name'];
        $notice['transfer_time'] = to_date($transfer['create_time'], "Y年m月d日");
        $notice['transfer_id'] = "Z-" . $transfer['load_id'];
        $notice['site_name'] = app_conf("SHOP_TITLE");
        $GLOBALS['tmpl']->assign("notice", $notice);
        $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
        $msg_data['dest'] = $transfer['user']['mobile'];
        $msg_data['send_type'] = 0;
        $msg_data['title'] = "“债权:Z-" . $transfer['load_id'] . "”转让通知";
        $msg_data['content'] = addslashes($msg);
        $msg_data['send_time'] = 0;
        $msg_data['is_send'] = 0;
        $msg_data['create_time'] = TIME_UTC;
        $msg_data['user_id'] = $transfer['user_id'];
        $msg_data['is_html'] = $tmpl['is_html'];
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    //发送债权协议
    send_transfer_contract_email($transfer_id);
}
 function savedebit()
 {
     $view["type"] = intval($_REQUEST["type"]);
     $view["debit_money"] = strim($_REQUEST["debit_money"]);
     $view["repay_time"] = intval($_REQUEST["repaytime"]);
     $view["university"] = strim($_REQUEST["university"]);
     $view["address"] = strim($_REQUEST["address"]);
     $view["mobile"] = strim($_REQUEST["mobile"]);
     $is_ajax = intval($_REQUEST["is_ajax"]);
     if (strim($GLOBALS["user_info"]["u_alipay"]) == "") {
         showErr("请先绑定支付宝", $is_ajax);
     }
     if ($view["university"] == "") {
         showErr("请填写学校信息", $is_ajax);
     }
     if ($view["address"] == "") {
         showErr("请填写地址", $is_ajax);
     }
     if ($view["mobile"] == "") {
         showErr("请填写联系电话", $is_ajax);
     }
     if ($view["type"] == "" || $view["debit_money"] == "" || $view["repay_time"] == "") {
         showErr("请返回重新提交", $is_ajax);
     }
     $is_ajax = intval($_REQUEST['is_ajax']);
     if (!$GLOBALS['user_info']) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $is_ajax);
     }
     $t = trim($_REQUEST['t']);
     if (!in_array($t, array("save", "publish"))) {
         showErr($GLOBALS['lang']['ERROR_TITLE'], $is_ajax);
     }
     /*读取白条配置*/
     $debit_conf = $GLOBALS["db"]->getRow("select * from " . DB_PREFIX . "debit_conf");
     /*读取标类别作为商品名*/
     $view["deal_loan_type"] = $GLOBALS["db"]->getOne("select name from " . DB_PREFIX . "deal_loan_type");
     if ($t == "save") {
         $data['is_delete'] = 2;
     } else {
         $data['is_delete'] = 0;
     }
     $data['name'] = $view["deal_loan_type"] . $view["debit_money"] . "元";
     if (empty($data['name'])) {
         showErr("请输入借款标题", $is_ajax);
     }
     $data['publish_wait'] = 1;
     $icon_type = "systemImg";
     if ($icon_type == "") {
         showErr("请选择借款图片类型", $is_ajax);
     }
     $icon_type_arr = array('upload' => 1, 'userImg' => 2, 'systemImg' => 3);
     $data['icon_type'] = $icon_type_arr[$icon_type];
     if (intval($data['icon_type']) == 0) {
         showErr("请选择借款图片类型", $is_ajax);
     }
     $_REQUEST['systemimgpath'] = $view["type"];
     switch ($data['icon_type']) {
         case 1:
             if (strim($_REQUEST['icon']) == '') {
                 showErr("请上传图片", $is_ajax);
             } else {
                 $data['icon'] = replace_public(strim($_REQUEST['icon']));
             }
             break;
         case 2:
             $data['icon'] = replace_public(get_user_avatar($GLOBALS['user_info']['id'], 'big'));
             break;
         case 3:
             if (intval($_REQUEST['systemimgpath']) == 0) {
                 showErr("请选择系统图片", $is_ajax);
             } else {
                 $data['icon'] = $GLOBALS['db']->getOne("SELECT icon FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . intval($_REQUEST['systemimgpath']));
             }
             break;
     }
     //$data['cate_id'] = $data['type_id'] = intval($view["type"]);
     $data['type_id'] = intval($view["type"]);
     if ($data['type_id'] == 0) {
         showErr("请选择借款用途", $is_ajax);
     }
     $data['borrow_amount'] = floatval($view["debit_money"]);
     /*if($data['borrow_amount'] < (int)trim(app_conf('MIN_BORROW_QUOTA')) || $data['borrow_amount'] > (int)trim(app_conf('MAX_BORROW_QUOTA')) || $data['borrow_amount'] %50 != 0){
      		showErr("请正确选择借款金额",$is_ajax);
      	}*/
     //判断是否需要额度
     if ($GLOBALS['db']->getOne("SELECT is_quota FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . $data['type_id']) == 1) {
         if (intval($GLOBALS['user_info']['quota']) != 0) {
             $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
             if ($data['borrow_amount'] > intval($can_use_quota)) {
                 showErr("输入借款的借款金额超过您的可用额度<br>您当前可用额度为:" . $can_use_quota, $is_ajax);
             }
         }
     }
     $data['repay_time'] = intval($_REQUEST['repaytime']);
     if ($data['repay_time'] == 0) {
         showErr("借款期限", $is_ajax);
     }
     $data['rate'] = floatval($view["rate"]);
     //
     $data['repay_time_type'] = 1;
     //按月
     $min_rate = 0;
     $max_rate = 0;
     $is_rate_lock = false;
     $level_list = load_auto_cache("level");
     $level_list_info = reset($level_list["repaytime_list"]);
     foreach ($level_list_info as $k => $v) {
         if ($v[1] != 0 && $v[0] == $view["repay_time"]) {
             $min_rate = $v[2];
             $max_rate = $v[3];
             break;
         }
     }
     if ($debit_conf["rate_cfg"] == 0) {
         $data["rate"] = $min_rate;
     } elseif ($debit_conf["rate_cfg"] == 1) {
         $data["rate"] = floatval(($min_rate + $max_rate) / 2);
     } elseif ($debit_conf["rate_cfg"] == 2) {
         $data["rate"] = $max_rate;
     }
     if (floatval($data['rate']) <= 0 || floatval($data['rate']) > $max_rate || floatval($data['rate']) < $min_rate) {
         showErr("请正确输入借款利率", $is_ajax);
     }
     $data['enddate'] = intval($debit_conf['enddate']);
     //筹标期限
     $data['description'] = $GLOBALS["user_info"]["user_name"] . "的白条:" . $view["deal_loan_type"] . $view["debit_money"] . "元";
     if (trim($data['description']) == '') {
         showErr("请输入项目描述", $is_ajax);
     }
     $datas["university"] = $view["university"];
     $datas["address"] = $view["address"];
     $datas["mobile"] = $view["mobile"];
     //$datas['view_info'] = serialize($user_view_info);
     $GLOBALS['db']->autoExecute(DB_PREFIX . "user", $datas, "UPDATE", "id=" . $GLOBALS['user_info']['id']);
     $data["services_fee"] = $debit_conf["services_fee"];
     $data["manage_fee"] = $debit_conf["manage_fee"];
     $data["manage_impose_fee_day1"] = $debit_conf["manage_impose_fee_day1"];
     $data["manage_impose_fee_day2"] = $debit_conf["manage_impose_fee_day2"];
     $data["impose_fee_day1"] = $debit_conf["impose_fee_day1"];
     $data["impose_fee_day2"] = $debit_conf["impose_fee_day2"];
     $data['voffice'] = 1;
     $data['vposition'] = 1;
     $data['is_effect'] = 1;
     $data['deal_status'] = 0;
     $data['agency_id'] = 0;
     //担保机构
     $data['agency_status'] = 1;
     $data['warrant'] = 0;
     //担保类型
     $data['guarantor_margin_amt'] = 0;
     //担保保证金
     $data['guarantor_pro_fit_amt'] = 0;
     //担保收益
     $data['user_id'] = intval($GLOBALS['user_info']['id']);
     $data['loantype'] = intval($view['loantype']);
     if ($data['repay_time_type'] == 0) {
         $data['loantype'] = 2;
     }
     //当为天的时候
     if ($data['repay_time_type'] == 0) {
         $true_repay_time = 1;
     } else {
         $true_repay_time = $data['repay_time'];
     }
     //本金担保
     if ($data['warrant'] == 1) {
         $data['guarantor_amt'] = $data['borrow_amount'];
     } elseif ($data['warrant'] == 2) {
         //等额本息
         if ($data['loantype'] == 0) {
             $data['guarantor_amt'] = pl_it_formula($data['borrow_amount'], $data['rate'] / 12 / 100, $true_repay_time) * $true_repay_time;
         }
     }
     $data['is_hidden'] = 1;
     $data['create_time'] = TIME_UTC;
     //推荐人
     $work_id = strim($_REQUEST["work_id"]);
     if ($work_id) {
         $data["admin_id"] = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "admin where work_id = '" . $work_id . "'");
     }
     $module = "INSERT";
     $jumpurl = url("debit", "debit_uc_center#order");
     $condition = "";
     $deal_id = $GLOBALS['db']->getOne("SELECT id FROM " . DB_PREFIX . "deal WHERE ((is_delete=2 or is_delete=3) or (is_delete=0 and publish_wait=1)) AND user_id=" . $GLOBALS['user_info']['id']);
     if ($deal_id > 0) {
         $module = "UPDATE";
         if ($t == "save") {
             $jumpurl = url("debit", "debit_uc_center#order");
         }
         $condition = "id = {$deal_id}";
     } else {
         if ($t == "save") {
             $jumpurl = url("debit", "debit_uc_center#order");
         }
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $data, $module, $condition);
     if ($module == "INSERT") {
         $deal_id = $GLOBALS['db']->insert_id();
     }
     require_once APP_ROOT_PATH . 'app/Lib/deal.php';
     $deal = get_deal($deal_id);
     //发送验证通知
     if ($t != "save" && trim(app_conf('CUSTOM_SERVICE')) != '' && ($GLOBALS['user_info']['idcardpassed'] == 0 || $GLOBALS['user_info']['incomepassed'] == 0 || $GLOBALS['user_info']['creditpassed'] == 0 || $GLOBALS['user_info']['workpassed'] == 0)) {
         $ulist = explode(",", trim(app_conf('CUSTOM_SERVICE')));
         $ulist = array_filter($ulist);
         if ($ulist) {
             $uuid = $ulist[array_rand($ulist)];
             if ($uuid > 0) {
                 $content = app_conf("SHOP_TITLE") . "用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话 " . app_conf('SHOP_TEL') . " 或给客服邮箱发邮件 " . app_conf("REPLY_ADDRESS") . " 我们会及时给您回复。";
                 require_once APP_ROOT_PATH . 'app/Lib/message.php';
                 //添加留言
                 $message['title'] = $content;
                 $message['content'] = htmlspecialchars(addslashes(valid_str($content)));
                 $message['title'] = valid_str($message['title']);
                 $message['create_time'] = TIME_UTC;
                 $message['rel_table'] = "deal";
                 $message['rel_id'] = $deal_id;
                 $message['user_id'] = $uuid;
                 $message['is_effect'] = 1;
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
                 //添加到动态
                 insert_topic("message", $message['rel_id'], $message['user_id'], get_user_name($message['user_id'], false), $GLOBALS['user_info']['id']);
                 //自己给自己留言不执行操作
                 if ($deal['user_id'] != $message['user_id']) {
                     $msg_conf = get_user_msg_conf($deal['user_id']);
                     //站内信
                     if ($msg_conf['sms_asked'] == 1) {
                         $notices['shop_title'] = app_conf("SHOP_TITLE");
                         $notices['shop_tel'] = app_conf('SHOP_TEL');
                         $notices['shop_address'] = app_conf("REPLY_ADDRESS");
                         /*{$notice.shop_title}用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话{$notice.shop_tel}或给客服邮箱发邮件{$notice.shop_address}我们会及时给您回复。*/
                         $notices['url'] = "“<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”";
                         $notices['user_name'] = get_user_name($message['user_id']);
                         $notices['money'] = $user_load_data['true_repay_money'] + $user_load_data['impose_money'];
                         $tmpl_content = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_WORDS_MSG'", false);
                         $GLOBALS['tmpl']->assign("notice", $notices);
                         $contents = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content['content']);
                         send_user_msg("", $contents, 0, $deal['user_id'], TIME_UTC, 0, true, 13, $message['rel_id']);
                     }
                     //邮件
                     if ($msg_conf['mail_asked'] == 1 && app_conf('MAIL_ON') == 1) {
                         $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_DEAL_MSG'");
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $GLOBALS['user_info']['user_name'];
                         $notice['msg_user_name'] = get_user_name($message['user_id'], false);
                         $notice['deal_name'] = $deal['name'];
                         $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $deal['id']));
                         $notice['message'] = $message['content'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                         $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                         $GLOBALS['tmpl']->assign("notice", $notice);
                         $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                         $msg_data['dest'] = $GLOBALS['user_info']['email'];
                         $msg_data['send_type'] = 1;
                         $msg_data['title'] = get_user_name($message['user_id'], false) . "给您的标留言!";
                         $msg_data['content'] = addslashes($msg);
                         $msg_data['send_time'] = 0;
                         $msg_data['is_send'] = 0;
                         $msg_data['create_time'] = TIME_UTC;
                         $msg_data['user_id'] = $GLOBALS['user_info']['id'];
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($is_ajax == 1) {
         showSuccess("提交成功,请等待管理员审核", $is_ajax, $jumpurl);
     } else {
         app_redirect($jumpurl);
     }
 }
Example #9
0
 /**
  * 代还款
  */
 function do_site_repay($page = 1)
 {
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $id = intval($_REQUEST['id']);
     $l_key = intval($_REQUEST['l_key']);
     $this->assign("jumpUrl", U("Deal/repay_plan", array("id" => $id)));
     if ($id == 0) {
         $this->success("数据错误");
     }
     $deal_info = get_deal($id);
     if (!$deal_info) {
         $this->success("借款不存在");
     }
     if ($deal_info['ips_bill_no'] != "") {
         $this->success("第三方同步暂无法代还款");
     }
     if ($page == 0) {
         $page = 1;
     }
     $page_size = 10;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $user_loan_list = get_deal_user_load_list($deal_info, 0, $l_key, -1, 0, 0, 1, $limit);
     $rs_count = $user_loan_list['count'];
     $page_all = ceil($rs_count / $page_size);
     require_once APP_ROOT_PATH . "system/libs/user.php";
     foreach ($user_loan_list['item'] as $kk => $vv) {
         if ($vv['has_repay'] == 0) {
             //借入者已还款,但是没打款到借出用户中心
             $user_load_data = array();
             $user_load_data['true_repay_time'] = TIME_UTC;
             $user_load_data['is_site_repay'] = 1;
             $user_load_data['status'] = 0;
             $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'];
             $user_load_data['repay_manage_impose_money'] = $vv['repay_manage_impose_money'];
             if ($vv['status'] > 0) {
                 $user_load_data['status'] = $vv['status'] - 1;
             }
             $user_load_data['has_repay'] = 1;
             $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "UPDATE", "id=" . $vv['id'] . " AND has_repay = 0 ", "SILENT");
             if ($GLOBALS['db']->affected_rows() > 0) {
                 $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”成功还款" . ($vv['month_repay_money'] + $vv['impose_money']) . "元,";
                 $unext_loan = $user_loan_list[$vv['u_key']][$kk + 1];
                 if ($unext_loan) {
                     $content .= "本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需还本息" . number_format($unext_loan['month_repay_money'], 2) . "元。";
                 } else {
                     $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=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']), 2);
                     $all_impose_money = number_format($GLOBALS['db']->getOne("SELECT sum(impose_money) FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']), 2);
                     $content .= "本次投标共获得收益:" . $all_repay_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!";
                 }
                 if ($user_load_data['impose_money'] != 0 || $user_load_data['manage_money'] != 0 || $user_load_data['repay_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 ($user_load_data['repay_money'] != 0) {
                         modify_account(array("money" => $user_load_data['repay_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",回报本息");
                     }
                     if ($user_load_data['impose_money'] != 0) {
                         modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",逾期罚息");
                     }
                     if ($user_load_data['manage_money'] != 0) {
                         modify_account(array("money" => -$user_load_data['manage_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",投标管理费");
                     }
                     $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_info['sub_name'];
                         $notice['deal_url'] = $deal_info['url'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['repay_money'] = number_format($vv['month_repay_money'] + $vv['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $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_UTC;
                         $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_UTC, 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_info['sub_name'];
                         $notice['deal_url'] = $deal_info['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'] = number_format($vv['month_repay_money'] + $vv['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $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_info['name'] . "”回款通知";
                         $msg_data['content'] = addslashes($msg);
                         $msg_data['send_time'] = 0;
                         $msg_data['is_send'] = 0;
                         $msg_data['create_time'] = TIME_UTC;
                         $msg_data['user_id'] = $in_user_id;
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($page >= $page_all) {
         $s_count = $GLOBALS['db']->getOne("SELECT count(*) FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0");
         if ($s_count == 0) {
             $rs_sum = $GLOBALS['db']->getRow("SELECT sum(repay_money) as total_repay_money,sum(manage_money) as total_manage_money,sum(impose_money) as total_impose_money,sum(repay_manage_impose_money) as total_repay_manage_impose_money FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 1");
             $deal_load_list = get_deal_load_list($deal_info);
             $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay set status = " . ($deal_load_list[$l_key]['status'] - 1) . ",true_repay_time = " . TIME_UTC . ", has_repay = 1, impose_money='" . floatval($rs_sum['total_impose_money']) . "',mange_impose_money='" . floatval($rs_sum['total_repay_manage_impose_money']) . "' where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0");
             if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "generation_repay WHERE deal_id=" . $id . " AND repay_id=" . $deal_load_list[$l_key]['repay_id'] . "") == 0) {
                 $generation_repay['deal_id'] = $id;
                 $generation_repay['repay_id'] = $deal_load_list[$l_key]['repay_id'];
                 $adm_session = es_session::get(md5(conf("AUTH_KEY")));
                 $generation_repay['admin_id'] = $adm_session['adm_id'];
                 $generation_repay['agency_id'] = $deal_info['agency_id'];
                 $generation_repay['repay_money'] = $rs_sum['total_repay_money'];
                 $generation_repay['impose_money'] = $rs_sum['total_impose_money'];
                 $generation_repay['manage_money'] = $rs_sum['total_manage_money'];
                 $generation_repay['manage_impose_money'] = $rs_sum['total_repay_manage_impose_money'];
                 $generation_repay['create_time'] = TIME_UTC;
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "generation_repay", $generation_repay);
             }
         }
         $this->success("代还款执行完毕!");
     } else {
         register_shutdown_function(array(&$this, 'do_site_repay'), $page + 1);
     }
 }