Example #1
0
 /**
  *处理微信服务器消息
  */
 public function defaultAction()
 {
     global $_F;
     $this->openDebug();
     require_once APP_ROOT . 'lib/weixin/WeixinChat.class.php';
     $options = array('token' => 'mumu2015api', 'appid' => 'wxe3ae7e3cf42d0825', 'appsecret' => '2d7b39fcb0813e7b07830683cc3caa50');
     $weixin = new WeixinChat($options);
     //        $weixin->valid();
     $logger = new FLogger("weixn");
     $logger->append('==============开始:===============');
     $getRev = $weixin->getRev();
     $logger->append($getRev->getRevText());
     if ($weixin->getRevType()) {
         $logger->append('getRevType:' . $weixin->getRevType());
         $eventData = $weixin->getRevEvent();
         $logger->append('eventData:' . var_export($eventData, true));
         if ($eventData) {
             $openid = $weixin->getRevFrom();
             if ($eventData['event'] == 'click') {
                 switch ($eventData['key']) {
                     case 'V1001_FREE':
                         $type = 1;
                         break;
                     case 'V1001_TODAY_ACTIVITY':
                         $type = 2;
                         break;
                     case 'V1001_FOUND':
                         $type = 3;
                         break;
                     default:
                         $type = 1;
                         break;
                 }
                 $data = $this->getNewsMsgData($type);
             } else {
                 if ($eventData['event'] == 'subscribe') {
                     //                        $upData = array(
                     //                            'subscribe' => 1,
                     //                            'subscribe_time' => date('Y-m-d H:i:s', time())
                     //                        );
                     $userInfo = $weixin->getUserInfo($openid);
                     FLogger::write($userInfo, 'subscribe');
                     Service_UserWechat::reg($userInfo, $openid);
                     //                        $data = $this->getNewsMsgData(2);
                     $data = '欢迎关注缘分吧';
                 }
                 if ($eventData['event'] == 'unsubscribe') {
                     //                        $upData = array(
                     //                            'subscribe' => 0
                     //                        );
                 }
             }
         }
         if ($data) {
             $logger->append(var_export($data, true));
             $logger->append(FRequest::getClientIP());
             //                $logger->append(json_encode($weixin->getRevData()));
             $weixin->text($data);
             $weixin->reply();
         }
     } else {
         $logger->append('getRevType为空' . $weixin->getRevType());
     }
     $logger->append('==============结束:===============');
 }
Example #2
0
<?php

//裝載模板文件
require_once "/var/www/html/site/lib/config.php";
require_once "/var/www/lib/saja/mysql.ini.php";
require_once "/var/www/html/site/lib/wechat.class.php";
require_once "/var/www/html/site/oauth/WeixinAPI/WeixinChat.class.php";
$options['appid'] = APP_ID;
$options['appsecret'] = APP_SECRET;
/*
$db = new mysql($config["db"][0]);
$db->connect();
$accessToken = weixin_access_token($config, $db);
error_log("[wxtest] access_token: ".$accessToken);

$options['token']='hxUSQCEEajHcSA8E';

error_log(json_encode($options));
*/
$wx = new WeixinChat($options);
$wx->sendCustomMessage('oNmoZtwAKJDadgwmxcdw594QndTk', '可以的,目前中国与台湾杀友都可以使用本服务。目前杀价王正在规划布局大型推广活动与合作,希望能提供更多元服务给所有杀友。也请您多加帮忙宣传杀价王。祝您杀价愉快。', 'text');
Example #3
0
 public function mk_history($product)
 {
     $time_start = microtime(true);
     global $db, $config;
     $r['err'] = '';
     $r['winner'] = '';
     $r['rank'] = '';
     $values = array();
     if ($_POST['use_sgift'] == 'Y') {
         /****************************
          * 使用禮券
          ****************************/
         //檢查禮券數量
         $query = "SELECT *\r\n\t\t\tFROM `{$config['db'][1]['dbname']}`.`{$config['default_prefix']}sgift`  \r\n\t\t\tWHERE \r\n\t\t\t\t`prefixid` = '{$config['default_prefix_id']}'\r\n\t\t\t\tAND productid = '{$product['productid']}' \r\n\t\t\t\tAND userid = '{$this->userid}'\r\n\t\t\t\tAND used = 'N'\r\n\t\t\t\tAND switch = 'Y'\r\n\t\t\tORDER BY seq\r\n\t\t\t";
         $table = $db->getQueryRecord($query);
         if (empty($table['table']['record'])) {
             $sgift = 0;
         } else {
             $sgift = count($table['table']['record']);
             //礼券數量
         }
         if ($this->tickets > $sgift) {
             //'礼券不足'
             $r['err'] = 15;
         } else {
             //使用礼券
             for ($i = 0; $i < round($this->tickets); $i++) {
                 $query = "UPDATE `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}sgift` \r\n\t\t\t\t\tSET \r\n\t\t\t\t\t\tused = 'Y',\r\n\t\t\t\t\t\tused_time = NOW()\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t`prefixid` = '{$config['default_prefix_id']}'\r\n\t\t\t\t\t\tAND sgiftid = '{$table['table']['record'][$i]['sgiftid']}'\r\n\t\t\t\t\t\tAND switch = 'Y'\r\n\t\t\t\t\t";
                 $res = $db->query($query);
                 //殺價下標歷史記錄(對應下標記錄與下標禮券id)
                 $values[$i] = "\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t'{$config['default_prefix_id']}',\r\n\t\t\t\t\t\t'{$product['productid']}',\r\n\t\t\t\t\t\t'{$this->userid}',\r\n\t\t\t\t\t\t'{$this->username}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'{$table['table']['record'][$i]['sgiftid']}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'" . ($this->price + $i * $this->currency_unit) . "',\r\n\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t)";
             }
             if (empty($values)) {
                 //'下标失败'
                 $r['err'] = -1;
             }
         }
     } elseif ($_POST['pay_type'] == 'oscode') {
         /****************************
          * 使用殺價券 : 為針對某特定商品免費的「下標次數」, 1張殺價券可以下標乙次
          ****************************/
         //檢查殺價券數量
         $query = "SELECT *\r\n\t\t\tFROM `{$config['db'][1]['dbname']}`.`{$config['default_prefix']}oscode`  \r\n\t\t\tWHERE `prefixid` = '{$config['default_prefix_id']}'\r\n\t\t\t\tAND productid = '{$product['productid']}' \r\n\t\t\t\tAND userid = '{$this->userid}'\r\n\t\t\t\tAND used = 'N'\r\n\t\t\t\tAND switch = 'Y'\r\n\t\t\t    ORDER BY oscodeid\r\n\t\t\t";
         $table = $db->getQueryRecord($query);
         if (empty($table['table']['record'])) {
             $osq = 0;
         } else {
             $osq = count($table['table']['record']);
         }
         error_log("[ajax/product/mk_history]: needed ==>" . round($this->tickets));
         error_log("[ajax/product/mk_history]:" . $query . "==>" . $osq);
         if (round($this->tickets) > $osq) {
             //'殺價券不足'
             $r['err'] = 14;
         } else {
             //使用殺價券
             for ($i = 0; $i < round($this->tickets); $i++) {
                 $query = "UPDATE `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}oscode` \r\n\t\t\t\t\tSET \r\n\t\t\t\t\t\t`behav`='user_saja',\r\n\t\t\t\t\t\tused = 'Y',\r\n\t\t\t\t\t\tused_time = NOW()\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t`prefixid` = '{$config['default_prefix_id']}'\r\n\t\t\t\t\t\tAND oscodeid = '{$table['table']['record'][$i]['oscodeid']}'\r\n\t\t\t\t\t\tAND switch = 'Y'\r\n\t\t\t\t\t";
                 $res = $db->query($query);
                 //殺價下標歷史記錄(對應下標記錄與 oscodeid)
                 $values[$i] = "\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t'{$config['default_prefix_id']}',\r\n\t\t\t\t\t\t'{$product['productid']}',\r\n\t\t\t\t\t\t'{$this->userid}',\r\n\t\t\t\t\t\t'{$this->username}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'{$table['table']['record'][$i]['oscodeid']}',\r\n\t\t\t\t\t\t'" . ($this->price + $i * $this->currency_unit) . "',\r\n\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t)";
             }
             if (empty($values)) {
                 //'下标失败'
                 $r['err'] = -1;
             }
         }
     } elseif ($_POST['pay_type'] == 'scode') {
         /****************************
          * 使用S碼 : 為免費的「下標次數」,1組S碼可以下標乙次
          * 有效時間為30天(發送當天開始算30天),逾期失效不補回。
          ****************************/
         $scodeModel = new ScodeModel();
         $scode = $scodeModel->get_scode($this->userid);
         //檢查S碼數量
         if ($this->tickets > $scode) {
             //'S碼不足'
             $r['err'] = 12;
         } else {
             //確認S碼
             $query = "select scodeid from `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}scode` \r\n\t\t\t\t\twhere \r\n\t\t\t\t\t`prefixid`='{$config['default_prefix_id']}' \r\n\t\t\t\t\tand `userid` = '{$this->userid}' \r\n\t\t\t\t\tand `behav` != 'a' \r\n\t\t\t\t\tand `closed` = 'N'\r\n\t\t\t\t\tand `remainder` > 0\r\n\t\t\t\t\tand `switch` = 'Y'\r\n\t\t\t\t\torder by insertt asc\r\n\t\t\t\t\tlimit 0, 1\r\n\t\t\t\t";
             $table = $db->getQueryRecord($query);
             //使用S碼
             $query = "update `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}scode` \r\n\t\t\t\tSET\r\n\t\t\t\t\t`remainder`=`remainder` - {$this->tickets},\r\n\t\t\t\t\t`modifyt`=NOW()\r\n\t\t\t\twhere\r\n\t\t\t\t\t`prefixid`='{$config['default_prefix_id']}' \r\n\t\t\t\t\tand `scodeid` =  '{$table['table']['record'][0]['scodeid']}'\r\n\t\t\t\t\tand `userid` = '{$this->userid}' \r\n\t\t\t\t\tand `behav` != 'a' \r\n\t\t\t\t\tand `closed` = 'N'\r\n\t\t\t\t\tand `remainder` > 0\r\n\t\t\t\t\tand `switch` = 'Y'\r\n\t\t\t\t";
             $res = $db->query($query);
             $query = "INSERT INTO `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}scode` \r\n\t\t\t\tSET\r\n\t\t\t\t\t`prefixid`='{$config['default_prefix_id']}',\r\n\t\t\t\t\t`userid`='{$this->userid}',\r\n\t\t\t\t\t`behav`='a',\r\n\t\t\t\t\t`productid`='{$product['productid']}',\r\n\t\t\t\t\t`amount`='" . -$this->tickets . "',\r\n\t\t\t\t\t`insertt`=NOW()\r\n\t\t\t\t";
             $res = $db->query($query);
             $scodeid = $db->_con->insert_id;
             for ($i = 0; $i < round($this->tickets); $i++) {
                 //殺價下標歷史記錄(對應下標記錄與使用S碼id)
                 $values[$i] = "\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t'{$config['default_prefix_id']}',\r\n\t\t\t\t\t\t'{$product['productid']}',\r\n\t\t\t\t\t\t'{$this->userid}',\r\n\t\t\t\t\t\t'{$this->username}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'{$scodeid}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'" . ($this->price + $i * $this->currency_unit) . "',\r\n\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t)";
             }
             if (empty($values)) {
                 //'下标失败'
                 $r['err'] = -1;
             }
         }
     } elseif ($_POST['pay_type'] == 'saja_test') {
         /****************************
          * 壓力測試 : 使用殺價券下標, 測試商品productid=2923
          ****************************/
         //檢查殺價券數量
         $query = "SELECT *\r\n\t\t\tFROM `{$config['db'][1]['dbname']}`.`{$config['default_prefix']}oscode`  \r\n\t\t\tWHERE `prefixid` = '{$config['default_prefix_id']}'\r\n\t\t\t\tAND productid = '2923' \r\n\t\t\t\tAND userid = '{$this->userid}'\r\n\t\t\t\tAND used = 'N'\r\n\t\t\t\tAND switch = 'Y'\r\n\t\t\t    ORDER BY oscodeid\r\n\t\t\t";
         $table = $db->getQueryRecord($query);
         if (empty($table['table']['record'])) {
             $osq = 0;
         } else {
             $osq = count($table['table']['record']);
         }
         $osq = 9999;
         // error_log("[ajax/product/saja_test]: needed ==>".round($this->tickets));
         // error_log("[ajax/product/saja_test]:".$query."==>".$osq);
         if (round($this->tickets) > $osq) {
             //'殺價券不足'
             $r['err'] = 14;
         } else {
             //使用殺價券
             for ($i = 0; $i < round($this->tickets); $i++) {
                 $query = "UPDATE `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}oscode` \r\n\t\t\t\t\tSET behav ='saja_test',\r\n\t\t\t\t\t\tused = 'Y',\r\n\t\t\t\t\t\tused_time = NOW()\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tprefixid = '{$config['default_prefix_id']}'\r\n\t\t\t\t\t\tAND oscodeid = 0\r\n\t\t\t\t\t\tAND switch = 'Y'\r\n\t\t\t\t\t";
                 $res = $db->query($query);
                 // error_log("[ajax/product/saja_test]:".$query."==>".$res);
                 //殺價下標歷史記錄(對應下標記錄與 oscodeid)
                 $values[$i] = "\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t'{$config['default_prefix_id']}',\r\n\t\t\t\t\t\t'2923',\r\n\t\t\t\t\t\t'{$_POST['userid']}',\r\n\t\t\t\t\t\t'{$_POST['username']}',\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\t'" . ($this->price + $i * $this->currency_unit) . "',\r\n\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t)";
             }
             if (empty($values)) {
                 //'下标失败'
                 $r['err'] = -1;
             }
         }
     } else {
         /****************************
          * 使用殺幣
          ****************************/
         $scode_fee = 0;
         //檢查殺幣餘額
         $query = "SELECT SUM(amount) as amount\r\n\t\t\tFROM `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}spoint` \r\n\t\t\tWHERE userid = '{$this->userid}'\r\n\t\t\t\tAND prefixid = '{$config['default_prefix_id']}' \r\n\t\t\t\tAND countryid = '{$this->countryid}'\r\n\t\t\t\tAND switch = 'Y'\r\n\t\t\t";
         $table = $db->getQueryRecord($query);
         $saja_fee = (double) $this->tickets * (double) $product['saja_fee'];
         //下標手續費
         $saja_fee_amount = $saja_fee;
         //下標費用 = 手續費
         if ($saja_fee_amount > (double) $table['table']['record'][0]['amount']) {
             //'杀价币不足'
             $r['err'] = 13;
         } else {
             //使用殺幣
             $query = "INSERT INTO `{$config['db'][1]["dbname"]}`.`{$config['default_prefix']}spoint` \r\n\t\t\t\tSET\r\n\t\t\t\t\t`prefixid`='{$config['default_prefix_id']}',\r\n\t\t\t\t\t`userid`='{$this->userid}',\r\n\t\t\t\t\t`countryid`='{$this->countryid}',\r\n\t\t\t\t\t`behav`='user_saja',\r\n\t\t\t\t\t`amount`='" . -$saja_fee_amount . "',\r\n\t\t\t\t\t`insertt`=NOW()\r\n\t\t\t\t";
             $res = $db->query($query);
             $spointid = $db->_con->insert_id;
             for ($i = 0; $i < round($this->tickets); $i++) {
                 //殺價下標歷史記錄(對應下標記錄與使用殺幣記錄id)
                 $values[$i] = "\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t'{$config['default_prefix_id']}',\r\n\t\t\t\t\t\t'{$product['productid']}',\r\n\t\t\t\t\t\t'{$this->userid}',\r\n\t\t\t\t\t\t'saja_test',\r\n\t\t\t\t\t\t'{$spointid}',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'0',\r\n\t\t\t\t\t\t'" . ($this->price + $i * $this->currency_unit) . "',\r\n\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t)";
             }
             if (empty($values)) {
                 //'下标失败'
                 $r['err'] = -1;
             }
         }
     }
     if (empty($r['err']) && !empty($values)) {
         // 取得目前winner
         $arr_ori_winner = array();
         $arr_ori_winner = $this->getBidWinner($product['productid']);
         if (!empty($arr_ori_winner)) {
             error_log("[ajax/product/mk_history]: ori Winner of " . $arr_ori_winner['prodname'] . " is :" . $arr_ori_winner['nickname']);
         } else {
             error_log("[ajax/product/mk_history]: ori Winner is Empty !");
         }
         //產生下標歷史記錄
         $query = "INSERT INTO `{$config['db'][4]["dbname"]}`.`{$config['default_prefix']}history` \r\n\t\t\t(\r\n\t\t\t\tprefixid,\r\n\t\t\t\tproductid,\r\n\t\t\t\tuserid,\r\n\t\t\t\tnickname,\r\n\t\t\t\tspointid,\r\n\t\t\t\tscodeid,\r\n\t\t\t\tsgiftid,\r\n\t\t\t\toscodeid,\r\n\t\t\t\tprice,\r\n\t\t\t\tinsertt\r\n\t\t\t)\r\n\t\t\tVALUES\r\n\t\t\t" . implode(',', $values) . "\r\n\t\t\t";
         $res = $db->query($query);
         // error_log("[ajax/product]:".$query."-->".$res);
         $r['rank'] = $last_rank;
         // 結標一分鐘以前, 單次下標將提示順位
         if ($_POST['type'] == 'single') {
             if ($product['offtime'] > 0 && $product['offtime'] - $product['now'] > $this->display_rank_time_limit) {
                 // 檢查重複
                 $query = "SELECT count(userid) as cnt \r\n\t\t\t\t\t\t\t   FROM `{$config['db'][4]["dbname"]}`.`{$config['default_prefix']}history` \r\n\t\t\t\t\t\t\t  WHERE productid='{$product['productid']}' \r\n\t\t\t\t\t\t\t\tAND price={$_POST['price']} \r\n\t\t\t\t\t\t\t\tAND switch='Y' ";
                 $table = $db->getQueryRecord($query);
                 $dup_cnt = $table['table']['record'][0]['cnt'];
                 // error_log("[ajax/product]Dup chk: ".$query." --> ".$dup_cnt);
                 if ($dup_cnt > 1) {
                     // 重複出價
                     $r['rank'] = -1;
                 } else {
                     if ($dup_cnt <= 1) {
                         // 無重複出價
                         $query1 = "SELECT count(*) as cnt FROM  `{$config['db'][4]["dbname"]}`.`v_unique_price` \r\n\t\t\t\t\t\t\t\t   WHERE productid='{$product['productid']}' AND price<{$_POST['price']} ";
                         error_log("[ajax/product]rank chk cnt : " . $query1);
                         $table1 = $db->getQueryRecord($query1);
                         $r['rank'] = $table1['table']['record'][0]['cnt'];
                         error_log("[ajax/product]rank : " . $r['rank']);
                     }
                 }
             }
         }
         // 結標一分鐘以前, 區間下標10標以上, 將提示該區間內唯一出价個數, 及該次下標的唯一最低價
         if ($_POST['type'] == 'range') {
             if ($product['offtime'] > 0 && $product['offtime'] - $product['now'] > $this->display_rank_time_limit) {
                 $r['total_num'] = $this->tickets;
                 error_log("range tickets : " . $this->tickets);
                 // 顯示提示
                 // 取得該區間內唯一出價的個數
                 if ($this->tickets > 1) {
                     $query = "SELECT * FROM saja_shop.saja_history sh JOIN saja_shop.v_unique_price up \r\n\t\t\t\t\t\t\t\t   ON sh.productid=up.productid AND sh.price=up.price AND sh.productid='{$product['productid']}' AND sh.switch='Y' \r\n\t\t\t\t\t\t\t\tWHERE sh.switch='Y'  \r\n\t\t\t\t\t\t\t\t  AND sh.productid='{$product['productid']}' \r\n\t\t\t\t\t\t\t\t  AND sh.price between {$_POST['price_start']} AND {$_POST['price_stop']}\r\n\t\t\t\t\t\t\t\t  AND sh.userid='{$this->userid}' ORDER BY sh.price asc ";
                     error_log("[ajax/product]range chk: " . $query);
                     $table = $db->getQueryRecord($query);
                     error_log("[ajax/product]range chk count:" . count($table['table']['record']) . "-->lowest" . $table['table']['record'][0]['price']);
                     if (empty($table['table']['record'])) {
                         // 無唯一出价
                         $r['num_uniprice'] = 0;
                         $r['lowest_uniprice'] = 0;
                     } else {
                         // 有唯一出价
                         $r['num_uniprice'] = count($table['table']['record']);
                         $r['lowest_uniprice'] = sprintf("%01.2f", $table['table']['record'][0]['price']);
                     }
                 } else {
                     // 不提示
                     $r['total_num'] = -1;
                 }
             } else {
                 // 不提示
                 $r['total_num'] = -1;
             }
         }
         // 結標一分鐘以前, 得標者改變會發微信通知(openid)
         if ($product['offtime'] > 0 && $product['offtime'] - $product['now'] > $this->display_rank_time_limit) {
             $arr_new_winner = array();
             $arr_new_winner = $this->getBidWinner($product['productid']);
             $r['winner'] = empty($arr_new_winner['nickname']) ? '无' : $arr_new_winner['nickname'];
             $redis = new Redis();
             $redis->connect('127.0.0.1');
             $redis->set('PROD:' . $product['productid'] . ':BIDDER', $r['winner']);
             if ($_POST['pay_type'] != 'saja_test') {
                 if ($arr_ori_winner['userid'] != $arr_new_winner['userid']) {
                     $options['appid'] = APP_ID;
                     $options['appsecret'] = APP_SECRET;
                     $wx = new WeixinChat($options);
                     if (!empty($arr_new_winner['openid'])) {
                         $msg = '【目前中标通知】 恭喜你!刚刚干掉之前<a href="http://www.shajiawang.com/wx_auth.php?jdata=gotourl:/site/product/saja/?productid=' . $arr_new_winner['productid'] . '">《' . $arr_new_winner['prodname'] . '》</a>的中标者。请持续关注,以确保领先地位。';
                         $wx->sendCustomMessage($arr_new_winner['openid'], $msg, 'text');
                         $wx->sendCustomMessage('oNmoZtxOu0pKnlUjZjO0beFCSfEY', $msg, 'text');
                     }
                     if (!empty($arr_ori_winner['openid'])) {
                         if (!empty($arr_new_winner['userid'])) {
                             $msg = '【紧急通知】原本你中标的<a href="http://www.shajiawang.com/wx_auth.php?jdata=gotourl:/site/product/saja/?productid=' . $arr_ori_winner['productid'] . '">《' . $arr_ori_winner['prodname'] . '》</a>在刚刚被某个小伙伴给抢走了!赶紧去看看是哪个家伙!再把它抢回来吧!';
                         } else {
                             if (empty($arr_new_winner['userid'])) {
                                 $msg = '【紧急通知】原本你中标的<a href="http://www.shajiawang.com/wx_auth.php?jdata=gotourl:/site/product/saja/?productid=' . $arr_ori_winner['productid'] . '">《' . $arr_ori_winner['prodname'] . '》</a>目前无人中标 ! 赶紧再去把它抢回来吧!';
                             }
                         }
                         $wx->sendCustomMessage($arr_ori_winner['openid'], $msg, 'text');
                         $wx->sendCustomMessage('oNmoZtxOu0pKnlUjZjO0beFCSfEY', $msg, 'text');
                     }
                 }
             }
         }
         // 得標者
         /*
         $query2="SELECT userid, productid, nickname, price FROM `{$config['db'][4]["dbname"]}`.`{$config['default_prefix']}history` 
         		  WHERE (productid, price) = (SELECT productid, min_price FROM  `{$config['db'][4]["dbname"]}`.`v_min_unique_price` WHERE productid='{$product['productid']}') ";
         		
         error_log("[ajax/product]winner chk: ".$query2);
         $table2 = $db->getQueryRecord($query2);
         $r['winner'] = $table2['table']['record'][0]['nickname'];  
         */
         //單次下標而且離結標還有$this->display_rank_time_limit秒以上,回傳目前順位
         //if($_POST['type'] == 'single')
         /*
         $rank = $this->last_rank-1;//最大顯示排名為第10位
                     $query = "SELECT h.userid, h.nickname, h.price
               			FROM `{$config['db'][4]["dbname"]}`.`{$config['default_prefix']}history` h 
           WHERE h.prefixid = '{$config['default_prefix_id']}'
         	AND h.productid = '{$product['productid']}'
         	AND h.price < '{$_POST['price']}'
         	AND h.price is not null
         	AND h.switch = 'Y'
         GROUP BY h.price
         HAVING COUNT(*) = 1
         ORDER BY h.price asc
         LIMIT {$rank}
         ";
         $table = $db->getQueryRecord($query);
         
         if (!empty($table['table']['record'])) 
         {
         	//回傳中標者
         	$r['winner'] = $table['table']['record'][0]['nickname']; 
         
         	//下標而且離結標還有十分鐘以上,回傳目前順位
         	if ($product['offtime'] > 0 && ($product['offtime'] - $product['now'] > $this->display_rank_time_limit) ) 
         	{
         		foreach ($table['table']['record'] as $rk => $rv)
         		{
         			if ($rv['price'] == $_POST['price']) {
         				$rank = $rk + 1;
         				break;
         			}
         		}
         		$r['rank'] = $rank;
         	}
         }
         else 
         {
         	if ($product['offtime'] > 0 && ($product['offtime'] - $product['now'] > $this->display_rank_time_limit) ) 
         	{
         		$r['rank'] = $rank;
         	}
         }
         */
     }
     $time_end = microtime(true);
     $time = number_format($time_end - $time_start, 10);
     //echo "產生下標歷史記錄 $time 秒<br>";
     error_log("[ajax/mk_history] r : " . json_encode($r));
     return $r;
 }
Example #4
0
    $accessToken = weixin_access_token($config, $db);
    if (!empty($accessToken)) {
        $scope = 1;
        $wxchat = new WeixinChat($options);
        $state = urlencode($_REQUEST['jdata']);
        if (empty($state)) {
            $state = STATE;
        }
        $code_url = $wxchat->redirectGetOauthCode("http://www.shajiawang.com/wx_auth.php", $scope, $state);
    } else {
        die("access token error !!");
    }
} else {
    if (!empty($state)) {
        // Call back from WeiXin with param $state,
        $wx_user = new WeixinChat($options);
        $token = '';
        // 從code去抓token(用curl方式)
        if (isset($_REQUEST['code'])) {
            $code = $_REQUEST['code'];
            try {
                $token = $wx_user->getSnsAccessToken($code);
            } catch (OAuthException $e) {
                echo "[wx_auth] Caught exception:", $e->getMessage();
            }
        }
        $jdata = $state;
        // $arr_data=json_decode($jdata,true);
        // 由token抓user info
        if (!empty($token)) {
            session_start();