コード例 #1
0
 public function doexchange()
 {
     $user_id = $GLOBALS['user_info']['id'];
     $address_id = intval($_REQUEST['address_id']);
     $add_addr = intval($_REQUEST['add_addr']);
     $goods_id = intval($_REQUEST['goods_id']);
     $number = intval($_REQUEST['number']);
     $attr = $_REQUEST['attr'];
     if ($user_id == 0) {
         $return['info'] = "请先登录!";
         $return['status'] = 2;
         ajax_return($return);
     }
     if ($number <= 0) {
         $return['info'] = "请输入正确的兑换数量";
         $return['status'] = 0;
         ajax_return($return);
     }
     $return = array("jump" => url("index", "uc_goods_order"));
     $goods = get_goods_info($goods_id, $user_id);
     if ($goods <= 0) {
         $return['info'] = "商品不存在";
         $return['status'] = 0;
         ajax_return($return);
     }
     if ($number > $goods['user_can_buy_number']) {
         $return['info'] = "超出你所能兑换的数量";
         $return['status'] = 0;
         ajax_return($return);
     }
     //判断是否有属性库存
     $attr_stocks = get_attr_stock($goods, $number, $goods_id, $attr);
     if ($add_addr == 1 && $goods['is_delivery'] == 1) {
         $user_name = strim($_REQUEST['user_name']);
         //收货名称
         if ($user_name == "") {
             $return['info'] = "请输入收货人姓名";
             $return['status'] = 0;
             ajax_return($return);
         }
         $user_phone = strim($_REQUEST['user_phone']);
         if ($user_phone == "") {
             $return['info'] = "请输入收货人电话";
             $return['status'] = 0;
             ajax_return($return);
         }
         $user_address = strim($_REQUEST['user_address']);
         if ($user_address == "") {
             $return['info'] = "请输入收货人地址";
             $return['status'] = 0;
             ajax_return($return);
         }
         //提交地址
         $addr_data['user_id'] = $user_id;
         $addr_data['name'] = $user_name;
         $addr_data['address'] = $user_address;
         $addr_data['phone'] = $user_phone;
         $addr_data['is_default'] = 1;
         $GLOBALS['db']->autoExecute(DB_PREFIX . "user_address", $addr_data, "INSERT");
         $address_id = $GLOBALS['db']->insert_id();
         if (intval($address_id) == 0) {
             $return['info'] = "地址保存失败";
             $return['status'] = 0;
             ajax_return($return);
         }
     }
     //库存属性 star
     $order_data = array();
     if (isset($temp_attr_stock[$attr_str])) {
         $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "goods_attr_stock SET buy_count = buy_count +" . $number . " WHERE id=" . $temp_attr_stock[$attr_str]['id']);
         $order_data['attr_stock_id'] = $temp_attr_stock[$attr_str]['id'];
     }
     if ($attr) {
         $order_data['attr'] = serialize($attr);
     }
     //库存属性 end
     $user_info = $GLOBALS['user_info'];
     if (($goods['score'] + $goods_attr_scoresum) * $number > $user_info['score']) {
         $return['info'] = "积分不足,无法兑换";
         $return['status'] = 0;
         ajax_return($return);
     }
     $order_data['order_sn'] = to_date(get_gmtime(), "Ymdhis") . rand(10, 99);
     $order_data['goods_id'] = $goods_id;
     $order_data['goods_name'] = $goods['name'];
     $order_data['score'] = $goods['score'];
     $order_data['total_score'] = ($goods['score'] + $goods_attr_scoresum) * $number;
     //总积分 =(积分+属性积分)*数量
     $order_data['number'] = $number;
     //数量
     $order_data['delivery_sn'] = "";
     //快递单号
     $order_data['order_status'] = 0;
     //(0:未发货;1:已发货)
     $order_data['user_id'] = $user_id;
     $order_data['ex_time'] = TIME_UTC;
     $order_data['ex_date'] = to_date(TIME_UTC, "Y-m-d");
     $order_data['delivery_time'] = "";
     $order_data['delivery_date'] = "";
     $order_data['is_delivery'] = $goods['is_delivery'];
     require_once APP_ROOT_PATH . "system/libs/user.php";
     if (intval($goods['is_delivery']) == 1) {
         $sql = "SELECT * from " . DB_PREFIX . "user_address where id = " . $address_id;
         $address_info = $GLOBALS['db']->getRow($sql);
         //提交订单
         $order_data['delivery_addr'] = strim($address_info['address']);
         $order_data['delivery_tel'] = strim($address_info['phone']);
         $order_data['delivery_name'] = strim($address_info['name']);
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "goods_order", $order_data, "INSERT");
     if ($GLOBALS['db']->affected_rows()) {
         //订单提交成功,增加购买用户数和扣除积分
         $goods_data['buy_number'] = $goods['buy_number'] + $number;
         $goods_data['invented_number'] = $goods['invented_number'] + 1;
         $GLOBALS['db']->autoExecute(DB_PREFIX . "goods", $goods_data, "UPDATE", "id=" . $goods['id']);
         $msg = '积分兑换商品<a href="' . url("index", "goods_information#index", array("id" => $goods['id'])) . '" target="_blank">' . $order_data['goods_name'] . '</a>';
         modify_account(array('score' => -$order_data['total_score']), $GLOBALS['user_info']['id'], $msg, 22);
         $return['info'] = "兑换成功";
         $return['status'] = 1;
     } else {
         $return['info'] = "兑换失败";
         $return['status'] = 0;
     }
     ajax_return($return);
 }
