本文整理汇总了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;
}
}