Exemplo n.º 1
0
/**
 * 获取指定的产品
 */
function get_goods($id = 0, $preview = 0)
{
    static $deal;
    if ($deal) {
        return $deal;
    }
    $deal = syn_deal_status($id);
    if ($preview) {
        $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($id) . " and is_delete = 0 ");
    }
    if ($deal) {
        $static_deal = load_auto_cache("static_goods_info", array("id" => $deal['id']));
        foreach ($static_deal as $k => $v) {
            $deal[$k] = $v;
        }
        if ($GLOBALS['user_info']) {
            if (app_conf("URL_MODEL") == 0) {
                $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            } else {
                $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            }
        }
        //查询抽奖号
        $deal['lottery_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($deal['id']) . " and buyer_id <> 0 ")) + intval($deal['buy_count']);
        //开始获取处理库存
        $deal['stock'] = $deal['max_bought'] - $deal['buy_count'];
    }
    return $deal;
}
 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);
     }
 }
Exemplo n.º 3
0
/**
 * 执行转让
 */
function getUcDoTransfer($id, $tid, $paypassword, $transfer_money)
{
    $paypassword = strim($paypassword);
    $id = intval($id);
    $tid = intval($tid);
    $transfer_money = floatval($transfer_money);
    $status = array('status' => 0, 'show_err' => '');
    if ($id == 0) {
        $status['status'] = 0;
        $status['show_err'] = "不存在的债权";
        return $status;
    }
    if ($transfer_money <= 0) {
        $status['status'] = 0;
        $status['show_err'] = "转让金额必须大于0";
        return $status;
    }
    $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load WHERE id=" . $id);
    if ($deal_id == 0) {
        $status['status'] = 0;
        $status['show_err'] = "不存在的债权";
        return $status;
    } else {
        syn_deal_status($deal_id);
    }
    //判断支付密码是否正确
    if ($paypassword == "") {
        $status['status'] = 0;
        $status['show_err'] = $GLOBALS['lang']['PAYPASSWORD_EMPTY'];
        return $status;
    }
    if (md5($paypassword) != $GLOBALS['user_info']['paypassword']) {
        $status['status'] = 0;
        $status['show_err'] = $GLOBALS['lang']['PAYPASSWORD_ERROR'];
        return $status;
    }
    $condition = ' AND dl.id=' . $id . ' AND d.deal_status = 4 and d.is_effect=1 and d.is_delete=0 and d.repay_time_type =1 and  d.publish_wait=0 and dl.user_id=' . $GLOBALS['user_info']['id'] . " and d.next_repay_time - " . TIME_UTC . " + 24*3600 - 1 > 0  ";
    $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id and dlt.load_id=dl.id ";
    $sql = 'SELECT dl.id as dlid,d.*,dl.money as load_money,dlt.status as tras_status,dlt.t_user_id,dlt.transfer_amount,dlt.create_time as tras_create_time FROM ' . DB_PREFIX . 'deal_load dl LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id = dl.deal_id ' . $union_sql . ' WHERE 1=1 ' . $condition;
    $transfer = $GLOBALS['db']->getRow($sql);
    if ($transfer) {
        //下个还款日
        if (intval($transfer['next_repay_time']) == 0) {
            $transfer['next_repay_time'] = next_replay_month($transfer['repay_start_time']);
        }
        if ($transfer['next_repay_time'] - TIME_UTC + 24 * 3600 - 1 < 0) {
            $status['status'] = 0;
            $status['show_err'] = "转让操作失败,有逾期未还款存在!";
            return $status;
        }
        //还款日
        $transfer['final_repay_time'] = next_replay_month($transfer['repay_start_time'], $transfer['repay_time']);
        //剩余期数
        if (intval($transfer['last_repay_time']) > 0) {
            $transfer['how_much_month'] = how_much_month($transfer['last_repay_time'], $transfer['final_repay_time']);
        } else {
            $transfer['how_much_month'] = how_much_month($transfer['repay_start_time'], $transfer['final_repay_time']);
        }
        $transfer_rs = deal_transfer($transfer);
        $transfer['month_repay_money'] = $transfer_rs['month_repay_money'];
        $transfer['all_must_repay_money'] = $transfer_rs['all_must_repay_money'];
        $transfer['left_benjin'] = $transfer_rs['left_benjin'];
        //剩多少利息
        $transfer['left_lixi'] = $transfer['all_must_repay_money'] - $transfer['left_benjin'];
        //判断转让金额是否超出了可转让的界限
        if (round($transfer_money, 2) > round(floatval($transfer['all_must_repay_money']), 2)) {
            $status['status'] = 0;
            $status['show_err'] = "转让金额不得大于最大转让金额";
            return $status;
        }
        $transfer_data['create_time'] = TIME_UTC;
        $transfer_data['create_date'] = to_date(TIME_UTC);
        $transfer_data['deal_id'] = $transfer['id'];
        $transfer_data['load_id'] = $id;
        $transfer_data['user_id'] = $GLOBALS['user_info']['id'];
        $transfer_data['transfer_number'] = $transfer['how_much_month'];
        $transfer_data['last_repay_time'] = $transfer['final_repay_time'];
        $transfer_data['load_money'] = $transfer['load_money'];
        $transfer_data['status'] = 1;
        $transfer_data['transfer_amount'] = $transfer_money;
        $transfer_data['near_repay_time'] = $transfer['next_repay_time'];
        if ($tid > 0) {
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_transfer", $transfer_data, "UPDATE", "id=" . $tid);
        } else {
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_transfer", $transfer_data);
        }
        if ($GLOBALS['db']->affected_rows()) {
            $status['status'] = 1;
            $status['show_err'] = "转让操作成功";
            return $status;
        } else {
            $status['status'] = 0;
            $status['show_err'] = "转让操作失败";
            return $status;
        }
    } else {
        $status['status'] = 0;
        $status['show_err'] = "不存在的债权";
        return $status;
    }
}
 function autobid()
 {
     $deal_list = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "Deal limit 1000");
     foreach ($deal_list as $v) {
         syn_deal_status($v['id']);
     }
 }
Exemplo n.º 5
0
 public function index()
 {
     $add_order_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "add_order where time < " . time() . " and state=0");
     if ($add_order_list) {
         $deal_id_array = array();
         foreach ($add_order_list as $key => $val) {
             if (!in_array($val['deal_id'], $deal_id_array)) {
                 $deal_id_array[] = $val['deal_id'];
             }
             $tmp_deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $val['deal_id']);
             $tmp_deal_item_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_item where id = " . $val['deal_item_id']);
             for ($i = 0; $i < $val['num']; $i++) {
                 $tmp_num = rand(0, 50000);
                 $tmp_time = rand(100, 86000);
                 //获取导入用户
                 $tmp_user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where login_ip = '' limit " . $tmp_num . ",1");
                 $tmp_order_info = array();
                 $tmp_order_info['deal_id'] = $val['deal_id'];
                 $tmp_order_info['deal_item_id'] = $val['deal_item_id'];
                 $tmp_order_info['user_id'] = $tmp_user_info['id'];
                 $tmp_order_info['user_name'] = $tmp_user_info['user_name'];
                 $tmp_order_info['pay_time'] = $val['time'] + $tmp_time;
                 $tmp_order_info['total_price'] = $tmp_deal_item_info['delivery_fee'] + $tmp_deal_item_info['price'];
                 $tmp_order_info['delivery_fee'] = $tmp_deal_item_info['delivery_fee'];
                 $tmp_order_info['deal_price'] = $tmp_deal_item_info['price'];
                 $tmp_order_info['support_memo'] = '支持!加油!';
                 $tmp_order_info['payment_id'] = 35;
                 $tmp_order_info['credit_pay'] = 0;
                 $tmp_order_info['online_pay'] = $tmp_deal_item_info['delivery_fee'] + $tmp_deal_item_info['price'];
                 $tmp_order_info['deal_name'] = $tmp_deal_info['name'];
                 $tmp_order_info['order_status'] = 3;
                 $tmp_order_info['create_time'] = $val['time'] + $tmp_time;
                 $tmp_order_info['is_has_send_success'] = 1;
                 if ($tmp_deal_item_info['is_delivery'] == 1) {
                     $tmp_order_info['consignee'] = '杨小帆';
                     $tmp_order_info['mobile'] = '18601911314';
                     $tmp_order_info['province'] = '北京';
                     $tmp_order_info['city'] = '东城区';
                     $tmp_order_info['address'] = '朝阳门 银河SOHO D2座 5层 50538';
                 }
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $tmp_order_info);
             }
             $GLOBALS['db']->query("update " . DB_PREFIX . "add_order set state = 1 where id = " . $val['id']);
         }
         foreach ($deal_id_array as $k2 => $v2) {
             $id = $v2;
             $order_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order where deal_id = " . $id . " and order_status=3");
             $item_array = array();
             foreach ($order_list as $k => $v) {
                 $log_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_support_log where deal_id = " . $v['deal_id'] . " and user_id=" . $v['user_id'] . " and create_time='" . $v['pay_time'] . "' and deal_item_id=" . $v['deal_item_id']);
                 if ($log_list) {
                 } else {
                     $tmp_log_info = array();
                     $tmp_log_info['deal_id'] = $v['deal_id'];
                     $tmp_log_info['deal_item_id'] = $v['deal_item_id'];
                     $tmp_log_info['user_id'] = $v['user_id'];
                     $tmp_log_info['create_time'] = $v['pay_time'];
                     $tmp_log_info['price'] = $v['total_price'];
                     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_support_log", $tmp_log_info);
                     $tmp_log_id = $GLOBALS['db']->insert_id();
                     echo 'add log id = ' . $tmp_log_id . ' 。' . "<br>";
                 }
                 if (isset($item_array[$v['deal_item_id']])) {
                     $item_array[$v['deal_item_id']]['num'] += 1;
                     $item_array[$v['deal_item_id']]['total'] += $v['total_price'];
                 } else {
                     $item_array[$v['deal_item_id']] = array();
                     $item_array[$v['deal_item_id']]['num'] = 1;
                     $item_array[$v['deal_item_id']]['total'] = $v['total_price'];
                 }
             }
             foreach ($item_array as $ki => $vi) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_item set support_count = " . intval($vi['num']) . ",support_amount = " . intval($vi['total']) . " where id = " . $ki);
                 echo 'update item num = ' . $vi['num'] . "<br>";
             }
             syn_deal_status($id);
             syn_deal($id);
             echo 'OK';
         }
     }
 }
