source: branches/dev/data/downloads/module/mdl_zero/recv.php @ 14794

Revision 14794, 15.3 KB checked in by kakinaka, 15 years ago (diff)
Line 
1<?php
2
3$objSiteSess = new SC_SiteSession();
4$objCartSess = new SC_CartSession();
5$objCampaignSess = new SC_CampaignSession();
6$objCustomer = new SC_Customer();
7
8$objSiteInfo = $objView->objSiteInfo;
9$arrInfo = $objSiteInfo->data;
10
11define("RECV_APPROVE_MAIL", $arrInfo["email03"]);    // ¾µÇ§¾ðÊó¤ò¼õ¿®¤¹¤ë¥á¡¼¥ë¥¢¥É¥ì¥¹
12define("SEND_MAIL", true);    // ¾µÇ§¾ðÊó¤ò¼õ¿®¤¹¤ë¥á¡¼¥ë¥¢¥É¥ì¥¹
13
14$log_path = DATA_PATH . "logs/zero.log";
15gfPrintLog("** zero start **", $log_path);
16
17$arrResult = $_GET;
18// GET¤ÎÆâÍƤòÁ´¤Æ¥í¥°Êݸ
19foreach($arrResult as $key => $val){
20    gfPrintLog( "\t" . $key . " => " . $val, $log_path);
21}
22
23$objQuery->begin();
24$order_id = lfDoComplete($objQuery, $arrResult);
25$objQuery->commit();
26
27// ´°Î»¥á¡¼¥ëÁ÷¿®
28if(sfIsInt($order_id)) {
29    sfSendOrderMail($order_id, '1');
30    print("OK");
31}else{
32    // ¥¨¥é¡¼¤Î¾ì¹ç¼õ¿®¥Ç¡¼¥¿¤òÁ÷¿®
33    gfPrintLog(" zero error ", $log_path);;
34    if(SEND_MAIL){
35        ob_start();
36        print($order_id . "\n");
37        print_r($arrResult);
38        $msg = ob_get_contents();
39        ob_end_clean();
40        mb_send_mail(RECV_APPROVE_MAIL, "¥¼¥í¥¯¥ì¥¸¥Ã¥È¥¨¥é¡¼:" . $arrResult['sendid'], $msg . "\n");
41    }
42    print("NG");
43}
44gfPrintLog("** zero end **", $log_path);
45//---------------------------------------------------------------------------------------------------------------------------------
46// ´°Î»½èÍý
47function lfDoComplete($objQuery, $arrResult) {
48    global $objCartSess;
49    global $objSiteSess;
50    global $objCampaignSess;
51    $objCustomer = new SC_Customer();
52    global $arrInfo;
53   
54    gfprintlog($objCustomer->isLoginSuccess(),DATA_PATH . "logs/zero.log");
55   
56    // sendid ¤ÎÃͤò¶èÀÚ¤ë
57    $arrSendid = preg_split("/\\".SEND_PARAM_DELIMITER."/", $arrResult["sendid"]);
58   
59    $uniqid = $arrSendid[0];          // order_temp_id
60    $money =  $arrResult["money"];    // payment_total
61
62    $arrCrilentIP = $objQuery->select("memo02, memo04", "dtb_payment", "payment_id = ? and del_flg = 0", array($arrSendid[1]));
63    //$client_id = $objQuery->getAll("SELECT memo04 FROM dtb_payment WHERE payment_id = ? and del_flg = 0", array($arrSendid[1]));
64   
65    // ²ÃÌÁŹ¥³¡¼¥É¤¬°ã¤¦¾ì¹ç¤Ë¤Ï¥¨¥é¡¼
66    if(count($arrResult)){
67        if(in_array($arrResult["clientip"], $arrCrilentIP)) return "²ÃÌÁŹ¥³¡¼¥É¤¬°ã¤¤¤Þ¤¹¡£";
68    }else{
69        return "²ÃÌÁŹ¥³¡¼¥É¤¬°ã¤¤¤Þ¤¹¡£";
70    }
71   
72    // °ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤ÎÆɹþ
73    $arrData = sfGetOrderTemp($uniqid);
74   
75    // °ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤«¤é¥Ç¡¼¥¿¤¬¼èÆÀ¤Ç¤­¤Ê¤±¤ì¤Ð¡¢¥¨¥é¡¼
76    if(count($arrData) <= 0) return "¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Ë»ØÄꤷ¤¿ID¤Î¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó¡£";
77   
78    // ·èºÑ´°Î»ºÑ¤ß¤Ç¤¢¤ì¤Ð¥¨¥é¡¼
79    if($arrData["del_flg"] == 1) return "»ØÄꤷ¤¿ID¤Î¥Ç¡¼¥¿¤Ï·èºÑ´°Î»ºÑ¤ß¤Ç¤¹¡£";
80   
81    // °ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤Î¤ª»Ùʧ¤¤¹ç·×¤È¡¢¥¼¥í¤«¤éÊ֤äƤ­¤¿¶â³Û¤È¤¬°ã¤¦¾ì¹ç¤Ï¥¨¥é¡¼
82    if($arrData["payment_total"] != $money) return "¤ª»Ùʧ¤¤¶â³Û¤¬°ã¤¤¤Þ¤¹¡£";
83   
84    // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤ÎÉüµ¢
85    $_SESSION = unserialize($arrData["session"]);
86
87    // ²ñ°÷¾ðÊóÅÐÏ¿½èÍý
88    if ($objCustomer->isLoginSuccess()) {
89        // ¿·¤ªÆϤ±Àè¤ÎÅÐÏ¿
90        lfSetNewAddr($uniqid, $objCustomer->getValue('customer_id'));
91        // ¹ØÆþ½¸·×¤ò¸ÜµÒ¥Æ¡¼¥Ö¥ë¤ËÈ¿±Ç
92        lfSetCustomerPurchase($objCustomer->getValue('customer_id'), $arrData, $objQuery);
93    } else {
94        //¹ØÆþ»þ¶¯À©²ñ°÷ÅÐÏ¿
95        switch(PURCHASE_CUSTOMER_REGIST) {
96        //̵¸ú
97        case '0':
98            // ¹ØÆþ»þ²ñ°÷ÅÐÏ¿
99            if($arrData['member_check'] == '1') {
100                // ²¾²ñ°÷ÅÐÏ¿
101                $customer_id = lfRegistPreCustomer($arrData, $arrInfo);
102                // ¹ØÆþ½¸·×¤ò¸ÜµÒ¥Æ¡¼¥Ö¥ë¤ËÈ¿±Ç
103                lfSetCustomerPurchase($customer_id, $arrData, $objQuery);
104            }
105            break;
106        //Í­¸ú
107        case '1':
108            // ²¾²ñ°÷ÅÐÏ¿
109            $customer_id = lfRegistPreCustomer($arrData, $arrInfo);
110            // ¹ØÆþ½¸·×¤ò¸ÜµÒ¥Æ¡¼¥Ö¥ë¤ËÈ¿±Ç
111            lfSetCustomerPurchase($customer_id, $arrData, $objQuery);
112            break;
113        }
114    }
115
116    // °ì»þ¥Æ¡¼¥Ö¥ë¤ò¼õÃí¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤¹¤ë
117    $order_id = lfRegistOrder($objQuery, $arrData, $objCampaignSess);
118    // ¥«¡¼¥È¾¦Éʤò¼õÃí¾ÜºÙ¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤¹¤ë
119    lfRegistOrderDetail($objQuery, $order_id, $objCartSess);
120    // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Î¾ðÊó¤òºï½ü¤¹¤ë¡£
121    lfDeleteTempOrder($objQuery, $uniqid);
122    // ¥­¥ã¥ó¥Ú¡¼¥ó¤«¤é¤ÎÁ«°Ü¤Î¾ì¹çÅÐÏ¿¤¹¤ë¡£
123    if($objCampaignSess->getIsCampaign()) {
124        lfRegistCampaignOrder($objQuery, $objCampaignSess, $order_id);
125    }
126   
127    return $order_id;
128}
129
130// ²ñ°÷ÅÐÏ¿¡Ê²¾ÅÐÏ¿¡Ë
131function lfRegistPreCustomer($arrData, $arrInfo) {
132    // ¹ØÆþ»þ¤Î²ñ°÷ÅÐÏ¿
133    $sqlval['name01'] = $arrData['order_name01'];
134    $sqlval['name02'] = $arrData['order_name02'];
135    $sqlval['kana01'] = $arrData['order_kana01'];
136    $sqlval['kana02'] = $arrData['order_kana02'];
137    $sqlval['zip01'] = $arrData['order_zip01'];
138    $sqlval['zip02'] = $arrData['order_zip02'];
139    $sqlval['pref'] = $arrData['order_pref'];
140    $sqlval['addr01'] = $arrData['order_addr01'];
141    $sqlval['addr02'] = $arrData['order_addr02'];
142    $sqlval['email'] = $arrData['order_email'];
143    $sqlval['tel01'] = $arrData['order_tel01'];
144    $sqlval['tel02'] = $arrData['order_tel02'];
145    $sqlval['tel03'] = $arrData['order_tel03'];
146    $sqlval['fax01'] = $arrData['order_fax01'];
147    $sqlval['fax02'] = $arrData['order_fax02'];
148    $sqlval['fax03'] = $arrData['order_fax03'];
149    $sqlval['sex'] = $arrData['order_sex'];
150    $sqlval['password'] = $arrData['password'];
151    $sqlval['reminder'] = $arrData['reminder'];
152    $sqlval['reminder_answer'] = $arrData['reminder_answer'];
153   
154    // ¥á¥ë¥Þ¥¬ÇÛ¿®Íѥե饰¤ÎȽÄê
155    switch($arrData['mail_flag']) {
156    case '1':   // HTML¥á¡¼¥ë
157        $mail_flag = 4;
158        break;
159    case '2':   // TEXT¥á¡¼¥ë
160        $mail_flag = 5;
161        break;
162    case '3':   // ´õ˾¤Ê¤·
163        $mail_flag = 6;
164        break;
165    default:
166        $mail_flag = 6;
167        break;
168    }
169    // ¥á¥ë¥Þ¥¬¥Õ¥é¥°
170    $sqlval['mailmaga_flg'] = $mail_flag;
171       
172    // ²ñ°÷²¾ÅÐÏ¿
173    $sqlval['status'] = 1;
174    // URLȽÄêÍÑ¥­¡¼
175    $sqlval['secret_key'] = sfGetUniqRandomId("t");
176   
177    $objQuery = new SC_Query();
178    $sqlval['create_date'] = "now()";
179    $sqlval['update_date'] = "now()";
180    $objQuery->insert("dtb_customer", $sqlval);
181   
182    // ¸ÜµÒID¤Î¼èÆÀ
183    $arrRet = $objQuery->select("customer_id", "dtb_customer", "secret_key = ?", array($sqlval['secret_key']));
184    $customer_id = $arrRet[0]['customer_id'];
185   
186    //¡¡²¾ÅÐÏ¿´°Î»¥á¡¼¥ëÁ÷¿®
187    $objMailPage = new LC_Page();
188    $objMailPage->to_name01 = $arrData['order_name01'];
189    $objMailPage->to_name02 = $arrData['order_name02'];
190    $objMailPage->CONF = $arrInfo;
191    $objMailPage->uniqid = $sqlval['secret_key'];
192    $objMailView = new SC_SiteView();
193    $objMailView->assignobj($objMailPage);
194    $body = $objMailView->fetch("mail_templates/customer_mail.tpl");
195   
196    $objMail = new GC_SendMail();
197    $objMail->setItem(
198                        ''                                      //¡¡°¸Àè
199                        , sfMakeSubject("²ñ°÷ÅÐÏ¿¤Î¤´³Îǧ")     //¡¡¥µ¥Ö¥¸¥§¥¯¥È
200                        , $body                                 //¡¡ËÜʸ
201                        , $arrInfo['email03']                   //¡¡ÇÛÁ÷¸µ¥¢¥É¥ì¥¹
202                        , $arrInfo['shop_name']                 //¡¡ÇÛÁ÷¸µ¡¡Ì¾Á°
203                        , $arrInfo["email03"]                   //¡¡reply_to
204                        , $arrInfo["email04"]                   //¡¡return_path
205                        , $arrInfo["email04"]                   //  Errors_to
206                        , $arrInfo["email01"]                   //  Bcc
207                                                        );
208    // °¸Àè¤ÎÀßÄê
209    $name = $arrData['order_name01'] . $arrData['order_name02'] ." ÍÍ";
210    $objMail->setTo($arrData['order_email'], $name);           
211    $objMail->sendMail();
212   
213    return $customer_id;
214}
215
216// ¼õÃí¥Æ¡¼¥Ö¥ë¤ØÅÐÏ¿
217function lfRegistOrder($objQuery, $arrData, $objCampaignSess) {
218    $sqlval = $arrData;
219
220    // ¼õÃí¥Æ¡¼¥Ö¥ë¤Ë½ñ¤­¹þ¤Þ¤Ê¤¤Îó¤ò½üµî
221    unset($sqlval['mailmaga_flg']);     // ¥á¥ë¥Þ¥¬¥Á¥§¥Ã¥¯
222    unset($sqlval['deliv_check']);      // Ê̤ΤªÆϤ±Àè¥Á¥§¥Ã¥¯
223    unset($sqlval['point_check']);      // ¥Ý¥¤¥ó¥ÈÍøÍÑ¥Á¥§¥Ã¥¯
224    unset($sqlval['member_check']);     // ¹ØÆþ»þ²ñ°÷¥Á¥§¥Ã¥¯
225    unset($sqlval['password']);         // ¥í¥°¥¤¥ó¥Ñ¥¹¥ï¡¼¥É
226    unset($sqlval['reminder']);         // ¥ê¥Þ¥¤¥ó¥À¡¼¼ÁÌä
227    unset($sqlval['reminder_answer']);  // ¥ê¥Þ¥¤¥ó¥À¡¼Åú¤¨
228    unset($sqlval['mail_flag']);        // ¥á¡¼¥ë¥Õ¥é¥°
229    unset($sqlval['session']);          // ¥»¥Ã¥·¥ç¥ó¾ðÊó
230   
231    // Ãíʸ¥¹¥Æ¡¼¥¿¥¹:»ØÄ̵꤬¤±¤ì¤Ð¿·µ¬¼õÉÕ¤ËÀßÄê
232    if($sqlval["status"] == ""){
233        $sqlval['status'] = '1';           
234    }
235   
236    // Ê̤ΤªÆϤ±Àè¤ò»ØÄꤷ¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢ÇÛÁ÷Àè¤ËÅÐÏ¿½»½ê¤ò¥³¥Ô¡¼¤¹¤ë¡£
237    if($arrData["deliv_check"] == "-1") {
238        $sqlval['deliv_name01'] = $arrData['order_name01'];
239        $sqlval['deliv_name02'] = $arrData['order_name02'];
240        $sqlval['deliv_kana01'] = $arrData['order_kana01'];
241        $sqlval['deliv_kana02'] = $arrData['order_kana02'];
242        $sqlval['deliv_pref'] = $arrData['order_pref'];
243        $sqlval['deliv_zip01'] = $arrData['order_zip01'];
244        $sqlval['deliv_zip02'] = $arrData['order_zip02'];
245        $sqlval['deliv_addr01'] = $arrData['order_addr01'];
246        $sqlval['deliv_addr02'] = $arrData['order_addr02'];
247        $sqlval['deliv_tel01'] = $arrData['order_tel01'];
248        $sqlval['deliv_tel02'] = $arrData['order_tel02'];
249        $sqlval['deliv_tel03'] = $arrData['order_tel03'];
250    }
251   
252    $order_id = $arrData['order_id'];       // ¥ª¡¼¥À¡¼ID
253    $sqlval['create_date'] = 'now()';       // ¼õÃíÆü
254   
255    // ¥­¥ã¥ó¥Ú¡¼¥óID
256    if($objCampaignSess->getIsCampaign()) $sqlval['campaign_id'] = $objCampaignSess->getCampaignId();
257
258    // ¥²¥Ã¥È¤ÎÃͤò¥¤¥ó¥µ¡¼¥È
259    //$sqlval = lfGetInsParam($sqlval);
260   
261    // INSERT¤Î¼Â¹Ô
262    $objQuery->insert("dtb_order", $sqlval);
263   
264    return $order_id;
265}
266
267// ¼õÃí¾ÜºÙ¥Æ¡¼¥Ö¥ë¤ØÅÐÏ¿
268function lfRegistOrderDetail($objQuery, $order_id, $objCartSess) {
269    // ¥«¡¼¥ÈÆâ¾ðÊó¤Î¼èÆÀ
270    $arrCart = $objCartSess->getCartList();
271    $max = count($arrCart);
272   
273    // ´û¤Ë¸ºß¤¹¤ë¾ÜºÙ¥ì¥³¡¼¥É¤ò¾Ã¤·¤Æ¤ª¤¯¡£
274    $objQuery->delete("dtb_order_detail", "order_id = $order_id");
275
276    // µ¬³Ê̾°ìÍ÷
277    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
278    // µ¬³ÊʬÎà̾°ìÍ÷
279    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
280           
281    for ($i = 0; $i < $max; $i++) {
282        // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
283        $arrData = sfGetProductsClass($arrCart[$i]['id']);
284       
285        // ¸ºß¤¹¤ë¾¦ÉʤΤßɽ¼¨¤¹¤ë¡£
286        if($arrData != "") {
287            $sqlval['order_id'] = $order_id;
288            $sqlval['product_id'] = $arrCart[$i]['id'][0];
289            $sqlval['classcategory_id1'] = $arrCart[$i]['id'][1];
290            $sqlval['classcategory_id2'] = $arrCart[$i]['id'][2];
291            $sqlval['product_name'] = $arrData['name'];
292            $sqlval['product_code'] = $arrData['product_code'];
293            $sqlval['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']];
294            $sqlval['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']];
295            $sqlval['point_rate'] = $arrCart[$i]['point_rate'];         
296            $sqlval['price'] = $arrCart[$i]['price'];
297            $sqlval['quantity'] = $arrCart[$i]['quantity'];
298            lfReduceStock($objQuery, $arrCart[$i]['id'], $arrCart[$i]['quantity']);
299            // INSERT¤Î¼Â¹Ô
300            $objQuery->insert("dtb_order_detail", $sqlval);
301        } else {
302            sfDispSiteError(CART_NOT_FOUND);
303        }
304    }
305}
306
307// ¥­¥ã¥ó¥Ú¡¼¥ó¼õÃí¥Æ¡¼¥Ö¥ë¤ØÅÐÏ¿
308function lfRegistCampaignOrder($objQuery, $objCampaignSess, $order_id) {
309
310    // ¼õÃí¥Ç¡¼¥¿¤ò¼èÆÀ
311    $cols = "order_id, campaign_id, customer_id, message, order_name01, order_name02,".
312            "order_kana01, order_kana02, order_email, order_tel01, order_tel02, order_tel03,".
313            "order_fax01, order_fax02, order_fax03, order_zip01, order_zip02, order_pref, order_addr01,".
314            "order_addr02, order_sex, order_birth, order_job, deliv_name01, deliv_name02, deliv_kana01,".
315            "deliv_kana02, deliv_tel01, deliv_tel02, deliv_tel03, deliv_fax01, deliv_fax02, deliv_fax03,".
316            "deliv_zip01, deliv_zip02, deliv_pref, deliv_addr01, deliv_addr02, payment_total";
317
318    $arrOrder = $objQuery->select($cols, "dtb_order", "order_id = ?", array($order_id));
319           
320    $sqlval = $arrOrder[0];
321    $sqlval['create_date'] = 'now()';
322       
323    // INSERT¤Î¼Â¹Ô
324    $objQuery->insert("dtb_campaign_order", $sqlval);
325   
326    // ¿½¤·¹þ¤ß¿ô¤Î¹¹¿·
327    $total_count = $objQuery->get("dtb_campaign", "total_count", "campaign_id = ?", array($sqlval['campaign_id']));
328    $arrCampaign['total_count'] = $total_count += 1;
329    $objQuery->update("dtb_campaign", $arrCampaign, "campaign_id = ?", array($sqlval['campaign_id']));
330   
331}
332
333/* ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Îºï½ü */
334function lfDeleteTempOrder($objQuery, $uniqid) {
335    $where = "order_temp_id = ?";
336    $sqlval['del_flg'] = 1;
337    $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
338    // $objQuery->delete("dtb_order_temp", $where, array($uniqid));
339}
340
341// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Î½»½ê¤¬ÅÐÏ¿ºÑ¤ß¥Æ¡¼¥Ö¥ë¤È°Û¤Ê¤ë¾ì¹ç¤Ï¡¢Ê̤ΤªÆϤ±Àè¤ËÄɲ乤ë
342function lfSetNewAddr($uniqid, $customer_id) {
343    $objQuery = new SC_Query();
344    $diff = false;
345    $find_same = false;
346   
347    $col = "deliv_name01,deliv_name02,deliv_kana01,deliv_kana02,deliv_tel01,deliv_tel02,deliv_tel03,deliv_zip01,deliv_zip02,deliv_pref,deliv_addr01,deliv_addr02";
348    $where = "order_temp_id = ?";
349    $arrRet = $objQuery->select($col, "dtb_order_temp", $where, array($uniqid));
350   
351    // Í×ÁÇ̾¤Îdeliv_¤òºï½ü¤¹¤ë¡£
352    foreach($arrRet[0] as $key => $val) {
353        $keyname = ereg_replace("^deliv_", "", $key);
354        $arrNew[$keyname] = $val;
355    }
356   
357    // ²ñ°÷¾ðÊó¥Æ¡¼¥Ö¥ë¤È¤ÎÈæ³Ó
358    $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02";
359    $where = "customer_id = ?";
360    $arrCustomerAddr = $objQuery->select($col, "dtb_customer", $where, array($customer_id));
361   
362    // ²ñ°÷¾ðÊó¤Î½»½ê¤È°Û¤Ê¤ë¾ì¹ç
363    if($arrNew != $arrCustomerAddr[0]) {
364        // Ê̤ΤªÆϤ±Àè¥Æ¡¼¥Ö¥ë¤Î½»½ê¤ÈÈæ³Ó¤¹¤ë
365        $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02";
366        $where = "customer_id = ?";
367        $arrOtherAddr = $objQuery->select($col, "dtb_other_deliv", $where, array($customer_id));
368
369        foreach($arrOtherAddr as $arrval) {
370            if($arrNew == $arrval) {
371                // ¤¹¤Ç¤ËƱ¤¸½»½ê¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë
372                $find_same = true;
373            }
374        }
375       
376        if(!$find_same) {
377            $diff = true;
378        }
379    }
380   
381    // ¿·¤·¤¤¤ªÆϤ±À褬ÅÐÏ¿ºÑ¤ß¤Î¤â¤Î¤È°Û¤Ê¤ë¾ì¹ç¤ÏÊ̤ΤªÆϤ±Àè¥Æ¡¼¥Ö¥ë¤ËÅÐÏ¿¤¹¤ë
382    if($diff) {
383        $sqlval = $arrNew;
384        $sqlval['customer_id'] = $customer_id;
385        $objQuery->insert("dtb_other_deliv", $sqlval);
386    }
387}
388
389/* ¹ØÆþ¾ðÊó¤ò²ñ°÷¥Æ¡¼¥Ö¥ë¤ËÅÐÏ¿¤¹¤ë */
390function lfSetCustomerPurchase($customer_id, $arrData, $objQuery) {
391    $col = "first_buy_date, last_buy_date, buy_times, buy_total, point";
392    $where = "customer_id = ?";
393    $arrRet = $objQuery->select($col, "dtb_customer", $where, array($customer_id));
394    $sqlval = $arrRet[0];
395   
396    if($sqlval['first_buy_date'] == "") {
397        $sqlval['first_buy_date'] = "Now()";
398    }
399    $sqlval['last_buy_date'] = "Now()";
400    $sqlval['buy_times']++;
401    $sqlval['buy_total']+= $arrData['total'];
402    $sqlval['point'] = ($sqlval['point'] + $arrData['add_point'] - $arrData['use_point']);
403   
404    // ¥Ý¥¤¥ó¥È¤¬ÉÔ­¤·¤Æ¤¤¤ë¾ì¹ç
405    if($sqlval['point'] < 0) {
406        $objQuery->rollback();
407        sfDispSiteError(LACK_POINT);
408    }
409   
410    $objQuery->update("dtb_customer", $sqlval, $where, array($customer_id));
411}
412
413// ºß¸Ë¤ò¸º¤é¤¹½èÍý
414function lfReduceStock($objQuery, $arrID, $quantity) {
415    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
416    $arrRet = $objQuery->select("stock, stock_unlimited", "dtb_products_class", $where, $arrID);
417   
418    // Çä¤êÀڤ쥨¥é¡¼
419    if(($arrRet[0]['stock_unlimited'] != '1' && $arrRet[0]['stock'] < $quantity) || $quantity == 0) {
420        $objQuery->rollback();
421        sfDispSiteError(SOLD_OUT, "", true);
422    // ̵À©¸Â¤Î¾ì¹ç¡¢ºß¸Ë¤ÏNULL
423    } elseif($arrRet[0]['stock_unlimited'] == '1') {
424        $sqlval['stock'] = null;
425        $objQuery->update("dtb_products_class", $sqlval, $where, $arrID);
426    // ºß¸Ë¤ò¸º¤é¤¹
427    } else {
428        $sqlval['stock'] = ($arrRet[0]['stock'] - $quantity);
429        if($sqlval['stock'] == "") {
430            $sqlval['stock'] = '0';
431        }       
432        $objQuery->update("dtb_products_class", $sqlval, $where, $arrID);
433    }
434}
435
436// GET¤ÎÃͤò¥¤¥ó¥µ¡¼¥ÈÍѤËÀ°¤¨¤ë
437function lfGetInsParam($sqlVal){
438   
439    foreach($_GET as $key => $val){
440        // ¥«¥é¥à¤Î¸ºß¥Á¥§¥Ã¥¯
441        if(sfColumnExists("dtb_order", $key)) $sqlVal[$key] = $val;
442    }
443   
444    return $sqlVal;
445}
446?>
Note: See TracBrowser for help on using the repository browser.