Example #1
0
 public function do_incharge()
 {
     $order_id = intval($_REQUEST['order_id']);
     $payment_id = intval($_REQUEST['payment_id']);
     $payment_info = M("Payment")->getById($payment_id);
     $memo = $_REQUEST['memo'];
     $order_info = M("DealOrder")->where("id=" . $order_id . " and is_delete = 0 and type = 0")->find();
     if (!$order_info) {
         $this->error(l("INVALID_ORDER"));
     }
     if ($order_info['region_lv4'] > 0) {
         $region_id = $order_info['region_lv4'];
     } elseif ($order_info['region_lv3'] > 0) {
         $region_id = $order_info['region_lv3'];
     } elseif ($order_info['region_lv2'] > 0) {
         $region_id = $order_info['region_lv2'];
     } else {
         $region_id = $order_info['region_lv1'];
     }
     $delivery_id = $order_info['delivery_id'];
     $payment_id = intval($_REQUEST['payment_id']);
     $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
     $GLOBALS['user_info']['id'] = $order_info['user_id'];
     require_once APP_ROOT_PATH . "system/model/cart.php";
     $result = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 0, $ecvsn, $ecvpassword, $goods_list, $order_info['account_money'], $order_info['ecv_money'], $order_info['bank_id']);
     $user_money = M("User")->where("id=" . $order_info['user_id'])->getField("money");
     //$pay_amount = $order_info['deal_total_price']+ $order_info['delivery_fee']-$order_info['account_money']-$order_info['ecv_money']+$payment_info['fee_amount'];
     $pay_amount = $result['pay_price'];
     if ($payment_info['class_name'] == 'Account' && $user_money < $pay_amount) {
         $this->error(l("ACCOUNT_NOT_ENOUGH"));
     }
     $notice_id = make_payment_notice($pay_amount, $order_id, $payment_id, $memo);
     $order_info['total_price'] = $result['pay_total_price'];
     $order_info['payment_fee'] = $result['payment_fee'];
     $order_info['delivery_fee'] = $result['delivery_fee'];
     $order_info['discount_price'] = $result['user_discount'];
     $order_info['payment_id'] = $payment_info['id'];
     $order_info['update_time'] = NOW_TIME;
     M("DealOrder")->save($order_info);
     $payment_notice = M("PaymentNotice")->getById($notice_id);
     $rs = payment_paid($payment_notice['id']);
     if ($rs && $payment_info['class_name'] == 'Account') {
         //余额支付
         require_once APP_ROOT_PATH . "system/payment/Account_payment.php";
         require_once APP_ROOT_PATH . "system/model/user.php";
         $msg = sprintf($payment_lang['USER_ORDER_PAID'], $order_info['order_sn'], $payment_notice['notice_sn']);
         modify_account(array('money' => "-" . $payment_notice['money'], 'score' => 0), $payment_notice['user_id'], $msg);
     }
     if ($rs) {
         order_paid($order_id);
         $msg = sprintf(l("MAKE_PAYMENT_NOTICE_LOG"), $order_info['order_sn'], $payment_notice['notice_sn']);
         save_log($msg, 1);
         order_log($msg . $_REQUEST['memo'], $order_id);
         $this->assign("jumpUrl", U("DealOrder/view_order", array("id" => $order_id)));
         $this->success(l("ORDER_INCHARGE_SUCCESS"));
     } else {
         $this->assign("jumpUrl", U("DealOrder/view_order", array("id" => $order_id)));
         $this->success(l("ORDER_INCHARGE_FAILED"));
     }
 }
 public function index()
 {
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         $order_id = intval($GLOBALS['request']['id']);
         require_once APP_ROOT_PATH . "system/model/deal_order.php";
         $order_table_name = get_user_order_table_name($user_id);
         //echo $order_id; exit;
         $sql = "select o.*,r1.name as r1_name, r2.name as r2_name, r3.name as r3_name, r4.name as r4_name from " . $order_table_name . " as o " . "left outer join " . DB_PREFIX . "delivery_region as r1 on r1.id = o.region_lv1 " . "left outer join " . DB_PREFIX . "delivery_region as r2 on r2.id = o.region_lv2 " . "left outer join " . DB_PREFIX . "delivery_region as r3 on r3.id = o.region_lv3 " . "left outer join " . DB_PREFIX . "delivery_region as r4 on r4.id = o.region_lv4 " . " where o.is_delete = 0 and o.user_id = {$user_id} and o.id = {$order_id} limit 1";
         $order_info = $GLOBALS['db']->getRow($sql);
         if ($order_info) {
             $root = get_order_goods($order_info);
             $root['return'] = 1;
             $root['user_login_status'] = 1;
             $deliveryAddr = array();
             $deliveryAddr['consignee'] = $order_info['consignee'];
             //联系人姓名
             $deliveryAddr['delivery'] = $order_info['r1_name'] . $order_info['r2_name'] . $order_info['r3_name'] . $order_info['r4_name'];
             $deliveryAddr['region_lv1'] = $order_info['region_lv1'];
             //国家
             $deliveryAddr['region_lv2'] = $order_info['region_lv2'];
             //省
             $deliveryAddr['region_lv3'] = $order_info['region_lv3'];
             //城市
             $deliveryAddr['region_lv4'] = $order_info['region_lv4'];
             //地区/县
             $deliveryAddr['delivery_detail'] = $order_info['address'];
             //详细地址
             $deliveryAddr['phone'] = $order_info['mobile'];
             //手机号码
             $deliveryAddr['postcode'] = $order_info['zip'];
             //邮编
             $root['deliveryAddr'] = $deliveryAddr;
             $root['delivery_status_2'] = $order_info['delivery_status'];
             $root['content'] = $order_info['memo'];
             //订单备注
             $root['send_mobile'] = $user['mobile'];
             //团购券手机
             $root['tax_title'] = $order_info['tax_title'];
             //发票抬头
             $root['tax_id'] = 0;
             //发票内容
             $root['deliver_time_id'] = 0;
             //配送日期ID 默认没有这个参数,所以填0
             $root['delivery_list'] = $GLOBALS['m_config']['delivery_list'];
             //$default_payment_id = $GLOBALS['m_config']['select_payment_id'];
             if ($GLOBALS['request']['payment_id']) {
                 $default_payment_id = intval($GLOBALS['request']['payment_id']);
             } else {
                 $default_payment_id = $order_info['payment_id'];
             }
             //$default_payment_id = $order_info['payment_id'];
             $root['payment_id'] = $default_payment_id;
             //支付方式
             $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
             $root['order_parm']['has_ecv'] = 0;
             //订单付款不支持代金券
             $root['evc_sn'] = '';
             //优惠券序号
             $root['evc_pwd'] = '';
             //优惠券序号
             $order_item_table_name = get_user_order_item_table_name($user_id);
             $goods_list = $GLOBALS['db']->getAll("select * from " . $order_item_table_name . " where order_id = " . $order_id);
             $ids = array();
             $cart_ids = array();
             $root['dp_able'] = 0;
             $root['goods_list'] = $goods_list;
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
                 array_push($cart_ids, $cart_goods['id']);
                 if (empty($cart_goods['dp_id'])) {
                     if ($root['pay_status'] == 2 && $root['order_status'] == 1 && ($root['delivery_status_code'] == 2 || $root['delivery_status_code'] == 5)) {
                         $root['dp_able'] = 1;
                         $root['dp_deal_id'] = $cart_goods['id'];
                     }
                 }
             }
             $ids_str = implode(",", $ids);
             $cart_ids_str = implode(",", $cart_ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
                 $root['order_parm']['has_delivery'] = 0;
             } else {
                 if ($GLOBALS['request']['delivery_id']) {
                     $delivery_id = intval($GLOBALS['request']['delivery_id']);
                 } else {
                     $delivery_id = $order_info['delivery_id'];
                     //配送方式;
                 }
                 //$delivery_id = $order_info['delivery_id'];
                 $root['order_parm']['has_delivery'] = 1;
             }
             $root['delivery_id'] = $delivery_id;
             //配送方式
             $has_coupon = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_coupon = 1 and id in (" . $ids_str . ")"));
             if ($has_coupon == 0) {
                 $root['order_parm']['has_moblie'] = 0;
                 $root['order_parm']['has_mcod'] = 1;
             } else {
                 $root['order_parm']['has_moblie'] = 1;
                 $root['order_parm']['has_mcod'] = 0;
                 //有团购券商品,不能做:货到付款
             }
             foreach ($root['order_parm']['payment_list'] as $k => $v) {
                 if ($v['code'] == 'Mcod' && $root['order_parm']['has_mcod'] == 0) {
                     unset($root['order_parm']['payment_list'][$k]);
                 }
             }
             $forbid_payment = $GLOBALS['db']->getAll("select payment_id from " . DB_PREFIX . "deal_payment where deal_id in (" . $ids_str . ")");
             foreach ($forbid_payment as $forbid_payment_item) {
                 foreach ($root['order_parm']['payment_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['payment_id']) {
                         unset($root['order_parm']['payment_list'][$k]);
                     }
                 }
             }
             $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
             foreach ($forbid_delivery as $forbid_delivery_item) {
                 foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['delivery_id']) {
                         unset($root['order_parm']['delivery_list'][$k]);
                     }
                 }
             }
             //数组按顺序排序
             $payment_list = array();
             foreach ($root['order_parm']['payment_list'] as $k => $v) {
                 $payment_list[] = $v;
             }
             $root['order_parm']['payment_list'] = $payment_list;
             $delivery_list = array();
             foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                 $delivery_list[] = $v;
             }
             $root['order_parm']['delivery_list'] = $delivery_list;
             $region4_id = intval($order_info['region_lv4']);
             $region3_id = intval($order_info['region_lv3']);
             $region2_id = intval($order_info['region_lv2']);
             $region1_id = intval($order_info['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;
             }
             require_once APP_ROOT_PATH . "system/model/cart.php";
             //订单的显示参数
             if ($order_info['pay_status'] == 0) {
                 $root['has_cancel'] = 1;
             } else {
                 $root['has_cancel'] = 0;
             }
             $delivery_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "delivery_notice where order_item_id in (" . $cart_ids_str . ") order by delivery_time desc limit 1");
             if ($delivery_notice) {
                 $express = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "express where id = " . intval($delivery_notice['express_id']));
                 $express['config'] = unserialize($express['config']);
                 $root['kd_com'] = $express['config']['app_code'];
                 if ($root['kd_com']) {
                     $root['kd_sn'] = $delivery_notice['notice_sn'];
                 }
             }
             if ($order_info['pay_status'] != 2) {
                 if ($root['order_parm']['has_delivery'] == 1) {
                     $root['has_edit_delivery'] = 1;
                 } else {
                     $root['has_edit_delivery'] = 0;
                 }
                 $root['has_edit_delivery_time'] = 0;
                 $root['has_edit_invoice'] = 0;
                 $root['has_edit_ecv'] = 0;
                 $root['has_edit_message'] = 1;
                 if ($root['order_parm']['has_moblie'] == 1) {
                     $root['has_edit_moblie'] = 1;
                 } else {
                     $root['has_edit_moblie'] = 0;
                 }
                 $GLOBALS['user_info']['id'] = $user_id;
                 $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
                 if ($account_pay) {
                     $data = count_buy_total($region_id, $delivery_id, $default_payment_id, $account_money = 0, $all_account_money = 1, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
                 } else {
                     $data = count_buy_total($region_id, $delivery_id, $default_payment_id, $account_money = 0, $all_account_money = 0, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
                 }
                 //print_r($data);exit;
                 if ($data['pay_price'] == 0) {
                     if ($data['account_money'] > 0 || $data['ecv_money'] > 0) {
                         $root['has_pay'] = 1;
                         $root['use_user_money'] = $data['account_price'];
                     } else {
                         $root['has_pay'] = 0;
                         $root['use_user_money'] = 0;
                     }
                     $root['pay_money'] = 0;
                     //还需要支付金额
                 } else {
                     $root['has_pay'] = 1;
                     $root['pay_money'] = $data['pay_price'];
                     //还需要支付金额
                     $root['use_user_money'] = 0;
                 }
                 if ($root['has_pay'] == 0) {
                     $root['has_edit_delivery'] = 0;
                     $root['has_edit_delivery_time'] = 0;
                     $root['has_edit_invoice'] = 0;
                     $root['has_edit_ecv'] = 0;
                     $root['has_edit_message'] = 0;
                     $root['has_edit_moblie'] = 0;
                 }
                 $root['feeinfo'] = getFeeItem($data);
             } else {
                 $root['has_pay'] = 0;
                 $root['has_edit_delivery'] = 0;
                 $root['has_edit_delivery_time'] = 0;
                 $root['has_edit_invoice'] = 0;
                 $root['has_edit_ecv'] = 0;
                 $root['has_edit_message'] = 0;
                 $root['has_edit_moblie'] = 0;
                 $data['pay_total_price'] = $order_info['total_price'];
                 $data['return_total_score'] = $order_info['return_total_score'];
                 $data['total_price'] = $order_info['deal_total_price'];
                 $data['delivery_fee'] = $order_info['delivery_fee'];
                 $data['account_money'] = $order_info['account_money'];
                 $data['ecv_money'] = $order_info['ecv_money'];
                 $root['pay_money'] = 0;
                 //还需要支付金额
                 $root['use_user_money'] = 0;
                 $root['feeinfo'] = getFeeItem($data);
                 //有团购券,再显示团购券列表
                 $couponlist = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_coupon where user_id = {$user_id} and order_id = " . $order_id);
                 foreach ($couponlist as $k => $v) {
                     $list[$k]['couponSn'] = $v['sn'];
                     $list[$k]['couponPw'] = $v['password'];
                     $list[$k]['qrcode'] = str_replace('sjmapi', '', get_domain() . gen_qrcode($v['password']));
                 }
                 $root['couponlist'] = $couponlist;
             }
             $root['complain_status'] = 0;
             $complain = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_order_complain WHERE order_id=" . $order_id . " AND user_id=" . $user_id);
             if (!empty($complain)) {
                 $root['complain_status'] = 1;
                 $root['complain_id'] = $complain['id'];
             }
             $order_item_info = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_order_item WHERE order_id=" . $order_id . " ");
             $root['order_item_info'] = $order_item_info;
         } else {
             $root['return'] = 0;
             $root['info'] = "订单不存在.";
         }
     } else {
         $root['user_login_status'] = 0;
     }
     $root['pay_status'] = $order_info['pay_status'];
     $root['refund_status'] = $order_info['refund_status'];
     $root['page_title'] = '订单明细';
     $root['city_name'] = $city_name;
     output($root);
 }
Example #3
0
 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);
     }
 }
 public function order_done()
 {
     save_debug_log('order_done', 'request:' . json_encode($_REQUEST));
     $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");
     if (!$order) {
         showErr($GLOBALS['lang']['INVALID_ORDER_DATA']);
     }
     $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'])) : '';
     $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order['id']);
     //验证购物车
     if (!$user_info) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], 0, url("shop", "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);
             }
         }
     }
     //结束验证购物车
     //开始验证订单接交信息
     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, $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']);
         }
         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']);
         //					}
     }
     if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) {
         showErr($GLOBALS['lang']['PLEASE_SELECT_PAYMENT']);
     }
     //结束验证订单接交信息
     //开始修正订单
     $now = get_gmtime();
     $order['total_price'] = $data['pay_total_price'];
     //应付总额  商品价 - 会员折扣 + 运费 + 支付手续费
     $order['memo'] = htmlspecialchars(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['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'] = htmlspecialchars(addslashes(trim($_REQUEST['bank_id'])));
     $order['promote_description'] = "";
     foreach ($data['promote_description'] as $promote_item) {
         $order['promote_description'] .= $promote_item . "<br />";
     }
     $coupon_mobile = htmlspecialchars(addslashes(trim($_REQUEST['coupon_mobile'])));
     $user_info = es_session::get("user_info");
     if ($coupon_mobile != '') {
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set mobile = '" . $coupon_mobile . "' where id = " . intval($user_info['id']));
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order, 'UPDATE', 'id=' . $order['id'], 'SILENT');
     if ($data['is_delivery'] == 1) {
         //保存收款人
         $user_consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where user_id = " . $order['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'] = $order['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');
         }
     }
     //生成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) {
         app_redirect(url("shop", "payment#done", array("id" => $order['id'])));
         //支付成功
     } else {
         app_redirect(url("shop", "payment#pay", array("id" => $payment_notice_id)));
     }
 }
 public function index()
 {
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     $root['first_calc'] = $GLOBALS['request']['first_calc'];
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         $region4_id = intval($GLOBALS['request']['region_lv4']);
         $region3_id = intval($GLOBALS['request']['region_lv3']);
         $region2_id = intval($GLOBALS['request']['region_lv2']);
         $region1_id = intval($GLOBALS['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;
         }
         require_once APP_ROOT_PATH . "system/libs/cart.php";
         $order_id = intval($GLOBALS['request']['id']);
         $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
         $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
         //$delivery_id = $GLOBALS['m_config']['delivery_id'];
         $delivery_id = $GLOBALS['request']['delivery_id'];
         $payment_id = intval($GLOBALS['request']['payment_id']);
         $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
         $ids = array();
         foreach ($goods_list as $cart_goods) {
             array_push($ids, $cart_goods['deal_id']);
         }
         $ids_str = implode(",", $ids);
         $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
         foreach ($forbid_delivery as $forbid_delivery_item) {
             foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                 if ($v['id'] == $forbid_payment_item['delivery_id']) {
                     unset($root['order_parm']['delivery_list'][$k]);
                 }
             }
         }
         //开始计算订单
         $GLOBALS['user_info']['id'] = $user_id;
         $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
         if ($account_pay) {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 1, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         } else {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 0, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         }
         $root['feeinfo'] = getFeeItem($data);
         $root['use_user_money'] = $data['account_money'];
         $root['pay_money'] = $data['pay_price'];
         $root['info'] = '';
         //"订单已重新计算";
         $root['status'] = 1;
         //end 计算订单
     } else {
         $root['user_login_status'] = 0;
         $root['status'] = 0;
     }
     output($root);
 }
Example #6
0
 public function index()
 {
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $money = floatval($user['money']);
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         //已登录
         $region4_id = intval($GLOBALS['request']['region_lv4']);
         $region3_id = intval($GLOBALS['request']['region_lv3']);
         $region2_id = intval($GLOBALS['request']['region_lv2']);
         $region1_id = intval($GLOBALS['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;
         }
         $payment = $GLOBALS['request']['payment_id'] ? intval($GLOBALS['request']['payment_id']) : 17;
         $account_money = floatval($GLOBALS['request']['use_user_money']);
         $address = strim($GLOBALS['request']['delivery_detail']);
         $consignee_mobile = strim($GLOBALS['request']['phone']);
         $zip = strim($GLOBALS['request']['postcode']);
         $consignee = strim($GLOBALS['request']['consignee']);
         $ecvsn = $GLOBALS['request']['ecv_sn'] ? strim($GLOBALS['request']['ecv_sn']) : '';
         $ecvpassword = $GLOBALS['request']['ecv_pwd'] ? strim($GLOBALS['request']['ecv_pwd']) : '';
         $order_memo = strim($GLOBALS['request']['content']);
         $send_mobile = strim($GLOBALS['request']['send_mobile']);
         $delivery_id = intval($GLOBALS['request']['delivery_id']);
         $order_time = $GLOBALS['request']['order_time'];
         $technician_id = $GLOBALS['request']['tech_id'];
         if (empty($order_time)) {
             $root['status'] = 0;
             $root['info'] = '请选择预约时间';
             output($root);
         }
         $order_time .= ':00';
         $order_time = strtotime($order_time);
         //$delivery_id = intval($GLOBALS['m_config']['delivery_id']);
         $coupon_mobile = htmlspecialchars($send_mobile);
         if ($coupon_mobile != '') {
             $i = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "user where mobile = '" . $coupon_mobile . "' and id != " . intval($user_id)));
             if ($i > 0) {
                 $root['status'] = 0;
                 $root['info'] = '该手机号码,已经被占用';
                 output($root);
             }
         }
         $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
         if ($account_pay) {
             $all_account_money = 1;
         } else {
             $all_account_money = 0;
         }
         if ($GLOBALS['request']['from'] == "wap") {
             $cartdata = unserialize(base64_decode($GLOBALS['request']['cartdata']));
             $res = insertCartData($user_id, es_session::id(), $cartdata);
         } else {
             $cartdata = $GLOBALS['request']['cartdata'];
             $res = insertCartData($user_id, es_session::id(), $cartdata);
         }
         if ($res['info'] != '') {
             //失败有错误
             $root['status'] = 0;
             $root['info'] = $res['info'];
             output($root);
         } else {
             //可以提交订单
             $goods_list = $res['data'];
             require_once APP_ROOT_PATH . "system/model/cart.php";
             $GLOBALS['user_info']['id'] = $user_id;
             $ids = array();
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
             }
             $ids_str = implode(",", $ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
             }
             $data = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list);
             if ($data['is_delivery'] == 1) {
                 //配送验证
                 if (!$data['region_info'] || $data['region_info']['region_level'] != 4) {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($consignee == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($address == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_ADDRESS'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($consignee_mobile == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_MOBILE_PHONE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif (!check_mobile(trim($consignee_mobile))) {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif (!$data['delivery_info']) {
                     $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_DELIVERY'];
                     $root['status'] = 0;
                     output($root);
                 }
             }
             if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) {
                 $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_PAYMENT'];
                 $root['status'] = 0;
                 output($root);
             } else {
                 //获取服务时间
                 foreach ($goods_list as $k => $v) {
                     $order['service_time'] = $v['service_time'];
                 }
                 //技师直约判断当前时间是否可约
                 if ($technician_id) {
                     $tech = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id=" . $technician_id);
                     $start_time = $order_time - $tech['distance_time'] * 60;
                     $end_time = $order_time + $tech['distance_time'] * 60 + $order['service_time'] * 60;
                     $order_able_sql = "SELECT \n                                                                * \n                                                              FROM\n                                                                " . DB_PREFIX . "deal_order DO \n                                                              WHERE  do.technician_id={$technician_id} \n                                                                  and order_status = 0 and is_delete = 0 and extra_status = 0 and after_sale = 0 and refund_status = 0 and  (\n                                                                  do.`order_time` + do.`service_time` * 60 BETWEEN " . $start_time . " \n                                                                  AND " . $end_time . " \n                                                                ) \n                                                                OR (\n                                                                  do.`order_time` BETWEEN " . $start_time . " \n                                                                  AND " . $end_time . "\n                                                                )";
                     $order_able = $GLOBALS['db']->getRow($order_able_sql);
                     if (!empty($order_able)) {
                         $root['info'] = "当前时间已被预约,请重新选择时间";
                         $root['status'] = 0;
                         output($root);
                     }
                 }
                 //验证成功
                 //开始生成订单
                 $now = time();
                 $order['type'] = 0;
                 //普通订单
                 $order['user_id'] = $user_id;
                 $order['user_name'] = $user['user_name'];
                 $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($order_memo);
                 $order['region_lv1'] = $region1_id;
                 $order['region_lv2'] = $region2_id;
                 $order['region_lv3'] = $region3_id;
                 $order['region_lv4'] = $region4_id;
                 $order['address'] = htmlspecialchars($address);
                 $order['mobile'] = htmlspecialchars($consignee_mobile);
                 $order['consignee'] = htmlspecialchars($consignee);
                 $order['zip'] = htmlspecialchars($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['bank_id'] = 0;
                 $order['order_time'] = $order_time;
                 $order['technician_id'] = $technician_id == '' ? 0 : $technician_id;
                 $order['order_end_time'] = $order_time + $order['service_time'] * 60;
                 //if($send_mobile!='')
                 //	$GLOBALS['db']->query("update ".DB_PREFIX."user set mobile = '".$send_mobile."' where id = ".$user_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);
                 //end 验证成功提交订单成功
                 //开始生成订单产品以及支付
                 //生成订单商品
                 foreach ($goods_list as $k => $v) {
                     $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['deal_icon'] = $v['icon'];
                     $goods_item['service_time'] = $v['service_time'];
                     $deal_info = load_auto_cache("cache_deal_cart", array("id" => $v['deal_id']));
                     $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);
                 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'] = $region1_id;
                     $user_consignee['region_lv2'] = $region2_id;
                     $user_consignee['region_lv3'] = $region3_id;
                     $user_consignee['region_lv4'] = $region4_id;
                     $user_consignee['address'] = htmlspecialchars($address);
                     $user_consignee['mobile'] = htmlspecialchars($consignee_mobile);
                     $user_consignee['consignee'] = htmlspecialchars($consignee);
                     $user_consignee['zip'] = htmlspecialchars($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) {
                     $GLOBALS['payment_lang'] = array('name' => '余额支付', 'account_credit' => '帐户余额', 'use_user_money' => '使用余额支付', 'use_all_money' => '全额支付', 'USER_ORDER_PAID' => '%s订单付款,付款单号%s');
                     $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);
                 }
                 $root['order_id'] = $order_id;
                 $rs = order_paid($order_id);
                 update_order_cache($order_id);
                 if ($rs) {
                     $root['pay_status'] = 1;
                 } else {
                     $root['pay_status'] = 0;
                 }
                 //end 订单产品生成及支付
                 $root['status'] = 1;
             }
             //end 提交订单
         }
     } else {
         $root['user_login_status'] = 0;
         $root['status'] = 0;
         $root['info'] = '请先登录';
         //未登录
     }
     output($root);
 }
 public function index()
 {
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     $order_id = intval($GLOBALS['request']['id']);
     $region4_id = intval($GLOBALS['request']['region_lv4']);
     $region3_id = intval($GLOBALS['request']['region_lv3']);
     $region2_id = intval($GLOBALS['request']['region_lv2']);
     $region1_id = intval($GLOBALS['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;
     }
     $payment_id = intval($GLOBALS['request']['payment_id']);
     $consignee = strim($GLOBALS['request']['consignee']);
     $delivery_detail = strim($GLOBALS['request']['delivery_detail']);
     $phone = strim($GLOBALS['request']['phone']);
     $postcode = strim($GLOBALS['request']['postcode']);
     $content = strim($GLOBALS['request']['content']);
     $send_mobile = strim($GLOBALS['request']['send_mobile']);
     //$delivery_id = $GLOBALS['m_config']['delivery_id'];
     $delivery_id = $GLOBALS['request']['delivery_id'];
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         //开始计算订单
         $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
         if (!$order_info) {
             $root['status'] = 0;
             $root['info'] = '订单不存在';
             output($root);
         }
         require_once APP_ROOT_PATH . "system/libs/cart.php";
         $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
         $GLOBALS['user_info']['id'] = $user_id;
         $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
         if ($account_pay) {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 1, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         } else {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 0, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         }
         if ($data['is_delivery'] == 1) {
             //配送验证
             if (!$data['region_info'] || $data['region_info']['region_level'] != 4) {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS'];
                 output($root);
             }
             if ($consignee == '') {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE'];
                 output($root);
             }
             if ($delivery_detail == '') {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_CORRECT_ADDRESS'];
                 output($root);
             }
             if ($postcode == '') {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_CORRECT_ZIP'];
                 output($root);
             }
             if ($phone == '') {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_MOBILE_PHONE'];
                 output($root);
             }
             if (!check_mobile($phone)) {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE'];
                 output($root);
             }
             if (!$data['delivery_info']) {
                 $root['status'] = 0;
                 $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_DELIVERY'];
                 output($root);
             }
         }
         if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) {
             $root['status'] = 0;
             $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_PAYMENT'];
             output($root);
         }
         //结束验证订单接交信息
         //开始修正订单
         $now = get_gmtime();
         $order_info['total_price'] = $data['pay_total_price'];
         //应付总额  商品价 - 会员折扣 + 运费 + 支付手续费
         $order_info['memo'] = htmlspecialchars($content);
         $order_info['region_lv1'] = intval($region1_id);
         $order_info['region_lv2'] = intval($region2_id);
         $order_info['region_lv3'] = intval($region3_id);
         $order_info['region_lv4'] = intval($region4_id);
         $order_info['address'] = htmlspecialchars($delivery_detail);
         $order_info['mobile'] = htmlspecialchars($phone);
         $order_info['consignee'] = htmlspecialchars($consignee);
         $order_info['zip'] = htmlspecialchars($postcode);
         $order_info['delivery_fee'] = $data['delivery_fee'];
         $order_info['delivery_id'] = $data['delivery_info']['id'];
         $order_info['payment_id'] = $data['payment_info']['id'];
         $order_info['payment_fee'] = $data['payment_fee'];
         $order_info['delivery_fee'] = $data['delivery_fee'];
         $order_info['discount_price'] = $data['user_discount'];
         $coupon_mobile = htmlspecialchars($send_mobile);
         if ($coupon_mobile != '') {
             $GLOBALS['db']->query("update " . DB_PREFIX . "user set mobile = '" . $coupon_mobile . "' where id = " . intval($user_id));
         }
         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order_info, 'UPDATE', 'id=' . $order_info['id'], 'SILENT');
         //生成order_id 后
         //1. 余额支付
         $account_money = $data['account_money'];
         if (floatval($account_money) > 0) {
             $GLOBALS['payment_lang'] = array('name' => '余额支付', 'account_credit' => '帐户余额', 'use_user_money' => '使用余额支付', 'use_all_money' => '全额支付', 'USER_ORDER_PAID' => '%s订单付款,付款单号%s');
             $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_info['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);
         }
         $rs = order_paid($order_info['id']);
         $root['status'] = 1;
         $root['info'] = '';
         $root['has_pay'] = 1;
         $root['order_id'] = $order_id;
     } else {
         $root['user_login_status'] = 0;
         $root['status'] = 0;
         $root['info'] = '请先登录';
     }
     output($root);
 }
 public function count_order_total()
 {
     require_once APP_ROOT_PATH . "system/libs/cart.php";
     $order_id = intval($_REQUEST['id']);
     $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
     $region_id = intval($_REQUEST['region_id']);
     //配送地区
     $delivery_id = intval($_REQUEST['delivery_id']);
     //配送方式
     $account_money = floatval($_REQUEST['account_money']);
     //余额
     $ecvsn = $_REQUEST['ecvsn'] ? addslashes(trim($_REQUEST['ecvsn'])) : '';
     $ecvpassword = $_REQUEST['ecvpassword'] ? addslashes(trim($_REQUEST['ecvpassword'])) : '';
     $payment = intval($_REQUEST['payment']);
     $all_account_money = intval($_REQUEST['all_account_money']);
     $bank_id = addslashes(trim($_REQUEST['bank_id']));
     $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
     $result = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list, $order_info['account_money'], $order_info['ecv_money'], $bank_id);
     $GLOBALS['tmpl']->assign("result", $result);
     $html = $GLOBALS['tmpl']->fetch("inc/inc_cart_total.html");
     $data = $result;
     $data['html'] = $html;
     ajax_return($data);
 }
 public function index()
 {
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         $order_id = intval($GLOBALS['request']['id']);
         //echo $order_id; exit;
         $sql = "select o.*,r1.name as r1_name, r2.name as r2_name, r3.name as r3_name, r4.name as r4_name from " . DB_PREFIX . "deal_order as o " . "left outer join " . DB_PREFIX . "delivery_region as r1 on r1.id = o.region_lv1 " . "left outer join " . DB_PREFIX . "delivery_region as r2 on r2.id = o.region_lv2 " . "left outer join " . DB_PREFIX . "delivery_region as r3 on r3.id = o.region_lv3 " . "left outer join " . DB_PREFIX . "delivery_region as r4 on r4.id = o.region_lv4 " . " where o.is_delete = 0 and o.user_id = {$user_id} and o.id = {$order_id} limit 1";
         $order_info = $GLOBALS['db']->getRow($sql);
         if ($order_info) {
             $root = get_order_goods($order_info);
             $root['return'] = 1;
             $root['user_login_status'] = 1;
             $deliveryAddr = array();
             $deliveryAddr['consignee'] = $order_info['consignee'];
             //联系人姓名
             $deliveryAddr['delivery'] = $order_info['r1_name'] . $order_info['r2_name'] . $order_info['r3_name'] . $order_info['r4_name'];
             $deliveryAddr['region_lv1'] = $order_info['region_lv1'];
             //国家
             $deliveryAddr['region_lv2'] = $order_info['region_lv2'];
             //省
             $deliveryAddr['region_lv3'] = $order_info['region_lv3'];
             //城市
             $deliveryAddr['region_lv4'] = $order_info['region_lv4'];
             //地区/县
             $deliveryAddr['delivery_detail'] = $order_info['address'];
             //详细地址
             $deliveryAddr['phone'] = $order_info['mobile'];
             //手机号码
             $deliveryAddr['postcode'] = $order_info['zip'];
             //邮编
             $root['deliveryAddr'] = $deliveryAddr;
             $root['content'] = $order_info['memo'];
             //订单备注
             $root['send_mobile'] = $user['mobile'];
             //团购券手机
             $root['tax_title'] = $item['tax_title'];
             //发票抬头
             $root['tax_id'] = 0;
             //发票内容
             $root['deliver_time_id'] = 0;
             //配送日期ID 默认没有这个参数,所以填0
             //$default_payment_id = $GLOBALS['m_config']['select_payment_id'];
             $default_payment_id = $order_info['payment_id'];
             $root['payment_id'] = $default_payment_id;
             //支付方式
             $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
             $root['order_parm']['has_ecv'] = 0;
             //订单付款不支持代金券
             $root['evc_sn'] = '';
             //优惠券序号
             $root['evc_pwd'] = '';
             //优惠券序号
             $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
             $ids = array();
             $cart_ids = array();
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
                 array_push($cart_ids, $cart_goods['id']);
             }
             $ids_str = implode(",", $ids);
             $cart_ids_str = implode(",", $cart_ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
                 $root['order_parm']['has_delivery'] = 0;
             } else {
                 $delivery_id = $order_info['delivery_id'];
                 $root['order_parm']['has_delivery'] = 1;
             }
             $root['delivery_id'] = $delivery_id;
             //配送方式
             $has_coupon = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_coupon = 1 and id in (" . $ids_str . ")"));
             if (!$has_coupon) {
                 $root['order_parm']['has_moblie'] = 0;
             } else {
                 $root['order_parm']['has_moblie'] = 1;
             }
             $root['order_parm']['has_mcod'] = 1;
             $forbid_payment = $GLOBALS['db']->getAll("select payment_id from " . DB_PREFIX . "deal_payment where deal_id in (" . $ids_str . ")");
             foreach ($forbid_payment as $forbid_payment_item) {
                 foreach ($root['order_parm']['payment_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['payment_id']) {
                         unset($root['order_parm']['payment_list'][$k]);
                     }
                 }
             }
             $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
             foreach ($forbid_delivery as $forbid_delivery_item) {
                 foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['delivery_id']) {
                         unset($root['order_parm']['delivery_list'][$k]);
                     }
                 }
             }
             $region4_id = intval($order_info['region_lv4']);
             $region3_id = intval($order_info['region_lv3']);
             $region2_id = intval($order_info['region_lv2']);
             $region1_id = intval($order_info['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;
             }
             require_once APP_ROOT_PATH . "system/libs/cart.php";
             //订单的显示参数
             if ($order_info['pay_status'] == 0) {
                 $root['has_cancel'] = 1;
             } else {
                 $root['has_cancel'] = 0;
             }
             $delivery_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "delivery_notice where order_item_id in (" . $cart_ids_str . ") order by delivery_time desc limit 1");
             if ($delivery_notice) {
                 $express = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "express where id = " . intval($delivery_notice['express_id']));
                 $express['config'] = unserialize($express['config']);
                 $root['kd_com'] = $express['config']['app_code'];
                 if ($root['kd_com']) {
                     $root['kd_sn'] = $delivery_notice['notice_sn'];
                 }
             }
             if ($order_info['pay_status'] != 2) {
                 $root['has_edit_delivery'] = 1;
                 $root['has_edit_delivery_time'] = 0;
                 $root['has_edit_invoice'] = 0;
                 $root['has_edit_ecv'] = 0;
                 $root['has_edit_message'] = 1;
                 $root['has_edit_moblie'] = 1;
                 $GLOBALS['user_info']['id'] = $user_id;
                 $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
                 if ($account_pay) {
                     $data = count_buy_total($region_id, $delivery_id, $default_payment_id, $account_money = 0, $all_account_money = 1, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
                 } else {
                     $data = count_buy_total($region_id, $delivery_id, $default_payment_id, $account_money = 0, $all_account_money = 0, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
                 }
                 //print_r($data);exit;
                 if ($data['pay_price'] == 0) {
                     if ($data['account_money'] > 0 || $data['ecv_money'] > 0) {
                         $root['has_pay'] = 1;
                         $root['use_user_money'] = $data['account_price'];
                     } else {
                         $root['has_pay'] = 0;
                         $root['use_user_money'] = 0;
                     }
                     $root['pay_money'] = 0;
                     //还需要支付金额
                 } else {
                     $root['has_pay'] = 1;
                     $root['pay_money'] = $data['pay_price'];
                     //还需要支付金额
                     $root['use_user_money'] = 0;
                 }
                 $root['feeinfo'] = getFeeItem($data);
             } else {
                 $root['has_pay'] = 0;
                 $root['has_edit_delivery'] = 0;
                 $root['has_edit_delivery_time'] = 0;
                 $root['has_edit_invoice'] = 0;
                 $root['has_edit_ecv'] = 0;
                 $root['has_edit_message'] = 0;
                 $root['has_edit_moblie'] = 0;
                 $data['pay_total_price'] = $order_info['total_price'];
                 $data['return_total_score'] = $order_info['return_total_score'];
                 $data['total_price'] = $order_info['deal_total_price'];
                 $data['delivery_fee'] = $order_info['delivery_fee'];
                 $data['account_money'] = $order_info['account_money'];
                 $data['ecv_money'] = $order_info['ecv_money'];
                 $root['pay_money'] = 0;
                 //还需要支付金额
                 $root['use_user_money'] = 0;
                 $root['feeinfo'] = getFeeItem($data);
             }
         } else {
             $root['return'] = 0;
             $root['info'] = "订单不存在.";
         }
     } else {
         $root['user_login_status'] = 0;
     }
     output($root);
 }