Exemplo n.º 6
0
 function dtcontact()
 {
     $win = 1;
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['TT_CONTACT'] . ' - ' . $GLOBALS['lang']['TOOLS']);
     $id = intval($_REQUEST['id']);
     if ($id > 0) {
         //先执行更新借贷信息
         $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load_transfer WHERE id=" . $id);
         if ($deal_id == 0) {
             echo "不存在的债权";
             die;
         } else {
             syn_deal_status($deal_id);
         }
         $condition = ' AND dlt.id=' . $id . ' AND d.deal_status >= 4 and d.is_effect=1 and d.is_delete=0  and d.repay_time_type =1 and  d.publish_wait=0 and (dlt.user_id=' . $GLOBALS['user_info']['id'] . ' or dlt.t_user_id = ' . $GLOBALS['user_info']['id'] . ') ';
         $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
         require APP_ROOT_PATH . "/app/Lib/deal_func.php";
         $transfer = get_transfer($union_sql, $condition);
         if ($transfer) {
             $GLOBALS['tmpl']->assign('transfer', $transfer);
         } else {
             echo "不存在的债权";
             die;
         }
         $GLOBALS['tmpl']->assign('SITE_URL', str_replace(array("https://", "http://"), "", SITE_DOMAIN));
         $GLOBALS['tmpl']->assign('SITE_TITLE', app_conf("SITE_TITLE"));
         $GLOBALS['tmpl']->assign('CURRENCY_UNIT', app_conf("CURRENCY_UNIT"));
         $contract = $GLOBALS['tmpl']->fetch("str:" . get_contract($transfer['tcontract_id']));
         $GLOBALS['tmpl']->assign('contract', $contract);
     }
     require APP_ROOT_PATH . "/system/utils/word.php";
     $word = new word();
     $word->start();
     $wordname = "债权转让及受让协议.doc";
     echo $GLOBALS['tmpl']->fetch("inc/tool/tcontact.html");
     $word->save($wordname);
 }
Exemplo n.º 7
0
 public function shop_update()
 {
     B('FilterString');
     $data = M(MODULE_NAME)->create();
     //对于商户请求操作
     if (intval($_REQUEST['edit_type']) == 2 && intval($_REQUEST['deal_id']) > 0) {
         //商户提交修改审核
         $deal_submit_id = intval($_REQUEST['id']);
         $data['id'] = intval($_REQUEST['deal_id']);
     }
     $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name");
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/shop_edit", array("id" => $data['id'])));
     if ($data['buy_type'] == 0) {
         if (intval($data['return_score']) < 0) {
             $this->error("积分返还不能为负数");
         }
         if (floatval($data['return_money']) < 0) {
             $this->error("现金返还不能为负数");
         }
     } else {
         $data['return_score'] = "-" . abs($_REQUEST['deal_score']);
         if (intval($_REQUEST['deal_score']) == 0) {
             $this->error("请输入所需的积分");
         }
     }
     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['shop_cate_id'] == 0) {
         $this->error(L("SHOP_CATE_EMPTY_TIP"));
     }
     if ($data['max_bought'] < 0) {
         $this->error(L("DEAL_MAX_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_min_bought'] < 0) {
         $this->error(L("DEAL_USER_MIN_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_max_bought'] < 0) {
         $this->error(L("DEAL_USER_MAX_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_max_bought'] < $data['user_min_bought'] && $data['user_max_bought'] > 0) {
         $this->error(L("DEAL_USER_MAX_MIN_BOUGHT_ERROR_TIP"));
     }
     if ($data['brand_promote'] == 1) {
         //品牌促销
         $brand_info = M("Brand")->getById($data['brand_id']);
         if ($brand_info['brand_promote'] == 1) {
             $data['begin_time'] = $brand_info['begin_time'];
             $data['end_time'] = $brand_info['end_time'];
         }
     } else {
         $data['begin_time'] = strim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']);
         $data['end_time'] = strim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']);
     }
     $data['coupon_begin_time'] = strim($data['coupon_begin_time']) == '' ? 0 : to_timespan($data['coupon_begin_time']);
     $data['coupon_end_time'] = strim($data['coupon_end_time']) == '' ? 0 : to_timespan($data['coupon_end_time']);
     //将第一张图片设为团购图片
     $imgs = $_REQUEST['img'];
     foreach ($imgs as $k => $v) {
         if ($v != '') {
             $data['img'] = $v;
             break;
         }
     }
     $data['update_time'] = NOW_TIME;
     $data['publish_wait'] = 0;
     if (intval($data['is_coupon']) == 1 && intval($data['is_refund']) == 1) {
         $data['expire_refund'] = intval($_REQUEST['expire_refund']);
         $data['any_refund'] = intval($_REQUEST['any_refund']);
     } else {
         $data['expire_refund'] = 0;
         $data['any_refund'] = 0;
     }
     if ($_REQUEST['deal_attr'] && count($_REQUEST['deal_attr']) > 0) {
         $data['multi_attr'] = 1;
     } else {
         $data['multi_attr'] = 0;
     }
     if ($data['buy_type'] != 1) {
         $deal_tags = $_REQUEST['deal_tag'];
         $deal_tag = 0;
         foreach ($deal_tags as $t) {
             $t2 = pow(2, $t);
             $deal_tag = $deal_tag | $t2;
         }
         $data['deal_tag'] = $deal_tag;
     } else {
         $data['deal_tag'] = 0;
     }
     $data['is_lottery'] = 0;
     foreach ($deal_tags as $t) {
         if ($t == 0) {
             $data['is_lottery'] = 1;
         }
     }
     if ($data['buy_type'] == 1) {
         $data['cart_type'] = 3;
         $data['is_refund'] = 0;
         $data['deal_tag'] = 0;
         $data['is_lottery'] = 0;
     }
     $inc_prices = $_REQUEST['inc_price'];
     if (isset($_REQUEST['level_ids'])) {
         //无数据
         $level_ids = $_REQUEST['level_ids'];
         foreach ($level_ids as $key => $value) {
             $deal_tech_level = array('level_id' => $value, 'deal_id' => $data['id'], 'price' => $inc_prices[$key], 'createtime' => time());
             M('dealTechLevel')->add($deal_tech_level);
         }
     } elseif ($_REQUEST['deal_tech_level_ids']) {
         //有数据
         $deal_tech_level_ids = $_REQUEST['deal_tech_level_ids'];
         foreach ($deal_tech_level_ids as $key => $value) {
             $deal_tech_level = array('id' => $value, 'price' => $inc_prices[$key], 'createtime' => time());
             M('dealTechLevel')->save($deal_tech_level);
         }
     }
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set expire_refund = " . $data['expire_refund'] . ",any_refund = " . $data['any_refund'] . ",supplier_id=" . $data['supplier_id'] . ",end_time=" . $data['coupon_end_time'] . ",begin_time=" . $data['coupon_begin_time'] . " where deal_id = " . $data['id']);
         //开始处理图片
         M("DealGallery")->where("deal_id=" . $data['id'])->delete();
         $imgs = $_REQUEST['img'];
         foreach ($imgs as $k => $v) {
             if ($v != '') {
                 $img_data['deal_id'] = $data['id'];
                 $img_data['img'] = $v;
                 $img_data['sort'] = $k;
                 M("DealGallery")->add($img_data);
             }
         }
         //end 处理图片
         //开始处理属性
         M("DealAttr")->where("deal_id=" . $data['id'])->delete();
         $deal_attr = $_REQUEST['deal_attr'];
         $deal_attr_price = $_REQUEST['deal_attr_price'];
         $deal_add_balance_price = $_REQUEST['deal_add_balance_price'];
         $deal_attr_stock_hd = $_REQUEST['deal_attr_stock_hd'];
         foreach ($deal_attr as $goods_type_attr_id => $arr) {
             foreach ($arr as $k => $v) {
                 if ($v != '') {
                     $deal_attr_item['deal_id'] = $data['id'];
                     $deal_attr_item['goods_type_attr_id'] = $goods_type_attr_id;
                     $deal_attr_item['name'] = $v;
                     $deal_attr_item['add_balance_price'] = $deal_add_balance_price[$goods_type_attr_id][$k];
                     $deal_attr_item['price'] = $deal_attr_price[$goods_type_attr_id][$k];
                     $deal_attr_item['is_checked'] = intval($deal_attr_stock_hd[$goods_type_attr_id][$k]);
                     M("DealAttr")->add($deal_attr_item);
                 }
             }
         }
         //开始创建属性库存
         M("AttrStock")->where("deal_id=" . $data['id'])->delete();
         $stock_cfg = $_REQUEST['stock_cfg_num'];
         $attr_cfg = $_REQUEST['stock_attr'];
         $attr_str = $_REQUEST['stock_cfg'];
         foreach ($stock_cfg as $row => $v) {
             $stock_data = array();
             $stock_data['deal_id'] = $data['id'];
             $stock_data['stock_cfg'] = $v;
             $stock_data['attr_str'] = $attr_str[$row];
             $attr_cfg_data = array();
             foreach ($attr_cfg as $attr_id => $cfg) {
                 $attr_cfg_data[$attr_id] = $cfg[$row];
             }
             $stock_data['attr_cfg'] = serialize($attr_cfg_data);
             $sql = "select sum(oi.number) from " . DB_PREFIX . "deal_order_item as oi left join " . DB_PREFIX . "deal as d on d.id = oi.deal_id left join " . DB_PREFIX . "deal_order as do on oi.order_id = do.id where" . " do.pay_status = 2 and do.is_delete = 0 and d.id = " . $data['id'] . " and oi.attr_str like '%" . $attr_str[$row] . "%'";
             $stock_data['buy_count'] = intval($GLOBALS['db']->getOne($sql));
             M("AttrStock")->add($stock_data);
         }
         M("FreeDelivery")->where("deal_id=" . $data['id'])->delete();
         if (intval($_REQUEST['free_delivery']) == 1) {
             $delivery_ids = $_REQUEST['delivery_id'];
             $free_counts = $_REQUEST['free_count'];
             foreach ($delivery_ids as $k => $v) {
                 $free_conf = array();
                 $free_conf['delivery_id'] = $delivery_ids[$k];
                 $free_conf['free_count'] = $free_counts[$k];
                 $free_conf['deal_id'] = $data['id'];
                 M("FreeDelivery")->add($free_conf);
             }
         }
         M("DealPayment")->where("deal_id=" . $data['id'])->delete();
         if (intval($_REQUEST['define_payment']) == 1) {
             $payment_ids = $_REQUEST['payment_id'];
             foreach ($payment_ids as $k => $v) {
                 $payment_conf = array();
                 $payment_conf['payment_id'] = $payment_ids[$k];
                 $payment_conf['deal_id'] = $data['id'];
                 M("DealPayment")->add($payment_conf);
             }
         }
         M("DealDelivery")->where("deal_id=" . $data['id'])->delete();
         $delivery_ids = $_REQUEST['forbid_delivery_id'];
         foreach ($delivery_ids as $k => $v) {
             $delivery_conf = array();
             $delivery_conf['delivery_id'] = $delivery_ids[$k];
             $delivery_conf['deal_id'] = $data['id'];
             M("DealDelivery")->add($delivery_conf);
         }
         //开始创建筛选项
         M("DealFilter")->where("deal_id=" . $data['id'])->delete();
         $filter = $_REQUEST['filter'];
         foreach ($filter as $filter_group_id => $filter_value) {
             $filter_data = array();
             $filter_data['filter'] = $filter_value;
             $filter_data['filter_group_id'] = $filter_group_id;
             $filter_data['deal_id'] = $data['id'];
             M("DealFilter")->add($filter_data);
             //				$filter_array = preg_split("/[ ,]/i",$filter_value);
             //				foreach($filter_array as $filter_item)
             //				{
             //					$filter_row = M("Filter")->where("filter_group_id = ".$filter_group_id." and name = '".$filter_item."'")->find();
             //					if(!$filter_row)
             //					{
             //						if(strim($filter_item)!='')
             //						{
             //							$filter_row = array();
             //							$filter_row['name'] = $filter_item;
             //							$filter_row['filter_group_id'] = $filter_group_id;
             //							M("Filter")->add($filter_row);
             //						}
             //
             //					}
             //				}
         }
         M("DealLocationLink")->where("deal_id=" . $data['id'])->delete();
         foreach ($_REQUEST['location_id'] as $location_id) {
             $link_data = array();
             $link_data['location_id'] = $location_id;
             $link_data['deal_id'] = $data['id'];
             M("DealLocationLink")->add($link_data);
         }
         //成功提示
         syn_deal_status($data['id']);
         syn_deal_match($data['id']);
         syn_attr_stock_key($data['id']);
         //对于商户请求操作
         if (intval($_REQUEST['edit_type']) == 2 && $deal_submit_id > 0) {
             //商户提交修改审核
             /*同步商户发布表状态*/
             $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_submit", array("admin_check_status" => 1), "UPDATE", "id=" . $deal_submit_id);
             // 1 通过 2 拒绝',
         }
         //成功提示
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         $dbErr = M()->getDbError();
         save_log($log_info . L("UPDATE_FAILED") . $dbErr, 0);
         $this->error(L("UPDATE_FAILED") . $dbErr, 0);
     }
 }
Exemplo n.º 8
0
 public function update_deal_vote()
 {
     B('FilterString');
     $ajax = intval($_REQUEST['ajax']);
     $data = M("DealVote")->create();
     $data['moeny'] = format_price($data['money']);
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/edit_deal_vote", array("id" => $data['id'])));
     if (!check_empty($data['moeny'])) {
         $this->error("请输入卖出金额");
     }
     $data['begin_time'] = trim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']);
     $data['end_time'] = trim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']);
     $data['create_time'] = get_gmtime();
     // 更新数据
     $this->deal_update(intval($data['deal_id']));
     $list = M("DealVote")->save($data);
     $log_info = "项目ID" . $data['deal_id'] . ":" . format_price($data['money']);
     if (false !== $list) {
         if ($data['virtual_person'] > 0) {
         }
         //成功提示
         M("Deal")->where("id=" . $data['deal_id'])->setField("deal_extra_cache", "");
         //end 处理图片
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         syn_deal($data['deal_id']);
         syn_deal_status($data['deal_id']);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"));
     }
 }
Exemplo n.º 9
0
/**
 * 更新 用户回款 计划数据
 * @param unknown_type $deal_id
 * @param unknown_type $deal_repay_id
 */
function syn_deal_repay_status($deal_id, $deal_repay_id)
{
    //has_repay 0未收到还款,1已收到还款
    $deal_id = intval($deal_id);
    $deal_repay_id = intval($deal_repay_id);
    $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal WHERE id=" . $deal_id);
    $deal['url'] = url("index", "deal", array("id" => $deal['id']));
    $deal["user"] = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "user WHERE id=" . $deal['user_id']);
    //未还款记录数
    $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 0 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
    $has_repay_0 = $GLOBALS['db']->getOne($sql);
    //已经还款记录数
    $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 1 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
    $has_repay_1 = $GLOBALS['db']->getOne($sql);
    //第几期
    $kk = $GLOBALS['db']->getOne("select l_key from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id);
    //has_repay 0未还,1已还 2部分还款
    if ($has_repay_0 == 0 && $has_repay_1 == 0 || $has_repay_0 == 0 && $has_repay_1 > 0) {
        $deal_rs_sql = "select sum(true_interest_money) as total_true_interest_money," . "sum(true_self_money) as total_true_self_money," . "sum(true_repay_money) as total_true_repay_money," . "sum(true_repay_manage_money) as total_true_repay_manage_money," . "sum(repay_manage_impose_money) as total_repay_manage_impose_money, " . "sum(impose_money) as total_impose_money " . "from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id;
        $deal_rs = $GLOBALS['db']->getRow($deal_rs_sql);
        $last_Rs = $GLOBALS['db']->getRow("SELECT `status`,`true_repay_time`,`repay_time` from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id . " ORDER BY `true_repay_time` DESC");
        $deal_repay_data['true_repay_money'] = $deal_rs['total_true_repay_money'];
        $deal_repay_data['true_manage_money'] = $deal_rs['total_true_repay_manage_money'];
        $deal_repay_data['manage_impose_money'] = $deal_rs['total_repay_manage_impose_money'];
        $deal_repay_data['true_self_repay'] = $deal_rs['total_true_self_money'];
        $deal_repay_data['impose_money'] = $deal_rs['total_impose_money'];
        $deal_repay_data['true_interest_money'] = $deal_rs['total_true_interest_money'];
        $deal_repay_data['true_repay_time'] = $last_Rs['true_repay_time'];
        $deal_repay_data['true_repay_date'] = to_date($last_Rs['true_repay_time']);
        $deal_repay_data['status'] = $last_Rs['status'];
        $deal_repay_data['has_repay'] = 1;
        //返佣金额
        $rebate_rs = get_rebate_fee($deal['user_id'], "borrow");
        $deal_repay_data['true_manage_money_rebate'] = floatval($deal_repay_data['true_manage_money']) * floatval($rebate_rs['rebate']) / 100;
        $true_manage_money_rebate = $deal_repay_data['true_manage_money'] * floatval($rebate_rs['rebate']) / 100;
        //借款者返佣
        if ($true_manage_money_rebate != 0) {
            /*ok*/
            $reback_memo = sprintf($GLOBALS['lang']["BORROW_REBATE_LOG"], $deal["url"], $deal["name"], $deal["user"]["user_name"], intval($kk) + 1);
            reback_rebate_money($deal['user_id'], $true_manage_money_rebate, "borrow", $reback_memo);
        }
        require_once APP_ROOT_PATH . "system/libs/user.php";
        if ($last_Rs['status'] > 1) {
            $impose_day = ceil(($last_Rs['true_repay_time'] - $last_Rs['repay_time'] + 24 * 3600 - 1) / 24 / 3600);
            //VIP降级-逾期还款
            $type = 2;
            $type_info = 5;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
            if ($impose_day < app_conf('YZ_IMPSE_DAY')) {
                modify_account(array("point" => trim(app_conf('IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,逾期还款", 11);
                $repay_update_data['status'] = 2;
            } else {
                modify_account(array("point" => trim(app_conf('YZ_IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,严重逾期", 11);
                $repay_update_data['status'] = 3;
            }
        } elseif ($last_Rs['status'] == 1) {
            //VIP升级 -正常还款
            $type = 1;
            $type_info = 3;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
        } elseif ($last_Rs['status'] == 0) {
            //VIP升级 -提前还款
            $type = 1;
            $type_info = 4;
            $resultdate = syn_user_vip($deal['user_id'], $type, $type_info);
        }
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $deal_repay_data, "UPDATE", "id = " . $deal_repay_id);
        $last_repay_key = $kk;
        //判断本借款是否还款完毕
        if ($GLOBALS['db']->getOne("SELECT count(*)  FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and l_key=" . $last_repay_key . " AND has_repay <> 1 ") == 0) {
            //全部还完
            if ($GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and has_repay=0 ") == 0) {
                //判断获取的信用是否超过限制
                if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_point_log WHERE  `type`=6 AND user_id=" . $deal['user_id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
                    //获取上一次还款时间
                    $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(create_time) FROM " . DB_PREFIX . "user_point_log WHERE  `type`=6 AND user_id=" . $deal['user_id']);
                    $day = ceil(($last_Rs['true_repay_time'] - $befor_repay_time) / 24 / 3600);
                    //当天数大于等于间隔时间 获得信用
                    if ($day >= (int) trim(app_conf('REPAY_SUCCESS_DAY'))) {
                        modify_account(array("point" => trim(app_conf('REPAY_SUCCESS_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款", 4);
                    }
                }
                //用户获得额度
                modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款获得额度", 4);
            }
        }
        sys_user_status(intval($GLOBALS['user_info']['id']), false, true);
        syn_deal_status($deal_id);
        syn_transfer_status(0, $deal_id);
    } else {
        if ($has_repay_0 > 0 && $has_repay_1 == 0) {
            $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 0 where id = " . $deal_repay_id;
        } else {
            $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 2 where id = " . $deal_repay_id;
        }
    }
    $GLOBALS['db']->query($sql);
}
Exemplo n.º 10
0
 public function show_detail()
 {
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $id = intval($_REQUEST['id']);
     syn_deal_status($id);
     $deal_info = M("Deal")->getById($id);
     $this->assign("deal_info", $deal_info);
     $true_repay_money = M("DealLoadRepay")->where("deal_id=" . $id)->sum("repay_money");
     $this->assign("true_repay_money", floatval($true_repay_money) + 1);
     $count = D("DealLoad")->where('deal_id=' . $id)->order("id ASC")->count();
     if (!empty($_REQUEST['listRows'])) {
         $listRows = $_REQUEST['listRows'];
     } else {
         $listRows = '';
     }
     $p = new Page($count, $listRows);
     if ($count > 0) {
         $loan_list = D("DealLoad")->where('deal_id=' . $id)->order("id ASC")->limit($p->firstRow . ',' . $p->listRows)->findall();
         $this->assign("loan_list", $loan_list);
     }
     $page = $p->show();
     $this->assign("page", $page);
     $this->display();
 }
Exemplo n.º 11
0
/**
 * 获取指定的优惠券
 */
function get_youhui($id = 0, $preview = 0)
{
    $time = get_gmtime();
    if ($id > 0) {
        syn_deal_status($id);
        if ($preview == 0) {
            $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($id) . " and is_effect = 1 and is_delete = 0 and is_shop = 2 ");
        } else {
            $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($id) . " and is_delete = 0 and is_shop = 2 ");
        }
    }
    if ($deal) {
        //格式化数据
        $deal['origin_price_format'] = format_price($deal['origin_price']);
        $deal['current_price_format'] = format_price($deal['current_price']);
        if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) {
            //手动折扣
            $deal['save_price'] = $deal['origin_price'] - $deal['current_price'];
        } else {
            $deal['save_price'] = $deal['origin_price'] * ((10 - $deal['discount']) / 10);
        }
        if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) {
            $deal['discount'] = round($deal['current_price'] / $deal['origin_price'] * 10, 2);
        }
        $deal['discount'] = round($deal['discount'], 2);
        $deal['save_price_format'] = format_price($deal['save_price']);
        //团购图片集
        $img_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_gallery where deal_id=" . intval($deal['id']) . " order by sort asc");
        foreach ($img_list as $k => $v) {
            $img_list[$k]['origin_img'] = preg_replace("/\\/big\\//", "/origin/", $v['img']);
        }
        $deal['image_list'] = $img_list;
        //商户信息
        $deal['supplier_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier where id = " . intval($deal['supplier_id']));
        $deal['supplier_address_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where supplier_id = " . intval($deal['supplier_id']) . " and is_main = 1");
        //品牌信息
        $deal['brand_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "brand where id = " . intval($deal['brand_id']));
        //属性列表
        $deal_attrs_res = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_attr where deal_id = " . intval($deal['id']) . " order by id asc");
        if ($deal_attrs_res) {
            foreach ($deal_attrs_res as $k => $v) {
                $deal_attr[$v['goods_type_attr_id']]['name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "goods_type_attr where id = " . intval($v['goods_type_attr_id']));
                $deal_attr[$v['goods_type_attr_id']]['attrs'][] = $v;
            }
            $deal['deal_attr_list'] = $deal_attr;
        }
        if ($deal['uname'] != '') {
            $gurl = url("shop", "goods", array("id" => $deal['uname']));
        } else {
            $gurl = url("shop", "goods", array("id" => $deal['id']));
        }
        $deal['share_url'] = $gurl;
        if ($GLOBALS['user_info']) {
            if (app_conf("URL_MODEL") == 0) {
                $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            } else {
                $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            }
        }
        //查询抽奖号
        $deal['lottery_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($deal['id']) . " and buyer_id <> 0 ")) + intval($deal['buy_count']);
        //开始获取处理库存
        $deal['stock'] = $deal['max_bought'] - $deal['buy_count'];
        $deal['is_today'] = get_is_today($deal);
    }
    return $deal;
}
Exemplo n.º 12
0
/**
 * 获取指定的团购产品
 */
function get_deal_show($id = 0, $cate_id = 0, $city_id = 0, $preview = 0)
{
    $time = get_gmtime();
    if ($id == 0) {
        $sql = "select * from " . DB_PREFIX . "deal where is_shop = 0 and is_effect = 1 and is_delete = 0 and buy_type <> 1 and (" . $time . ">= begin_time or begin_time = 0 or notice = 1) and (" . $time . "<end_time or end_time = 0) and buy_status <> 2 ";
        if ($cate_id > 0) {
            $ids = load_auto_cache("deal_sub_parent_cate_ids", array("cate_id" => $cate_id));
            $sql .= " and cate_id in (" . implode(",", $ids) . ")";
        }
        if ($city_id > 0) {
            $ids = load_auto_cache("deal_city_belone_ids", array("city_id" => $city_id));
            if ($ids) {
                $sql .= " and city_id in (" . implode(",", $ids) . ")";
            }
        }
        $sql .= " order by sort desc";
        $deal = $GLOBALS['db']->getRow($sql);
    }
    $deal = syn_deal_status($id);
    if ($deal) {
        $static_deal = load_auto_cache("static_goods_info", array("id" => $deal['id']));
        foreach ($static_deal as $k => $v) {
            $deal[$k] = $v;
        }
        $deal['success_time_tip'] = sprintf($GLOBALS['lang']['SUCCESS_TIME_TIP'], $deal['success_time_format'], $deal['min_bought']);
        $deal['deal_success_num'] = sprintf($GLOBALS['lang']['SUCCESS_BUY_COUNT'], $deal['buy_count']);
        $deal['current_bought'] = $deal['buy_count'];
        if ($deal['buy_status'] == 0) {
            $deal['success_less'] = sprintf($GLOBALS['lang']['SUCCESS_LESS_BUY_COUNT'], $deal['min_bought'] - $deal['buy_count']);
        }
        if ($deal['uname'] != '') {
            $durl = url("tuan", "deal", array("id" => $deal['uname']));
        } else {
            $durl = url("tuan", "deal", array("id" => $deal['id']));
        }
        $deal['share_url'] = get_domain() . $durl;
        if ($GLOBALS['user_info']) {
            if (app_conf("URL_MODEL") == 0) {
                $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            } else {
                $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            }
        }
        $deal['is_today'] = get_is_today($deal);
        //查询抽奖号
        $deal['lottery_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($deal['id']) . " and buyer_id <> 0 ")) + intval($deal['buy_count']);
    }
    return $deal;
}
Exemplo n.º 13
0
Arquivo: cart.php Projeto: macall/jsd
function order_paid_done($order_id)
{
    //处理支付成功后的操作
    /**
     * 1. 发货
     * 2. 超量发货的存到会员中心
     * 3. 发券
     * 4. 发放抽奖
     */
    require_once APP_ROOT_PATH . "system/model/deal.php";
    require_once APP_ROOT_PATH . "system/model/supplier.php";
    require_once APP_ROOT_PATH . "system/model/deal_order.php";
    $order_id = intval($order_id);
    $stock_status = true;
    //团购状态
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
    if ($order_info['type'] == 0) {
        //首先验证所有的规格库存
        $order_goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
        foreach ($order_goods_list as $k => $v) {
            if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "attr_stock where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0")) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count + " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and ((buy_count + " . $v['number'] . " <= stock_cfg) or stock_cfg = 0 )" . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_attr_list[] = $v;
                } else {
                    $stock_status = false;
                    break;
                }
            }
        }
        if ($stock_status) {
            $goods_list = $GLOBALS['db']->getAll("select buy_type,deal_id,sum(number) as num,sum(add_balance_price_total) as add_balance_price_total,sum(balance_total_price) as balance_total_price,sum(return_total_money) as return_total_money,sum(return_total_score) as return_total_score from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " group by deal_id");
            foreach ($goods_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count + " . $v['num'] . ",user_count = user_count + 1 where id=" . $v['deal_id'] . " and ((buy_count + " . $v['num'] . "<= max_bought) or max_bought = 0) " . " and time_status = 1 and buy_status <> 2";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_list[] = $v;
                    //记录下更新成功的团购商品,用于回滚
                } else {
                    //失败成功,即过期支付,超量支付
                    $stock_status = false;
                    break;
                }
            }
        }
        $return_money = 0;
        //非发券非配送的即时返还
        $return_score = 0;
        //非发券非配送的即时返还
        $use_score = 0;
        //积分商品所耗费的积分
        if ($stock_status) {
            foreach ($goods_list as $k => $v) {
                $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($v['deal_id']));
                //统计商户销售额
                $supplier_log = "ID:" . $deal_info['id'] . " " . $deal_info['sub_name'] . " 订单:" . $order_info['order_sn'];
                modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 0, $supplier_log);
                if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0) {
                    //更新订单中相关产品的消费状态
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set consume_count = consume_count + 1 where order_id = " . $order_info['id'] . " and deal_id = " . $deal_info['id']);
                    update_order_cache($order_info['id']);
                    distribute_order($order_info['id']);
                    modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 2, $supplier_log);
                    //等结算金额增加
                } else {
                    modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 1, $supplier_log);
                    //冻结资金
                }
                //不发货不发券的实时返还
                if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0 && $v['buy_type'] == 0) {
                    $return_money += $v['return_total_money'];
                    $return_score += $v['return_total_score'];
                }
                if ($v['buy_type'] == 1) {
                    $use_score += $v['return_total_score'];
                }
                $balance_price += $v['balance_total_price'];
                $add_balance_price += $v['add_balance_price_total'];
                //发券
                if ($deal_info['is_coupon'] == 1) {
                    if ($deal_info['deal_type'] == 1) {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            //							for($i=0;$i<$item['number'];$i++) //按单
                            //							{
                            //需要发券
                            /**
                             * 1. 先从已有团购券中发送
                             * 2. 无有未发送的券,自动发送
                             * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                             */
                            /*修正后台手动建团购劵,购买的时候按单发送团购劵,数量不一致*/
                            $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['total_price'] . ",coupon_score = " . $item['return_total_score'] . ",coupon_money = " . $item['return_total_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_total_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 order by id ASC limit 1";
                            $GLOBALS['db']->query($sql);
                            $exist_coupon = $GLOBALS['db']->affected_rows();
                            if (!$exist_coupon) {
                                //未发送成功,即无可发放的预设团购券
                                add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                            }
                            //							}
                        }
                    } else {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            for ($i = 0; $i < $item['number']; $i++) {
                                //需要发券
                                /**
                                 * 1. 先从已有团购券中发送
                                 * 2. 无有未发送的券,自动发送
                                 * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                                 */
                                $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['unit_price'] . ",coupon_score = " . $item['return_score'] . ",coupon_money = " . $item['return_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_unit_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 limit 1";
                                $GLOBALS['db']->query($sql);
                                $exist_coupon = $GLOBALS['db']->affected_rows();
                                if (!$exist_coupon) {
                                    //未发送成功,即无可发放的预设团购券
                                    add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                                }
                            }
                        }
                    }
                }
                //发券结束
            }
            //开始处理返还的积分或现金,此处返还不用发货不用配送不用发券的产品返还
            require_once APP_ROOT_PATH . "system/model/user.php";
            if ($return_money != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_MONEY'], $order_info['order_sn']);
                modify_account(array('money' => $return_money, 'score' => 0), $order_info['user_id'], $msg);
            }
            if ($return_score != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_SCORE'], $order_info['order_sn']);
                modify_account(array('money' => 0, 'score' => $return_score), $order_info['user_id'], $msg);
                send_score_sms($order_info['id']);
                send_score_mail($order_info['id']);
            }
            if ($use_score != 0) {
                $user_score = $GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . $order_info['user_id']);
                if ($user_score + $use_score < 0) {
                    //积分不足,不能支付
                    $msg = $order_info['order_sn'] . "订单支付失败,积分不足";
                    $refund_money = $order_info['pay_amount'];
                    if ($order_info['account_money'] > $refund_money) {
                        $account_money_now = $order_info['account_money'] - $refund_money;
                    } else {
                        $account_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']);
                    if ($order_info['ecv_money'] > $refund_money) {
                        $ecv_money_now = $order_info['ecv_money'] - $refund_money;
                    } else {
                        $ecv_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']);
                    if ($refund_money > 0) {
                        modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg);
                        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . ",after_sale = 1,refund_status = 2 where id = " . $order_info['id']);
                        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']);
                        order_log($order_info['order_sn'] . "积分不足," . format_price($refund_money) . "已退到会员余额", $order_info['id']);
                        modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "积分不足,退款");
                        modify_statements($refund_money, 2, $order_info['order_sn'] . "积分不足,退款");
                    } else {
                        order_log($order_info['order_sn'] . "积分不足", $order_info['id']);
                    }
                    require_once APP_ROOT_PATH . "system/model/deal_order.php";
                    update_order_cache($order_info['id']);
                    over_order($order_info['id']);
                } else {
                    modify_account(array('score' => $use_score), $order_info['user_id'], "积分商品兑换");
                    send_score_sms($order_info['id']);
                    send_score_mail($order_info['id']);
                    order_log($order_info['order_sn'] . "积分订单支付成功", $order_info['id']);
                    send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "兑换成功", "orderitem", $order_goods_list[0]['id']);
                    if ($order_info['total_price'] > 0) {
                        modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款");
                    }
                    //增加营业额
                }
            } else {
                //开始处理返利,只创建返利, 发放将与msg_list的自动运行一起执行
                // 			$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$order_info['user_id']);
                // 			//开始查询所购买的列表中支不支持促销
                // 			$is_referrals = 1; //默认为返利
                // 			foreach($goods_list as $k=>$v)
                // 			{
                // 				$is_referrals = $GLOBALS['db']->getOne("select is_referral from ".DB_PREFIX."deal where id = ".$v['deal_id']);
                // 				if($is_referrals == 0)
                // 				{
                // 					break;
                // 				}
                // 			}
                // 			if($user_info['referral_count']<app_conf("REFERRAL_LIMIT")&&$is_referrals == 1)
                // 			{
                // 				//开始返利给推荐人
                // 				$parent_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$user_info['pid']);
                // 				if($parent_info)
                // 				{
                // 					if((app_conf("REFERRAL_IP_LIMIT")==1&&$parent_info['login_ip']!=CLIENT_IP)||app_conf("REFERRAL_IP_LIMIT")==0) //IP限制
                // 					{
                // 						if(app_conf("INVITE_REFERRALS_TYPE")==0) //现金返利
                // 						{
                // 							$referral_data['user_id'] = $parent_info['id']; //初返利的会员ID
                // 							$referral_data['rel_user_id'] = $user_info['id'];	 //被推荐且发生购买的会员ID
                // 							$referral_data['create_time'] = NOW_TIME;
                // 							$referral_data['money']	=	app_conf("INVITE_REFERRALS");
                // 							$referral_data['order_id']	=	$order_info['id'];
                // 							$GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入
                // 						}
                // 						else
                // 						{
                // 							$referral_data['user_id'] = $parent_info['id']; //初返利的会员ID
                // 							$referral_data['rel_user_id'] = $user_info['id'];	 //被推荐且发生购买的会员ID
                // 							$referral_data['create_time'] = NOW_TIME;
                // 							$referral_data['score']	=	app_conf("INVITE_REFERRALS");
                // 							$referral_data['order_id']	=	$order_info['id'];
                // 							$GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入
                // 						}
                // 						$GLOBALS['db']->query("update ".DB_PREFIX."user set referral_count = referral_count + 1 where id = ".$user_info['id']);
                // 					}
                // 				}
                // 			}
                //超出充值
                if ($order_info['pay_amount'] > $order_info['total_price']) {
                    require_once APP_ROOT_PATH . "system/model/user.php";
                    if ($order_info['total_price'] < 0) {
                        $msg = sprintf($GLOBALS['lang']['MONEYORDER_INCHARGE'], $order_info['order_sn']);
                    } else {
                        $msg = sprintf($GLOBALS['lang']['OUTOFMONEY_INCHARGE'], $order_info['order_sn']);
                    }
                    $refund_money = $order_info['pay_amount'] - $order_info['total_price'];
                    if ($order_info['account_money'] > $refund_money) {
                        $account_money_now = $order_info['account_money'] - $refund_money;
                    } else {
                        $account_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']);
                    if ($order_info['ecv_money'] > $refund_money) {
                        $ecv_money_now = $order_info['ecv_money'] - $refund_money;
                    } else {
                        $ecv_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']);
                    modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg);
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . " where id = " . $order_info['id']);
                    order_log($order_info['order_sn'] . "订单超额支付," . format_price($refund_money) . "已退到会员余额", $order_info['id']);
                    modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "订单超额");
                    modify_statements($refund_money, 2, $order_info['order_sn'] . "订单超额");
                }
                modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款");
                //增加营业额
                $balance_total = $GLOBALS['db']->getOne("select sum(balance_total_price)+sum(add_balance_price_total) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id']);
                modify_statements($balance_total, 9, $order_info['order_sn'] . "订单成功付款");
                //增加营业额中的成本
                //生成抽奖
                $lottery_list = $GLOBALS['db']->getAll("select d.id as did,doi.number from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id left join " . DB_PREFIX . "deal as d on doi.deal_id = d.id where d.is_lottery = 1 and do.id = " . $order_info['id']);
                $lottery_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($order_info['user_id']));
                //如为首次抽奖,先为推荐人生成抽奖号
                $lottery_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where user_id = " . intval($order_info['user_id']));
                if ($lottery_count == 0 && $lottery_user['pid'] != 0) {
                    $lottery_puser = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($lottery_user['pid']));
                    foreach ($lottery_list as $lottery) {
                        $k = 0;
                        do {
                            if ($k > 10) {
                                break;
                            }
                            $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                            $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                            //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                            $sn = $max_sn + 1;
                            $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                            $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $lottery_puser['id'] . ",'" . $lottery_puser['lottery_mobile'] . "'," . NOW_TIME . "," . $order_info['user_id'] . " from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                            $GLOBALS['db']->query($sql);
                            send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                            $k++;
                        } while (intval($GLOBALS['db']->insert_id()) == 0);
                    }
                }
                foreach ($lottery_list as $lottery) {
                    for ($i = 0; $i < $lottery['number']; $i++) {
                        $k = 0;
                        do {
                            if ($k > 10) {
                                break;
                            }
                            $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                            $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                            //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                            $sn = $max_sn + $i + 1;
                            $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                            $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $order_info['user_id'] . ",'" . $lottery_user['mobile'] . "'," . NOW_TIME . ",0 from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                            $GLOBALS['db']->query($sql);
                            send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                            $k++;
                        } while (intval($GLOBALS['db']->insert_id()) == 0);
                    }
                }
                send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "付款成功", "orderitem", $order_goods_list[0]['id']);
            }
        } else {
            //开始模拟事务回滚
            foreach ($affect_attr_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count - " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            foreach ($affect_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count - " . $v['num'] . ",user_count = user_count - 1 where id=" . $v['deal_id'];
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']);
            //超出充值
            require_once APP_ROOT_PATH . "system/model/user.php";
            $msg = sprintf($GLOBALS['lang']['OUTOFSTOCK_INCHARGE'], $order_info['order_sn']);
            modify_account(array('money' => $order_info['total_price'], 'score' => 0), $order_info['user_id'], $msg);
            order_log($order_info['order_sn'] . "订单库存不足," . format_price($order_info['total_price']) . "已退到会员余额", $order_info['id']);
            modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "订单库存不足");
            modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "订单库存不足");
            //将订单的extra_status 状态更新为2,并自动退款
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set extra_status = 2, after_sale = 1, refund_money = pay_amount where id = " . intval($order_info['id']));
            update_order_cache($order_info['id']);
            //记录退款的订单日志
            $log['log_info'] = $msg;
            $log['log_time'] = NOW_TIME;
            $log['order_id'] = intval($order_info['id']);
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_log", $log);
        }
        //同步所有未过期的团购状态
        foreach ($goods_list as $item) {
            syn_deal_status($item['deal_id'], true);
        }
        auto_over_status($order_id);
        //自动结单
    } else {
        //订单充值
        // 		$GLOBALS['db']->query("update ".DB_PREFIX."deal_order set order_status = 1 where id = ".$order_info['id']); //充值单自动结单
        require_once APP_ROOT_PATH . "system/model/user.php";
        $msg = sprintf($GLOBALS['lang']['USER_INCHARGE_DONE'], $order_info['order_sn']);
        modify_account(array('money' => $order_info['total_price'] - $order_info['payment_fee'], 'score' => 0), $order_info['user_id'], $msg);
        modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "会员充值");
        modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "会员充值,含手续费");
        send_msg($order_info['user_id'], "成功充值" . format_price($order_info['total_price'] - $order_info['payment_fee']), "notify", $order_id);
        auto_over_status($order_id);
        //自动结单
    }
}
function pay_order($order_id)
{
    require_once APP_ROOT_PATH . "system/libs/user.php";
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
    if ($order_info['credit_pay'] + $order_info['online_pay'] >= $order_info['total_price']) {
        if ($order_info['credit_pay'] + $order_info['online_pay'] > $order_info['total_price']) {
            $more_money = $order_info['credit_pay'] + $order_info['online_pay'] - $order_info['total_price'];
            modify_account(array("money" => $more_money), $order_info['user_id'], $order_info['deal_name'] . "超额支付,转存入会员帐户");
        }
        $order_info['pay_time'] = get_gmtime();
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal set support_count = support_count + 1,support_amount = support_amount + " . $order_info['deal_price'] . ",pay_amount = pay_amount + " . $order_info['total_price'] . ",delivery_fee_amount = delivery_fee_amount + " . $order_info['delivery_fee'] . " where id = " . $order_info['deal_id'] . " and is_effect = 1 and is_delete = 0 and begin_time < " . get_gmtime() . " and (end_time > " . get_gmtime() . " or end_time = 0)");
        if ($GLOBALS['db']->affected_rows() > 0) {
            //记录支持日志
            $support_log['deal_id'] = $order_info['deal_id'];
            $support_log['user_id'] = $order_info['user_id'];
            $support_log['create_time'] = get_gmtime();
            $support_log['price'] = $order_info['deal_price'];
            $support_log['deal_item_id'] = $order_info['deal_item_id'];
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_support_log", $support_log);
            $support_log_id = intval($GLOBALS['db']->insert_id());
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_item set support_count = support_count + 1,support_amount = support_amount +" . $order_info['deal_price'] . " where (support_count + 1 <= limit_user or limit_user = 0) and id = " . $order_info['deal_item_id']);
            if ($GLOBALS['db']->affected_rows() > 0) {
                $result['status'] = 3;
                $order_info['order_status'] = 3;
                $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $order_info['deal_id'] . " and is_effect = 1 and is_delete = 0");
                //下单项目成功,准备加入准备队列
                if ($deal_info['is_success'] == 0) {
                    //未成功的项止准备生成队列
                    $notify['user_id'] = $GLOBALS['user_info']['id'];
                    $notify['deal_id'] = $deal_info['id'];
                    $notify['create_time'] = get_gmtime();
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "user_deal_notify", $notify, "INSERT", "", "SILENT");
                }
                //更新用户的支持数
                $GLOBALS['db']->query("update " . DB_PREFIX . "user set support_count = support_count + 1 where id = " . $order_info['user_id']);
                //同步项目状态
                syn_deal_status($order_info['deal_id']);
                syn_deal($order_info['deal_id']);
            } else {
                $result['status'] = 2;
                $order_info['order_status'] = 2;
                $order_info['is_refund'] = 1;
                $GLOBALS['db']->query("update " . DB_PREFIX . "deal set support_count = support_count - 1,support_amount = support_amount - " . $order_info['deal_price'] . ",pay_amount = pay_amount - " . $order_info['total_price'] . ",delivery_fee_amount = delivery_fee_amount - " . $order_info['delivery_fee'] . " where id = " . $order_info['deal_id']);
                $GLOBALS['db']->query("delete from " . DB_PREFIX . "deal_support_log where id = " . $support_log_id);
                modify_account(array("money" => $order_info['total_price']), $order_info['user_id'], $order_info['deal_name'] . "限额已满,转存入会员帐户");
            }
        } else {
            $result['status'] = 1;
            $order_info['order_status'] = 1;
            $order_info['is_refund'] = 1;
            modify_account(array("money" => $order_info['total_price']), $order_info['user_id'], $order_info['deal_name'] . "已过期,转存入会员帐户");
        }
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set order_status = " . intval($order_info['order_status']) . ",pay_time = " . $order_info['pay_time'] . ",is_refund = " . $order_info['is_refund'] . " where id = " . $order_info['id']);
    } else {
        $result['status'] = 0;
        $result['money'] = $order_info['total_price'] - $order_info['online_pay'] - $order_info['credit_pay'];
    }
    return $result;
}
Exemplo n.º 15
0
 public function youhui_update()
 {
     B('FilterString');
     $data = M(MODULE_NAME)->create();
     $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name");
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/youhui_edit", array("id" => $data['id'])));
     if (!check_empty($data['name'])) {
         $this->error(L("DEAL_YOUHUI_NAME_EMPTY_TIP"));
     }
     if (!check_empty($data['sub_name'])) {
         $this->error(L("DEAL_YOUHUI_SUB_NAME_EMPTY_TIP"));
     }
     if ($data['cate_id'] == 0) {
         $this->error(L("DEAL_YOUHUI_CATE_EMPTY_TIP"));
     }
     if ($data['city_id'] == 0) {
         $this->error(L("DEAL_YOUHUI_CITY_EMPTY_TIP"));
     }
     if ($data['max_bought'] < 0) {
         $this->error(L("DEAL_YOUHUI_MAX_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_min_bought'] < 0) {
         $this->error(L("DEAL_USER_MIN_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_max_bought'] < 0) {
         $this->error(L("DEAL_USER_MAX_BOUGHT_ERROR_TIP"));
     }
     if ($data['user_max_bought'] < $data['user_min_bought'] && $data['user_max_bought'] > 0) {
         $this->error(L("DEAL_USER_MAX_MIN_BOUGHT_ERROR_TIP"));
     }
     $data['is_shop'] = 2;
     $data['is_coupon'] = 1;
     if (intval($data['is_coupon']) == 1 && intval($data['is_refund']) == 1) {
         $data['expire_refund'] = intval($_REQUEST['expire_refund']);
         $data['any_refund'] = intval($_REQUEST['any_refund']);
     } else {
         $data['expire_refund'] = 0;
         $data['any_refund'] = 0;
     }
     $data['notice'] = intval($_REQUEST['notice']);
     $data['begin_time'] = trim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']);
     $data['end_time'] = trim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']);
     $data['coupon_begin_time'] = trim($data['coupon_begin_time']) == '' ? 0 : to_timespan($data['coupon_begin_time']);
     $data['coupon_end_time'] = trim($data['coupon_end_time']) == '' ? 0 : to_timespan($data['coupon_end_time']);
     //将第一张图片设为团购图片
     $imgs = $_REQUEST['img'];
     foreach ($imgs as $k => $v) {
         if ($v != '') {
             $data['img'] = $v;
             break;
         }
     }
     $data['update_time'] = get_gmtime();
     $data['publish_wait'] = 0;
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set expire_refund = " . $data['expire_refund'] . ",any_refund = " . $data['any_refund'] . ",supplier_id=" . $data['supplier_id'] . ",end_time=" . $data['coupon_end_time'] . ",begin_time=" . $data['coupon_begin_time'] . " where deal_id = " . $data['id']);
         //开始处理图片
         M("DealGallery")->where("deal_id=" . $data['id'])->delete();
         $imgs = $_REQUEST['img'];
         foreach ($imgs as $k => $v) {
             if ($v != '') {
                 $img_data['deal_id'] = $data['id'];
                 $img_data['img'] = $v;
                 $img_data['sort'] = $k;
                 M("DealGallery")->add($img_data);
             }
         }
         //end 处理图片
         M("DealPayment")->where("deal_id=" . $data['id'])->delete();
         if (intval($_REQUEST['define_payment']) == 1) {
             $payment_ids = $_REQUEST['payment_id'];
             foreach ($payment_ids as $k => $v) {
                 $payment_conf = array();
                 $payment_conf['payment_id'] = $payment_ids[$k];
                 $payment_conf['deal_id'] = $data['id'];
                 M("DealPayment")->add($payment_conf);
             }
         }
         //成功提示
         M("DealCateTypeDealLink")->where("deal_id=" . $data['id'])->delete();
         foreach ($_REQUEST['deal_cate_type_id'] as $type_id) {
             $link_data = array();
             $link_data['deal_cate_type_id'] = $type_id;
             $link_data['deal_id'] = $data['id'];
             M("DealCateTypeDealLink")->add($link_data);
         }
         M("DealLocationLink")->where("deal_id=" . $data['id'])->delete();
         foreach ($_REQUEST['location_id'] as $location_id) {
             $link_data = array();
             $link_data['location_id'] = $location_id;
             $link_data['deal_id'] = $data['id'];
             M("DealLocationLink")->add($link_data);
         }
         syn_deal_status($data['id']);
         foreach ($_REQUEST['location_id'] as $location_id) {
             recount_supplier_data_count($location_id, "daijin");
         }
         syn_deal_match($data['id']);
         rm_auto_cache("cache_deal_cart", array("id" => $data['id']));
         rm_auto_cache("static_goods_info", array("id" => $data['id']));
         //成功提示
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         $dbErr = M()->getDbError();
         save_log($log_info . L("UPDATE_FAILED") . $dbErr, 0);
         $this->error(L("UPDATE_FAILED") . $dbErr, 0);
     }
 }
Exemplo n.º 16
0
function check_trans($id, $paypassword)
{
    $paypassword = strim($paypassword);
    $id = intval($id);
    $root = array();
    $root["status"] = 0;
    //0:出错;1:正确;
    if (!$GLOBALS['user_info']) {
        $root["show_err"] = $GLOBALS['lang']['PLEASE_LOGIN_FIRST'];
        return $root;
    }
    if ($paypassword == "") {
        $root["show_err"] = $GLOBALS['lang']['PAYPASSWORD_EMPTY'];
        return $root;
    }
    if (md5($paypassword) != $GLOBALS['user_info']['paypassword']) {
        $root["show_err"] = $GLOBALS['lang']['PAYPASSWORD_ERROR'];
        //.$GLOBALS['user_info']['paypassword'].';'.md5($paypassword).';'.$paypassword;
        return $root;
    }
    $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load_transfer WHERE id=" . $id);
    if ($deal_id == 0) {
        $root["show_err"] = "不存在的债权";
        return $root;
    } else {
        syn_deal_status($deal_id);
    }
    $condition = ' AND dlt.id=' . $id . ' AND d.deal_status = 4 and d.is_effect=1 and d.is_delete=0 and d.loantype = 0 and d.repay_time_type =1 and  d.publish_wait=0 ';
    $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
    $sql = 'SELECT dlt.load_id,dlt.id,dlt.t_user_id,dlt.transfer_amount,dlt.user_id,dlt.near_repay_time,d.next_repay_time,d.last_repay_time,d.rate,d.repay_start_time,d.repay_time,dlt.load_money,dlt.id as dltid,dlt.status as tras_status,dlt.t_user_id,dlt.transfer_amount,dlt.create_time as tras_create_time,d.user_id as duser_id,d.ips_bill_no FROM ' . DB_PREFIX . 'deal_load dl LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id = dl.deal_id ' . $union_sql . ' WHERE 1=1 ' . $condition;
    $transfer = $GLOBALS['db']->getRow($sql);
    if ($transfer) {
        if ($transfer['user_id'] == $GLOBALS['user_info']['id']) {
            $root["show_err"] = "不能购买自己转让的债权";
            return $root;
        }
        if ($transfer['duser_id'] == $GLOBALS['user_info']['id']) {
            $root["show_err"] = "不能购买自己的的借贷债权";
            return $root;
        }
        if ($transfer['tras_status'] == 0) {
            $root["show_err"] = "债权已撤销";
            return $root;
        }
        if (intval($transfer['t_user_id']) > 0) {
            $root["show_err"] = "债权已转让";
            return $root;
        }
        //下个还款日
        if (intval($transfer['next_repay_time']) == 0) {
            $transfer['next_repay_time'] = next_replay_month($transfer['repay_start_time']);
        }
        if ($transfer['next_repay_time'] - TIME_UTC + 24 * 3600 - 1 <= 0) {
            $root["show_err"] = "债权转让已过期";
            return $root;
        }
        $root["transfer"] = $transfer;
        $root["deal_id"] = $deal_id;
    } else {
        $root["show_err"] = "债权转让不存在";
        return $root;
    }
    if ($transfer['ips_bill_no'] != "") {
        $root["status"] = 2;
    } else {
        $root["status"] = 1;
    }
    //0:出错;1:正确;
    return $root;
}
Exemplo n.º 17
0
function order_paid_done($order_id)
{
    //处理支付成功后的操作
    /**
     * 1. 发货
     * 2. 超量发货的存到会员中心
     * 3. 发券
     * 4. 发放抽奖
     */
    require_once APP_ROOT_PATH . "system/libs/deal.php";
    $order_id = intval($order_id);
    $stock_status = true;
    //团购状态
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
    if ($order_info['type'] == 0) {
        //首先验证所有的规格库存
        $order_goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
        foreach ($order_goods_list as $k => $v) {
            if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "attr_stock where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0")) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count + " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and ((buy_count + " . $v['number'] . " <= stock_cfg) or stock_cfg = 0 )" . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_attr_list[] = $v;
                } else {
                    $stock_status = false;
                    break;
                }
            }
        }
        if ($stock_status) {
            $goods_list = $GLOBALS['db']->getAll("select deal_id,sum(number) as num from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " group by deal_id");
            foreach ($goods_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count + " . $v['num'] . ",user_count = user_count + 1 where id=" . $v['deal_id'] . " and ((buy_count + " . $v['num'] . "<= max_bought) or max_bought = 0) " . " and time_status = 1 and buy_status <> 2";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_list[] = $v;
                    //记录下更新成功的团购商品,用于回滚
                } else {
                    //失败成功,即过期支付,超量支付
                    $stock_status = false;
                    break;
                }
            }
        }
        if ($stock_status) {
            //发货成功,发券
            foreach ($goods_list as $k => $v) {
                //为相应团购发券
                $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($v['deal_id']));
                if ($deal_info['is_coupon'] == 1) {
                    if ($deal_info['deal_type'] == 1) {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            //							for($i=0;$i<$item['number'];$i++) //按单
                            //							{
                            //需要发券
                            /**
                             * 1. 先从已有团购券中发送
                             * 2. 无有未发送的券,自动发送
                             * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                             */
                            /*修正后台手动建团购劵,购买的时候按单发送团购劵,数量不一致*/
                            $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['total_price'] . ",coupon_score = " . $item['return_total_score'] . ",coupon_money = " . $item['return_total_money'] . ",deal_type = " . $deal_info['deal_type'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 order by id ASC limit 1";
                            $GLOBALS['db']->query($sql);
                            $exist_coupon = $GLOBALS['db']->affected_rows();
                            if (!$exist_coupon) {
                                //未发送成功,即无可发放的预设团购券
                                add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                            }
                            //							}
                        }
                    } else {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            for ($i = 0; $i < $item['number']; $i++) {
                                //需要发券
                                /**
                                 * 1. 先从已有团购券中发送
                                 * 2. 无有未发送的券,自动发送
                                 * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                                 */
                                $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['unit_price'] . ",coupon_score = " . $item['return_score'] . ",coupon_money = " . $item['return_money'] . ",deal_type = " . $deal_info['deal_type'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 limit 1";
                                $GLOBALS['db']->query($sql);
                                $exist_coupon = $GLOBALS['db']->affected_rows();
                                if (!$exist_coupon) {
                                    //未发送成功,即无可发放的预设团购券
                                    add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                                }
                            }
                        }
                    }
                }
                //发券结束
            }
            //开始处理返还的积分或现金
            require_once APP_ROOT_PATH . "system/libs/user.php";
            if ($order_info['return_total_money'] != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_MONEY'], $order_info['order_sn']);
                modify_account(array('money' => $order_info['return_total_money'], 'score' => 0), $order_info['user_id'], $msg);
            }
            if ($order_info['return_total_score'] != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_SCORE'], $order_info['order_sn']);
                modify_account(array('money' => 0, 'score' => $order_info['return_total_score']), $order_info['user_id'], $msg);
                send_score_sms($order_info['id']);
                send_score_mail($order_info['id']);
            }
            //开始处理返利,只创建返利, 发放将与msg_list的自动运行一起执行
            $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $order_info['user_id']);
            //开始查询所购买的列表中支不支持促销
            $is_referrals = 1;
            //默认为返利
            foreach ($goods_list as $k => $v) {
                $is_referrals = $GLOBALS['db']->getOne("select is_referral from " . DB_PREFIX . "deal where id = " . $v['deal_id']);
                if ($is_referrals == 0) {
                    break;
                }
            }
            if ($user_info['referral_count'] < app_conf("REFERRAL_LIMIT") && $is_referrals == 1) {
                //开始返利给推荐人
                $parent_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_info['pid']);
                if ($parent_info) {
                    if (app_conf("REFERRAL_IP_LIMIT") == 1 && $parent_info['login_ip'] != get_client_ip() || app_conf("REFERRAL_IP_LIMIT") == 0) {
                        if (app_conf("INVITE_REFERRALS_TYPE") == 0) {
                            $referral_data['user_id'] = $parent_info['id'];
                            //初返利的会员ID
                            $referral_data['rel_user_id'] = $user_info['id'];
                            //被推荐且发生购买的会员ID
                            $referral_data['create_time'] = get_gmtime();
                            $referral_data['money'] = app_conf("INVITE_REFERRALS");
                            $referral_data['order_id'] = $order_info['id'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "referrals", $referral_data);
                            //插入
                        } else {
                            $referral_data['user_id'] = $parent_info['id'];
                            //初返利的会员ID
                            $referral_data['rel_user_id'] = $user_info['id'];
                            //被推荐且发生购买的会员ID
                            $referral_data['create_time'] = get_gmtime();
                            $referral_data['score'] = app_conf("INVITE_REFERRALS");
                            $referral_data['order_id'] = $order_info['id'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "referrals", $referral_data);
                            //插入
                        }
                        $GLOBALS['db']->query("update " . DB_PREFIX . "user set referral_count = referral_count + 1 where id = " . $user_info['id']);
                    }
                }
            }
            //超出充值
            if ($order_info['pay_amount'] > $order_info['total_price']) {
                require_once APP_ROOT_PATH . "system/libs/user.php";
                if ($order_info['total_price'] < 0) {
                    $msg = sprintf($GLOBALS['lang']['MONEYORDER_INCHARGE'], $order_info['order_sn']);
                } else {
                    $msg = sprintf($GLOBALS['lang']['OUTOFMONEY_INCHARGE'], $order_info['order_sn']);
                }
                $refund_money = $order_info['pay_amount'] - $order_info['total_price'];
                if ($order_info['account_money'] > $refund_money) {
                    $account_money_now = $order_info['account_money'] - $refund_money;
                } else {
                    $account_money_now = 0;
                }
                $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']);
                if ($order_info['ecv_money'] > $refund_money) {
                    $ecv_money_now = $order_info['ecv_money'] - $refund_money;
                } else {
                    $ecv_money_now = 0;
                }
                $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']);
                modify_account(array('money' => $order_info['pay_amount'] - $order_info['total_price'], 'score' => 0), $order_info['user_id'], $msg);
            }
            //生成抽奖
            $lottery_list = $GLOBALS['db']->getAll("select d.id as did,doi.number from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id left join " . DB_PREFIX . "deal as d on doi.deal_id = d.id where d.is_lottery = 1 and do.id = " . $order_info['id']);
            $lottery_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($order_info['user_id']));
            //如为首次抽奖,先为推荐人生成抽奖号
            $lottery_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where user_id = " . intval($order_info['user_id']));
            if ($lottery_count == 0 && $lottery_user['pid'] != 0) {
                $lottery_puser = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($lottery_user['pid']));
                foreach ($lottery_list as $lottery) {
                    $k = 0;
                    do {
                        if ($k > 10) {
                            break;
                        }
                        $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                        $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                        //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                        $sn = $max_sn + 1;
                        $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                        $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $lottery_puser['id'] . ",'" . $lottery_puser['lottery_mobile'] . "'," . get_gmtime() . "," . $order_info['user_id'] . " from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                        $GLOBALS['db']->query($sql);
                        send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                        $k++;
                    } while (intval($GLOBALS['db']->insert_id()) == 0);
                }
            }
            foreach ($lottery_list as $lottery) {
                for ($i = 0; $i < $lottery['number']; $i++) {
                    $k = 0;
                    do {
                        if ($k > 10) {
                            break;
                        }
                        $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                        $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                        //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                        $sn = $max_sn + $i + 1;
                        $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                        $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $order_info['user_id'] . "," . $lottery_user['lottery_mobile'] . "," . get_gmtime() . ",0 from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                        $GLOBALS['db']->query($sql);
                        send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                        $k++;
                    } while (intval($GLOBALS['db']->insert_id()) == 0);
                }
            }
        } else {
            //开始模拟事务回滚
            foreach ($affect_attr_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count - " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            foreach ($affect_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count - " . $v['num'] . ",user_count = user_count - 1 where id=" . $v['deal_id'];
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            //超出充值
            require_once APP_ROOT_PATH . "system/libs/user.php";
            $msg = sprintf($GLOBALS['lang']['OUTOFSTOCK_INCHARGE'], $order_info['order_sn']);
            modify_account(array('money' => $order_info['total_price'], 'score' => 0), $order_info['user_id'], $msg);
            //将订单的extra_status 状态更新为2,并自动退款,结单
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set extra_status = 2, after_sale = 1, refund_money = pay_amount, order_status = 1 where id = " . intval($order_info['id']));
            //记录退款的订单日志
            $log['log_info'] = $msg;
            $log['log_time'] = get_gmtime();
            $log['order_id'] = intval($order_info['id']);
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_log", $log);
        }
        //同步所有未过期的团购状态
        foreach ($goods_list as $item) {
            syn_deal_status($item['deal_id'], true);
        }
    } else {
        //订单充值
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set order_status = 1 where id = " . $order_info['id']);
        //充值单自动结单
        require_once APP_ROOT_PATH . "system/libs/user.php";
        $msg = sprintf($GLOBALS['lang']['USER_INCHARGE_DONE'], $order_info['order_sn']);
        modify_account(array('money' => $order_info['total_price'] - $order_info['payment_fee'], 'score' => 0), $order_info['user_id'], $msg);
    }
}
Exemplo n.º 18
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);
     }
 }