コード例 #2
0
function get_stocklist()
{
    $result = get_filter();
    if ($result === false) {
        $filter = array();
        $filter['sid'] = empty($_REQUEST['sid']) ? '0' : intval($_REQUEST['sid']);
        $filter['ssid'] = empty($_REQUEST['ssid']) ? '0' : intval($_REQUEST['ssid']);
        $filter['goods_sn'] = empty($_REQUEST['goods_sn']) ? '' : trim($_REQUEST['goods_sn']);
        $filter['goods_name'] = empty($_REQUEST['goods_name']) ? '' : trim($_REQUEST['goods_name']);
        $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 's.goods_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
        $where = ' AND store_type_id=0 ';
        if (!empty($filter['goods_sn'])) {
            $sql1 = "select goods_id from " . $GLOBALS['ecs']->table('goods') . " where goods_sn like '%{$filter['goods_sn']}%' ";
            $goods_id1 = $GLOBALS['db']->getCol($sql1);
            if (count($goods_id1) > 0) {
                $where .= " AND goods_id in (" . implode(',', $goods_id1) . ")";
            } else {
                $where .= " AND 1!=1 ";
            }
        } elseif (!empty($filter['goods_name'])) {
            $sql1 = "select goods_id from " . $GLOBALS['ecs']->table('goods') . " where goods_name LIKE '%" . mysql_like_quote($filter['goods_name']) . "%' ";
            $res_goods = $GLOBALS['db']->query($sql1);
            $goods_id = "0";
            while ($row_goods = $GLOBALS['db']->fetchRow($res_goods)) {
                $goods_id .= "," . $row_goods['goods_id'];
            }
            $where .= " AND goods_id in ({$goods_id})";
        }
        if ($filter['ssid']) {
            $where .= " AND store_id = '" . $filter['ssid'] . "' ";
        } else {
            if ($filter['sid']) {
                $where .= " AND store_id in " . get_ssid_list($filter['sid']);
            }
        }
        /* 库存总数 */
        $sql = 'select count(*) from (select count(*) from ' . $GLOBALS['ecs']->table('store_goods_stock') . ' WHERE 1 ' . $where . " group by goods_id,store_id) AS countTemp  ";
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        $filter = page_and_size($filter);
        /* 获取库存数据 */
        $sql = 'SELECT stock_id, goods_id, store_id  ' . 'FROM ' . $GLOBALS['ecs']->table('store_goods_stock') . ' WHERE 1 ' . $where . ' group by goods_id,store_id  ORDER BY  NULL ';
        $filter['goods_name'] = stripslashes($filter['goods_name']);
        set_filter($filter, $sql);
    } else {
        $sql = $result['sql'];
        $filter = $result['filter'];
    }
    $arr = array();
    $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);
    while ($rows = $GLOBALS['db']->fetchRow($res)) {
        $sql = "select  goods_name, goods_sn, goods_thumb from " . $GLOBALS['ecs']->table('goods') . "  where goods_id='{$rows['goods_id']}' ";
        $goods_row = $GLOBALS['db']->getRow($sql);
        $rows['goods_thumb'] = get_image_path($rows['goods_id'], $goods_row['goods_thumb'], true);
        $rows['goods_name'] = $goods_row['goods_name'];
        $rows['goods_sn'] = $goods_row['goods_sn'];
        $rows['store_name'] = get_store_fullname($rows['store_id']);
        $rows['attr_stock'] = get_attr_stock($rows['goods_id'], $rows['store_id']);
        $arr[] = $rows;
    }
    return array('arr' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}