/** * 注册 * @param array $data 注册数据 */ public function regist($data) { // 将用户信息添加到User表中 $tranDb = new Model(); $tranDb->startTrans(); $username = $data['username']; $result = $tranDb->table('world_user')->where("username = '******'")->find(); if ($result == null) { $user_info = array('username' => $username, 'password' => $data['password'], 'session' => md5(time() . $username), 'modify_time' => time(), 'last_time' => time()); $uid = $tranDb->table('world_user')->data($user_info)->add(); $tranDb->commit(); return 1; // 注册用户成功 } else { return -1; // 用户名已存在 } }
/** * 检查该QQ是否已被注册 * @param string qq 用户提交的qq字段 * @access protected * */ protected function checkQq($qq) { $mo = new Model(); $mo->table('__USERS__'); if (empty($mo->where(array('qq' => $qq))->find())) { return true; } else { return false; } }
/** * 注册 * @param array $data 注册数据 */ public function regist($data) { // 将用户信息添加到User表中 $tranDb = new Model(); $tranDb->startTrans(); $username = $data['username']; $result = $tranDb->table('west_user')->where("username = '******'")->find(); if ($result == null) { $user_info = array('username' => $username, 'password' => $data['password'], 'group' => 'user', 'status' => 0, 'modify_time' => time()); $uid = $tranDb->table('west_user')->data($user_info)->add(); if ($uid) { // 判断公司是否存在 $company_name = $data['company_name']; $result = $tranDb->table('west_company')->where("name = '{$company_name}'")->find(); if ($result == null) { $company_info = array('uid' => $user_id, 'name' => $data['company_name'], 'mail' => $data['company_mail'], 'tel' => $data['company_tel'], 'modify_time' => time()); $result = $tranDb->table('west_company')->data($company_info)->add(); if ($result) { $tranDb->commit(); return 1; // 注册用户成功 } else { $tranDb->rollback(); return -4; // 添加公司信息失败 } } else { $tranDb->rollback(); return -3; // 公司名称已存在 } } else { $tranDb->rollback(); return -2; // 添加用户信息失败 } } else { return -1; // 用户名已存在 } }
public function touchCheck() { $pub = Utility::sslTrimKey($this->platform['public_key']); $ret = "<biz_content>{$pub}</biz_content><success>true</success>"; $dat = $this->client->encryptAndSign($ret, false, true); parent::touchCheck(); $message = $this->parse($this->params['biz_content']); $rec = array(); $rec['appid'] = $message['to']; $m = new Model(); $m->table('__PLATFORM_ALIPAY__')->data($rec)->where("`id`='{$this->platform['id']}'")->save(); exit($dat); }
function getNews($page, $page_size) { /*return $this->join('term_relationships ON post.ID = term_relationships.object_id ') ->where(array('post_type' => 'post','post_status'=>'publish') ->page($page, $page_size) ->order('post_date DESC') ->select(); */ $Model = new Model(); return $Model->table('wp_posts')->join('wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id')->where(array('wp_posts.post_type' => 'post', 'wp_posts.post_status' => 'publish'))->where("wp_term_relationships.term_taxonomy_id = 1")->page($page, $page_size)->order('post_date DESC')->select(); /* $Model = new Model(); return $Model->query("SELECT * from wp_posts wp where wp.post_type = 'post' and wp.post_status = 'publish' join wp_term_relationships wtr where wp.ID = wtr.object_id and wtr.term_taxonomy_id = 1 ")->page($page, $page_size) ->order('post_date DESC') ; */ }
/** * 将配置项写入数据库, 一般预留给模块封装调用, 控制其中不应该直接调用 * @param $moduleName string 模块名称 * @param $settings array 配置项名称 * @return bool */ public static function saveSettings($moduleName, $settings) { $moduleName = strtoupper($moduleName); $ds = array(); foreach ($settings as $key => $value) { if (!empty($key)) { $key = strtoupper($key); $origKey = "{$moduleName}:{$key}"; $ds[$origKey] = serialize($value); } } if (empty($ds)) { return false; } $m = new Model(); foreach ($ds as $key => $value) { $rec = array(); $rec['key'] = $key; $rec['value'] = $value; $m->table('__CORE_SETTINGS__')->add($rec, array(), true); } return true; }
public static function getAddon($name, $fromDefineFile = false) { if ($fromDefineFile) { $path = MB_ROOT . "addons/{$name}/define.xml"; if (is_file($path)) { $xml = file_get_contents($path); $addon = self::parseDefineFile($xml); if (is_error($addon)) { return $addon; } } else { return error(-1, '不存在这个扩展或者扩展定义文件不存在'); } } else { $condition = '`name`=:name'; $pars = array(); $pars[':name'] = $name; $m = new Model(); $addon = $m->table('__EX_ADDONS__')->where($condition)->bind($pars)->find(); if (empty($addon)) { return error(-1, '不存在这个扩展'); } } if (!empty($addon)) { $addon['icon'] = __SITE__ . "addons/{$addon['name']}/icon.png"; } return $addon; }
/** * 支付成功,改变订单状态 * @param int $order_id * @return bool */ public function changeOrderStatus($order_id) { $flag = false; if ($order_id) { $db = new Model(); $flag = $db->table($this->_table)->where(['id' => $order_id])->save(['status' => 2]); } return $flag; }
/** * 检测数据库连接,成功则输出成功信息,失败则报错 * @access public * */ public function test_db() { $mo = new Model(); $msg = $mo->table('wa_users')->getDbFields(); echo '连接成功!'; }
public function uninstallAction() { $a = I('get.addon'); if (empty($a)) { $this->error('访问错误'); } $addon = new Addon($a); Addon::autoload(); $class = "Addon\\{$a}\\Api\\Application"; if (class_exists($class)) { $instance = new $class(); if (!empty($instance)) { $instance->addon = $addon; if (method_exists($instance, 'install')) { $instance->uninstall(); } } } $condition = '`name`=:name'; $pars = array(); $pars[':name'] = $a; $m = new Model(); $m->table('__EX_ADDONS__')->where($condition)->bind($pars)->delete(); $m->table('__EX_ADDON_ENTRIES__')->where('`addon`=:name')->bind($pars)->delete(); $m->table('__RP_PROCESSORS__')->where('`from`=:name')->bind($pars)->delete(); $m->table('__RP_REPLIES__')->where('`from`=:name')->bind($pars)->delete(); $this->success('扩展卸载成功'); }
/** * 订单详情 */ public function get_order() { $order_no = isset($_POST['order_no']) ? htmlspecialchars($_POST['order_no']) : ''; $mer_session_id = $_POST['mer_session_id']; $merchant_id = $this->session_handle->getsession_userid($mer_session_id); if (empty($order_no)) { $this->jsonUtils->echo_json_msg(4, '订单ID为空...'); exit; } $model = new Model(); $arr = $model->table(C('DB_PREFIX') . "order as a ")->field("b.header,b.nick_name,a.member_id,a.service_name,a.id,a.order_no,a.addtime,b.mobile,a.cart_id,a.cart_data,a.reach_time,a.total_price,a.total_time,a.type,a.sub_id,a.sub_data,a.status,a.merchant_comment,a.member_comment,a.merchant_remark,a.member_remark,ifnull(a.fail_content,'') as fail_content,b.mobile")->join(C('DB_PREFIX') . "member as b on a.member_id = b.id")->where("a.order_no = {$order_no} and a.merchant_id = {$merchant_id} and a.merchant_del = 0")->find(); //echo $model->getLastSql(); if ($arr) { //获取jid $jid = CommonController::getSystemUserid($arr['member_id'], 0); $cart = json_decode($arr['cart_data'], true); unset($arr['cart_data']); $arr['system_user_id'] = $jid; $arr['cart_model'] = $cart['cart_model']; $arr['reach_time'] = date('Y-m-d H:i:s', $arr['reach_time']); $arr['addtime'] = date('Y-m-d H:i:s', $arr['addtime']); $arr['header'] = imgUrl($arr['header']); // 商家是否评价 if ($arr['status'] != 0) { // 未完成订单 没有评价 if ($arr['merchant_comment'] > 0) { $sql = "select a.desc,c.header,a.service_attitude,c.merchant_name as nick_name,from_unixtime(a.addtime,'%Y-%m-%d %H:%i:%s') as addtime\r\n\t \t\tfrom " . C('DB_PREFIX') . "comment as a\r\n\t \t\tleft join " . C('DB_PREFIX') . "merchant as c\r\n\t \t\ton a.merchant_id=c.id\r\n\t \t\twhere a.order_no={$arr['order_no']} and type=2 limit 1"; $arro = $this->dao->query($sql); $arro[0]['header'] = imgUrl($arro[0]['header']); $arr['merchant_comment_info'] = $arro[0]; } else { $arr['merchant_comment_info'] = ''; $arr['merchant_comment'] = '0'; } // 用户是否评论 if ($arr['member_comment'] > 0) { $sql = "select a.desc,c.header,c.nick_name,a.service_attitude,a.service_quality,a.merchant_setting,a.pics,from_unixtime(a.addtime,'%Y-%m-%d %H:%i:%s') as addtime\r\n\t\t \tfrom " . C('DB_PREFIX') . "comment as a \r\n\t\t \tleft join " . C('DB_PREFIX') . "member as c \r\n\t\t \ton a.member_id=c.id \r\n\t\t \twhere a.order_no={$arr['order_no']} and type=0 limit 1"; $arro = $this->dao->query($sql); $arro[0]['header'] = imgUrl($arro[0]['header']); $arro[0]['pics'] = imgUrl(json_decode($arro[0]['pics'], true)); $arr['member_comment_info'] = $arro[0]; } else { $arr['member_comment_info'] = ''; $arr['member_comment'] = '0'; } } else { $arr['merchant_comment'] = '0'; $arr['member_comment'] = '0'; $arr['merchant_comment_info'] = ''; $arr['member_comment_info'] = ''; } $sub_data = json_decode($arr['sub_data'], true); switch ($arr['type']) { // 0 预约 1需求 2活动 case '0': $arr['pics'] = imgUrl($sub_data['pics']); $arr['distance'] = ''; $arr['list'] = $sub_data['list']; break; case '1' or '3': // 需求 $arr['pics'] = imgUrl($sub_data['pics']); $arr['distance'] = $sub_data['distance']; $arr['list'] = $sub_data['list']; break; case '2': // 活动 $arr['distance'] = ''; $arr['list'] = array(); break; default: $this->jsonUtils->echo_json_msg(4, '数据异常'); exit; break; } unset($arr['sub_data']); $this->jsonUtils->echo_json_data(0, 'ok', $arr); } else { $this->jsonUtils->echo_json_msg(1, '该订单不存在...'); exit; } }
/** *修改用户 */ public function EditSave() { //获取参数 $id = I('id', 0, 'int'); $username = I('username'); $password = I('password'); $email = I('email'); $mobile = I('mobile'); $roleid = I('role_id'); //是否修改 if ($id == 0) { $result['result'] = false; $result['msg'] = '该用户不存在'; $this->ajaxReturn($result); } //开启事务 $model = new Model(); $model->startTrans(); $flage === false; //申明修改用户对象 $data['UserName'] = $username; if (!empty($password)) { $data['PassWord'] = md5($password); } $data['Email'] = $email; $data['Mobile'] = $mobile; //更新 $flage = $model->table('sys_user')->where('id=%d', $id)->save($data); if ($flage === false) { //事务回滚 $model->rollback(); $result['result'] = false; $result['msg'] = '修改用户资料失败!'; $this->ajaxReturn($result); } else { $flage = $model->table('sys_role_user')->where('user_id=%d', $id)->delete(); if ($flage === false) { //事务回滚 $model->rollback(); $result['result'] = false; $result['msg'] = '修改用户资料失败!'; $this->ajaxReturn($result); } //角色处理 foreach ($roleid as $key => $value) { # code... $data2['role_id'] = $value; $data2['user_id'] = $id; $flage = $model->table('sys_role_user')->add($data2); if ($flage === false) { //事务回滚 $model->rollback(); $result['result'] = false; $result['msg'] = '修改用户资料失败!'; $this->ajaxReturn($result); } } if ($flage) { //事务提交 $model->commit(); $result['result'] = true; $result['msg'] = '修改用户资料成功!'; $this->ajaxReturn($result); } } }
public function testUnion() { $config = $this->getConfig(); $user_model = new Model('user', $config); $union = "SELECT consignee FROM __USER_ADDRESS__"; $result = $user_model->field('username')->union($union)->select(); $this->assertEquals(4, count($result)); $model = new Model('', $config); $union = ["SELECT create_time FROM __ORDER__"]; $result = $model->table([$config['prefix'] . 'user'])->field('create_time')->union($union, true)->select(); $this->assertEquals(4, count($result)); }
/** * 获取商家对某个需求的各个项目报价 */ public function getMerchantBiddingBy($demand_id, $merchant_id, $publish) { $prefix = C('DB_PREFIX'); if ($publish == 0) { $dbname = 'category'; } elseif ($publish == 1) { $dbname = 'car_maintain_category'; } else { $this->jsonUtils->echo_json_msg(4, 'publish方式出错'); exit; } $db = new Model(); $data = $db->table($prefix . "member_demand_subitems as a")->field('b.name,b.id')->join($prefix . $dbname . ' as b on a.category_id = b.id')->where("a.demand_id = {$demand_id}")->select(); $rel = M("MerchantBidding ")->field('sub_id as id,price,out_time as time')->where("demand_id = {$demand_id} and merchant_id\r\n \t\t\t= {$merchant_id}")->select(); foreach ($rel as $key => $row) { $price[$row['id']] = $row; } foreach ($data as $l => $r) { $data[$l]['price'] = !isset($price[$r['id']]['price']) ? '-1' : $price[$r['id']]['price']; $data[$l]['time'] = !isset($price[$r['id']]['time']) ? '-1' : $price[$r['id']]['time']; } return $data; }
/** * 删除数据 * @param string $datalist 数据集合 */ public function Del_Form_Data($vid, $mid) { $db_form = new DbformModel(); $tables = $db_form->GetDBFormVid($vid); $Model = new Model(); $tmd = $Model->table($tables['form_table']); $result = $tmd->where('id=' . $mid)->delete(); return $result; }
/** * 登记当前消息中的用户资料, 在派生类中实现时, 应至少传递 openid, unionid, subscribe, subscribetime, unsubscribetime, tag * @param $message * @return boolean */ public function booking($message) { $account = $this->getAccount(); if (!empty($account) && !empty($message)) { $fan = coll_elements(array('openid', 'unionid', 'subscribe', 'subscribetime', 'unsubscribetime', 'tag'), $message); $fan['platformid'] = $account['id']; $condition = '`platformid`=:platformid AND `openid`=:openid'; $pars = array(); $pars[':platformid'] = $fan['platformid']; $pars[':openid'] = $fan['openid']; $m = new Model(); $fanid = $m->table('__MMB_MAPPING_FANS__')->where($condition)->bind($pars)->getField('`fanid`'); if (empty($fanid)) { $fan['uid'] = 0; //判断用户中心策略 $fan['salt'] = util_random(8); if (empty($fan['subscribetime'])) { $fan['subscribetime'] = TIMESTAMP; } $m->table('__MMB_MAPPING_FANS__')->data($fan)->add(); } else { if (empty($fan['subscribetime'])) { unset($fan['subscribetime']); } if (empty($fan['unsubscribetime'])) { unset($fan['unsubscribetime']); } $m->table('__MMB_MAPPING_FANS__')->data($fan)->where("`fanid`='{$fanid}'")->save(); } } }
function getPageById($id) { $Model = new Model(); return $Model->table('wp_posts')->join('wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id')->where(array('wp_posts.post_type' => 'post', 'wp_posts.post_status' => 'publish'))->where("wp_term_relationships.term_taxonomy_id = {$id}")->select(); }
private function fetchToken() { if (is_array($this->account['access_token']) && !empty($this->account['access_token']) && !empty($this->account['access_expire']) && $this->account['access_expire'] > TIMESTAMP) { return $this->account['access_token']; } else { $token = self::getAccessToken($this->account['appid'], $this->account['secret']); if (is_error($token)) { return $token; } $record = array(); $record['access_token'] = $token['token']; $record['access_expire'] = TIMESTAMP + $token['expire']; $m = new Model(); $m->table('__PLATFORM_WEIXIN__')->data($record)->where("`id`='{$this->account['id']}'")->save(); $this->account['access_token'] = $record['access_token']; $this->account['access_expire'] = $record['access_expire']; return $this->account['access_token']; } }
/** * 作品详情展示 */ public function detail() { $workid = I('get.workid'); if (empty($workid)) { $this->error('您访问的页面不存在'); } //增加点击数 M('Works')->where(array('workid' => $workid))->setInc('clicknum'); $detail = D('Works')->relation(true)->find($workid); if (!$detail) { $this->error('您访问的作品不存在'); } //start yf $yf_thumb = array(); $yf_pic = array(); if (!empty($detail['all_pic'])) { $yf_arr = json_decode($detail['all_pic'], true); $yf_temp = array(); foreach ($yf_arr as $k => $v) { $yf_thumb[] = $v; $yf_ex = explode("/", $v); $yf_ex[count($yf_ex) - 1] = str_replace("yf_", "", $yf_ex[count($yf_ex) - 1]); $yf_pic[] = implode("/", $yf_ex); } } else { $yf_arr = array(); $yf_thumb[] = $yf_pic[] = $detail['image']; } $detail['pic_num'] = count($yf_thumb); $detail['thumb'] = implode(",", $yf_thumb); $detail['pic'] = implode(",", $yf_pic); $detail['WorksMaterials_count'] = count($detail['WorksMaterials']); //end $this->assign('data', $detail); //点赞总数 $this->digallnum = $detail['goodnum'] + $detail['badnum']; //综合评价 if ($detail['goodnum'] == 0 && $detail['badnum'] == 0) { $dig['digavg'] = 0; $dig['goodprecent'] = 50; $dig['badprecent'] = 50; } else { $digavg = round($detail['goodnum'] / ($detail['goodnum'] + $detail['badnum']), 2); $dig['digavg'] = $digavg * 10; $dig['goodprecent'] = $digavg * 100; $dig['badprecent'] = (1 - $digavg) * 100; } $this->dig = $dig; //点赞判断 $this->digtype = M('Dig')->field('digtype,id')->where(array('userid' => $this->userid, 'status' => true, 'infoid' => $workid))->find(); //收藏判断 $this->favoritenum = getCount('UserFavorite', array('userid' => $this->userid, 'status' => true, 'infoid' => $workid)); //右侧广告 $this->rightad = parent::getAdvert(8, 3, 0, 2); //点赞人员列表 $diguser = new Model(); $diguerlist = $diguser->table(array(C('DB_PREFIX') . 'dig' => 'D', C('DB_PREFIX') . 'user' => 'U'))->where('D.userid=U.userid and D.status=true and D.digtype=1 and D.infoid=' . $workid . '')->field('U.uavatar,U.openuid')->select(); $this->assign('diglist', $diguerlist); //评论 $where['infoid'] = $workid; $where['type'] = 1; $where['parent_id'] = 0; $count = M('UserMessage')->where($where)->count(); // $limitRows = 5; // 设置每页记录数 $limitRows = C('YF_PAGE'); $page = $this->ajaxpage($count, $limitRows, '#msg', 'ajax_div', 'ajax_page_div'); $Model = new Model(); $message = $Model->table(array(C('DB_PREFIX') . 'user_message' => 'M', C('DB_PREFIX') . 'user' => 'U'))->where('M.userid=U.userid and M.status=true and M.infoid=' . $workid . ' and M.type=1 and M.parent_id=0')->field('M.create_time,M.content,U.nickname,U.uavatar,U.openuid,U.uprovince,U.ucity,U.userid,M.id,M.touserid,U.ifrz')->order('M.create_time DESC')->limit($page->firstRow . ',' . $page->listRows)->select(); foreach ($message as $k => $v) { $child_temp = array(); $child_temp = $Model->table(C('DB_PREFIX') . 'user_message')->field('*')->where(array('parent_id' => $v['id']))->order('create_time ASC')->select(); $message[$k]['childlist'] = array(); if ($child_temp) { foreach ($child_temp as $yk => $yv) { if ($yv['userid'] == 0) { $child_temp[$yk]['nickname'] = "烘焙圈"; $child_temp[$yk]['openuid'] = 0; } else { $yf_user = array(); $yf_user = M('User')->field('openuid, nickname, uprovince, ucity, uavatar, ifrz')->where(array('userid' => $yv['userid']))->find(); $child_temp[$yk]['nickname'] = $yf_user['nickname']; $child_temp[$yk]['openuid'] = $yf_user['openuid']; $child_temp[$yk]['uprovince'] = $yf_user['uprovince']; $child_temp[$yk]['ucity'] = $yf_user['ucity']; $child_temp[$yk]['uavatar'] = $yf_user['uavatar']; $child_temp[$yk]['ifrz'] = $yf_user['ifrz']; } if ($yv['touserid'] != 0) { $child_temp[$yk]['touser'] = M('User')->field('openuid,nickname')->where(array('userid' => $yv['touserid']))->find(); } else { $child_temp[$yk]['touser']['nickname'] = "烘焙圈"; $child_temp[$yk]['touser']['openuid'] = 0; } } $message[$k]['childlist'] = $child_temp; } $message[$k]['tempname'] = hy_substr($v['nickname'], 4, true); //$message[$k]['tempname'] = $v['nickname']; $message[$k]['touser'] = array(); if (!empty($v['touserid'])) { $message[$k]['touser'] = M('User')->field('openuid,nickname')->where(array('userid' => $v['touserid']))->find(); } } unset($where['parent_id']); $this->msgcount = M('UserMessage')->where($where)->count(); $this->msgtype = 1; $this->assign('msglist', $message); $this->assign('page', $page->show()); if (IS_AJAX) { exit($this->fetch('msglist')); } //参照做出的作品 $copylist = $Model->table(array(C('DB_PREFIX') . 'works' => 'W', C('DB_PREFIX') . 'user' => 'U'))->where('W.userid=U.userid and W.status=true and W.type=2 and W.copyid=' . $workid)->field('U.openuid,U.nickname,U.uavatar,W.title,W.image,W.workid,W.create_time,W.title')->order('W.workid DESC')->limit(2)->select(); $this->copylist = $copylist; $this->display(); }
public function saveQrcode() { $model = new Model(); $delRe = $model->table('image')->where(array('type' => array('in', array(self::WEIBO_QRCODE, self::WEIXIN_QRCODE))))->delete(); if (false !== $delRe) { $data = array(); if ($_POST['weibo_path'] && $_POST['weibo_name']) { $data[] = array('type' => self::WEIBO_QRCODE, 'path' => trim($_POST['weibo_path']), 'name' => trim($_POST['weibo_name']), 'create_time' => date('Y-m-d H:i:s')); } if ($_POST['weixin_path'] && $_POST['weixin_name']) { $data[] = array('type' => self::WEIXIN_QRCODE, 'path' => trim($_POST['weixin_path']), 'name' => trim($_POST['weixin_name']), 'create_time' => date('Y-m-d H:i:s')); } $saveRe = $model->table('image')->addAll($data); if ($saveRe) { echo json_encode(array('code' => 0, 'msg' => '')); return; } } echo json_encode(array('code' => 1, 'msg' => '')); return; }