Exemplo n.º 19
0
 public function contact()
 {
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         echo "不存在的债权";
         die;
     }
     //先执行更新借贷信息
     $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load WHERE id=" . $id);
     if ($deal_id == 0) {
         echo "不存在的债权";
         die;
     } else {
         syn_deal_status($deal_id);
     }
     $condition = ' AND dlt.id=' . $id . ' AND d.deal_status >= 4 and d.is_effect=1 and d.is_delete=0 and d.loantype = 0 and d.repay_time_type =1 and  d.publish_wait=0 and (dlt.user_id=' . $GLOBALS['user_info']['id'] . ' or dlt.t_user_id = ' . $GLOBALS['user_info']['id'] . ') ';
     $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
     $sql = 'SELECT dlt.id,dlt.deal_id,dlt.load_id,dlt.transfer_amount,dlt.near_repay_time,dlt.user_id,d.next_repay_time,d.last_repay_time,d.rate,d.repay_start_time,d.repay_time,dlt.load_money,dlt.id as dltid,dlt.status as tras_status,dlt.t_user_id,dlt.transfer_amount,dlt.create_time as tras_create_time,dlt.transfer_time,d.user_id as duser_id FROM ' . DB_PREFIX . 'deal_load dl LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id = dl.deal_id ' . $union_sql . ' WHERE 1=1 ' . $condition;
     $transfer = $GLOBALS['db']->getRow($sql);
     if ($transfer) {
         //下个还款日
         $transfer['next_repay_time_format'] = to_date($transfer['near_repay_time'], "Y 年 m 月 d 日");
         $transfer['near_repay_time_format'] = to_date(next_replay_month($transfer['near_repay_time'], " -1 "), "Y 年 m 月 d 日");
         //什么时候开始借
         $transfer['repay_start_time_format'] = to_date($transfer['repay_start_time'], "Y 年 m 月 d 日");
         //还款日
         $transfer['final_repay_time'] = next_replay_month($transfer['repay_start_time'], $transfer['repay_time']);
         $transfer['final_repay_time_format'] = to_date($transfer['final_repay_time'], "Y 年 m 月 d 日");
         //剩余期数
         $transfer['how_much_month'] = how_much_month($transfer['near_repay_time'], $transfer['final_repay_time']) + 1;
         //本息还款金额
         $transfer['month_repay_money'] = pl_it_formula($transfer['load_money'], $transfer['rate'] / 12 / 100, $transfer['repay_time']);
         $transfer['month_repay_money_format'] = format_price($transfer['month_repay_money']);
         //剩余多少钱未回
         $transfer['all_must_repay_money'] = $transfer['month_repay_money'] * $transfer['how_much_month'];
         $transfer['all_must_repay_money_format'] = format_price($transfer['all_must_repay_money']);
         //剩余多少本金未回
         $transfer['left_benjin'] = get_benjin($transfer['repay_time'] - $transfer['how_much_month'] - 1, $transfer['repay_time'], $transfer['load_money'], $transfer['month_repay_money'], $transfer['rate']);
         $transfer['left_benjin_format'] = format_price($transfer['left_benjin']);
         //剩多少利息
         $transfer['left_lixi'] = $transfer['all_must_repay_money'] - $transfer['left_benjin'];
         $transfer['left_lixi_format'] = format_price($transfer['left_lixi']);
         //投标价格
         $transfer['load_money_format'] = format_price($transfer['load_money']);
         //转让价格
         $transfer['transfer_amount_format'] = format_price($transfer['transfer_amount']);
         //转让管理费
         $transfer_fee = $transfer['transfer_amount'] * (double) app_conf("USER_LOAD_TRANSFER_FEE");
         if ($transfer_fee != 0) {
             $transfer_fee = $transfer_fee / 100;
         }
         $transfer['transfer_fee_format'] = format_price($transfer_fee);
         //转让收益
         $transfer['transfer_income_format'] = format_price($transfer['all_must_repay_money'] - $transfer['transfer_amount']);
         if ($transfer['tras_create_time'] != "") {
             $transfer['tras_create_time_format'] = to_date($transfer['tras_create_time'], "Y 年 m 月 d 日");
         }
         $transfer['transfer_time_format'] = to_date($transfer['transfer_time'], "Y 年 m 月 d 日");
         $transfer['user'] = get_user("user_name,real_name,idno,level_id", $transfer['user_id']);
         $transfer['tuser'] = get_user("user_name,real_name,idno,level_id", $transfer['t_user_id']);
         $transfer['duser'] = get_user("user_name,real_name,idno,level_id", $transfer['duser_id']);
         $GLOBALS['tmpl']->assign('transfer', $transfer);
     } else {
         echo "不存在的债权";
         die;
     }
     $contract = $GLOBALS['tmpl']->fetch("str:" . app_conf("TCONTRACT"));
     $GLOBALS['tmpl']->assign('contract', $contract);
     $GLOBALS['tmpl']->display("inc/uc/transfer_contact.html");
 }
