public function indexAction() { $shoppingCart = $this->shoppingcart; $openid = get_openid(); $shoppingCart->setOpenid($openid); //读取信息 $resArr = $shoppingCart->selectInfo(); //拼接商品信息 foreach ($resArr as $key => $value) { $goods = M('goods'); $map['id'] = $value['product_number']; $map['state'] = 1; $good = $goods->where($map)->find(); if ($good != FALSE) { $resGoods[$key] = $good; $resGoods[$key]['product_quantity'] = $resArr[$key]['product_quantity']; } } //无记录则提示继续逛逛 if (!is_array($resArr) || count($resArr) === 0) { $flag = 1; $this->assign('flag', $flag); } //拼接附件信息 $attachmentInfo = D('Attachment/Attachment'); //设置关键字:即哪个字段代表的附件ID $attachmentInfo->setKey('focus_pictures'); $resGoods = $attachmentInfo->selectInfo($resGoods); /* * 按商品来源及物流方式分类 */ $resGoods = group_by_key($resGoods, 'source'); foreach ($resGoods as $key => $value) { $resGoods[$key] = group_by_key($value, 'logistics_mode'); } $this->assign('shoppingcart', $resGoods); $submitUrl = U('OrderForm/Submit/index'); $actionUrl['deleteUrl'] = U('delete'); $actionUrl['changeCountUrl'] = U('changeCount'); $indexUrl = U('Home/Index/index'); $this->assign('actionUrl', $actionUrl); $this->assign('submitUrl', $submitUrl); $js = $this->fetch('js'); $css = $this->fetch('css'); $this->assign('css', $css); $this->assign('js', $js); $this->assign('indexUrl', $indexUrl); $this->assign('url', $url); $TPL = T('index'); //$this ->fetch($TPL); $this->assign('YZBody', $this->fetch($TPL)); $this->display(YZ_TEMPLATE); }
private function _getSettles($beginTime, $endTime) { $orderForm = D('OrderForm'); $orderForm->setBeginTime($beginTime); $orderForm->setEndTime($endTime); $settles = $orderForm->getSettle(); /* * 数组最后添加popenid * 上级的OPENID信息 */ foreach ($settles as $key => $value) { $customer = get_customer_info($value['openid']); $pid = $customer['parentid']; $pcustomer = get_customer_info($pid); $settles[$key]['pOpenid'] = $pcustomer['openid']; } /* * 按不同的openid进行分组 * 将子元素求和 */ $key = 'openid'; $currentSettles = group_by_key($settles, $key); $currentSettles = $this->_getTotal($currentSettles); /* * 按不同的父级openid进行分组 */ $key = 'pOpenid'; $childSettles = group_by_key($settles, $key); $childSettles = $this->_getTotal($childSettles); foreach ($currentSettles as $key => $value) { $currentSettles[$key]['_child'] = $childSettles[$key]; } return $currentSettles; }
public function getPayedOrder() { if ($this->beginTime == null || $this->endTime == null) { return false; } /* * 取出本时间段的全部信息 * 1.拼接PID信息 * 2.按ID进行分组 * 3.按PID分组 * * 4.得到PID信息 * 5.在原ID信息拼接上对应的PID信息 */ $map['payed_time'] = array('BETWEEN', $this->beginTime . ',' . $this->endTime); $map['is_pay'] = 1; $map['is_cancel'] = 0; $resData = $this->where($map)->select(); //拼接客户信息 $kewWord = 'buy_openid'; $resData = get_customer_info_by_openid($resData, $kewWord); //按客户id分组 $key1 = 'buy_openid'; $key2 = 'id'; $direData = group_by_key1_key2($resData, $key1, $key2); $dataRes = array(); //生成客户信息 foreach ($direData as $key => $value) { $data = array(); $totalDirectFee = 0; //直销业绩 $totalLineFee = 0; //线销业绩 $totalGoodsFee = 0; //商品总价(基数) foreach ($value as $ke => $va) { $totalDirectFee += $va['total_direct_fee']; $totalLineFee += $va['total_line_fee']; $totalGoodsFee += $va['total_goods_fee']; } //添加业绩信息 $data['totalDirectFee'] = $totalDirectFee; $data['totalLineFee'] = $totalLineFee; $data['totalGoodsFee'] = $totalGoodsFee; $data['_detail'] = $value; //添加parentId $data['parId'] = $value[0]['buy_openid']['parentid']; $data['_customer_id'] = $value[0]['buy_openid']['id']; $dataRes[$key] = $data; } //按客户pid再分组,拼接线销信息 $key2 = 'parId'; $lineData = group_by_key($dataRes, $key2); $lineDateRes = array(); foreach ($lineData as $key1 => $value1) { $ltotalDirectFee = 0; //下线直销业绩 $ltotalLineFee = 0; //下线线销业绩 $ltotalGoodsFee = 0; //下线商品总价(基数) foreach ($value1 as $key => $value) { $ltotalDirectFee += $value['totalDirectFee']; $ltotalLineFee += $value['totalLineFee']; $ltotalGoodsFee += $value['totalGoodsFee']; } $lineDateRes[$key1]['parId'] = $value['parId']; $lineDateRes[$key1]['totalDirectFee'] = $ltotalDirectFee; $lineDateRes[$key1]['totalLineFee'] = $ltotalLineFee; $lineDateRes[$key1]['totalGoodsFee'] = $ltotalGoodsFee; $lineDateRes[$key1]['_lineDetail'] = $value1; } //设置空数组 $emptyArr = array("totalDirectFee" => 0, "totalLineFee" => 0, "totalGoodsFee" => 0, "_lineDetail" => array()); //把id与它所对应的下线信息拼接到一起 foreach ($dataRes as $key => $value) { if (isset($lineDateRes[$key])) { $dataRes[$key]['_line'] = $lineDateRes[$key]; unset($lineDateRes[$key]); } else { $dataRes[$key]['_line'] = $emptyArr; } $dataRes[$key]['lineTotalLineFee'] = $dataRes[$key]['_line']['totalLineFee']; $dataRes[$key]['lineTotalGoodsFee'] = $dataRes[$key]['_line']['totalGoodsFee']; } //设置空数组 $emptyArr = array("totalDirectFee" => 0, "totalLineFee" => 0, "totalGoodsFee" => 0, "_detail" => array()); //将上线无数据的元素进行空数拼接 foreach ($lineDateRes as $key => $value) { $dataRes[$key] = $emptyArr; $dataRes[$key]['_line'] = $value; $dataRes[$key]['_customer_id'] = $key; $dataRes[$key]['lineTotalLineFee'] = $value['totalLineFee']; $dataRes[$key]['lineTotalGoodsFee'] = $value['totalGoodsFee']; } //去除上线为系统的记录 unset($dataRes[0]); return $dataRes; // // // // // // // // /* // * 先获取直销信息,再获取线销信息 // */ // foreach($customerArr as $ke => $value) // { // $map['openid'] = $value[$key]; // // $res = $this->where($map)->select(); // $customerArr[$ke]['achievement'] = $res; // $customerArr[$ke] = array_merge($value,$this->_getAchieveData($res)); // // //取下线的业绩 // $mapChild = array(); // $mapChild['parentid'] = $v['id']; // $child = $this->where($mapChild)->select(); // // $totalDirectFee = 0; //直销业绩 // $totalLineFee = 0; //线销业绩 // $totalGoodsFee = 0; //商品总价(基数) // foreach($child as $cke => $cva) // { // $map['openid'] = $cva[$key]; // $res = $this->where($map)->select(); // $detailData = $this->_getAchieveData($res); // $child[$cke]['achievement'] = array_merge($cva,$detailData); // $totalDirectFee += $detailData['_totalDirectFee']; // $totalLineFee += $detailData['_totalLineFee']; // $totalGoodsFee += $detailData['_totalGoodsFee']; // } // $child['_totalDirectFee'] = $totalDirectFee; // $child['_totalLineFee'] = $totalLineFee; // $child['_totalGoodsFee'] = $totalGoodsFee; // // $customerArr[$ke]['_child'] = $child; // } // // return $customerArr; }
<?php // No direct access defined('_JEXEC') or die; //get repeatable fields $json = json_decode($params->get("repeatable-fields"), true); if (!function_exists('group_by_key')) { function group_by_key($array) { $result = array(); foreach ($array as $sub) { foreach ($sub as $k => $v) { $result[$k][] = $v; } } return $result; } } $filtered_array = group_by_key($json); foreach ($filtered_array as $index => $collapse) { echo $collapse[0] . '<br /> '; echo $collapse[1] . '<br /> '; echo $collapse[2] . '<br /> '; echo $collapse[3] . '<br /> '; }
public function dataAccess($ids, $counts) { if (count($counts) != count($ids)) { return false; } $goodsM = D('Goods'); $product = $goodsM->getProduct($ids, $counts); //根据商品id获取商品对应的信息 $attachmentinfo = D('Attachment/Attachment'); //取附件表里面的置换图片url $attachmentinfo->setKey('focus_pictures'); $product = $attachmentinfo->selectinfo($product); foreach ($product as $key => $value) { $product[$key]['product_quantity'] = $counts[$key] == '' || $counts[$key] == 0 ? 1 : $counts[$key]; //加上商品数量这个字段 } $product = group_by_key($product, 'source'); //商品按国家分类 foreach ($product as $key => $value) { $product[$key] = group_by_key($value, 'logistics_mode'); //商品按物流方式分类 } $i = 0; $total['totalFee'] = 0; //商品总价值 $total['totalCount'] = 0; //商品总数量 $total['totalLogisticFee'] = 0; //商品总运费 $total['totalAmount'] = 0; //商品总优惠金额 $total['totalPayable'] = 0; //商品总应付金额 $total['totalDirectFee'] = 0; //直销返点 $total['totallineFee'] = 0; //线销返点 $total['totalCustomsFee'] = 0; //总关税 $logistic = new ConfigModel(); //运费配置 $logisticM = new LogisticsModel(); //物流方式 $sourceM = new SourceModel(); //来源 foreach ($product as $key => $value) { foreach ($value as $ke => $va) { $weightTotal = 0; //商品总重量 $countTotal = 0; //商品总数量 $feeTotal = 0; //商品总金额 $maxAmount = 0; //商品最大优惠金额 $maxLogisFee = 0; //最大国内运费 $directTotal = 0; //直销返点 $lineTotal = 0; //线销返点 $customsTotal = 0; //关税 foreach ($va as $k => $v) { $count = $v['product_quantity']; $weightTotal += $v['weight'] * $count; $countTotal += $count; $feeTotal += $count * $v['purchasing_price']; $directTotal += floor($v['purchasing_price'] * $v['direct_selling_commission'] / 100) * $count; $lineTotal += floor($v['purchasing_price'] * $v['line_selling_commission'] / 100) * $count; //$customsTotal += $count*$v['customs'];不计算关税 if ($v['discount_amount'] > $maxAmount) { $maxAmount = $v['discount_amount']; $amountWay = $v['discount_way']; } if ($v['domestic_transportation_expenses'] > $maxLogisFee) { $maxLogisFee = $v['domestic_transportation_expenses']; } $res[$i]['goods'][] = $v; //商品信息 } $res[$i]['weightTotal'] = $weightTotal; $res[$i]['countTotal'] = $countTotal; $res[$i]['feeTotal'] = $feeTotal; $res[$i]['maxAmount'] = $maxAmount; $res[$i]['maxLogisFee'] = $maxLogisFee; $res[$i]['directTotal'] = $directTotal; //直销返点 $res[$i]['lineTotal'] = $lineTotal; $res[$i]['amountWay'] = $amountWay; //优惠政策 $res[$i]['customsTotal'] = $customsTotal; /*按物流方式,计算国内国际运费 */ if ($ke == 1) { $internationLogisticFee = $logistic->getFee($weightTotal); $domesticLogisticFee = 0; } else { $internationLogisticFee = 0; $domesticLogisticFee = $maxLogisFee; } $logisticFee = $domesticLogisticFee + $internationLogisticFee; $res[$i]['internationLogisticFee'] = $internationLogisticFee; $res[$i]['domesticLogisticFee'] = $domesticLogisticFee; $res[$i]['logisticFee'] = $logisticFee; //取来源与物流方式 $res[$i]['source'] = $sourceM->getInfoById($key); //来源 $res[$i]['logisticType'] = $logisticM->getInfoByMode($ke); //物流方式 //应付总金额 = 商品总价格-最大优惠金额+物流费用+总关税 $res[$i]['payable'] = $feeTotal - $maxAmount + $logisticFee + $customsTotal; /* 商品总信息 */ $total['totalFee'] += $feeTotal; //商品总价值 $total['totalCount'] += $countTotal; //商品总数量 $total['totalLogisticFee'] += $logisticFee; //商品总运费 $total['totalAmount'] += $maxAmount; //商品总优惠金额 $total['totalPayable'] += $res[$i]['payable']; //商品总应付金额 $total['totalDirectFee'] += $res[$i]['directTotal']; //直销返点 $total['totallineFee'] += $res[$i]['lineTotal']; //线销返点 $total['totalCustomsFee'] += $res[$i]['customsTotal']; //关税 $i++; } } //最低付款1分 $total['totalPayable'] = $total['totalPayable'] > 0 ? $total['totalPayable'] : 1; $data[] = $res; $data[] = $total; return $data; }