public function do_refuse() { $order_item_id = intval($_REQUEST['order_item_id']); $coupon_id = intval($_REQUEST['coupon_id']); $price = floatval($_REQUEST['price']); $balance_price = floatval($_REQUEST['balance_price']); $content = strim($_REQUEST['content']); if ($order_item_id) { $oi = $order_item_id; $data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $order_item_id); if ($data['refund_status'] == 2) { $this->error("已退款", 1); } if ($data) { $order_id = $data['order_id']; $supplier_id = $data['supplier_id']; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 3,is_arrival = 0 where id = " . $order_item_id); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 3,is_refuse_delivery=0 where id = " . $order_id); } elseif ($coupon_id) { $data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where id = " . $coupon_id); if ($data['refund_status'] == 2) { $this->error("已退款", 1); } if ($data) { $oi = $data['order_deal_id']; $order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $data['order_deal_id']); $data['name'] = $order_item['name']; $order_id = $data['order_id']; $supplier_id = $data['supplier_id']; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 3 where id = " . $coupon_id); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 3 where id = " . $data['order_deal_id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 3 where id = " . $order_id); } $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id); require_once APP_ROOT_PATH . "system/model/deal_order.php"; order_log($data['name'] . "退款不通过 " . " " . $content, $order_id); auto_over_status($order_id); update_order_cache($order_id); distribute_order($order_id); send_msg($order_info['user_id'], $data['name'] . "退款不通过 " . " " . $content, "orderitem", $oi); $this->success("操作成功", 1); }
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 done() { require_once APP_ROOT_PATH . "system/model/cart.php"; require_once APP_ROOT_PATH . "system/model/deal.php"; require_once APP_ROOT_PATH . "system/model/deal_order.php"; global_run(); $ajax = 1; $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']) : ''; $user_id = intval($GLOBALS['user_info']['id']); $session_id = es_session::id(); $cart_result = load_cart_list(); $goods_list = $cart_result['cart_list']; if (!$goods_list) { showErr($GLOBALS['lang']['CART_EMPTY_TIP'], $ajax); } //验证购物车 if (check_save_login() != LOGIN_STATUS_LOGINED) { showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax, url("index", "user#login")); } $deal_ids = array(); foreach ($goods_list as $k => $v) { $data = check_cart($v['id'], $v['number']); if (!$data['status']) { showErr($data['info'], $ajax, url("index", "cart#index")); } $deal_ids[$v['deal_id']]['deal_id'] = $v['deal_id']; } foreach ($deal_ids as $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, url("index", "cart#index")); } } } //结束验证购物车 //开始验证订单接交信息 $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) { 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['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'] = 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['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'] = strim($_REQUEST['bank_id']); foreach ($data['promote_description'] as $promote_item) { $order['promote_description'] .= $promote_item . "<br />"; } //更新来路 $order['referer'] = $GLOBALS['referer']; $user_info = es_session::get("user_info"); $order['user_name'] = $user_info['user_name']; /** 更新会员手机号 $coupon_mobile = htmlspecialchars(addslashes(trim($_REQUEST['coupon_mobile']))); if($coupon_mobile!='') $GLOBALS['db']->query("update ".DB_PREFIX."user set mobile = '".$coupon_mobile."' where id = ".intval($user_info['id'])); */ if ($user_info['mobile'] == "") { $user_mobile = strim($_REQUEST['user_mobile']); if ($user_mobile == "") { $data = array(); $data['status'] = false; $data['info'] = "请输入手机号"; $data['jump'] = ""; ajax_return($data); } if (!check_mobile($user_mobile)) { $data = array(); $data['status'] = false; $data['info'] = "手机号格式不正确"; $data['jump'] = ""; ajax_return($data); } if (app_conf("SMS_ON") == 1) { $mobile_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "sms_mobile_verify where mobile_phone = '" . $user_mobile . "'"); $sms_verify = strim($_POST['sms_verify']); if (empty($mobile_data) || $mobile_data['code'] != $sms_verify) { $data = array(); $data['status'] = false; $data['info'] = "手机验证码错误"; $data['jump'] = ""; ajax_return($data); } } $GLOBALS['db']->query("update " . DB_PREFIX . "user set mobile = '" . $user_mobile . "' where id = " . $user_info['id'], "SILENT"); if ($GLOBALS['db']->affected_rows() > 0) { $GLOBALS['db']->query("delete from " . DB_PREFIX . "sms_mobile_verify where mobile_phone = '" . $user_mobile . "'"); //删除验证码 } else { $data = array(); $data['status'] = false; $data['info'] = "手机号已被注册"; $data['jump'] = ""; ajax_return($data); } } do { $order['order_sn'] = to_date(NOW_TIME, "Ymdhis") . rand(10, 99); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order, 'INSERT', '', 'SILENT'); $order_id = intval($GLOBALS['db']->insert_id()); } while ($order_id == 0); //生成订单商品 foreach ($goods_list as $k => $v) { $deal_info = load_auto_cache("deal", array("id" => $v['deal_id'])); $goods_item = array(); $goods_item['deal_id'] = $v['deal_id']; $goods_item['number'] = $v['number']; $goods_item['unit_price'] = $v['unit_price']; $goods_item['total_price'] = $v['total_price']; $goods_item['name'] = $v['name']; $goods_item['sub_name'] = $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['add_balance_price'] = $v['add_balance_price']; $goods_item['add_balance_price_total'] = $v['add_balance_price'] * $v['number']; $goods_item['balance_unit_price'] = $deal_info['balance_price']; $goods_item['balance_total_price'] = $deal_info['balance_price'] * $v['number']; $goods_item['delivery_status'] = $deal_info['is_delivery'] == 1 ? 0 : 5; $goods_item['is_coupon'] = $deal_info['is_coupon']; $goods_item['deal_icon'] = $deal_info['icon']; $goods_item['supplier_id'] = $deal_info['supplier_id']; $goods_item['is_refund'] = $deal_info['is_refund']; $goods_item['user_id'] = $user_id; $goods_item['order_sn'] = $order['order_sn']; $goods_item['is_shop'] = $deal_info['is_shop']; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_item", $goods_item, 'INSERT', '', 'SILENT'); } //开始更新订单表的deal_ids $deal_ids = $GLOBALS['db']->getOne("select group_concat(deal_id) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set deal_ids = '" . $deal_ids . "' where id = " . $order_id); $GLOBALS['db']->query("delete from " . DB_PREFIX . "deal_cart where session_id = '" . $session_id . "'"); load_cart_list(true); 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. 代金券支付 $ecv_data = $data['ecv_data']; if ($ecv_data) { $ecv_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Voucher'"); if ($ecv_data['money'] > $order['total_price']) { $ecv_data['money'] = $order['total_price']; } $payment_notice_id = make_payment_notice($ecv_data['money'], $order_id, $ecv_payment_id); require_once APP_ROOT_PATH . "system/payment/Voucher_payment.php"; $voucher_payment = new Voucher_payment(); $voucher_payment->direct_pay($ecv_data['sn'], $ecv_data['password'], $payment_notice_id); } //2. 余额支付 $account_money = $data['account_money']; if (floatval($account_money) > 0) { $account_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Account'"); $payment_notice_id = make_payment_notice($account_money, $order_id, $account_payment_id); require_once APP_ROOT_PATH . "system/payment/Account_payment.php"; $account_payment = new Account_payment(); $account_payment->get_payment_code($payment_notice_id); } //3. 相应的支付接口 $payment_info = $data['payment_info']; if ($payment_info && $data['pay_price'] > 0) { $payment_notice_id = make_payment_notice($data['pay_price'], $order_id, $payment_info['id']); //创建支付接口的付款单 } $rs = order_paid($order_id); update_order_cache($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); } }
/** * 维权没收到货 * @param unknown_type $delivery_sn * @param unknown_type $order_item_id 订单商品ID,将会确认相关的所有订单的同序号发货号。 */ function refuse_delivery($delivery_sn, $order_item_id) { $order_id = $GLOBALS['db']->getOne("select order_id from " . DB_PREFIX . "deal_order_item where id = '" . $order_item_id . "'"); $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . intval($order_id)); if ($order_info) { $delivery_notices = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "delivery_notice where order_id = " . $order_info['id'] . " and notice_sn = '" . $delivery_sn . "'"); $order_item_ids = array(0); foreach ($delivery_notices as $k => $v) { $order_item_ids[] = $v['order_item_id']; } $sql = "update " . DB_PREFIX . "deal_order_item set is_arrival = 2 where is_arrival = 0 and id in (" . implode(",", $order_item_ids) . ")"; $GLOBALS['db']->query($sql); if ($GLOBALS['db']->affected_rows() || true) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set is_refuse_delivery = 1 where id = " . $order_id); $GLOBALS['db']->query("update " . DB_PREFIX . "delivery_notice set is_arrival = 2 where notice_sn = '" . $delivery_sn . "' and is_arrival = 0 and order_id = " . $order_info['id']); $log = "订单:" . $order_info['order_sn'] . ",运单:" . $delivery_sn . "未收到货"; order_log($log, $order_id); update_order_cache($order_info['id']); distribute_order($order_info['id']); return true; } } return false; }
public function index() { $city_name = strim($GLOBALS['request']['city_name']); //城市名称 $root = array(); //检查用户,用户密码 $user = $GLOBALS['user_info']; $user_id = intval($user['id']); $root['return'] = 1; if ($user_id > 0) { $did = intval($GLOBALS['request']['did']); $cid = intval($GLOBALS['request']['cid']); $content = strim($GLOBALS['request']['content']); if (empty($content)) { $root['status'] = 0; $root['info'] = "请填写退款原因"; output($root); } if ($did) { //退单 $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $did); $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = '" . $deal_order_item['order_id'] . "' and order_status = 0 and user_id = " . $user_id); if ($order_info) { if ($deal_order_item['delivery_status'] == 0 && $order_info['pay_status'] == 2 && $deal_order_item['is_refund'] == 1) { if ($deal_order_item['refund_status'] == 0) { //执行退单,标记:deal_order_item表与deal_order表, $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $deal_order_item['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $deal_order_item['order_id']); $msg = array(); $msg['rel_table'] = "deal_order"; $msg['rel_id'] = $deal_order_item['order_id']; $msg['title'] = "退款申请"; $msg['content'] = "退款申请:" . $content; $msg['create_time'] = NOW_TIME; $msg['user_id'] = $user_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg); update_order_cache($deal_order_item['order_id']); order_log($deal_order_item['sub_name'] . "申请退款,等待审核", $deal_order_item['order_id']); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($order_info['id']); $root['status'] = 1; $root['info'] = "退款申请已提交,请等待审核"; output($root); } else { $root['status'] = 0; $root['info'] = "不允许退款"; output($root); } } else { $root['status'] = 0; $root['info'] = "非法操作"; output($root); } } else { $root['status'] = 0; $root['info'] = "非法操作"; output($root); } } elseif ($cid) { //退券 $coupon = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where user_id = " . $user_id . " and id = " . $cid); if ($coupon) { if ($coupon['refund_status'] == 0 && $coupon['confirm_time'] == 0) { //从未退过款可以退款,且未使用过 if ($coupon['any_refund'] == 1 || $coupon['expire_refund'] == 1 && $coupon['end_time'] > 0 && $coupon['end_time'] < NOW_TIME) { //随时退或过期退已过期 //执行退券 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 1 where id = " . $coupon['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $coupon['order_deal_id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $coupon['order_id']); $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $coupon['order_deal_id']); $msg = array(); $msg['rel_table'] = "deal_order"; $msg['rel_id'] = $coupon['order_id']; $msg['title'] = "退款申请"; $msg['content'] = $content; $msg['create_time'] = NOW_TIME; $msg['user_id'] = $user_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg); update_order_cache($coupon['order_id']); order_log($deal_order_item['sub_name'] . "申请退一张团购券,等待审核", $coupon['order_id']); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($coupon['order_id']); $root['status'] = 1; $root['info'] = "退款申请已提交,请等待审核"; output($root); } else { $root['status'] = 0; $root['info'] = "不允许退款"; output($root); } } else { $root['status'] = 0; $root['info'] = "非法操作"; output($root); } } else { $root['status'] = 0; $root['info'] = "非法操作"; output($root); } } else { $root['status'] = 0; $root['info'] = "非法操作"; output($root); } } else { $root['user_login_status'] = 0; } output($root); }
function order_paid_done($order_id) { //处理支付成功后的操作 /** * 1. 发货 * 2. 超量发货的存到会员中心 * 3. 发券 * 4. 发放抽奖 */ require_once APP_ROOT_PATH . "system/model/deal.php"; require_once APP_ROOT_PATH . "system/model/supplier.php"; require_once APP_ROOT_PATH . "system/model/deal_order.php"; $order_id = intval($order_id); $stock_status = true; //团购状态 $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id); if ($order_info['type'] == 0) { //首先验证所有的规格库存 $order_goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); foreach ($order_goods_list as $k => $v) { if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "attr_stock where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0")) { $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count + " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and ((buy_count + " . $v['number'] . " <= stock_cfg) or stock_cfg = 0 )" . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 "; $GLOBALS['db']->query($sql); //增加商品的发货量 $rs = $GLOBALS['db']->affected_rows(); if ($rs) { $affect_attr_list[] = $v; } else { $stock_status = false; break; } } } if ($stock_status) { $goods_list = $GLOBALS['db']->getAll("select buy_type,deal_id,sum(number) as num,sum(add_balance_price_total) as add_balance_price_total,sum(balance_total_price) as balance_total_price,sum(return_total_money) as return_total_money,sum(return_total_score) as return_total_score from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " group by deal_id"); foreach ($goods_list as $k => $v) { $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count + " . $v['num'] . ",user_count = user_count + 1 where id=" . $v['deal_id'] . " and ((buy_count + " . $v['num'] . "<= max_bought) or max_bought = 0) " . " and time_status = 1 and buy_status <> 2"; $GLOBALS['db']->query($sql); //增加商品的发货量 $rs = $GLOBALS['db']->affected_rows(); if ($rs) { $affect_list[] = $v; //记录下更新成功的团购商品,用于回滚 } else { //失败成功,即过期支付,超量支付 $stock_status = false; break; } } } $return_money = 0; //非发券非配送的即时返还 $return_score = 0; //非发券非配送的即时返还 $use_score = 0; //积分商品所耗费的积分 if ($stock_status) { foreach ($goods_list as $k => $v) { $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($v['deal_id'])); //统计商户销售额 $supplier_log = "ID:" . $deal_info['id'] . " " . $deal_info['sub_name'] . " 订单:" . $order_info['order_sn']; modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 0, $supplier_log); if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0) { //更新订单中相关产品的消费状态 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set consume_count = consume_count + 1 where order_id = " . $order_info['id'] . " and deal_id = " . $deal_info['id']); update_order_cache($order_info['id']); distribute_order($order_info['id']); modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 2, $supplier_log); //等结算金额增加 } else { modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 1, $supplier_log); //冻结资金 } //不发货不发券的实时返还 if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0 && $v['buy_type'] == 0) { $return_money += $v['return_total_money']; $return_score += $v['return_total_score']; } if ($v['buy_type'] == 1) { $use_score += $v['return_total_score']; } $balance_price += $v['balance_total_price']; $add_balance_price += $v['add_balance_price_total']; //发券 if ($deal_info['is_coupon'] == 1) { if ($deal_info['deal_type'] == 1) { $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']); foreach ($deal_order_item_list as $item) { // for($i=0;$i<$item['number'];$i++) //按单 // { //需要发券 /** * 1. 先从已有团购券中发送 * 2. 无有未发送的券,自动发送 * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理 */ /*修正后台手动建团购劵,购买的时候按单发送团购劵,数量不一致*/ $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['total_price'] . ",coupon_score = " . $item['return_total_score'] . ",coupon_money = " . $item['return_total_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_total_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 order by id ASC limit 1"; $GLOBALS['db']->query($sql); $exist_coupon = $GLOBALS['db']->affected_rows(); if (!$exist_coupon) { //未发送成功,即无可发放的预设团购券 add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']); } // } } } else { $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']); foreach ($deal_order_item_list as $item) { for ($i = 0; $i < $item['number']; $i++) { //需要发券 /** * 1. 先从已有团购券中发送 * 2. 无有未发送的券,自动发送 * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理 */ $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['unit_price'] . ",coupon_score = " . $item['return_score'] . ",coupon_money = " . $item['return_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_unit_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 limit 1"; $GLOBALS['db']->query($sql); $exist_coupon = $GLOBALS['db']->affected_rows(); if (!$exist_coupon) { //未发送成功,即无可发放的预设团购券 add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']); } } } } } //发券结束 } //开始处理返还的积分或现金,此处返还不用发货不用配送不用发券的产品返还 require_once APP_ROOT_PATH . "system/model/user.php"; if ($return_money != 0) { $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_MONEY'], $order_info['order_sn']); modify_account(array('money' => $return_money, 'score' => 0), $order_info['user_id'], $msg); } if ($return_score != 0) { $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_SCORE'], $order_info['order_sn']); modify_account(array('money' => 0, 'score' => $return_score), $order_info['user_id'], $msg); send_score_sms($order_info['id']); send_score_mail($order_info['id']); } if ($use_score != 0) { $user_score = $GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . $order_info['user_id']); if ($user_score + $use_score < 0) { //积分不足,不能支付 $msg = $order_info['order_sn'] . "订单支付失败,积分不足"; $refund_money = $order_info['pay_amount']; if ($order_info['account_money'] > $refund_money) { $account_money_now = $order_info['account_money'] - $refund_money; } else { $account_money_now = 0; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']); if ($order_info['ecv_money'] > $refund_money) { $ecv_money_now = $order_info['ecv_money'] - $refund_money; } else { $ecv_money_now = 0; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']); if ($refund_money > 0) { modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . ",after_sale = 1,refund_status = 2 where id = " . $order_info['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']); order_log($order_info['order_sn'] . "积分不足," . format_price($refund_money) . "已退到会员余额", $order_info['id']); modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "积分不足,退款"); modify_statements($refund_money, 2, $order_info['order_sn'] . "积分不足,退款"); } else { order_log($order_info['order_sn'] . "积分不足", $order_info['id']); } require_once APP_ROOT_PATH . "system/model/deal_order.php"; update_order_cache($order_info['id']); over_order($order_info['id']); } else { modify_account(array('score' => $use_score), $order_info['user_id'], "积分商品兑换"); send_score_sms($order_info['id']); send_score_mail($order_info['id']); order_log($order_info['order_sn'] . "积分订单支付成功", $order_info['id']); send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "兑换成功", "orderitem", $order_goods_list[0]['id']); if ($order_info['total_price'] > 0) { modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款"); } //增加营业额 } } else { //开始处理返利,只创建返利, 发放将与msg_list的自动运行一起执行 // $user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$order_info['user_id']); // //开始查询所购买的列表中支不支持促销 // $is_referrals = 1; //默认为返利 // foreach($goods_list as $k=>$v) // { // $is_referrals = $GLOBALS['db']->getOne("select is_referral from ".DB_PREFIX."deal where id = ".$v['deal_id']); // if($is_referrals == 0) // { // break; // } // } // if($user_info['referral_count']<app_conf("REFERRAL_LIMIT")&&$is_referrals == 1) // { // //开始返利给推荐人 // $parent_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$user_info['pid']); // if($parent_info) // { // if((app_conf("REFERRAL_IP_LIMIT")==1&&$parent_info['login_ip']!=CLIENT_IP)||app_conf("REFERRAL_IP_LIMIT")==0) //IP限制 // { // if(app_conf("INVITE_REFERRALS_TYPE")==0) //现金返利 // { // $referral_data['user_id'] = $parent_info['id']; //初返利的会员ID // $referral_data['rel_user_id'] = $user_info['id']; //被推荐且发生购买的会员ID // $referral_data['create_time'] = NOW_TIME; // $referral_data['money'] = app_conf("INVITE_REFERRALS"); // $referral_data['order_id'] = $order_info['id']; // $GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入 // } // else // { // $referral_data['user_id'] = $parent_info['id']; //初返利的会员ID // $referral_data['rel_user_id'] = $user_info['id']; //被推荐且发生购买的会员ID // $referral_data['create_time'] = NOW_TIME; // $referral_data['score'] = app_conf("INVITE_REFERRALS"); // $referral_data['order_id'] = $order_info['id']; // $GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入 // } // $GLOBALS['db']->query("update ".DB_PREFIX."user set referral_count = referral_count + 1 where id = ".$user_info['id']); // } // } // } //超出充值 if ($order_info['pay_amount'] > $order_info['total_price']) { require_once APP_ROOT_PATH . "system/model/user.php"; if ($order_info['total_price'] < 0) { $msg = sprintf($GLOBALS['lang']['MONEYORDER_INCHARGE'], $order_info['order_sn']); } else { $msg = sprintf($GLOBALS['lang']['OUTOFMONEY_INCHARGE'], $order_info['order_sn']); } $refund_money = $order_info['pay_amount'] - $order_info['total_price']; if ($order_info['account_money'] > $refund_money) { $account_money_now = $order_info['account_money'] - $refund_money; } else { $account_money_now = 0; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']); if ($order_info['ecv_money'] > $refund_money) { $ecv_money_now = $order_info['ecv_money'] - $refund_money; } else { $ecv_money_now = 0; } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']); modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . " where id = " . $order_info['id']); order_log($order_info['order_sn'] . "订单超额支付," . format_price($refund_money) . "已退到会员余额", $order_info['id']); modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "订单超额"); modify_statements($refund_money, 2, $order_info['order_sn'] . "订单超额"); } modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款"); //增加营业额 $balance_total = $GLOBALS['db']->getOne("select sum(balance_total_price)+sum(add_balance_price_total) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id']); modify_statements($balance_total, 9, $order_info['order_sn'] . "订单成功付款"); //增加营业额中的成本 //生成抽奖 $lottery_list = $GLOBALS['db']->getAll("select d.id as did,doi.number from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id left join " . DB_PREFIX . "deal as d on doi.deal_id = d.id where d.is_lottery = 1 and do.id = " . $order_info['id']); $lottery_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($order_info['user_id'])); //如为首次抽奖,先为推荐人生成抽奖号 $lottery_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where user_id = " . intval($order_info['user_id'])); if ($lottery_count == 0 && $lottery_user['pid'] != 0) { $lottery_puser = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($lottery_user['pid'])); foreach ($lottery_list as $lottery) { $k = 0; do { if ($k > 10) { break; } $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']); $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 ")); //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1")); $sn = $max_sn + 1; $sn = str_pad($sn, "6", "0", STR_PAD_LEFT); $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $lottery_puser['id'] . ",'" . $lottery_puser['lottery_mobile'] . "'," . NOW_TIME . "," . $order_info['user_id'] . " from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')"; $GLOBALS['db']->query($sql); send_lottery_sms(intval($GLOBALS['db']->insert_id())); $k++; } while (intval($GLOBALS['db']->insert_id()) == 0); } } foreach ($lottery_list as $lottery) { for ($i = 0; $i < $lottery['number']; $i++) { $k = 0; do { if ($k > 10) { break; } $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']); $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 ")); //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1")); $sn = $max_sn + $i + 1; $sn = str_pad($sn, "6", "0", STR_PAD_LEFT); $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $order_info['user_id'] . ",'" . $lottery_user['mobile'] . "'," . NOW_TIME . ",0 from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')"; $GLOBALS['db']->query($sql); send_lottery_sms(intval($GLOBALS['db']->insert_id())); $k++; } while (intval($GLOBALS['db']->insert_id()) == 0); } } send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "付款成功", "orderitem", $order_goods_list[0]['id']); } } else { //开始模拟事务回滚 foreach ($affect_attr_list as $k => $v) { $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count - " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 "; $GLOBALS['db']->query($sql); //回滚已发的货量 } foreach ($affect_list as $k => $v) { $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count - " . $v['num'] . ",user_count = user_count - 1 where id=" . $v['deal_id']; $GLOBALS['db']->query($sql); //回滚已发的货量 } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']); //超出充值 require_once APP_ROOT_PATH . "system/model/user.php"; $msg = sprintf($GLOBALS['lang']['OUTOFSTOCK_INCHARGE'], $order_info['order_sn']); modify_account(array('money' => $order_info['total_price'], 'score' => 0), $order_info['user_id'], $msg); order_log($order_info['order_sn'] . "订单库存不足," . format_price($order_info['total_price']) . "已退到会员余额", $order_info['id']); modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "订单库存不足"); modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "订单库存不足"); //将订单的extra_status 状态更新为2,并自动退款 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set extra_status = 2, after_sale = 1, refund_money = pay_amount where id = " . intval($order_info['id'])); update_order_cache($order_info['id']); //记录退款的订单日志 $log['log_info'] = $msg; $log['log_time'] = NOW_TIME; $log['order_id'] = intval($order_info['id']); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_log", $log); } //同步所有未过期的团购状态 foreach ($goods_list as $item) { syn_deal_status($item['deal_id'], true); } auto_over_status($order_id); //自动结单 } else { //订单充值 // $GLOBALS['db']->query("update ".DB_PREFIX."deal_order set order_status = 1 where id = ".$order_info['id']); //充值单自动结单 require_once APP_ROOT_PATH . "system/model/user.php"; $msg = sprintf($GLOBALS['lang']['USER_INCHARGE_DONE'], $order_info['order_sn']); modify_account(array('money' => $order_info['total_price'] - $order_info['payment_fee'], 'score' => 0), $order_info['user_id'], $msg); modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "会员充值"); modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "会员充值,含手续费"); send_msg($order_info['user_id'], "成功充值" . format_price($order_info['total_price'] - $order_info['payment_fee']), "notify", $order_id); auto_over_status($order_id); //自动结单 } }
/** * 提交保存点评 * @param unknown_type $user_id 提交点评的会员 * @param unknown_type $param 参数 详细规则见 check_dp_status函数说明 * @param unknown_type $content 点评文字内容 * @param unknown_type $dp_point 总评分 * @param unknown_type $dp_image 点评的图片数组 array("./public/...","./public/....."); * @param unknown_type $tag_group 点评标签(二维数组),格式如下 * array( * "group_id" = array("tag","tag") * ); 其中group_id为分组的ID,第二维为每个分组中的tag * @param unknown_type $point_group 点评评分分组数据,格式如下 * array( * "group_id" => "point" * ); 其中group_id为分组的ID,point为对应分组的评分 * * 返回 array("status"=>bool, "info"=>"消息","location_id"=>"门店的ID","deal_id"=>"","youhui_id"=>"","event_id"=>""); */ function save_review($user_id, $param = array("deal_id" => 0, "youhui_id" => 0, "event_id" => 0, "location_id" => 0, "order_item_id" => 0, "youhui_log_id" => 0, "event_submit_id" => 0), $content, $dp_point, $dp_image = array(), $tag_group = array(), $point_group = array()) { //获取参数 $order_item_id = intval($param['order_item_id']); //订单商品ID $youhui_log_id = intval($param['youhui_log_id']); //优惠券领取日志ID $event_submit_id = intval($param['event_submit_id']); //活动报名日志ID if ($order_item_id > 0) { $deal_id = intval($GLOBALS['db']->getOne("select deal_id from " . DB_PREFIX . "deal_order_item where id = " . $order_item_id)); } else { $deal_id = intval($param['deal_id']); } if ($youhui_log_id > 0) { $youhui_id = intval($GLOBALS['db']->getOne("select youhui_id from " . DB_PREFIX . "youhui_log where id = " . $youhui_log_id)); } else { $youhui_id = intval($param['youhui_id']); } if ($event_submit_id > 0) { $event_id = intval($GLOBALS['db']->getOne("select event_id from " . DB_PREFIX . "event_submit where id = " . $event_submit_id)); } else { $event_id = intval($param['event_id']); } $location_id = intval($param['location_id']); //部份初始化的变量 $is_buy = 0; //默认的点评为非购物点评 $avg_price = 0; //均价为0 if ($deal_id > 0) { require_once APP_ROOT_PATH . "system/model/deal.php"; $deal_info = get_deal($deal_id); if ($deal_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("deal_id" => $deal_id, "order_item_id" => $order_item_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } $is_buy = 1; $avg_price = $checker['avg_price']; } else { return array("status" => false, "info" => "你要点评的商品不存在"); } } elseif ($youhui_id > 0) { require_once APP_ROOT_PATH . "system/model/youhui.php"; $youhui_info = get_youhui($youhui_id); if ($youhui_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("youhui_id" => $youhui_id, "youhui_log_id" => $youhui_log_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的优惠券不存在"); } } elseif ($event_id > 0) { require_once APP_ROOT_PATH . "system/model/event.php"; $event_info = get_event($event_id); if ($event_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("event_id" => $event_id, "event_submit_id" => $event_submit_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的活动不存在"); } } elseif ($location_id > 0) { require_once APP_ROOT_PATH . "system/model/supplier.php"; $location_info = get_location($location_id); if ($location_info) { //验证是否可以点评 $checker = check_dp_status($GLOBALS['user_info']['id'], array("location_id" => $location_id)); if (!$checker['status']) { return array("status" => false, "info" => $checker['info']); } else { $supplier_location_id = $checker['supplier_location_id']; } } else { return array("status" => false, "info" => "你要点评的商家不存在"); } } if ($deal_id == 0 && $youhui_id == 0 && $event_id == 0 && $location_id == 0) { return array("status" => false, "info" => "非法的数据"); } //点评入库 $supplier_info = $GLOBALS['db']->getRow("select name,id,new_dp_count_time,supplier_id from " . DB_PREFIX . "supplier_location where id = " . intval($supplier_location_id)); $supplier_id = $supplier_info['supplier_id']; $dp_data = array(); if ($content != "") { $dp_data['is_content'] = 1; $dp_data['content'] = $content; } $dp_data['create_time'] = NOW_TIME; $dp_data['point'] = $dp_point; $dp_data['user_id'] = $user_id; $dp_data['supplier_location_id'] = $supplier_location_id; $dp_data['youhui_id'] = $youhui_id; $dp_data['event_id'] = $event_id; $dp_data['deal_id'] = $deal_id; $dp_data['images_cache'] = serialize($dp_image); $dp_data['supplier_id'] = $supplier_id; $dp_data['status'] = 1; if (count($dp_image) > 0) { $dp_data['is_img'] = 1; } $dp_data['avg_price'] = floatval($avg_price); $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $dp_data, "INSERT"); $dp_id = $GLOBALS['db']->insert_id(); if ($dp_id > 0) { if ($checker['order_item_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set dp_id = " . $dp_id . " where id = '" . $checker['order_item_id'] . "'"); $order_id = intval($GLOBALS['db']->getOne("select order_id from " . DB_PREFIX . "deal_order_item where id = " . $checker['order_item_id'])); update_order_cache($order_id); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($order_id); } if ($checker['youhui_log_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "youhui_log set dp_id = " . $dp_id . " where id = '" . $checker['youhui_log_id'] . "'"); } if ($checker['event_submit_id']) { $GLOBALS['db']->query("update " . DB_PREFIX . "event_submit set dp_id = " . $dp_id . " where id = '" . $checker['event_submit_id'] . "'"); } increase_user_active($user_id, "发表了一则点评"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count + 1 where id = " . $user_id); //创建点评图库 if (count($dp_image) > 0) { foreach ($dp_image as $pkey => $photo) { //点评图片不入商户图片库 // $c_data = array(); // $c_data['image'] = $photo; // $c_data['sort'] = 10; // $c_data['create_time'] = NOW_TIME; // $c_data['user_id'] = $user_id; // $c_data['supplier_location_id'] = $supplier_location_id; // $c_data['dp_id'] = $dp_id; // $c_data['status'] = 0; // $GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_images", $c_data,"INSERT"); $c_data = array(); $c_data['image'] = $photo; $c_data['dp_id'] = $dp_id; $c_data['create_time'] = NOW_TIME; $c_data['location_id'] = $supplier_location_id; $c_data['supplier_id'] = $supplier_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_images", $c_data, "INSERT"); } } //创建点评评分 foreach ($point_group as $group_id => $point) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['supplier_location_id'] = $supplier_location_id; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_point_result", $point_data, "INSERT"); //创建商品点评数据 if ($dp_data['deal_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['deal_id'] = $dp_data['deal_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_point_result", $point_data, "INSERT"); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['youhui_id'] = $dp_data['youhui_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_point_result", $point_data, "INSERT"); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { $point_data = array(); $point_data['group_id'] = $group_id; $point_data['dp_id'] = $dp_id; $point_data['event_id'] = $dp_data['event_id']; $point_data['point'] = $point; $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_point_result", $point_data, "INSERT"); } } //创建点评分组的标签 foreach ($tag_group as $group_id => $tag_row_arr) { foreach ($tag_row_arr as $tag_row) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['supplier_location_id'] = $supplier_location_id; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_tag_result", $tag_row_data, "INSERT"); insert_match_item($tag_row, "supplier_location_dp", $dp_id, "tags_match"); //更新点评的索引 review_supplier_location_match($supplier_location_id, $tag_row, $group_id); //创建商品点评数据 if ($dp_data['deal_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['deal_id'] = $dp_data['deal_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_tag_result", $tag_row_data, "INSERT"); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['youhui_id'] = $dp_data['youhui_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_tag_result", $tag_row_data, "INSERT"); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { $tag_row_data = array(); $tag_row_data['tags'] = $tag_row; $tag_row_data['dp_id'] = $dp_id; $tag_row_data['event_id'] = $dp_data['event_id']; $tag_row_data['group_id'] = $group_id; $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_tag_result", $tag_row_data, "INSERT"); } } } //更新统计 syn_supplier_locationcount($supplier_info); cache_store_point($supplier_info['id']); //统计商品点评数据 if ($dp_data['deal_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $dp_data['deal_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where deal_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_deal_review_count($item_data['id']); } //创建优惠券点评数据 if ($dp_data['youhui_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "youhui where id = " . $dp_data['youhui_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where youhui_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_youhui_review_count($item_data['id']); } //创建活动点评数据 if ($dp_data['event_id'] > 0) { //计算总点评1-5星人数 $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "event where id = " . $dp_data['event_id']); $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where event_id = " . $item_data['id'] . " group by point "; $data_result = $GLOBALS['db']->getAll($sql); foreach ($data_result as $k => $v) { $item_data['dp_count_' . $v['point']] = $v['total']; } $GLOBALS['db']->autoExecute(DB_PREFIX . "event", $item_data, "UPDATE", " id = " . $item_data['id'] . " "); syn_event_review_count($item_data['id']); } $return['location_id'] = $supplier_location_id; $return['deal_id'] = $dp_data['deal_id']; $return['youhui_id'] = $dp_data['youhui_id']; $return['event_id'] = $dp_data['event_id']; $return['status'] = 1; $return['info'] = "发表成功"; return $return; } else { $return['status'] = 0; $return['info'] = "数据库异常,提交失败"; return $return; } }
public function index() { $city_name = strim($GLOBALS['request']['city_name']); //城市名称 $root = array(); $root['page_title'] = '技师订单'; $root['mana_page_title'] = '技师订单'; //检查用户,用户密码 $user = $GLOBALS['user_info']; $user_id = intval($user['id']); $root['return'] = 1; if ($user_id > 0) { $tech_id = $GLOBALS['request']['tech_id']; $tech = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "user WHERE id =" . $tech_id); $root['tech_name'] = $tech['user_name']; $root['user_login_status'] = 1; //配置分页参数 require_once APP_ROOT_PATH . "wap/lib/page.php"; $page_size = 10; $page = intval($GLOBALS['request']['page']); if ($page == 0) { $page = 1; } $limit = ($page - 1) * $page_size . "," . $page_size; $sql = "select do.* from " . DB_PREFIX . "deal_order as do where do.is_delete = 0 and " . " do.technician_id = " . $tech_id . " and do.type = 0 order by do.create_time desc limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "deal_order as do where do.is_delete = 0 and " . " do.technician_id = " . $tech_id . " and do.type = 0 "; $list = $GLOBALS['db']->getAll($sql); foreach ($list as $k => $v) { $c_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $v['user_id']); $list[$k]['user_id'] = $v['user_id']; $list[$k]['user_name'] = $c_user['user_name']; $list[$k]['user_mobile'] = $c_user['mobile']; //服务项目 $deals = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "deal WHERE id IN(" . $v['deal_ids'] . ") ORDER BY id DESC"); $deal_order_item_for_dp = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $v['id'] . ' limit 1'); foreach ($deals as $key => $value) { $comment = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "supplier_location_dp WHERE id = " . $deal_order_item_for_dp['dp_id'] . " ORDER BY create_time DESC LIMIT 1"); if (!empty($comment)) { $list[$k]['user_comment'] = $comment['content']; //星级 for ($i = 0; $i < $comment['point']; $i++) { $list[$k]['points'][] = $i; } break; } } $list[$k]['deals'] = $deals; $list[$k]['create_time'] = to_date($v['create_time']); $list[$k]['pay_amount'] = format_price($v['pay_amount']); $list[$k]['total_price'] = format_price($v['total_price']); if ($v['deal_order_item']) { $list[$k]['deal_order_item'] = unserialize($v['deal_order_item']); } else { $order_id = $v['id']; update_order_cache($order_id); $list[$k]['deal_order_item'] = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); } $list[$k]['c'] = count($list[$k]['deal_order_item']); foreach ($list[$k]['deal_order_item'] as $kk => $vv) { $list[$k]['deal_order_item'][$kk]['total_price'] = format_price($vv['total_price']); $deal_info = load_auto_cache("deal", array("id" => $vv['deal_id'])); $list[$k]['deal_order_item'][$kk]['url'] = $deal_info['url']; } } $list[$k]['complain'] = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_complain where order_id= " . $v['id'] . " limit 1"); //配置分页 $count = $GLOBALS['db']->getOne($sql_count); $page_total = ceil($count / $page_size); $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size); $root['list'] = $list; } else { $root['user_login_status'] = 0; } $root['user'] = $user; $root['city_name'] = $city_name; output($root); }
public function index() { $id = intval($GLOBALS['request']['id']); if ($id == '') { $root['status'] = 0; $root['info'] = '订单号不能为空'; } /*设置发货开始*/ $silent = intval($_REQUEST['silent']); $order_id = $id; $order_items = $GLOBALS['db']->getAll("select id from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); foreach ($order_items as $k => $v) { $order_deals[] = $v['id']; } $delivery_sn = $_REQUEST['delivery_sn']; $express_id = intval($_REQUEST['express_id']); $memo = $_REQUEST['memo']; if (!$order_deals) { } else { $deal_names = array(); foreach ($order_deals as $order_deal_id) { $deal_info = $GLOBALS['db']->getRow("select d.*,doi.id as doiid from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_order_item as doi on doi.deal_id = d.id where doi.id = " . $order_deal_id); $deal_name = $deal_info['sub_name']; array_push($deal_names, $deal_name); $rs = make_delivery_notice($order_id, $order_deal_id, $delivery_sn, $memo, $express_id); if ($rs) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set delivery_status = 1,is_arrival = 0 where id = " . $order_deal_id); update_balance($order_deal_id, $deal_info['id']); } } $deal_names = implode(",", $deal_names); //开始同步订单的发货状态 $order_deal_items = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); foreach ($order_deal_items as $k => $v) { if ($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "Deal where id = " . $v['deal_id']) == 0) { unset($order_deal_items[$k]); } } $delivery_deal_items = $order_deal_items; foreach ($delivery_deal_items as $k => $v) { if ($v['delivery_status'] == 0) { unset($delivery_deal_items[$k]); } } if (count($delivery_deal_items) == 0 && count($order_deal_items) != 0) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 0 where id = " . $order_id); //未发货 } elseif (count($delivery_deal_items) > 0 && count($order_deal_items) != 0 && count($delivery_deal_items) < count($order_deal_items)) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 1 where id = " . $order_id); //部分发 } else { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 2 where id = " . $order_id); //全部发 } $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set update_time = " . time() . ",is_refuse_delivery=0 where id = " . $order_id); //全部发 $refund_item_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order_item where (refund_status = 1 or is_arrival = 2) and order_id = " . $order_id); $coupon_item_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_coupon where refund_status = 1 and order_id = " . $order_id); if ($refund_item_count == 0 && $coupon_item_count == 0) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 0,is_refuse_delivery=0 where id = " . $order_id); } //查询快递名 $express_name = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "Express where id = " . $express_id); require_once APP_ROOT_PATH . "system/model/deal_order.php"; order_log("发货成功" . $express_name . $delivery_sn . $_REQUEST['memo'], $order_id); update_order_cache($order_id); distribute_order($order_id); } /*设置发货结束*/ $result = $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", array("service_start_time" => time()), "UPDATE", "id=" . intval($id)); // 更新服务时间为当前时间 if ($result) { $root['status'] = 1; $root['info'] = '服务开始'; } output($root); }
public function index() { //logUtils::log_obj($GLOBALS['request']); //检查用户,用户密码 $user = $GLOBALS['user_info']; $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; $root['order_id'] = $order_id; if ($user_id > 0) { $root['user_login_status'] = 1; //开始计算订单 //logUtils::log_str("==================1=================="); $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); } } $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/model/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']); } //logUtils::log_obj($data); //logUtils::log_str("==================2=================="); 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 ($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); } //结束验证订单接交信息 //logUtils::log_str("==================3=================="); //开始修正订单 $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)); } //logUtils::log_obj($order_info); $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order_info, 'UPDATE', 'id=' . $order_info['id'], 'SILENT'); //logUtils::log_str("==================4=================="); //生成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']); update_order_cache($order_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 do_delivery() { $s_account_info = $GLOBALS['account_info']; $supplier_id = intval($s_account_info['supplier_id']); require_once APP_ROOT_PATH . "system/model/deal_order.php"; $order_item_table_name = get_supplier_order_item_table_name($supplier_id); $order_table_name = get_supplier_order_table_name($supplier_id); $id = intval($_REQUEST['id']); //发货商品的ID $delivery_sn = strim($_REQUEST['delivery_sn']); $memo = strim($_REQUEST['memo']); $express_id = intval($_REQUEST['express_id']); $location_id = intval($_REQUEST['location_id']); $order_id = $GLOBALS['db']->getOne("select order_id from " . $order_item_table_name . " where id = " . $id); $order_info = $GLOBALS['db']->getRow("select * from " . $order_table_name . " where id = '" . $order_id . "'"); if (empty($delivery_sn)) { $data['status'] = 0; $data['info'] = "请输入快递单号"; ajax_return($data); } $item = $GLOBALS['db']->getRow("select doi.* from " . $order_item_table_name . " as doi left join " . DB_PREFIX . "deal_location_link as l on doi.deal_id = l.deal_id where doi.id = " . $id . " and l.location_id in (" . implode(",", $s_account_info['location_ids']) . ")"); if ($item) { $rs = make_delivery_notice($order_id, $id, $delivery_sn, $memo, $express_id, $location_id); if ($rs) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set delivery_status = 1 where id = " . $id); } send_delivery_mail($delivery_sn, $item['name'], $order_id); send_delivery_sms($delivery_sn, $item['name'], $order_id); //开始同步订单的发货状态 $order_deal_items = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id); foreach ($order_deal_items as $k => $v) { if ($v['delivery_status'] == 5) { unset($order_deal_items[$k]); } } $delivery_deal_items = $order_deal_items; foreach ($delivery_deal_items as $k => $v) { if ($v['delivery_status'] == 0) { unset($delivery_deal_items[$k]); } } if (count($delivery_deal_items) == 0 && count($order_deal_items) != 0) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 0,update_time = '" . NOW_TIME . "' where id = " . $order_id); //未发货 } elseif (count($delivery_deal_items) > 0 && count($order_deal_items) != 0 && count($delivery_deal_items) < count($order_deal_items)) { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 1,update_time = '" . NOW_TIME . "' where id = " . $order_id); //部分发 } else { $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 2,update_time = '" . NOW_TIME . "' where id = " . $order_id); //全部发 } order_log($item['name'] . "发货了,发货单号:" . $delivery_sn, $order_id); update_order_cache($order_id); distribute_order($order_id); send_msg($order_info['user_id'], $item['name'] . "发货了,发货单号:" . $delivery_sn, "orderitem", $item['id']); $data['status'] = 1; $data['info'] = "发货成功"; ajax_return($data); } else { $data['status'] = 0; $data['info'] = "非法的数据"; ajax_return($data); } }
/** * 退款申请 */ public function do_refund() { global_run(); if (check_save_login() != LOGIN_STATUS_LOGINED) { $data['status'] = 1000; ajax_return($data); } else { $did = intval($_REQUEST['did']); $cid = intval($_REQUEST['cid']); $content = strim($_REQUEST['content']); if (empty($content)) { $data['status'] = 0; $data['info'] = "请填写退款原因"; ajax_return($data); } if ($did) { //退单 $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $did); $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = '" . $deal_order_item['order_id'] . "' and order_status = 0 and user_id = " . $GLOBALS['user_info']['id']); if ($order_info) { if ($deal_order_item['delivery_status'] == 0 && $order_info['pay_status'] == 2 && $deal_order_item['is_refund'] == 1) { if ($deal_order_item['refund_status'] == 0) { //执行退单,标记:deal_order_item表与deal_order表, $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $deal_order_item['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $deal_order_item['order_id']); $msg = array(); $msg['rel_table'] = "deal_order"; $msg['rel_id'] = $deal_order_item['order_id']; $msg['title'] = "退款申请"; $msg['content'] = "退款申请:" . $content; $msg['create_time'] = NOW_TIME; $msg['user_id'] = $GLOBALS['user_info']['id']; $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg); update_order_cache($deal_order_item['order_id']); order_log($deal_order_item['sub_name'] . "申请退款,等待审核", $deal_order_item['order_id']); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($order_info['id']); $data['status'] = true; $data['info'] = "退款申请已提交,请等待审核"; ajax_return($data); } else { $data['status'] = 0; $data['info'] = "不允许退款"; ajax_return($data); } } else { $data['status'] = 0; $data['info'] = "非法操作"; ajax_return($data); } } else { $data['status'] = 0; $data['info'] = "非法操作"; ajax_return($data); } } elseif ($cid) { //退券 $coupon = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where user_id = " . $GLOBALS['user_info']['id'] . " and id = " . $cid); if ($coupon) { if ($coupon['refund_status'] == 0 && $coupon['confirm_time'] == 0) { if ($coupon['any_refund'] == 1 || $coupon['expire_refund'] == 1 && $coupon['end_time'] > 0 && $coupon['end_time'] < NOW_TIME) { //执行退券 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 1 where id = " . $coupon['id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $coupon['order_deal_id']); $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $coupon['order_id']); $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $coupon['order_deal_id']); $msg = array(); $msg['rel_table'] = "deal_order"; $msg['rel_id'] = $coupon['order_id']; $msg['title'] = "退款申请"; $msg['content'] = $content; $msg['create_time'] = NOW_TIME; $msg['user_id'] = $GLOBALS['user_info']['id']; $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg); update_order_cache($coupon['order_id']); order_log($deal_order_item['sub_name'] . "申请退一张团购券,等待审核", $coupon['order_id']); require_once APP_ROOT_PATH . "system/model/deal_order.php"; distribute_order($coupon['order_id']); $data['status'] = true; $data['info'] = "退款申请已提交,请等待审核"; ajax_return($data); } else { $data['status'] = 0; $data['info'] = "不允许退款"; ajax_return($data); } } else { $data['status'] = 0; $data['info'] = "非法操作"; ajax_return($data); } } else { $data['status'] = 0; $data['info'] = "非法操作"; ajax_return($data); } } else { $data['status'] = 0; $data['info'] = "非法操作"; ajax_return($data); } } }