Exemplo n.º 20
0
/**
 * 流标还返
 * $id deal_id
 * $type 0 普通返回,  1资金托管
 */
function do_received($id, $type = 0, $bad_msg = "")
{
    $return = array("status" => 0, "info" => "");
    if ($id == 0) {
        $return['info'] = "返还失败,借款不存在";
        return $return;
    }
    require_once APP_ROOT_PATH . "app/Lib/deal.php";
    syn_deal_status($id);
    $deal_info = get_deal($id);
    if ($deal['cate_id'] == 6) {
        // 体验金
        $is_ty = 1;
    } else {
        $is_ty = 0;
    }
    if (!$deal_info) {
        $return['info'] = "返还失败,借款不存在";
        return $return;
    }
    if (intval($deal_info['deal_status']) >= 4) {
        $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=RegisterSubject&pOperationType=2&status=2&status_msg={$bad_msg}&deal_id=" . $id;
        return $return;
    }
    if ($type == 0) {
        //流标时返还
        require_once APP_ROOT_PATH . "system/libs/user.php";
        $r_load_list = $GLOBALS['db']->getAll("SELECT id,user_id,money,is_old_loan FROM " . DB_PREFIX . "deal_load WHERE is_repay=0 AND deal_id={$id}");
        foreach ($r_load_list as $k => $v) {
            if ($v['is_old_loan'] == 0) {
                modify_account(array("money" => $v['money'], "lock_money" => -$v['money']), $v['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],流标返还", 19, $is_ty);
            } else {
                modify_account(array("money" => $v['money']), $v['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],流标返还", 19, $is_ty);
            }
            $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_repay=1 WHERE id=" . $v['id']);
        }
    } else {
        $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_repay=1 WHERE deal_id={$id}");
    }
    if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_load WHERE is_repay=0 AND deal_id={$id}") > 0) {
        $bad_data['bad_msg'] = $bad_msg;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $bad_data, "UPDATE", "id=" . $id);
        $return['status'] = 1;
        $return['info'] = "部分返还";
        return $return;
    } else {
        $bad_data['is_has_received'] = 1;
        $bad_data['bad_msg'] = $bad_msg;
        $bad_data['bad_time'] = TIME_UTC;
        $bad_data['deal_status'] = 3;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $bad_data, "UPDATE", "id=" . $id);
        $return['status'] = 1;
        $return['info'] = "返还成功";
        return $return;
    }
}
Exemplo n.º 21
0
/**
 * 获取指定的团购产品
 */
function get_preview_deal($id = 0, $cate_id = 0, $city_id = 0)
{
    $time = get_gmtime();
    if ($id > 0) {
        $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($id));
    }
    if ($deal) {
        if ($deal['time_status'] == 0 && $deal['begin_time'] == 0 || $deal['begin_time'] < get_gmtime()) {
            syn_deal_status($deal['id']);
        }
        //格式化数据
        $deal['begin_time_format'] = to_date($deal['begin_time']);
        $deal['end_time_format'] = to_date($deal['end_time']);
        $deal['origin_price_format'] = format_price($deal['origin_price']);
        $deal['current_price_format'] = format_price($deal['current_price']);
        $deal['success_time_format'] = to_date($deal['success_time']);
        if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) {
            //手动折扣
            $deal['save_price'] = $deal['origin_price'] - $deal['current_price'];
        } else {
            $deal['save_price'] = $deal['origin_price'] * ((10 - $deal['discount']) / 10);
        }
        if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) {
            $deal['discount'] = round($deal['current_price'] / $deal['origin_price'] * 10, 2);
        }
        $deal['discount'] = round($deal['discount'], 2);
        $deal['save_price_format'] = format_price($deal['save_price']);
        $deal['deal_success_num'] = sprintf($GLOBALS['lang']['SUCCESS_BUY_COUNT'], $deal['buy_count']);
        $deal['current_bought'] = $deal['buy_count'];
        if ($deal['buy_status'] == 0) {
            $deal['success_less'] = sprintf($GLOBALS['lang']['SUCCESS_LESS_BUY_COUNT'], $deal['min_bought'] - $deal['buy_count']);
        }
        $deal['success_time_tip'] = sprintf($GLOBALS['lang']['SUCCESS_TIME_TIP'], $deal['success_time_format'], $deal['min_bought']);
        //团购图片集
        $img_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_gallery where deal_id=" . intval($deal['id']) . " order by sort asc");
        $deal['image_list'] = $img_list;
        //商户信息
        $deal['supplier_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier where id = " . intval($deal['supplier_id']));
        $deal['supplier_address_info'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where supplier_id = " . intval($deal['supplier_id']) . " and is_main = 1");
        //属性列表
        $deal_attrs_res = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_attr where deal_id = " . intval($deal['id']) . " order by id asc");
        if ($deal_attrs_res) {
            foreach ($deal_attrs_res as $k => $v) {
                $deal_attr[$v['goods_type_attr_id']]['name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "goods_type_attr where id = " . intval($v['goods_type_attr_id']));
                $deal_attr[$v['goods_type_attr_id']]['attrs'][] = $v;
            }
            $deal['deal_attr_list'] = $deal_attr;
        }
        if ($deal['uname'] != '') {
            $durl = url("tuan", "deal", array("id" => $deal['uname']));
        } else {
            $durl = url("tuan", "deal", array("id" => $deal['id']));
        }
        $deal['share_url'] = get_domain() . $durl;
        if ($GLOBALS['user_info']) {
            if (app_conf("URL_MODEL") == 0) {
                $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            } else {
                $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id']));
            }
        }
    }
    return $deal;
}
Exemplo n.º 22
0
 public function update_deal_item()
 {
     B('FilterString');
     $ajax = intval($_REQUEST['ajax']);
     $data = M("CrowdItem")->create();
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/edit_deal_item", array("id" => $data['id'])));
     if (!check_empty($data['price'])) {
         $this->error("请输入价格");
     }
     // 更新数据
     $this->deal_update(intval($data['deal_id']));
     $list = M("CrowdItem")->save($data);
     $log_info = "项目ID" . $data['deal_id'] . ":" . format_price($data['price']);
     if (false !== $list) {
         if ($data['virtual_person'] > 0) {
         }
         //成功提示
         //开始处理图片
         M("CrowdItemImage")->where("deal_item_id=" . $data['id'])->delete();
         $imgs = array($_REQUEST['img0'], $_REQUEST['img1'], $_REQUEST['img2'], $_REQUEST['img3']);
         //$imgs = $_REQUEST['image'];
         foreach ($imgs as $k => $v) {
             if ($v != '') {
                 $img_data['deal_item_id'] = $data['id'];
                 $img_data['deal_id'] = $data['deal_id'];
                 $img_data['image'] = $v;
                 M("CrowdItemImage")->add($img_data);
             }
         }
         M("Crowd")->where("id=" . $data['deal_id'])->setField("deal_extra_cache", "");
         M("CrowdLog")->where("deal_id=" . $data['deal_id'])->setField("deal_info_cache", "");
         //end 处理图片
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         syn_deal($data['deal_id']);
         syn_deal_status($data['deal_id']);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"));
     }
 }