Example #10
0
 public function index()
 {
     $root = array();
     $mobile = trim($GLOBALS['request']['mobile']);
     $code = strim($GLOBALS['request']['code']);
     /*验证码*/
     $ref_uid = intval($GLOBALS['request']['ref_uid']);
     /*邀请id*/
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     if (!empty($mobile)) {
         if (!check_mobile($mobile)) {
             $root['status'] = 2;
             $root['info'] = "请输入正确的手机号码";
             output($root);
         }
         //print_r($GLOBALS['request']);
         if ($code == '') {
             $root['info'] = "请输入验证码!";
             $root['status'] = 2;
             output($root);
         }
         $db_code = $GLOBALS['db']->getRow("select id,code,add_time from " . DB_PREFIX . "sms_mobile_verify where mobile_phone = '{$mobile}' order by id desc");
         //print_r($db_code['code']);
         //$root['code']="select id,code,add_time from ".DB_PREFIX."sms_mobile_verify where status=0 and mobile_phone = '$mobile' and type=0 order by id desc";
         if ($db_code['code'] != $code) {
             $root['info'] = "请输入正确的验证码!";
             $root['status'] = 2;
             output($root);
         }
         $new_time = get_gmtime();
         if ($new_time - $db_code['add_time'] > 60 * 30) {
             $root['info'] = "验证码已失效,请重新获取!";
             $root['status'] = 2;
             $GLOBALS['db']->query("delete from " . DB_PREFIX . "sms_mobile_verify  where mobile_phone = " . $mobile . "");
             output($root);
         }
         //$GLOBALS['db']->query("update ".DB_PREFIX."sms_mobile_verify set status = 1 where id=".$db_code['id']."");
         $GLOBALS['db']->query("delete from " . DB_PREFIX . "sms_mobile_verify where id=" . $db_code['id'] . "");
         $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where mobile = '{$mobile}'");
         require_once APP_ROOT_PATH . "/system/model/user.php";
         if (!$user_data) {
             //自动注册一个用户;
             $pwd = rand(1111, 9999);
             $pwd = md5($pwd);
             $user_data = mobile_reg($mobile, $pwd, $ref_uid);
         } else {
             $mobile = $user_data['mobile'];
             $pwd = $user_data['user_pwd'];
         }
         //检查用户,用户密码
         auto_do_login_user($mobile, $pwd, false);
         $user = $GLOBALS['user_info'];
         $user_id = intval($user['id']);
         if ($user_id > 0) {
             $root['mobile_user_id'] = $user_id;
             $root['mobile_user_name'] = $user['user_name'];
             $root['mobile_user_pwd'] = $user['user_pwd'];
         } else {
             $root['info'] = "用户登陆失败!";
             $root['status'] = 2;
         }
     } else {
         //检查用户,用户密码
         $user = $GLOBALS['user_info'];
         $user_id = intval($user['id']);
     }
     $root['return'] = 1;
     $root['first_calc'] = $GLOBALS['request']['first_calc'];
     if ($user_id > 0) {
         //用户登陆状态:1:成功登陆;0:未成功登陆
         $root['user_login_status'] = 1;
         //第一次计算,主要是处理一些初始化参数,比如:默认配送地址
         if ($GLOBALS['request']['first_calc'] == 1) {
             $delivery = getUserAddr($user_id, false, 1);
             $root['delivery'] = $delivery;
             $delivery_region = array('region_lv1' => intval($delivery['region_lv1']), 'region_lv2' => intval($delivery['region_lv2']), 'region_lv3' => intval($delivery['region_lv3']), 'region_lv4' => intval($delivery['region_lv4']));
             $root['send_mobile'] = $user['mobile'];
             //默认填上用户手机号码
             $payment_id = intval($GLOBALS['m_config']['select_payment_id']);
             //默认支付方式
             //$payment_id = intval($root['order_parm']['select_payment_id']);//默认支付方式
             $delivery_id = intval($GLOBALS['m_config']['delivery_id']);
             //配送方式;
         } else {
             $delivery_region = array('region_lv1' => intval($GLOBALS['request']['region_lv1']), 'region_lv2' => intval($GLOBALS['request']['region_lv2']), 'region_lv3' => intval($GLOBALS['request']['region_lv3']), 'region_lv4' => intval($GLOBALS['request']['region_lv4']));
             if ($GLOBALS['request']['payment_id']) {
                 $payment_id = intval($GLOBALS['request']['payment_id']);
             } else {
                 $payment_id = intval($GLOBALS['m_config']['select_payment_id']);
                 //默认支付方式
             }
             if ($GLOBALS['request']['delivery_id']) {
                 $delivery_id = intval($GLOBALS['request']['delivery_id']);
             } else {
                 $delivery_id = intval($GLOBALS['m_config']['delivery_id']);
                 //配送方式;
             }
         }
         if ($GLOBALS['request']['from'] == "wap") {
             //用户信息
             $cartdata = unserialize(base64_decode($GLOBALS['request']['cartdata']));
             $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id);
             $root['user_info'] = $user_info;
             $root['delivery_list'] = $GLOBALS['m_config']['delivery_list'];
             //商品信息
             $res = insertCartData($user_id, es_session::id(), $cartdata);
             $cart_info = $res['data'];
             foreach ($cart_info as $k => $v) {
                 //查询数据库,获取商品信息
                 $deal = $GLOBALS['db']->getRow("select img,max_bought from " . DB_PREFIX . "deal where id=" . $v['deal_id']);
                 //单价*数量=总价
                 $cart_info[$k]['current_price_format'] = format_price($v['unit_price']);
                 $cart_info[$k]['img'] = get_abs_img_root($deal['img']);
                 $cart_info[$k]['max_bought'] = $deal['max_bought'];
                 $cart_info[$k]['current_price'] = round($v['unit_price'], 2);
                 $cart_info[$k]['tech_id'] = $v['tech_id'];
                 $tech_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $v['tech_id']);
                 $cart_info[$k]['tech_name'] = $tech_info['user_name'];
             }
             $root['cartinfo'] = $cart_info;
         } else {
             $cartdata = $GLOBALS['request']['cartdata'];
             $res = insertCartData($user_id, es_session::id(), $cartdata);
         }
         if ($res['info'] != '') {
             //不可购买
             $root['info'] = $res['info'];
             $root['status'] = 0;
         } else {
             //可以购买
             $root['status'] = 1;
             //$delivery_id = intval($requestData['delivery_id']);//配送方式;
             if ($delivery_id == 0) {
                 $delivery_id = intval($GLOBALS['m_config']['delivery_id']);
             }
             //取系统配置
             $root['select_delivery_id'] = $delivery_id;
             $ecvSn = strim($GLOBALS['request']['ecv_sn']);
             //优惠券
             $ecvPassword = strim($GLOBALS['request']['ecv_pwd']);
             //优惠券密码
             require_once APP_ROOT_PATH . "system/model/cart.php";
             $region4_id = intval($delivery_region['region_lv4']);
             $region3_id = intval($delivery_region['region_lv3']);
             $region2_id = intval($delivery_region['region_lv2']);
             $region1_id = intval($delivery_region['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;
             }
             $goods_list = $res['data'];
             $GLOBALS['user_info']['id'] = $user_id;
             $ids = array();
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
             }
             $ids_str = implode(",", $ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
             }
             $root['is_delivery'] = $is_delivery;
             $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
             if ($account_pay) {
                 $data = count_buy_total($region_id, $delivery_id, $payment_id, 0, 1, $ecvSn, $ecvPassword, $goods_list);
             } else {
                 $data = count_buy_total($region_id, $delivery_id, $payment_id, 0, 0, $ecvSn, $ecvPassword, $goods_list);
             }
             $root['use_user_money'] = floatval($data['account_money']);
             //使用会员余额支付金额
             $root['pay_money'] = $data['pay_price'];
             //还需要支付金额
             $root['feeinfo'] = getFeeItem($data);
             $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
             $root['order_parm']['delivery_id'] = $delivery_id;
             $root['order_parm']['payment_id'] = $payment_id;
             $ecv_payment_id = intval($GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Voucher'"));
             //重新为order_parm赋值
             if ($ecv_payment_id) {
                 $forbid_ecv = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_payment where payment_id =" . $ecv_payment_id . " and deal_id in (" . $ids_str . ")");
                 if ($forbid_ecv) {
                     $root['order_parm']['has_ecv'] = 0;
                 }
                 //无优惠券
             } else {
                 $root['order_parm']['has_ecv'] = 0;
             }
             //无优惠券
             $has_coupon = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_coupon = 1 and id in (" . $ids_str . ")"));
             if ($has_coupon == 0) {
                 $root['order_parm']['has_moblie'] = 0;
                 $root['order_parm']['has_mcod'] = 1;
             } else {
                 $root['order_parm']['has_moblie'] = 1;
                 $root['order_parm']['has_mcod'] = 0;
                 //有团购券商品,不能做:货到付款
             }
             //下单时需要绑定手机号码
             if (intval($GLOBALS['m_config']['order_has_bind_mobile']) == 1) {
                 //前面已经绑定手机号码了,这时不能再修改手机号码
                 $root['order_parm']['has_moblie'] = 0;
             }
             foreach ($root['order_parm']['payment_list'] as $k => $v) {
                 if ($v['code'] == 'Mcod' && $root['order_parm']['has_mcod'] == 0) {
                     unset($root['order_parm']['payment_list'][$k]);
                 }
             }
             $has_delivery = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if (!$has_delivery) {
                 $root['order_parm']['has_delivery'] = 0;
             } else {
                 $root['order_parm']['has_delivery'] = 1;
             }
             //$root['order_parm']['has_mcod'] = 1;
             $forbid_payment = $GLOBALS['db']->getAll("select payment_id from " . DB_PREFIX . "deal_payment where deal_id in (" . $ids_str . ")");
             foreach ($forbid_payment as $forbid_payment_item) {
                 foreach ($root['order_parm']['payment_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['payment_id']) {
                         unset($root['order_parm']['payment_list'][$k]);
                     }
                 }
             }
             $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
             foreach ($forbid_delivery as $forbid_delivery_item) {
                 foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['delivery_id']) {
                         unset($root['order_parm']['delivery_list'][$k]);
                     }
                 }
             }
             //数组按顺序排序
             $payment_list = array();
             foreach ($root['order_parm']['payment_list'] as $k => $v) {
                 $payment_list[] = $v;
             }
             $root['order_parm']['payment_list'] = $payment_list;
             $delivery_list = array();
             foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                 $delivery_list[] = $v;
             }
             $root['order_parm']['delivery_list'] = $delivery_list;
             //has_delivery_list
             //$root['order_parm']['delivery_list'] = $GLOBALS['db']->getAll("select id,name from ".DB_PREFIX."delivery");
         }
     } else {
         //未登录
         $root['user_login_status'] = 0;
     }
     $root['page_title'] = '确认订单';
     $root['city_name'] = $city_name;
     output($root);
 }
Example #11
0
 public function index()
 {
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     $root['first_calc'] = $GLOBALS['request']['first_calc'];
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         $region4_id = intval($GLOBALS['request']['region_lv4']);
         $region3_id = intval($GLOBALS['request']['region_lv3']);
         $region2_id = intval($GLOBALS['request']['region_lv2']);
         $region1_id = intval($GLOBALS['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;
         }
         require_once APP_ROOT_PATH . "system/model/cart.php";
         $order_id = intval($GLOBALS['request']['id']);
         $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
         $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
         //$delivery_id = $GLOBALS['m_config']['delivery_id'];
         $delivery_id = $GLOBALS['request']['delivery_id'];
         $payment_id = intval($GLOBALS['request']['payment_id']);
         $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
         $ids = array();
         foreach ($goods_list as $cart_goods) {
             array_push($ids, $cart_goods['deal_id']);
         }
         $ids_str = implode(",", $ids);
         $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
         foreach ($forbid_delivery as $forbid_delivery_item) {
             foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                 if ($v['id'] == $forbid_delivery_item['delivery_id']) {
                     unset($root['order_parm']['delivery_list'][$k]);
                 }
             }
         }
         $has_coupon = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_coupon = 1 and id in (" . $ids_str . ")"));
         if ($has_coupon == 0) {
             $root['order_parm']['has_moblie'] = 0;
             $root['order_parm']['has_mcod'] = 1;
         } else {
             $root['order_parm']['has_moblie'] = 1;
             $root['order_parm']['has_mcod'] = 0;
             //有团购券商品,不能做:货到付款
         }
         //下单时需要绑定手机号码
         if (intval($GLOBALS['m_config']['order_has_bind_mobile']) == 1) {
             //前面已经绑定手机号码了,这时不能再修改手机号码
             $root['order_parm']['has_moblie'] = 0;
         }
         foreach ($root['order_parm']['payment_list'] as $k => $v) {
             if ($v['code'] == 'Mcod' && $root['order_parm']['has_mcod'] == 0) {
                 unset($root['order_parm']['payment_list'][$k]);
             }
         }
         $has_delivery = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
         if (!$has_delivery) {
             $root['order_parm']['has_delivery'] = 0;
         } else {
             $root['order_parm']['has_delivery'] = 1;
         }
         $forbid_payment = $GLOBALS['db']->getAll("select payment_id from " . DB_PREFIX . "deal_payment where deal_id in (" . $ids_str . ")");
         foreach ($forbid_payment as $forbid_payment_item) {
             foreach ($root['order_parm']['payment_list'] as $k => $v) {
                 if ($v['id'] == $forbid_payment_item['payment_id']) {
                     unset($root['order_parm']['payment_list'][$k]);
                 }
             }
         }
         //数组按顺序排序
         $payment_list = array();
         foreach ($root['order_parm']['payment_list'] as $k => $v) {
             $payment_list[] = $v;
         }
         $root['order_parm']['payment_list'] = $payment_list;
         $delivery_list = array();
         foreach ($root['order_parm']['delivery_list'] as $k => $v) {
             $delivery_list[] = $v;
         }
         $root['order_parm']['delivery_list'] = $delivery_list;
         //开始计算订单
         $GLOBALS['user_info']['id'] = $user_id;
         $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
         if ($account_pay) {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 1, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         } else {
             $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 0, '', '', $goods_list, $order_info['account_money'], $order_info['ecv_money']);
         }
         $root['feeinfo'] = getFeeItem($data);
         $root['use_user_money'] = $data['account_money'];
         $root['pay_money'] = $data['pay_price'];
         $root['info'] = '';
         //"订单已重新计算";
         $root['status'] = 1;
         //end 计算订单
     } else {
         $root['user_login_status'] = 0;
         $root['status'] = 0;
     }
     output($root);
 }
 public function index()
 {
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     //print_r($user); exit;
     $cartdata = $GLOBALS['request']['cartdata'];
     $root = array();
     $root['return'] = 1;
     $root['first_calc'] = $GLOBALS['request']['first_calc'];
     if ($user_id > 0) {
         //用户登陆状态:1:成功登陆;0:未成功登陆
         $root['user_login_status'] = 1;
         //第一次计算,主要是处理一些初始化参数,比如:默认配送地址
         if ($GLOBALS['request']['first_calc'] == 1) {
             $delivery = getUserAddr($user_id, false);
             $root['delivery'] = $delivery;
             $delivery_region = array('region_lv1' => intval($delivery['region_lv1']), 'region_lv2' => intval($delivery['region_lv2']), 'region_lv3' => intval($delivery['region_lv3']), 'region_lv4' => intval($delivery['region_lv4']));
             $root['send_mobile'] = $user['mobile'];
             //默认填上用户手机号码
             $payment_id = intval($root['order_parm']['select_payment_id']);
             //默认支付方式
         } else {
             $delivery_region = array('region_lv1' => intval($GLOBALS['request']['region_lv1']), 'region_lv2' => intval($GLOBALS['request']['region_lv2']), 'region_lv3' => intval($GLOBALS['request']['region_lv3']), 'region_lv4' => intval($GLOBALS['request']['region_lv4']));
             $payment_id = intval($GLOBALS['request']['payment_id']);
         }
         $res = insertCartData($user_id, session_id(), $cartdata);
         if ($res['info'] != '') {
             //不可购买
             $root['info'] = $res['info'];
             $root['status'] = 0;
         } else {
             //可以购买
             $root['status'] = 1;
             $delivery_id = intval($requestData['delivery_id']);
             //配送方式;
             if ($delivery_id == 0) {
                 $delivery_id = intval($GLOBALS['m_config']['delivery_id']);
             }
             //取系统配置
             $root['select_delivery_id'] = $delivery_id;
             $ecvSn = strim($GLOBALS['request']['ecv_sn']);
             //优惠券
             $ecvPassword = strim($GLOBALS['request']['ecv_pwd']);
             //优惠券密码
             require_once APP_ROOT_PATH . "system/libs/cart.php";
             $region4_id = intval($delivery_region['region_lv4']);
             $region3_id = intval($delivery_region['region_lv3']);
             $region2_id = intval($delivery_region['region_lv2']);
             $region1_id = intval($delivery_region['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;
             }
             $goods_list = $res['data'];
             $GLOBALS['user_info']['id'] = $user_id;
             $ids = array();
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
             }
             $ids_str = implode(",", $ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
             }
             $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
             if ($account_pay) {
                 $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 1, $ecvSn, $ecvPassword, $goods_list);
             } else {
                 $data = count_buy_total($region_id, $delivery_id, $payment_id, $account_money = 0, $all_account_money = 0, $ecvSn, $ecvPassword, $goods_list);
             }
             $root['use_user_money'] = floatval($data['account_money']);
             //使用会员余额支付金额
             $root['pay_money'] = $data['pay_price'];
             //还需要支付金额
             $root['feeinfo'] = getFeeItem($data);
             $root['order_parm'] = init_order_parm($GLOBALS['m_config']);
             $ecv_payment_id = intval($GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Voucher'"));
             //重新为order_parm赋值
             if ($ecv_payment_id) {
                 $forbid_ecv = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_payment where payment_id =" . $ecv_payment_id . " and deal_id in (" . $ids_str . ")");
                 if ($forbid_ecv) {
                     $root['order_parm']['has_ecv'] = 0;
                 }
                 //无优惠券
             } else {
                 $root['order_parm']['has_ecv'] = 0;
             }
             //无优惠券
             $has_coupon = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_coupon = 1 and id in (" . $ids_str . ")"));
             if (!$has_coupon) {
                 $root['order_parm']['has_moblie'] = 0;
             } else {
                 $root['order_parm']['has_moblie'] = 1;
             }
             $has_delivery = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if (!$has_delivery) {
                 $root['order_parm']['has_delivery'] = 0;
             } else {
                 $root['order_parm']['has_delivery'] = 1;
             }
             $root['order_parm']['has_mcod'] = 1;
             $forbid_payment = $GLOBALS['db']->getAll("select payment_id from " . DB_PREFIX . "deal_payment where deal_id in (" . $ids_str . ")");
             foreach ($forbid_payment as $forbid_payment_item) {
                 foreach ($root['order_parm']['payment_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['payment_id']) {
                         unset($root['order_parm']['payment_list'][$k]);
                     }
                 }
             }
             $forbid_delivery = $GLOBALS['db']->getAll("select delivery_id from " . DB_PREFIX . "deal_delivery where deal_id in (" . $ids_str . ")");
             foreach ($forbid_delivery as $forbid_delivery_item) {
                 foreach ($root['order_parm']['delivery_list'] as $k => $v) {
                     if ($v['id'] == $forbid_payment_item['delivery_id']) {
                         unset($root['order_parm']['delivery_list'][$k]);
                     }
                 }
             }
             //has_delivery_list
             //$root['order_parm']['delivery_list'] = $GLOBALS['db']->getAll("select id,name from ".DB_PREFIX."delivery");
         }
     } else {
         //未登录
         $root['user_login_status'] = 0;
     }
     output($root);
 }
 public function index()
 {
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     $money = floatval($user['money']);
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         //已登录
         $region4_id = intval($GLOBALS['request']['region_lv4']);
         $region3_id = intval($GLOBALS['request']['region_lv3']);
         $region2_id = intval($GLOBALS['request']['region_lv2']);
         $region1_id = intval($GLOBALS['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;
         }
         $payment = intval($GLOBALS['request']['payment_id']);
         $account_money = floatval($GLOBALS['request']['use_user_money']);
         $address = strim($GLOBALS['request']['delivery_detail']);
         $consignee_mobile = strim($GLOBALS['request']['phone']);
         $zip = strim($GLOBALS['request']['postcode']);
         $consignee = strim($GLOBALS['request']['consignee']);
         $ecvsn = $GLOBALS['request']['ecv_sn'] ? strim($GLOBALS['request']['ecv_sn']) : '';
         $ecvpassword = $GLOBALS['request']['ecv_pwd'] ? strim($GLOBALS['request']['ecv_pwd']) : '';
         $order_memo = strim($GLOBALS['request']['content']);
         $send_mobile = strim($GLOBALS['request']['send_mobile']);
         $delivery_id = intval($GLOBALS['request']['delivery_id']);
         //$delivery_id = intval($GLOBALS['m_config']['delivery_id']);
         $account_pay = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name = 'Account'");
         if ($account_pay) {
             $all_account_money = 1;
         } else {
             $all_account_money = 0;
         }
         $res = insertCartData($user_id, session_id(), $GLOBALS['request']['cartdata']);
         if ($res['info'] != '') {
             //失败有错误
             $root['status'] = 0;
             $root['info'] = $res['info'];
             output($root);
         } else {
             //可以提交订单
             $goods_list = $res['data'];
             require_once APP_ROOT_PATH . "system/libs/cart.php";
             $GLOBALS['user_info']['id'] = $user_id;
             $ids = array();
             foreach ($goods_list as $cart_goods) {
                 array_push($ids, $cart_goods['deal_id']);
             }
             $ids_str = implode(",", $ids);
             $is_delivery = intval($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "deal where is_delivery = 1 and id in (" . $ids_str . ")"));
             if ($is_delivery == 0) {
                 $delivery_id = 0;
             }
             $data = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list);
             if ($data['is_delivery'] == 1) {
                 //配送验证
                 if (!$data['region_info'] || $data['region_info']['region_level'] != 4) {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($consignee == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_CONSIGNEE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($address == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_ADDRESS'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($zip == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_ZIP'];
                     $root['status'] = 0;
                     output($root);
                 } elseif ($consignee_mobile == '') {
                     $root['info'] = $GLOBALS['lang']['FILL_MOBILE_PHONE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif (!check_mobile(trim($consignee_mobile))) {
                     $root['info'] = $GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE'];
                     $root['status'] = 0;
                     output($root);
                 } elseif (!$data['delivery_info']) {
                     $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_DELIVERY'];
                     $root['status'] = 0;
                     output($root);
                 }
             }
             if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) {
                 $root['info'] = $GLOBALS['lang']['PLEASE_SELECT_PAYMENT'];
                 $root['status'] = 0;
                 output($root);
             } else {
                 //验证成功
                 //开始生成订单
                 $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($order_memo);
                 $order['region_lv1'] = $region1_id;
                 $order['region_lv2'] = $region2_id;
                 $order['region_lv3'] = $region3_id;
                 $order['region_lv4'] = $region4_id;
                 $order['address'] = htmlspecialchars($address);
                 $order['mobile'] = htmlspecialchars($consignee_mobile);
                 $order['consignee'] = htmlspecialchars($consignee);
                 $order['zip'] = htmlspecialchars($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'] = 0;
                 if ($send_mobile != '') {
                     $GLOBALS['db']->query("update " . DB_PREFIX . "user set mobile = '" . $send_mobile . "' where id = " . $user_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);
                 //end 验证成功提交订单成功
                 //开始生成订单产品以及支付
                 //生成订单商品
                 foreach ($goods_list as $k => $v) {
                     $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'];
                     $deal_info = load_auto_cache("cache_deal_cart", array("id" => $v['deal_id']));
                     $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);
                 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'] = $region1_id;
                     $user_consignee['region_lv2'] = $region2_id;
                     $user_consignee['region_lv3'] = $region3_id;
                     $user_consignee['region_lv4'] = $region4_id;
                     $user_consignee['address'] = htmlspecialchars($address);
                     $user_consignee['mobile'] = htmlspecialchars($consignee_mobile);
                     $user_consignee['consignee'] = htmlspecialchars($consignee);
                     $user_consignee['zip'] = htmlspecialchars($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) {
                     $GLOBALS['payment_lang'] = array('name' => '余额支付', 'account_credit' => '帐户余额', 'use_user_money' => '使用余额支付', 'use_all_money' => '全额支付', 'USER_ORDER_PAID' => '%s订单付款,付款单号%s');
                     $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);
                 }
                 $root['order_id'] = $order_id;
                 $rs = order_paid($order_id);
                 if ($rs) {
                     $root['pay_status'] = 1;
                 } else {
                     $root['pay_status'] = 0;
                 }
                 //end 订单产品生成及支付
                 $root['status'] = 1;
             }
             //end 提交订单
         }
     } else {
         $root['user_login_status'] = 1;
         $root['status'] = 0;
         //未登录
     }
     output($root);
 }