단골고객 구매건수 누적 금액 최종접속일 추가

단골고객 구매건수 누적 금액 최종접속일 추가

QA

단골고객 구매건수 누적 금액 최종접속일 추가

본문

안녕하세요! 판다왕 입니다. 

빗아님이 남겨주신 단골고객 불러오기

https://sir.kr/yc5_tip/1182

보고 영카트 관리자 페이지에 단골고객 페이지를 만들어 누적 구매 건수와 금액 추가 하는데 성공하였습니다.

 

해당 고객의 최종접속일을 추가하려 하는데 화면 캡쳐이미지와 같이 구매건수, 금액은 잘 나옵니다.

최종접속일을 추가 했는데 날짜가 제대로 안나오네요~ 코드가 잘못된거 같은데 도움 부탁 드립니다.

항상 도와주셔서 감사합니다. 

3740209594_1643779367.2738.png

 


<?php
$sub_menu = "200850";
include_once('./_common.php');
auth_check_menu($auth, $sub_menu, 'r');
include_once ('./admin.head.php');
?>

<?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);
}
?>
<link rel="stylesheet" href="<?php echo G5_ADMIN_URL; ?>/css/admin.css">
<div class="local_desc02 local_desc">
<p>단골 고객<span>(비회원은 포함되지 않습니다.)</span></p>
</div>
<div class="tbl_head01 tbl_wrap">
<table>
    <tr>
        <th>순위</th>
        <th>회원 ID</th>
        <th>이름</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;
            $ranking[$list]['mb_today_login'] = $row['mb_today_login'];
            $list++;
        }
    }
    $rank = array_msort($ranking, array('price'=>SORT_DESC)); // 배열 재정열
    if(count($rank) > 20) $count = 20; // 출력 갯수
    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>
        <td><?php echo date("Y.m.d H:i", strtotime($row['mb_today_login'])); ?></td>
    </tr>
    <?php } if($i == 0){?>
    <tr>
        <td colspan="50">아직 단골 고객이 없습니다.</td>
    </tr>
    <?php }?>
</table>
</div>

<?php
include_once ('./admin.tail.php');

이 질문에 댓글 쓰기 :

답변 2

이게 빠져있어서 그렇습니다 b.mb_today_login



$sql = "select a.mb_id,a.od_cart_price,b.mb_name,b.mb_today_login  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 != ''"; // 주문상태 취소를 제외, 비회원 제외하고 불러옵니다.

<td><?=$ranking[$list]['mb_today_login']?></td> 그냥 한번 이렇게 변경 해보시겠어요?
원인이 mb_today_login이것을 쿼리에 반영하지 못한 것이고요.
두번째 원인은 출력에 문제가 있을수 있습니다.

원하던 자료였는데 감사합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 16,740
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT