public function done() { save_debug_log('cart done', 'request:' . json_encode($_REQUEST)); $region4_id = intval($_REQUEST['region_lv4']); $region3_id = intval($_REQUEST['region_lv3']); $region2_id = intval($_REQUEST['region_lv2']); $region1_id = intval($_REQUEST['region_lv1']); if ($region4_id == 0) { if ($region3_id == 0) { if ($region2_id == 0) { $region_id = $region1_id; } else { $region_id = $region2_id; } } else { $region_id = $region3_id; } } else { $region_id = $region4_id; } $delivery_id = intval($_REQUEST['delivery']); $payment = intval($_REQUEST['payment']); $account_money = floatval($_REQUEST['account_money']); $all_account_money = intval($_REQUEST['all_account_money']); $ecvsn = $_REQUEST['ecvsn'] ? addslashes(trim($_REQUEST['ecvsn'])) : ''; $ecvpassword = $_REQUEST['ecvpassword'] ? addslashes(trim($_REQUEST['ecvpassword'])) : ''; $user_id = intval($GLOBALS['user_info']['id']); $session_id = es_session::id(); $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cart where session_id='" . $session_id . "' and user_id=" . $user_id); if (!$goods_list) { showErr($GLOBALS['lang']['CART_EMPTY_TIP'], $ajax); } //验证购物车 if (!$GLOBALS['user_info']) { showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax, url("shop", "user#login")); } $deal_ids = $GLOBALS['db']->getAll("select distinct(deal_id) as deal_id,number from " . DB_PREFIX . "deal_cart where session_id = '" . $session_id . "' and user_id = " . $user_id); foreach ($deal_ids as $row) { $checker = check_deal_time($row['deal_id']); if ($checker['status'] == 0) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax, url("shop", "cart#index")); } $check = check_user_bought_day($row['deal_id'], $row['number']); if ($check['status'] == 0) { $res = array('ret' => '-1', 'info' => $check['info']); showErr($check['info'], $ajax, url("shop", "cart#index")); } $checker = check_deal_number($row['deal_id']); if ($checker['status'] == 0) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax, url("shop", "cart#index")); } //验证支付方式的支持 if ($GLOBALS['db']->getOne("select define_payment from " . DB_PREFIX . "deal where id = " . $row['deal_id']) == 1) { if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_payment where deal_id = " . $row['deal_id'] . " and payment_id = " . $payment)) { showErr($GLOBALS['lang']['INVALID_PAYMENT'], $ajax, url("shop", "cart#index")); } } } //开始验证关于属性的库存 $deal_attr_ids = $GLOBALS['db']->getAll("select deal_id,attr,name,attr_str from " . DB_PREFIX . "deal_cart where session_id = '" . es_session::id() . "' and user_id = " . $user_id); foreach ($deal_attr_ids as $row) { $attr_setting_str = ''; if ($row['attr_str'] != '') { $attr_setting_str = $row['attr_str']; } if ($attr_setting_str != '') { $checker = check_deal_number_attr($row['deal_id'], $attr_setting_str); if ($checker['status'] == 0) { if ($ajax == 1) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']] . "|" . $row['deal_id'] . "|" . $checker['attr'], $ajax, url("shop", "cart#index")); } else { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax, url("shop", "cart#index")); } } } } //结束验证购物车 //开始验证订单接交信息 require_once APP_ROOT_PATH . "system/libs/cart.php"; $data = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list); if ($data['is_delivery'] == 1) { // 如果服务站为空或者服务站为“暂不支持配送” $region4 = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "delivery_region where id=" . $region4_id); if ($region4 == false) { showErr($GLOBALS['lang']['DELIVERY_REGION_LV4_IS_NONE']); } if ($region4 == $GLOBALS['lang']['DELETERY_REGION_LV4_NOT_SUPPORT_STR']) { showErr($GLOBALS['lang']['DELETERY_REGION_LV4_NOT_SUPPORT']); } //配送验证 if (!$data['region_info'] || $data['region_info']['region_level'] != 4) { showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS']); } if (trim($_REQUEST['consignee']) == '') { showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE']); } if (trim($_REQUEST['address']) == '') { showErr($GLOBALS['lang']['FILL_CORRECT_ADDRESS']); } // if(trim($_REQUEST['zip'])=='') // { // showErr($GLOBALS['lang']['FILL_CORRECT_ZIP']); // } if (trim($_REQUEST['mobile']) == '') { showErr($GLOBALS['lang']['FILL_MOBILE_PHONE']); } if (!check_mobile(trim($_REQUEST['mobile']))) { showErr($GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE']); } // if(!$data['delivery_info']) // { // showErr($GLOBALS['lang']['PLEASE_SELECT_DELIVERY']); // } } //TODO if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) { showErr($GLOBALS['lang']['PLEASE_SELECT_PAYMENT']); } //结束验证订单接交信息 //开始生成订单 $now = get_gmtime(); $order['type'] = 0; //普通订单 $order['user_id'] = $user_id; $order['create_time'] = $now; $order['total_price'] = $data['pay_total_price']; //应付总额 商品价 - 会员折扣 + 运费 + 支付手续费 $order['pay_amount'] = 0; $order['pay_status'] = 0; //新单都为零, 等下面的流程同步订单状态 $order['delivery_status'] = $data['is_delivery'] == 0 ? 5 : 0; $order['order_status'] = 0; //新单都为零, 等下面的流程同步订单状态 $order['return_total_score'] = $data['return_total_score']; //结单后送的积分 $order['return_total_money'] = $data['return_total_money']; //结单后送的现金 $order['memo'] = htmlspecialchars(addslashes(trim($_REQUEST['memo']))); $order['region_lv1'] = intval($_REQUEST['region_lv1']); $order['region_lv2'] = intval($_REQUEST['region_lv2']); $order['region_lv3'] = intval($_REQUEST['region_lv3']); $order['region_lv4'] = intval($_REQUEST['region_lv4']); $order['address'] = htmlspecialchars(addslashes(trim($_REQUEST['address']))); $order['mobile'] = htmlspecialchars(addslashes(trim($_REQUEST['mobile']))); $order['consignee'] = htmlspecialchars(addslashes(trim($_REQUEST['consignee']))); $order['zip'] = htmlspecialchars(addslashes(trim($_REQUEST['zip']))); $order['deal_total_price'] = $data['total_price']; //团购商品总价 $order['discount_price'] = $data['user_discount']; $order['delivery_fee'] = $data['delivery_fee']; $order['ecv_money'] = 0; $order['account_money'] = 0; $order['ecv_sn'] = ''; $order['delivery_id'] = $data['delivery_info']['id']; $order['payment_id'] = $data['payment_info']['id']; $order['payment_fee'] = $data['payment_fee']; $order['payment_fee'] = $data['payment_fee']; $order['bank_id'] = htmlspecialchars(addslashes(trim($_REQUEST['bank_id']))); foreach ($data['promote_description'] as $promote_item) { $order['promote_description'] .= $promote_item . "<br />"; } //更新来路 $order['referer'] = $GLOBALS['referer']; $user_info = es_session::get("user_info"); $order['user_name'] = $user_info['user_name']; $coupon_mobile = htmlspecialchars(addslashes(trim($_REQUEST['coupon_mobile']))); if ($coupon_mobile != '') { $GLOBALS['db']->query("update " . DB_PREFIX . "user set mobile = '" . $coupon_mobile . "' where id = " . intval($user_info['id'])); } do { $order['order_sn'] = to_date(get_gmtime(), "Ymdhis") . rand(10, 99); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order, 'INSERT', '', 'SILENT'); $order_id = intval($GLOBALS['db']->insert_id()); } while ($order_id == 0); //生成订单商品 foreach ($goods_list as $k => $v) { $deal_info = load_auto_cache("cache_deal_cart", array("id" => $v['deal_id'])); $goods_item = array(); $goods_item['deal_id'] = $v['deal_id']; $goods_item['number'] = $v['number']; $goods_item['unit_price'] = $v['unit_price']; $goods_item['total_price'] = $v['total_price']; $goods_item['name'] = addslashes($v['name']); $goods_item['sub_name'] = addslashes($v['sub_name']); $goods_item['attr'] = $v['attr']; $goods_item['verify_code'] = $v['verify_code']; $goods_item['order_id'] = $order_id; $goods_item['return_score'] = $v['return_score']; $goods_item['return_total_score'] = $v['return_total_score']; $goods_item['return_money'] = $v['return_money']; $goods_item['return_total_money'] = $v['return_total_money']; $goods_item['buy_type'] = $v['buy_type']; $goods_item['attr_str'] = $v['attr_str']; $goods_item['balance_unit_price'] = $deal_info['balance_price']; $goods_item['balance_total_price'] = $deal_info['balance_price'] * $v['number']; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_item", $goods_item, 'INSERT', '', 'SILENT'); } //开始更新订单表的deal_ids $deal_ids = $GLOBALS['db']->getOne("select group_concat(deal_id) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set deal_ids = '" . $deal_ids . "' where id = " . $order_id); $GLOBALS['db']->query("delete from " . DB_PREFIX . "deal_cart where session_id = '" . $session_id . "' and user_id = " . $user_id); if ($data['is_delivery'] == 1) { //保存收款人 $user_consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where user_id = " . $user_id . " order by id desc"); $user_consignee['region_lv1'] = intval($_REQUEST['region_lv1']); $user_consignee['region_lv2'] = intval($_REQUEST['region_lv2']); $user_consignee['region_lv3'] = intval($_REQUEST['region_lv3']); $user_consignee['region_lv4'] = intval($_REQUEST['region_lv4']); $user_consignee['address'] = htmlspecialchars(addslashes(trim($_REQUEST['address']))); $user_consignee['mobile'] = htmlspecialchars(addslashes(trim($_REQUEST['mobile']))); $user_consignee['consignee'] = htmlspecialchars(addslashes(trim($_REQUEST['consignee']))); $user_consignee['zip'] = htmlspecialchars(addslashes(trim($_REQUEST['zip']))); $user_consignee['user_id'] = $user_id; if (intval($user_consignee['id']) == 0) { //新增 $GLOBALS['db']->autoExecute(DB_PREFIX . "user_consignee", $user_consignee, 'INSERT', '', 'SILENT'); } else { //更新 $GLOBALS['db']->autoExecute(DB_PREFIX . "user_consignee", $user_consignee, 'UPDATE', 'id=' . $user_consignee['id'], 'SILENT'); rm_auto_cache("consignee_info", array("consignee_id" => intval($user_consignee['id']))); } } //生成order_id 后 //1. 代金券支付 $ecv_data = $data['ecv_data']; if ($ecv_data) { $ecv_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Voucher'"); $payment_notice_id = make_payment_notice($ecv_data['money'], $order_id, $ecv_payment_id); require_once APP_ROOT_PATH . "system/payment/Voucher_payment.php"; $voucher_payment = new Voucher_payment(); $voucher_payment->direct_pay($ecv_data['sn'], $ecv_data['password'], $payment_notice_id); } //2. 余额支付 $account_money = $data['account_money']; if (floatval($account_money) > 0) { $account_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Account'"); $payment_notice_id = make_payment_notice($account_money, $order_id, $account_payment_id); require_once APP_ROOT_PATH . "system/payment/Account_payment.php"; $account_payment = new Account_payment(); $account_payment->get_payment_code($payment_notice_id); } //3. 相应的支付接口 $payment_info = $data['payment_info']; if ($payment_info && $data['pay_price'] > 0) { $payment_notice_id = make_payment_notice($data['pay_price'], $order_id, $payment_info['id']); //创建支付接口的付款单 } $rs = order_paid($order_id); save_debug_log('cart done', 'order_paid rs:' . $rs . 'order_id:' . $order_id); if ($rs) { app_redirect(url("shop", "payment#done", array("id" => $order_id))); //支付成功 } else { app_redirect(url("shop", "payment#pay", array("id" => $payment_notice_id))); } }
function insertCartData($user_id, $session_id, $cartdata) { $GLOBALS['user_info']['id'] = $user_id; require APP_ROOT_PATH . 'system/model/deal.php'; //require APP_ROOT_PATH.'app/Lib/deal.php'; $res = array('status' => 0, 'info' => ''); $score_enough = true; foreach ($cartdata as $key => $cart) { /* $cart['goods_id'] = 1; $cart['num'] = 1; $cart['attr_value_a'] = '红色'; $cart['attr_value_b'] = '大码'; $cart['attr_id_a'] = 255; $cart['attr_id_b'] = 239; [id] => 57 [goods_id] => 57 [attr_id_a] => 257 [attr_id_b] => 259 [attr_value_a] => 白色 [attr_value_b] => 170 [num] => 3 */ //加入每个 //file_put_contents(APP_ROOT_PATH."tmapi/log/".$key.".txt",print_r($cart,true)); $id = intval($cart['goods_id']); $check = check_deal_time($id); if ($check['status'] == 0) { $res['info'] .= $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; continue; } $check = check_deal_number($id, $cart['num']); if ($check['status'] == 0) { $res['info'] .= $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; continue; } $attr_setting_str = $cart['attr_value_a'] . $cart['attr_value_b']; if ($attr_setting_str != '') { $check = check_deal_number_attr($cart['goods_id'], $attr_setting_str, $cart['num']); if ($check['status'] == 0) { $res['info'] .= $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']] . $check['attr']; continue; } } $deal_info = load_auto_cache("deal", array("id" => $id)); if ($deal_info['return_score'] < 0) { //需要积分兑换 $user_score = intval($GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . $user_id)); if ($user_score < abs(intval($deal_info['return_score']) * $cart['num'])) { $score_enough = false; } } $attr_ids = array(); //chenfq by add 2014-08-26 if (intval($cart['attr_id_a']) > 0 && intval($cart['attr_id_b']) > 0) { $attr_ids = array(intval($cart['attr_id_a']), intval($cart['attr_id_b'])); } elseif (intval($cart['attr_id_a']) > 0) { $attr_ids = array(intval($cart['attr_id_a'])); } //加入购物车处理,有提交属性, 或无属性时 $attr_str = '0'; $attr_name = ''; $attr_name_str = ''; if (count($attr_ids) > 0) { $attr_str = implode(",", $attr_ids); $attr_names = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "deal_attr where id in(" . $attr_str . ")"); $attr_name = ''; foreach ($attr_names as $attr) { $attr_name .= $attr['name'] . ","; $attr_name_str .= $attr['name']; } $attr_name = substr($attr_name, 0, -1); } $verify_code = md5($id . "_" . $attr_str); $cart_item = array(); $attr_price = $GLOBALS['db']->getOne("select sum(price) from " . DB_PREFIX . "deal_attr where id in({$attr_str})"); $cart_item['session_id'] = $session_id; $cart_item['user_id'] = intval($user_id); $cart_item['deal_id'] = $id; $cart_item['id'] = $cart['id']; //chenfq by add 2014-08-26 //属性 if ($attr_name != '') { $cart_item['name'] = $deal_info['name'] . " [" . $attr_name . "]"; $cart_item['sub_name'] = $deal_info['sub_name'] . " [" . $attr_name . "]"; } else { $cart_item['name'] = $deal_info['name']; $cart_item['sub_name'] = $deal_info['sub_name']; } $cart_item['name'] = addslashes($cart_item['name']); $cart_item['sub_name'] = addslashes($cart_item['sub_name']); $cart_item['attr'] = $attr_str; $cart_item['unit_price'] = $deal_info['current_price'] + $attr_price; $cart_item['number'] = $cart['num']; $cart_item['total_price'] = $cart_item['unit_price'] * $cart_item['number']; $cart_item['verify_code'] = $verify_code; $cart_item['create_time'] = get_gmtime(); $cart_item['update_time'] = get_gmtime(); $cart_item['return_score'] = $deal_info['return_score']; $cart_item['return_total_score'] = $deal_info['return_score'] * $cart_item['number']; $cart_item['return_money'] = $deal_info['return_money']; $cart_item['return_total_money'] = $deal_info['return_money'] * $cart_item['number']; $cart_item['buy_type'] = $deal_info['buy_type']; $cart_item['supplier_id'] = $deal_info['supplier_id']; $cart_item['attr_str'] = $attr_name_str; $cart_list[] = $cart_item; //end } if (!$score_enough) { $res['info'] .= " " . $GLOBALS['lang']['NOT_ENOUGH_SCORE']; } $res['data'] = $cart_list; $res['status'] = 1; return $res; }
public function order_done() { require_once APP_ROOT_PATH . "system/model/deal.php"; require_once APP_ROOT_PATH . "system/model/deal_order.php"; global_run(); $ajax = 1; $user_info = $GLOBALS['user_info']; $id = intval($_REQUEST['id']); //订单号 $order = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $id . " and is_delete = 0 and user_id = " . $user_info['id']); if (!$order) { showErr($GLOBALS['lang']['INVALID_ORDER_DATA'], $ajax); } if ($order['refund_status'] == 1) { showErr($GLOBALS['lang']['REFUNDING_CANNOT_PAY'], $ajax); } if ($order['refund_status'] == 2) { showErr($GLOBALS['lang']['REFUNDED_CANNOT_PAY'], $ajax); } $region4_id = intval($_REQUEST['region_lv4']); $region3_id = intval($_REQUEST['region_lv3']); $region2_id = intval($_REQUEST['region_lv2']); $region1_id = intval($_REQUEST['region_lv1']); if ($region4_id == 0) { if ($region3_id == 0) { if ($region2_id == 0) { $region_id = $region1_id; } else { $region_id = $region2_id; } } else { $region_id = $region3_id; } } else { $region_id = $region4_id; } $delivery_id = intval($_REQUEST['delivery']); $payment = intval($_REQUEST['payment']); $account_money = floatval($_REQUEST['account_money']); $all_account_money = intval($_REQUEST['all_account_money']); $ecvsn = $_REQUEST['ecvsn'] ? strim($_REQUEST['ecvsn']) : ''; $ecvpassword = $_REQUEST['ecvpassword'] ? strim($_REQUEST['ecvpassword']) : ''; $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order['id']); //验证购物车 if (check_save_login() != LOGIN_STATUS_LOGINED) { showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax, url("index", "user#login")); } //验证支付方式的支持 foreach ($goods_list as $k => $row) { if ($GLOBALS['db']->getOne("select define_payment from " . DB_PREFIX . "deal where id = " . $row['deal_id']) == 1) { if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_payment where deal_id = " . $row['deal_id'] . " and payment_id = " . $payment)) { showErr($GLOBALS['lang']['INVALID_PAYMENT'], $ajax); } } } //结束验证购物车 $deal_s = $GLOBALS['db']->getAll("select distinct(deal_id) as deal_id from " . DB_PREFIX . "deal_order_item where order_id = " . $order['id']); //如果属于未支付的 if ($order['pay_status'] == 0) { foreach ($deal_s as $row) { $checker = check_deal_number($row['deal_id'], 0); if ($checker['status'] == 0) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax); } } foreach ($goods_list as $k => $v) { $checker = check_deal_number_attr($v['deal_id'], $v['attr_str'], 0); if ($checker['status'] == 0) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax); } } //验证商品是否过期 foreach ($deal_s as $row) { $checker = check_deal_time($row['deal_id']); if ($checker['status'] == 0) { showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax); } } } //开始验证订单接交信息 require_once APP_ROOT_PATH . "system/model/cart.php"; $data = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list, $order['account_money'], $order['ecv_money']); if ($data['is_delivery'] == 1) { //配送验证 if (!$data['region_info'] || $data['region_info']['region_level'] != 4) { showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS'], $ajax); } if (trim($_REQUEST['consignee']) == '') { showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE'], $ajax); } if (trim($_REQUEST['address']) == '') { showErr($GLOBALS['lang']['FILL_CORRECT_ADDRESS'], $ajax); } if (trim($_REQUEST['zip']) == '') { showErr($GLOBALS['lang']['FILL_CORRECT_ZIP'], $ajax); } if (trim($_REQUEST['mobile']) == '') { showErr($GLOBALS['lang']['FILL_MOBILE_PHONE'], $ajax); } if (!check_mobile(trim($_REQUEST['mobile']))) { showErr($GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE'], $ajax); } if (!$data['delivery_info']) { showErr($GLOBALS['lang']['PLEASE_SELECT_DELIVERY'], $ajax); } } if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) { showErr($GLOBALS['lang']['PLEASE_SELECT_PAYMENT'], $ajax); } //结束验证订单接交信息 //开始修正订单 $now = NOW_TIME; $order['total_price'] = $data['pay_total_price']; //应付总额 商品价 - 会员折扣 + 运费 + 支付手续费 $order['memo'] = strim($_REQUEST['memo']); $order['region_lv1'] = intval($_REQUEST['region_lv1']); $order['region_lv2'] = intval($_REQUEST['region_lv2']); $order['region_lv3'] = intval($_REQUEST['region_lv3']); $order['region_lv4'] = intval($_REQUEST['region_lv4']); $order['address'] = strim($_REQUEST['address']); $order['mobile'] = strim($_REQUEST['mobile']); $order['consignee'] = strim($_REQUEST['consignee']); $order['zip'] = strim($_REQUEST['zip']); $order['delivery_fee'] = $data['delivery_fee']; $order['delivery_id'] = $data['delivery_info']['id']; $order['payment_id'] = $data['payment_info']['id']; $order['payment_fee'] = $data['payment_fee']; $order['discount_price'] = $data['user_discount']; $order['bank_id'] = strim($_REQUEST['bank_id']); $order['promote_description'] = ""; foreach ($data['promote_description'] as $promote_item) { $order['promote_description'] .= $promote_item . "<br />"; } $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order, 'UPDATE', 'id=' . $order['id'], 'SILENT'); if ($data['is_delivery'] == 1) { //保存收款人 $consignee_id = intval($_REQUEST['consignee_id']); $user_consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where user_id = " . $order['user_id'] . " and id = " . $consignee_id); $user_consignee['region_lv1'] = intval($_REQUEST['region_lv1']); $user_consignee['region_lv2'] = intval($_REQUEST['region_lv2']); $user_consignee['region_lv3'] = intval($_REQUEST['region_lv3']); $user_consignee['region_lv4'] = intval($_REQUEST['region_lv4']); $user_consignee['address'] = strim($_REQUEST['address']); $user_consignee['mobile'] = strim($_REQUEST['mobile']); $user_consignee['consignee'] = strim($_REQUEST['consignee']); $user_consignee['zip'] = strim($_REQUEST['zip']); $user_consignee['user_id'] = $order['user_id']; if (intval($user_consignee['id']) == 0) { //新增,修改订单不新增配送 // $user_consignee['is_default'] = 1; // $GLOBALS['db']->autoExecute(DB_PREFIX."user_consignee",$user_consignee,'INSERT','','SILENT'); } else { //更新 $GLOBALS['db']->autoExecute(DB_PREFIX . "user_consignee", $user_consignee, 'UPDATE', 'id=' . $user_consignee['id'], 'SILENT'); rm_auto_cache("consignee_info", array("consignee_id" => intval($user_consignee['id']))); } } //生成order_id 后 //1. 余额支付 $account_money = $data['account_money']; if (floatval($account_money) > 0) { $account_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Account'"); $payment_notice_id = make_payment_notice($account_money, $order['id'], $account_payment_id); require_once APP_ROOT_PATH . "system/payment/Account_payment.php"; $account_payment = new Account_payment(); $account_payment->get_payment_code($payment_notice_id); } //3. 相应的支付接口 $payment_info = $data['payment_info']; if ($payment_info && $data['pay_price'] > 0) { $payment_notice_id = make_payment_notice($data['pay_price'], $order['id'], $payment_info['id']); //创建支付接口的付款单 } $rs = order_paid($order['id']); if ($rs) { $data = array(); $data['info'] = ""; $data['jump'] = url("index", "payment#done", array("id" => $order['id'])); ajax_return($data); //支付成功 } else { distribute_order($order['id']); $data = array(); $data['info'] = ""; $data['jump'] = url("index", "payment#pay", array("id" => $payment_notice_id)); ajax_return($data); } }
/** * 验证购物车 */ function check_cart($id, $number) { $cart_result = load_cart_list(); $cart_item = $cart_result['cart_list'][$id]; if (empty($cart_item)) { $result['info'] = "非法的数据"; $result['status'] = 0; return $result; } if ($number <= 0) { $result['info'] = "数量不能为0"; $result['status'] = 0; return $result; } $add_number = $number - $cart_item['number']; require_once APP_ROOT_PATH . "system/model/deal.php"; $check = check_deal_number($cart_item['deal_id'], $add_number); if ($check['status'] == 0) { $result['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; $result['status'] = 0; return $result; } //属性库存的验证 $attr_setting_str = ''; if ($cart_item['attr'] != '') { $attr_setting_str = $cart_item['attr_str']; } if ($attr_setting_str != '') { $check = check_deal_number_attr($cart_item['deal_id'], $attr_setting_str, $add_number); if ($check['status'] == 0) { $result['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; $result['status'] = 0; return $result; } } //属性库存的验证 //验证时间 $checker = check_deal_time($cart_item['deal_id']); if ($checker['status'] == 0) { $result['info'] = $checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']]; $result['status'] = 0; return $result; } //验证时间 $result['status'] = 1; return $result; }
public function addcart() { if (empty($_REQUEST['id'])) { $res = array('ret' => '102', 'msg' => '参数不得为空'); ajax_return($res); } $id = intval($_REQUEST['id']); save_debug_log("addcart", 'post:' . json_encode($_POST)); save_debug_log("addcart", 'get:' . json_encode($_GET)); $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id=" . $id); $session_id = "app"; if (!$deal_info) { $res = array('ret' => '-1', 'msg' => '该商品不存在'); ajax_return($res); } else { $attr_str = '0'; $verify_code = md5($id . "_" . $attr_str); $cart_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_cart where session_id='" . $session_id . "' and user_id = " . intval($GLOBALS['user_info']['id']) . " and verify_code = '" . $verify_code . "'"); $add_number = $number = intval($_REQUEST['number']) <= 0 ? 1 : intval($_REQUEST['number']); //开始运算购物车的验证 if ($cart_item) { $check = check_deal_time($cart_item['deal_id']); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "不在可购买时间内"); ajax_return($res); } $check = check_user_bought_day($cart_item['deal_id'], $add_number, $session_id); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => $check['info']); ajax_return($res); } $check = check_deal_number($cart_item['deal_id'], $add_number); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "库存不足"); ajax_return($res); } } else { $check = check_deal_time($cart_item['deal_id']); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "不在可购买时间内"); ajax_return($res); } $check = check_user_bought_day($deal_info['id'], $add_number); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => $check['info']); ajax_return($res); } $check = check_deal_number($deal_info['id'], $add_number); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "库存不足"); ajax_return($res); } } if ($deal_info['return_score'] < 0) { //需要积分兑换 $user_score = intval($GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . intval($GLOBALS['user_info']['id']))); if ($user_score < abs(intval($deal_info['return_score']) * $add_number)) { $res['err'] = 1; $res['open_win'] = 1; $res['html'] = $check['info'] . " " . $GLOBALS['lang']['NOT_ENOUGH_SCORE']; $res['number'] = $GLOBALS['db']->getOne("select sum(number) from " . DB_PREFIX . "deal_cart where session_id = '" . es_session::id() . "' and user_id = " . intval($GLOBALS['user_info']['id'])); ajax_return($res); } } //验证over if (!$cart_item) { $attr_price = $GLOBALS['db']->getOne("select sum(price) from " . DB_PREFIX . "deal_attr where id in({$attr_str})"); $cart_item['session_id'] = $session_id; $cart_item['user_id'] = intval($GLOBALS['user_info']['id']); $cart_item['deal_id'] = $id; //属性 if ($attr_name != '') { $cart_item['name'] = $deal_info['name'] . " [" . $attr_name . "]"; $cart_item['sub_name'] = $deal_info['sub_name'] . " [" . $attr_name . "]"; } else { $cart_item['name'] = $deal_info['name']; $cart_item['sub_name'] = $deal_info['sub_name']; } $cart_item['name'] = addslashes($cart_item['name']); $cart_item['sub_name'] = addslashes($cart_item['sub_name']); $cart_item['attr'] = $attr_str; $cart_item['unit_price'] = $deal_info['current_price'] + $attr_price; $cart_item['number'] = $number; $cart_item['total_price'] = $cart_item['unit_price'] * $cart_item['number']; $cart_item['verify_code'] = $verify_code; $cart_item['create_time'] = get_gmtime(); $cart_item['update_time'] = get_gmtime(); $cart_item['return_score'] = $deal_info['return_score']; $cart_item['return_total_score'] = $deal_info['return_score'] * $cart_item['number']; $cart_item['return_money'] = $deal_info['return_money']; $cart_item['return_total_money'] = $deal_info['return_money'] * $cart_item['number']; $cart_item['buy_type'] = $deal_info['buy_type']; $cart_item['supplier_id'] = $deal_info['supplier_id']; $cart_item['attr_str'] = $attr_name_str; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_cart", $cart_item); } else { if ($number > 0) { $cart_item['number'] += $number; $cart_item['total_price'] = $cart_item['unit_price'] * $cart_item['number']; $cart_item['return_total_score'] = $deal_info['return_score'] * $cart_item['number']; $cart_item['return_total_money'] = $deal_info['return_money'] * $cart_item['number']; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_cart", $cart_item, "UPDATE", "id=" . $cart_item['id']); } } $res['number'] = $GLOBALS['db']->getOne("select sum(number) from " . DB_PREFIX . "deal_cart where session_id = '" . $session_id . "' and user_id = " . intval($GLOBALS['user_info']['id'])); $res['ret'] = '0'; save_debug_log('add cart', 'post :' . json_encode($_POST) . ' res:' . json_encode($res)); ajax_return($res); } }
public function addcart() { global_run(); require_once APP_ROOT_PATH . 'system/model/cart.php'; require_once APP_ROOT_PATH . 'system/model/deal.php'; $id = intval($_REQUEST['id']); $deal_info = get_deal($id); if (!$deal_info) { $res['status'] = 0; $res['info'] = "没有可以购买的产品"; ajax_return($res); } if ($deal_info['is_lottery'] == 1 || $deal_info['buy_type'] == 1) { if (check_save_login() == LOGIN_STATUS_NOLOGIN) { $res['status'] = -1; $res['info'] = $GLOBALS['lang']['PLEASE_LOGIN_FIRST']; ajax_return($res); } } $check = check_deal_time($id); if ($check['status'] == 0) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; ajax_return($res); } $attr = $_REQUEST['attr']; if (count($attr) != count($deal_info['deal_attr'])) { $res['status'] = 0; $res['info'] = "请选择商品规格"; ajax_return($res); } else { //加入购物车处理,有提交属性, 或无属性时 $attr_str = '0'; $attr_name = ''; $attr_name_str = ''; if ($attr) { foreach ($attr as $kk => $vv) { $attr[$kk] = intval($vv[0]); } $attr_str = implode(",", $attr); $attr_names = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "deal_attr where id in(" . $attr_str . ")"); $attr_name = ''; foreach ($attr_names as $attr) { $attr_name .= $attr['name'] . ","; $attr_name_str .= $attr['name']; } $attr_name = substr($attr_name, 0, -1); } $verify_code = md5($id . "_" . $attr_str); $session_id = es_session::id(); if (app_conf("CART_ON") == 0) { $GLOBALS['db']->query("delete from " . DB_PREFIX . "deal_cart where session_id = '" . $session_id . "'"); load_cart_list(true); } $cart_result = load_cart_list(); foreach ($cart_result['cart_list'] as $k => $v) { if ($v['verify_code'] == $verify_code) { $cart_item = $v; } } $add_number = $number = intval($_REQUEST['number']) <= 0 ? 1 : intval($_REQUEST['number']); //开始运算购物车的验证 if ($cart_item) { $check = check_deal_number($cart_item['deal_id'], $add_number); if ($check['status'] == 0) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; ajax_return($res); } //属性库存的验证 $attr_setting_str = ''; if ($cart_item['attr'] != '') { $attr_setting_str = $cart_item['attr_str']; } if ($attr_setting_str != '') { $check = check_deal_number_attr($cart_item['deal_id'], $attr_setting_str, $add_number); if ($check['status'] == 0) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; ajax_return($res); } } //属性库存的验证 } else { $check = check_deal_number($deal_info['id'], $add_number); if ($check['status'] == 0) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; ajax_return($res); } //属性库存的验证 $attr_setting_str = ''; if ($attr_name_str != '') { $attr_setting_str = $attr_name_str; } if ($attr_setting_str != '') { $check = check_deal_number_attr($deal_info['id'], $attr_setting_str, $add_number); if ($check['status'] == 0) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $check['data']]; ajax_return($res); } } //属性库存的验证 } if ($deal_info['return_score'] < 0) { //需要积分兑换 $user_score = intval($GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . intval($GLOBALS['user_info']['id']))); if ($user_score < abs(intval($deal_info['return_score']) * $add_number)) { $res['status'] = 0; $res['info'] = $check['info'] . " " . $GLOBALS['lang']['NOT_ENOUGH_SCORE']; ajax_return($res); } } //验证over if (!$cart_item) { $attr_price = $GLOBALS['db']->getOne("select sum(price) from " . DB_PREFIX . "deal_attr where id in({$attr_str})"); $add_balance_price = $GLOBALS['db']->getOne("select sum(add_balance_price) from " . DB_PREFIX . "deal_attr where id in({$attr_str})"); $cart_item['session_id'] = $session_id; $cart_item['user_id'] = intval($GLOBALS['user_info']['id']); $cart_item['deal_id'] = $id; //属性 if ($attr_name != '') { $cart_item['name'] = $deal_info['name'] . " [" . $attr_name . "]"; $cart_item['sub_name'] = $deal_info['sub_name'] . " [" . $attr_name . "]"; } else { $cart_item['name'] = $deal_info['name']; $cart_item['sub_name'] = $deal_info['sub_name']; } $cart_item['name'] = strim($cart_item['name']); $cart_item['sub_name'] = strim($cart_item['sub_name']); $cart_item['attr'] = $attr_str; $cart_item['add_balance_price'] = $add_balance_price; $cart_item['unit_price'] = $deal_info['current_price'] + $attr_price; $cart_item['number'] = $number; $cart_item['total_price'] = $cart_item['unit_price'] * $cart_item['number']; $cart_item['verify_code'] = $verify_code; $cart_item['create_time'] = NOW_TIME; $cart_item['update_time'] = NOW_TIME; $cart_item['return_score'] = $deal_info['return_score']; $cart_item['return_total_score'] = $deal_info['return_score'] * $cart_item['number']; $cart_item['return_money'] = $deal_info['return_money']; $cart_item['return_total_money'] = $deal_info['return_money'] * $cart_item['number']; $cart_item['buy_type'] = $deal_info['buy_type']; $cart_item['supplier_id'] = $deal_info['supplier_id']; $cart_item['attr_str'] = $attr_name_str; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_cart", $cart_item); } else { if ($number > 0) { $cart_item['number'] += $number; $cart_item['total_price'] = $cart_item['unit_price'] * $cart_item['number']; $cart_item['return_total_score'] = $deal_info['return_score'] * $cart_item['number']; $cart_item['return_total_money'] = $deal_info['return_money'] * $cart_item['number']; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_cart", $cart_item, "UPDATE", "id=" . $cart_item['id']); } } syn_cart(); //同步购物车中的状态 cart_type $cart_result = load_cart_list(true); $cart_total = count($cart_result['cart_list']); $GLOBALS['tmpl']->assign("cart_total", $cart_total); $relate_list = get_deal_list(4, array(DEAL_ONLINE), array("cid" => $deal_info['cate_id'], "city_id" => $GLOBALS['city']['id']), "", "d.id<>" . $deal_info['id']); $GLOBALS['tmpl']->assign("relate_list", $relate_list['list']); $res['html'] = $GLOBALS['tmpl']->fetch("inc/pop_cart.html"); $res['status'] = 1; ajax_return($res); } }
/** * 下订单 */ public function add_deal_order() { if (empty($_REQUEST['deal_id'])) { echo json_encode(array('ret' => '-1', 'msg' => '请求参数为空')); } else { save_debug_log("add_deal_order post", json_encode($_POST)); $deal_id = $_REQUEST['deal_id']; $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id =" . $deal_id); if (!$deal_info) { $res = array('ret' => '-1', 'msg' => '该商品不存在'); ajax_return($res); } $number = empty($_REQUEST['number']) ? 1 : $_REQUEST['number']; $is_cash_pay = isset($_REQUEST['is_cash_pay']) ? $_REQUEST['is_cash_pay'] : 0; //是否货到付款 if ($is_cash_pay && !is_deal_cash_pay($deal_id)) { //检测商品是否支持货到付款 $res = array('ret' => '-1', 'msg' => "该商品不支持货到付款"); ajax_return($res); } $check = check_deal_number($deal_id, $number, "app"); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => $check['info']); ajax_return($res); } $check = check_user_bought_day($deal_id, $number); if ($check['status'] == 0) { $res = array('ret' => '-1', 'msg' => $check['info']); ajax_return($res); } $check_deal_time = check_deal_time($deal_id); if ($check_deal_time['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "不在可购买时间内"); ajax_return($res); } $deal_order = array(); $deal_order['order_sn'] = to_date(get_gmtime(), "Ymdhis") . rand(10, 99); $deal_order['type'] = 0; $deal_order['user_id'] = $GLOBALS['user_info']['id']; $deal_order['create_time'] = time(); $deal_order['pay_status'] = 0; $deal_order['pay_amount'] = 0; $deal_order['delivery_status'] = $deal_info['is_delivery'] == 0 ? 5 : 0; //$deal_order['delivery_status'] = 0; $deal_order['is_delete'] = 0; $deal_order['return_total_score'] = 0; $deal_order['refund_amount'] = 0; if ($deal_info['is_delivery'] == 1) { // 填写收货地址 if (!empty($_POST['consignee_id'])) { $consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where id=" . $_POST['consignee_id']); } else { $consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where user_id=" . $GLOBALS['user_info']['id'] . " and isdef=1"); } save_debug_log("add_deal_order consignee", json_encode($consignee)); if ($consignee) { $is_region_lv4_exist = $GLOBALS['db']->getOne("select count(1) from " . DB_PREFIX . "delivery_region where id=" . $consignee['region_lv4']); save_debug_log('is_region_lv4', "sql " . "select count(1) from " . DB_PREFIX . "delivery_region where id=" . $consignee['region_lv4'] . " is_regioin_lv4: {$is_region_lv4_exist}"); if ($is_region_lv4_exist <= 0) { $res = array('ret' => '-1', 'msg' => "所选地址服务站不存在,请重新选择"); ajax_return($res); } $deal_order['region_lv1'] = $consignee['region_lv1']; $deal_order['region_lv2'] = $consignee['region_lv2']; $deal_order['region_lv3'] = $consignee['region_lv3']; $deal_order['region_lv4'] = $consignee['region_lv4']; //判断收货地址是否支持货到付款 if ($is_cash_pay && !is_region_cash_pay($deal_order['region_lv4'])) { $res = array('ret' => '-1', 'msg' => '所选地址服务站不支持货到付款'); ajax_return($res); } $deal_order['address'] = $consignee['address']; $deal_order['mobile'] = $consignee['mobile']; $deal_order['zip'] = $consignee['zip']; } else { $res = array('ret' => '-1', 'msg' => "收货地址不得为空"); ajax_return($res); } } $deal_order['deal_ids'] = $deal_id; $deal_order['user_name'] = $GLOBALS['user_info']['user_name']; $total_price = $deal_info['current_price'] * $number; $deal_order['total_price'] = $total_price; // 需要计算 $deal_order['deal_total_price'] = $total_price; $deal_order['discount_price'] = 0; $deal_order['delivery_fee'] = 0; $deal_order['ecv_money'] = 0; $deal_order['account_money'] = 0; $deal_order['delivery_id'] = 0; $deal_order['payment_id'] = $is_cash_pay ? 22 : 0; $deal_order['payment_fee'] = 0; $deal_order['return_total_money'] = 0; $deal_order['extra_status'] = 0; $deal_order['after_sale'] = 0; $deal_order['refund_money'] = 0; $deal_order['refund_status'] = 0; $deal_order['retake_status'] = 0; if ($GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $deal_order, "INSERT")) { $order_id = $GLOBALS['db']->insert_id(); // 成功插入订单数据后 $deal_order_item = array(); $deal_order_item['deal_id'] = $deal_info['id']; $deal_order_item['number'] = $number; $deal_order_item['unit_price'] = $deal_info['current_price']; $deal_order_item['total_price'] = $total_price; $deal_order_item['delivery_status'] = $deal_info['is_delivery'] == 0 ? 5 : 0; $deal_order_item['name'] = $deal_info['name']; $deal_order_item['sub_name'] = $deal_info['sub_name']; $deal_order_item['return_score'] = 0; $deal_order_item['return_total_score'] = 0; $deal_order_item['order_id'] = $order_id; $deal_order_item['attr'] = ''; $deal_order_item['verify_code'] = ''; $deal_order_item['return_money'] = 0; $deal_order_item['return_total_money'] = 0; $deal_order_item['buy_type'] = $deal_info['buy_type']; $deal_order_item['is_balance'] = 0; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_item", $deal_order_item, "INSERT"); echo json_encode(array('ret' => '0', 'order_id' => $order_id, 'order_sn' => $deal_order['order_sn'])); save_debug_log('add_deal_order ret id', json_encode(array('ret' => '0', 'order_id' => $order_id, 'order_sn' => $deal_order['order_sn'])) . "\n"); } else { echo json_encode(array('ret' => '-1', 'msg' => '订单添加失败')); } } }
/** * 根据订单号判断商品是否可购物 * $id 订单id */ function check_deal_order_is_can_buy($id, $col = 'id') { if (empty($id)) { $res = array('ret' => '-1', 'msg' => "订单为空"); ajax_return($res); } $deal_ids = $GLOBALS['db']->getOne("select deal_ids from " . DB_PREFIX . "deal_order where {$col}=" . $id); if (!$deal_ids) { $res = array('ret' => '-1', 'msg' => "订单为空"); ajax_return($res); } $deal_id_arr = explode(",", $deal_ids); foreach ($deal_id_arr as $deal_id) { $checker = check_deal_time($deal_id); if ($checker['status'] == 0) { $res = array('ret' => '-1', 'msg' => "商品:" . $check['info'] . "不在可购买时间内"); ajax_return($res); } } return true; }