안녕하세요 빗아입니다.
영카트 5.3.x 관리자 리뉴얼 해보면서 쇼핑몰 관리자 메인 만들다가 누적 구매 금액순으로 단골 고객 가져와 보았습니다.
필요하신 분들은 가져가서 쓰시면 될 거 같네요ㅎㅎ
css는 따로 안 올려드리니 만들어서 사용하시면 되겠습니다
[code]
<?php
function array_msort($array, $cols){ // 배열 재정열 함수
$colarr = array();
foreach ($cols as $col => $order) {
$colarr[$col] = array();
foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); }
}
$eval = 'array_multisort(';
foreach ($cols as $col => $order) {
$eval .= '$colarr[\''.$col.'\'],'.$order.',';
}
$eval = substr($eval,0,-1).');';
eval($eval);
$ret = array();
foreach ($colarr as $col => $arr) {
foreach ($arr as $k => $v) {
$k = substr($k,1);
if (!isset($ret[$k])) $ret[$k] = $array[$k];
$ret[$k][$col] = $array[$k][$col];
}
}
return array_values($ret);
}
?>
<p>단골 고객<span>(비회원은 포함되지 않습니다.)</span></p>
<table>
<tr>
<th>순위</th>
<th>회원 ID</th>
<th>이름</th>
<th>누적 주문</th>
<th>총 구매금액</th>
</tr>
<?php
$ranking = array();
$list = 0;
$sql = "select a.mb_id,a.od_cart_price,b.mb_name from {$g5['g5_shop_order_table']} a inner join {$g5['member_table']} b on a.mb_id = b.mb_id where a.od_status != '취소' and a.mb_id != ''"; // 주문상태 취소를 제외, 비회원 제외하고 불러옵니다.
$rs = sql_query($sql);
while($row = sql_fetch_array($rs)){
$search_key = array_search($row['mb_id'], array_column($ranking, 'mb_id'));
if($search_key > -1){
$ranking[$search_key]['price'] += $row['od_cart_price'];
$ranking[$search_key]['count'] += 1;
} else {
$ranking[$list]['mb_id'] = $row['mb_id'];
$ranking[$list]['mb_name'] = $row['mb_name'];
$ranking[$list]['price'] = $row['od_cart_price'];
$ranking[$list]['count'] = 1;
$list++;
}
}
$rank = array_msort($ranking, array('price'=>SORT_DESC)); // 배열 재정열
if(count($rank) > 7) $count = 7; // 출력 갯수
else $count = count($rank);
for($i=0; $i<$count; $i++){
?>
<tr>
<td><?php echo $i + 1;?></td>
<td><?=$rank[$i]['mb_id']?></td>
<td><?=$rank[$i]['mb_name']?></td>
<td><?=number_format($rank[$i]['count'])?><span>건</span></td>
<td><?=number_format($rank[$i]['price'])?><span>원</span></td>
</tr>
<?php } if($i == 0){?>
<tr>
<td colspan="50">아직 단골 고객이 없습니다.</td>
</tr>
<?php }?>
</table>
[/code]
영카트 5.3.x 관리자 리뉴얼 해보면서 쇼핑몰 관리자 메인 만들다가 누적 구매 금액순으로 단골 고객 가져와 보았습니다.
필요하신 분들은 가져가서 쓰시면 될 거 같네요ㅎㅎ
css는 따로 안 올려드리니 만들어서 사용하시면 되겠습니다
[code]
<?php
function array_msort($array, $cols){ // 배열 재정열 함수
$colarr = array();
foreach ($cols as $col => $order) {
$colarr[$col] = array();
foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); }
}
$eval = 'array_multisort(';
foreach ($cols as $col => $order) {
$eval .= '$colarr[\''.$col.'\'],'.$order.',';
}
$eval = substr($eval,0,-1).');';
eval($eval);
$ret = array();
foreach ($colarr as $col => $arr) {
foreach ($arr as $k => $v) {
$k = substr($k,1);
if (!isset($ret[$k])) $ret[$k] = $array[$k];
$ret[$k][$col] = $array[$k][$col];
}
}
return array_values($ret);
}
?>
<p>단골 고객<span>(비회원은 포함되지 않습니다.)</span></p>
<table>
<tr>
<th>순위</th>
<th>회원 ID</th>
<th>이름</th>
<th>누적 주문</th>
<th>총 구매금액</th>
</tr>
<?php
$ranking = array();
$list = 0;
$sql = "select a.mb_id,a.od_cart_price,b.mb_name from {$g5['g5_shop_order_table']} a inner join {$g5['member_table']} b on a.mb_id = b.mb_id where a.od_status != '취소' and a.mb_id != ''"; // 주문상태 취소를 제외, 비회원 제외하고 불러옵니다.
$rs = sql_query($sql);
while($row = sql_fetch_array($rs)){
$search_key = array_search($row['mb_id'], array_column($ranking, 'mb_id'));
if($search_key > -1){
$ranking[$search_key]['price'] += $row['od_cart_price'];
$ranking[$search_key]['count'] += 1;
} else {
$ranking[$list]['mb_id'] = $row['mb_id'];
$ranking[$list]['mb_name'] = $row['mb_name'];
$ranking[$list]['price'] = $row['od_cart_price'];
$ranking[$list]['count'] = 1;
$list++;
}
}
$rank = array_msort($ranking, array('price'=>SORT_DESC)); // 배열 재정열
if(count($rank) > 7) $count = 7; // 출력 갯수
else $count = count($rank);
for($i=0; $i<$count; $i++){
?>
<tr>
<td><?php echo $i + 1;?></td>
<td><?=$rank[$i]['mb_id']?></td>
<td><?=$rank[$i]['mb_name']?></td>
<td><?=number_format($rank[$i]['count'])?><span>건</span></td>
<td><?=number_format($rank[$i]['price'])?><span>원</span></td>
</tr>
<?php } if($i == 0){?>
<tr>
<td colspan="50">아직 단골 고객이 없습니다.</td>
</tr>
<?php }?>
</table>
[/code]
댓글 12개
게시글 목록
| 번호 | 제목 |
|---|---|
| 1483 | |
| 1481 | |
| 1479 | |
| 1474 | |
| 1473 | |
| 1463 | |
| 1458 | |
| 1457 | |
| 1456 | |
| 1452 | |
| 1449 | |
| 1448 | |
| 1442 | |
| 1441 | |
| 1426 | |
| 1411 | |
| 1389 | |
| 1388 | |
| 1372 | |
| 1359 | |
| 1357 | |
| 1355 | |
| 1348 | |
| 1347 | |
| 1338 | |
| 1332 | |
| 1328 | |
| 1313 | |
| 1307 | |
| 1303 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기