1.现在我有一个订单,已经处理成了这样一个数组:[detail=[[goods1],[goods2]...],total=[]...]
2.我的商品详情都在detail里面.其中有三个字段分别是store_id,send_way,goods_price
3.拆单规则:先根据store_id拆成一个子订单,如果其中send_way不同,则又拆出来成为一个子订单,如果其中一个子订单的商品价格总和超过了2000则再次拆分出来成为一个子订单.
4.我最后想得到的订单数组格式:[总订单=[[子订单1],[子订单2]...],total=[]...]
测试数据:
$goods_detail = [
["goods_name"=> "商品1", "store_id"=> "1", "goods_send_way"=> "1", "goods_total_price"=> "1000.00" ],
["goods_name"=> "商品2", "store_id"=> "1", "goods_send_way"=> "2", "goods_total_price"=> "1000.00" ],
["goods_name"=> "商品3", "store_id"=> "2", "goods_send_way"=> "2", "goods_total_price"=> "1500.00" ],
["goods_name"=> "商品4", "store_id"=> "2", "goods_send_way"=> "1", "goods_total_price"=> "2000.00" ],
["goods_name"=> "商品5", "store_id"=> "3", "goods_send_way"=> "2", "goods_total_price"=> "1000.00" ],
["goods_name"=> "商品6", "store_id"=> "3", "goods_send_way"=> "2", "goods_total_price"=> "500.00" ],
];
我现在做到根据store_id拆出来了,但是接下来根据send_way和goods_price不知道该怎么拆了,求指教
$store_id_arr = array_unique(array_column($goods_detail,'store_id'));
$store = [];
foreach ($goods_detail as $key => $value){
foreach ($store_id_arr as $store_id_val){
if($value['store_id'] == $store_id_val){
$store['store'.$store_id_val][] = $value;
}
}
}
题主我弄了一下午弄出来了QAQ好心塞