public function mobile()
 {
     /*if(!$GLOBALS['user_info']){
     			set_gopreview();
     			app_redirect(url("index","user#login"));
     		}*/
     $id = intval($_REQUEST['id']);
     $deal = get_deal($id);
     send_deal_contract_email($id, $deal, $deal['user_id']);
     if (!$deal) {
         app_redirect(url("index"));
     }
     //借款列表
     $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']);
     $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']) {
         $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);
             $GLOBALS['tmpl']->assign("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);
         $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     }
     $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));
     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", $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 . ",");
     //留言
     require APP_ROOT_PATH . 'app/Lib/message.php';
     require APP_ROOT_PATH . 'app/Lib/page.php';
     $rel_table = 'deal';
     $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', "deal");
     //分页
     $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']);
     if (!$GLOBALS['user_info']) {
         $GLOBALS['tmpl']->assign("message_login_tip", sprintf($GLOBALS['lang']['MESSAGE_LOGIN_TIP'], url("shop", "user#login"), url("shop", "user#register")));
     }
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->display("deal_mobile.html");
 }
 public function update()
 {
     B('FilterString');
     $data = M("Deal")->create();
     $log_info = M("Deal")->where("id=" . intval($data['id']))->getField("name");
     //开始验证有效性
     $this->assign("jumpUrl", "javascript:history.back(-1);");
     if (!check_empty($data['name'])) {
         $this->error(L("DEAL_NAME_EMPTY_TIP"));
     }
     if (!check_empty($data['sub_name'])) {
         $this->error(L("DEAL_SUB_NAME_EMPTY_TIP"));
     }
     if ($data['cate_id'] == 0) {
         $this->error(L("DEAL_CATE_EMPTY_TIP"));
     }
     if (D("Deal")->where("deal_sn='" . $data['deal_sn'] . "' and id<>" . $data['id'])->count() > 0) {
         $this->error("借款编号已存在");
     }
     $loantype_list = load_auto_cache("loantype_list");
     if (!in_array($data['repay_time_type'], $loantype_list[$data['loantype']]['repay_time_type'])) {
         $this->error("还款方式不支持当前借款期限类型");
     }
     $data['update_time'] = TIME_UTC;
     $data['publish_wait'] = 0;
     $data['start_time'] = trim($data['start_time']) == '' ? 0 : to_timespan($data['start_time']);
     $user_info = M("User")->getById($data['user_id']);
     $old_imgdata_str = unserialize($user_info['view_info']);
     $data['view_info'] = array();
     foreach ($_REQUEST['key'] as $k => $v) {
         if (isset($old_imgdata_str[$v])) {
             $data['view_info'][$v] = $old_imgdata_str[$v];
         }
     }
     $data['view_info'] = serialize($data['view_info']);
     if ($data['deal_status'] == 4) {
         if ($GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "deal_load where deal_id=" . $data['id']) < floatval($data['borrow_amount'])) {
             $this->error("未满标无法设置为还款状态!");
             exit;
         }
     }
     if ($data['agency_id'] != M("Deal")->where("id=" . $data['id'])->getField("agency_id")) {
         $data['agency_status'] = 0;
     }
     // 更新数据
     $list = M("Deal")->save($data);
     if (false !== $list) {
         M("DealCityLink")->where("deal_id=" . $data['id'])->delete();
         foreach ($_REQUEST['city_id'] as $k => $v) {
             if (intval($v) > 0) {
                 $deal_city_link['deal_id'] = $data['id'];
                 $deal_city_link['city_id'] = intval($v);
                 M("DealCityLink")->add($deal_city_link);
             }
         }
         require_once APP_ROOT_PATH . "app/Lib/common.php";
         if ($data['is_delete'] == 3) {
             //发送失败短信通知
             if (app_conf("SMS_ON") == 1) {
                 $user_info = D("User")->where("id=" . $data['user_id'])->find();
                 $deal_info = D("Deal")->where("id=" . $data['id'])->find();
                 $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_DEAL_DELETE'");
                 $tmpl_content = $tmpl['content'];
                 $notice['user_name'] = $user_info["user_name"];
                 $notice['deal_name'] = $data['name'];
                 $notice['site_name'] = app_conf("SHOP_TITLE");
                 $notice['delete_msg'] = $data['delete_msg'];
                 $notice['deal_publish_time'] = to_date($deal_info['create_time'], "Y年m月d日");
                 $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);
                 //插入
             }
         } else {
             //成功提示
             syn_deal_status($data['id']);
             syn_deal_match($data['id']);
             //发送电子协议邮件
             require_once APP_ROOT_PATH . "app/Lib/deal.php";
             send_deal_contract_email($data['id'], array(), $data['user_id']);
         }
         //成功提示
         save_log("编号:" . $data['id'] . "," . $log_info . L("UPDATE_SUCCESS"), 1);
         $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         $dbErr = M()->getDbError();
         save_log("编号:" . $data['id'] . "," . $log_info . L("UPDATE_FAILED") . $dbErr, 0);
         $this->error(L("UPDATE_FAILED") . $dbErr, 0);
     }
 }