本文整理匯總了PHP中Factory::getDb方法的典型用法代碼示例。如果您正苦於以下問題:PHP Factory::getDb方法的具體用法?PHP Factory::getDb怎麽用?PHP Factory::getDb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Factory
的用法示例。
在下文中一共展示了Factory::getDb方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Model
public function Model($tab = '', $dbname = null)
{
if ($tab != '') {
$this->tab = $tab;
}
$this->db = Factory::getDb($dbname);
}
示例2: __construct
public function __construct(Factory $factory)
{
$this->factory = $factory;
$this->db = $factory->getDb();
$this->logger = $factory->getLogger();
$this->mainTable = $this->getMainTable();
$this->relationsTable = $this->getRelationsTable();
$this->createTables();
}
示例3: getInfoByActionKey
/**
* 通過活動關鍵字獲取活動信息
*/
public function getInfoByActionKey($actionKey) {
try{
$strsql = "SELECT * FROM `".DBConfig::$table['config']."` WHERE `key` = '{$actionKey}' LIMIT 1";
$res = Factory::getDb("weixin_active","MySql")->getRow($strsql);
return (is_array($res) && $res) ? $res : array();
} catch (Exception $e) {
Logger::error("通過關鍵字獲取活動信息失敗".$e->getmessage());
return false;
}
}
示例4: getBindingInfo
/**
* 獲取用戶綁定信息
* @param string $uid 用戶id
* @param int $aid 活動id
* @return int state 0-沒有參與綁定 1-綁定用戶 2-解綁用戶
*/
public function getBindingInfo($uid,$aid) {
try{
$strsql = "SELECT * FROM ".DBConfig::$table['user']." WHERE `uid` = '{$uid}' AND `aid` = {$aid} LIMIT 1";
$res = Factory::getDb("weixin_active")->getRow($strsql);
return ($res['state']) ? $res['state'] : 0;
} catch (Exception $e) {
Logger::error("獲取用戶綁定信息失敗".$e->getMessage());
return false;
}
}
示例5: insertSource
/**
* 插入一條來源記錄
* @param int $aid 活動id
* @param int $scontent 來源值
* @param int $memo 備注信息(默認空字符)
* @return int $sid 插入的id即(來源id)
*/
public function insertSource($aid,$scontent,$memo=""){
try {
$scontent = mysql_real_escape_string($scontent);
if($memo) $memo = mysql_real_escape_string($memo);
$sid = Factory::getDb("weixin_active")->insert(DBConfig::$table['source'],array("aid"=>$aid,"svalue"=>$scontent,"memo"=>$memo));
return $sid;
} catch (Exception $e) {
Logger::error("插入一條來源記錄失敗".$e->getmessage());
return false;
}
}
示例6: updateData
/**
* 插入業務數據或者更新之
*/
public function updateData($uid,$aid,$wid,$key,$data) {
try {
$curTime = time();
$data = mysql_real_escape_string($data);
$strsql = "INSERT INTO `".DBConfig::$table['data']."`(`uid`,`aid`,`wid`,`key`,`data`,`time`) VALUES ('{$uid}',{$aid},{$wid},'{$key}','{$data}',{$curTime}) ON DUPLICATE KEY UPDATE `filed`=`data`,`data`='{$data}',`time`={$curTime}";
Factory::getDb("weixin_active")->query($strsql);
return Factory::getDb("weixin_active")->affectedRows();
} catch (Exception $e) {
Logger::error("插入業務數據或者更新之失敗".$e->getmessage());
return false;
}
}
示例7: insertInfo
/**
* 插入記錄
*/
public function insertInfo($data) {
if(!$uid = $data['uid']) return false;
if(!$aid = $data['aid']) return false;
if(!$wid = $data['wid']) return false;
$name = $data['name'];
$cardID = $data['cardID'];
if(!$address = $data['address']) return false;
$code = $data['code'];
if(!$tel = $data['tel']) return false;
if(!$rid = $data['rid']) return false;
Factory::getDb("weixin_active")->insert(DBConfig::$table['mail'],array('uid'=>$uid,'aid'=>$aid,'wid'=>$wid,'name'=>$name,'cardID'=>$cardID,'address'=>$address,'code'=>$code,'tel'=>$tel,'rid'=>$rid,'time'=>time()));
return Factory::getDb("weixin_active")->insertId();
}
示例8: updateRecord
/**
* 插入一條操作記錄或更新一條操作記錄
*/
public function updateRecord($uid,$aid,$key,$filed = "") {
try {
$curTime = time();
if($filed) {
$strsql = "INSERT INTO `".DBConfig::$table['oper']."`(`uid`,`aid`,`operNum`,`operKey`,`operValue`,`time`) VALUES ('{$uid}',{$aid},1,'{$key}','{$filed}',{$curTime}) ON DUPLICATE KEY UPDATE `operNum`=`operNum`+1,`operValue`=CONCAT(`operValue`,'{$filed}'),`time`={$curTime}";
} else {
$strsql = "INSERT INTO `".DBConfig::$table['oper']."`(`uid`,`aid`,`operNum`,`operKey`,`operValue`,`time`) VALUES ('{$uid}',{$aid},1,'{$key}','{$filed}',{$curTime}) ON DUPLICATE KEY UPDATE `operNum`=`operNum`+1,`time`={$curTime}";
}
Factory::getDb("weixin_active")->query($strsql);
return Factory::getDb("weixin_active")->affectedRows();
} catch (Exception $e) {
Logger::error("插入業務數據或者更新之失敗".$e->getmessage());
return false;
}
}
示例9: create
/**
* 列表
*/
public function create()
{
$tab_name = I('tab_name', '');
if (!empty($tab_name)) {
$this->table = $tab_name;
$db = Factory::getDb('DEFAULT_DB');
//得到具體的業務邏輯行數,進行tpl處理
$sql = "show full columns from {$tab_name}";
$list = $db->query($sql);
if (empty($list)) {
exit('數據表無法讀取');
}
$row_id = array_slice($list, 0, 1);
$row_date = array_slice($list, -2, 2);
$this->columns = array_slice($list, 1, -3);
foreach ($this->columns as $v) {
$this->field[] = $v['Field'];
}
//得到語句
$sql = "SHOW CREATE TABLE {$tab_name}";
$row = $db->query($sql);
$tab = $row[0]['Create Table'];
//生成add,tpl,edit tpl,list tpl
$action_tpl = $add_tpl = $edit_tpl = $list_tpl = '';
$add_tpl = $this->getTpl('add');
$edit_tpl = $this->getTpl('edit');
$list_tpl = $this->getTpl('list');
$action_tpl = $this->getTpl('act');
$this->assign('table_ddl', $tab);
$this->assign('tab_name', $tab_name);
$this->assign("action_tpl", $action_tpl);
$this->assign("add_tpl", $add_tpl);
$this->assign("edit_tpl", $edit_tpl);
$this->assign("list_tpl", $list_tpl);
$this->assign("showType", 'tpl');
}
$this->display();
}
示例10: getDb
/**
* 獲取db實例
* @param string $dbname 配置中數據庫名稱
* @param string $dbClassName db
*/
public function getDb ($dbname = null, $dbClassName = 'MySql') {
return Factory::getDb($dbname, $dbClassName);
}
示例11: subscrib
/**
* 處理關注事件
*
* @param array $params [description]
*
* @return void
*/
public function subscrib(array $params) {
if (!isset($params['openid']) || !isset($params['event_key'])) {
return false;
}
// 隻記錄新關注的用戶
// {"a":"Invitation","apiKey":"9d351e5444ca8328721988dc84234e3d","timestamp":"1446186825","sig":"72b2481e8696a09119406955daa489cd","openid":"onwtvsw1aSkZDwyeQtac7DElG9O8","event_key":"456"}
// event_key 參數的數值帶 “qrscene_xxx” 標識表示成功關注了的,隻是數字的話表示 已關注過 重新掃描進來的。
$event_key = explode('_', $params['event_key']);
// 入庫並發放獎勵
if ($event_key[0] == 'qrscene' && !empty($event_key[1])) {
// 根據 qimg_id 獲得 scene_id
$ywcDb = Factory::getDb('YWC_DB');
$codeSceneParams = array(
'where' => array(
'scene_id' => $event_key[1],
),
);
$sceneInfo = $ywcDb->get('wx_qr_code_scene', $codeSceneParams, true);
if (empty($sceneInfo)) {
// 獲取用戶信息失敗
Logger::error('合夥人信息不存在! OpenId' . $params['openid']);
return false;
}
// 根據 qimg_id 獲得合夥人的 openId
$invitationQrcParams = array(
'qimg_id' => intval($sceneInfo['qimg_id']),
);
$qrInfo = loadModel('Index.InvitationQrc')->getDetail($invitationQrcParams);
if (!empty($qrInfo)) {
//關注後發送卡券領取消息
$source_openid = $qrInfo['open_id'] ? $qrInfo['open_id'] : '';
$url = 'http://sh.app.socialjia.com/5100App/www/partners.php?a=Draw&m=index&openid=' . $params['openid'] . '&source_openid=' . $source_openid . '&wechat_card_js=1';
$msg_text = "5100Skincare,<a href=\"{$url}\">領取優惠券</a>";
//關注後被動回複發送卡券領取消息
//echo (loadModel('Common')->msgText($params['openid'], '領取優惠券'));
//發送消息
Logger::debug('關注後發送領取卡券信息', $params);
loadModel('Common')->insertOneMessage($params['openid'], $msg_text);
// 獲得關注用戶的基礎信息
$userInfo = loadModel('Common')->getUserToApi($params['openid']);
$userInfo = json_decode($userInfo, true);
if ($userInfo['error'] != 0) {
// 獲取用戶信息失敗
Logger::error('獲取用戶信息失敗 OpenId' . $params['openid']);
}
// 檢查用戶是否重複關注
$invitationParams = array(
'open_id' => $params['openid'],
);
$userWxInfo = $this->getDetail($invitationParams);
if (!empty($userWxInfo)) {
// 用戶重複關注
Logger::error('用戶重複關注 OpenId' . $params['openid']);
return true;
}
// 獲得發放獎勵的參數
$awardParams = array(
'where' => array(
'id' => 1,
),
);
$award = $this->_db->get('wx_partner_award', $awardParams, true);
if (empty($award)) {
// 沒有配置獎勵參數
Logger::error('沒有配置獎勵參數 OpenId' . $params['openid']);
}
$score = intval($award['score']);
$money = floatval($award['money']);
$limitMoney = 500; // 每月上限金額
// 檢查當月獎勵金額是否到達每月上限
$sql = "SELECT SUM(money) money FROM wx_partner_invitation WHERE `invitation_open_id`='{$qrInfo['open_id']}' AND DATE_FORMAT(create_time, '%Y-%m') = '" . date('Y-m') . "' ";
$totalMoney = $this->_db->getOne($sql);
$totalMoney = floatval($totalMoney);
if (($totalMoney + $money) > $limitMoney) {
if ($totalMoney < $limitMoney) {
$money = number_format($limitMoney - $totalMoney, 2);
} else {
$money = 0;
}
}
$insert = array(
//.........這裏部分代碼省略.........
示例12: __construct
public function __construct()
{
parent::__construct();
$this->_db = Factory::getDb();
}
示例13: __construct
public function __construct ()
{
$this->_db = Factory::getDb();
}
示例14: updateState
/**
* 更新用戶業務數據狀態
*/
public function updateState($wid,$data) {
try {
$data['time'] = time();
$where = "`wid` = '{$wid}'";
Factory::getDb("weixin_active")->update(DBConfig::$table['record'],$where,$data);
return Factory::getDb("weixin_active")->affectedRows();
} catch (Exception $e) {
Logger::error("更新用戶業務數據狀態失敗".$e->getMessage());
return false;
}
}
示例15: updateLastRewardInfo
/**
* 更新用戶最近的獲獎記錄狀態
* @param int $id 記錄id
* @param int $state 狀態
*/
public function updateLastRewardInfo($id,$state) {
try{
$strsql = "UPDATE ".DBConfig::$table['ureward']." SET `state` = {$state} WHERE `id` = '{$id}'";
Factory::getDb("weixin_active")->query($strsql);
return Factory::getDb("weixin_active")->affectedRows();
}catch (Exception $e) {
Logger::error("更新用戶最近的獲獎記錄狀態".$e->getmessage());
return false;
}
}