超子超 2015-03-21 23:52 采纳率: 0%
浏览 5049
已结题

如何把相同的订单号合并到一起?

/**********定单基本信息表******************/
drop table if exists sh_order;
create table sh_order
(
id mediumint unsigned not null auto_increment,
order_sn char(16) not null comment '定单编号',
member_id mediumint unsigned not null comment '会员id',
addtime int unsigned not null comment '下单时间',
pay_status enum("是","否") not null default '否' comment '支付状态',
post_status enum("是","否") not null default '否' comment '发货状态',
total_price decimal(10,2) not null comment '总价',
postage decimal(10,2) not null comment '邮费',
pay_time int unsigned not null default '0' comment '付款时间',
pay_method enum("支付宝") not null default '支付宝' comment '支付方式',
post_method enum("顺风","圆通") not null comment '配送方式',
shr_name varchar(30) not null comment '收货人',
shr_province varchar(30) not null comment '收货人省',
shr_city varchar(30) not null comment '收货城市',
shr_area varchar(30) not null comment '收货地区',
shr_address varchar(150) not null comment '收货地址',
shr_postcode varchar(30) not null comment '收货邮编',
shr_mobile varchar(30) not null comment '收货人手机',
primary key (id),
key member_id(member_id),
key order_sn(order_sn),
key addtime(addtime)
)engine=InnoDB default charset=utf8 comment '定单基本信息表';

/****************订单商品表**************************/
drop table if exists sh_order_goods;
create table sh_order_goods
(
id mediumint unsigned not null auto_increment,
order_id mediumint unsigned not null comment '定单id',
goods_id mediumint unsigned not null comment '商品id',
goods_name varchar(60) not null comment '商品名称',
goods_attr_id varchar(150) not null default '' comment '商品属性id',
price decimal(10,2) not null comment '购买时的价格',
goods_number int unsigned not null comment '购买的数量',
primary key (id),
key order_id(order_id),
key goods_id(goods_id)
)engine=InnoDB default charset=utf8 comment '定单商品表';

/**************商品表*******************/
drop table if exists sh_goods;
create table sh_goods
(
id mediumint unsigned not null auto_increment,
sm_logo varchar(150) not null default '' comment 'logo的缩略图路径(150*150)',
logo varchar(150) not null default '' comment 'logo的路径',
sm_show_pic varchar(150) not null default '' comment '展示图的缩略图路径(150*150)',
show_pic varchar(150) not null default '' comment '展示图的原图路径',
goods_brand_id mediumint unsigned not null comment '商品品牌id',
goods_name varchar(60) not null comment '商品名称',
market_price decimal(10,2) not null comment '市场价',
shop_price decimal(10,2) not null comment '本店价',
is_on_sale enum('是','否') not null default '是' comment '是否上架',
goods_number mediumint unsigned not null default '0' comment '库存量',
type_id mediumint unsigned not null default '0' comment '类型id',
goods_desc text comment '商品描述',
order_num tinyint unsigned not null default '100' comment '排序数字',
addtime int unsigned not null comment '添加时间',
primary key (id),
key shop_price(shop_price),
key is_on_sale(is_on_sale),
key addtime(addtime),
key order_num(order_num)
)engine=MyISAM default charset=utf8 comment '商品';

/**************商品属性表************************/
drop table if exists sh_goods_attr;
create table sh_goods_attr
(
id mediumint unsigned not null auto_increment,
goods_id mediumint unsigned not null comment '商品id',
attr_id mediumint unsigned not null comment '属性id',
attr_value varchar(150) default '' not null comment '属性的值',
primary key (id),
key goods_id(goods_id),
key attr_id(attr_id)
)engine=MyISAM default charset=utf8 comment '商品属性';

// Model模型中,根据会员ID从数据库中取出会员自己的订单,
public function getOrder($mid)
{
$orderModel = M('Order');
$orderData = $orderModel->field('a.order_sn, a.addtime, a.shr_name,
c.goods_name, c.sm_logo, b.goods_number,
b.price, d.attr_value, a.postage, a.post_status')
->alias('a')->join('LEFT JOIN sh_order_goods b ON a.id = b.order_id')->
join('LEFT JOIN sh_goods c ON b.goods_id = c.id')->
join('LEFT JOIN sh_goods_attr d ON b.goods_attr_id = d.id')
->where('a.member_id='.$mid)->select();
}

//在Controller控制器用户中心里调用
public function center()
{
if(session('id'))
{
$mid = session('id');//session('id')就是会员ID
$memberModel = D('Member/Member');
$orderData = $memberModel->getOrder($mid);
$this->assign('orderData',$orderData);
}
else
{
redirect('login');
}
$this->display();
}

HTML页面中输出:
<?php foreach($orderData as $k => $v):?>


<?php echo $v['order_sn'];?>
<?php showImage($v['sm_logo']);?>
<?php echo $v['goods_name'];?>
<?php echo $v['shr_name'];?>
<?php echo $v['goods_number'].' * '.$v['price'].'¥'.'='.$v['goods_number']*$v['price'].'¥' ;?>
<?php echo date('Y-m-d',$v['addtime']);?>
<?php echo $v['post_status'];?>
取消订单

<?php endforeach;?>
图片说明
怎样把订单号相同的合并起来呢,我该怎样改变数组结构呢?类似淘宝的订单
图片说明
  • 写回答

4条回答

  • threenewbee 2015-03-22 10:51
    关注

    可以,但是你的代码太多了,懒得看了,思路是用group by按照订单号分组。

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)