Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PHP] 쇼핑몰에 쓰려고 만든 함수 몇개

2012-01-17 by 편리

쇼핑몰 관리자 페이지에서 사용하려고 만든 함수 몇가지.. 매출액이나 주문건수 등을 계산할 때 쓰는 함수이다.

// 매출액 계산
function get_shop_sales($period)
{
    global $g4;
    $len = strlen($period);

    $sql = ” select SUM( a.ct_amount * a.ct_qty ) – SUM( IF(a.ct_status = ‘취소’ OR a.ct_status = ‘반품’ OR a.ct_status = ‘품절’, a.ct_amount * a.ct_qty, 0) ) as sales
                from $g4[shop_cart_table] as a left join $g4[shop_order_table] as b on ( a.on_uid = b.on_uid )
                where substring(b.od_time, 1, $len) = ‘$period’ “;
    $row = sql_fetch($sql);

    return $row[sales];
}

// 결재완료수
function get_credit_count($period)
{
    global $g4;
    $len = strlen($period);

    $sql = ” select od_id from $g4[shop_order_table]
                where ((od_temp_bank – od_receipt_bank – od_receipt_point) = 0)
                    or ((od_temp_card – od_receipt_card – od_receipt_point) = 0)
                    and substring(od_receipt_time, 1, $len) = ‘$period’ “;
    $result = sql_query($sql);
    $count = mysql_num_rows($result);

    return $count;
}

// 주문수
function get_order_count($period)
{
    global $g4;
    $len = strlen($period);

    $sql = ” select od_id from $g4[shop_order_table] where substring(od_time, 1, $len) = ‘$period’ “;
    $result = sql_query($sql);
    $count = mysql_num_rows($result);

    return $count;
}

// 회원수
function get_member_count($period)
{
    global $g4;
    $len = strlen($period);

    $sql = ” select mb_no from $g4[member_table] where substring(mb_datetime, 1, $len) = ‘$period’ “;
    $result = sql_query($sql);
    $count = mysql_num_rows($result);

    return $count;
}

// 취소수
function get_cancel_count($period)
{
    global $g4;
    $len = strlen($period);

    $sql = ” select distinct b.od_id
                from $g4[shop_cart_table] as a left join $g4[shop_order_table] as b on ( a.on_uid = b.on_uid )
                where a.ct_status IN (‘취소’, ‘반품’, ‘품절’) and substring(b.od_time, 1, $len) = ‘$period’ “;
    $result = sql_query($sql);
    $count = mysql_num_rows($result);

    return $count;
}

넘겨받은 $period 의 길이를 계산해서 그것만큼 substring 결과 값이 같은 것만 계산하도록 했다. 기간이 일단위에서
월단위가 될 때도 있고 어쩌면 년단위가 될 수도 있으니까.. 저런  꼼수를 부려봤는데 괜찮게 한 것인지는 모르겠다.

Post navigation

Previous Post:

div 안에서 텍스트 세로 가운데 정렬

Next Post:

구글 Page Speed

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes