public function createForm($course_id) { $create_table = new Model(); /*新建表*/ $check_name_table = "check_name_" . $course_id; $str = "create table {$check_name_table}(\n student_id VARCHAR (32) NOT NULL ,\n student_name VARCHAR (32) ,\n attend_stage VARCHAR (32) ,\n primary key(student_id)\n )ENGINE=InnoDB DEFAULT CHARSET=utf8 "; $create_table->execute($str); /*把之前原始数据插入表中*/ $select_course = $course_id . "_course"; $student_string = $create_table->query("select {$select_course} from course_student "); $student_string = $student_string[0][$select_course]; $student_id_sum = explode(',', $student_string); /*先把部分学生信息插入表中*/ for ($index = 0; $index < count($student_id_sum); $index++) { $student_id = $student_id_sum[$index]; $student_name = $create_table->query("select student_name from student_information where student_id='{$student_id}' "); $student_name = $student_name[0]['student_name']; $create_table->execute("insert into {$check_name_table} VALUES('{$student_id}','{$student_name}','absent')"); } }
public function saveUser() { $data = null; $name = $_POST['name']; $truename = $_POST['truename']; $deptId = $_POST['deptId']; $adminFlag = $_POST['adminFlag']; $delFlag = $_POST['delFlag']; $model = new Model(); if ($_POST['addFlag'] == 1) { //insert $sql = "insert into user (name,truename,pwd,dept_id,admin_flag,del_flag) values('" . $name . "','" . $truename . "',md5(123456),'" . $deptId . "','" . $adminFlag . "','" . $delFlag . "')"; $model->execute($sql); } else { //update $sql = "update user set name = '" . $name . "'\n\t\t\t,truename = '" . $truename . "'\n\t\t\t,dept_id = '" . $deptId . "'\n\t\t\t,admin_flag = '" . $adminFlag . "'\n\t\t\t,del_flag = '" . $delFlag . "'\n\t\t\twhere uid = '" . $_POST['uid'] . "'\n\t\t\t"; $model->execute($sql); } $userTreeHtml = $this->createUserTree(); $data["userTree"] = $userTreeHtml; $data["status"] = 1; $this->ajaxReturn($data, 'JSON'); }
public function adminUpdate() { if (session('?userid') && session('?usertype') && $_SESSION['usertype'] == 1) { //dump($_POST); $Form = new Model(); //$exist = $Form->query('select admin_id from admin_personal where admin_id = "%s"',$_POST['id']); $result = $Form->execute('replace into admin_personal (admin_id,admin_pwd,admin_type) values ("%s","%s",%d)', $_POST['id'], $_POST['key1'], $_POST['key3']); if ($result) { echo 2; } else { echo -1; } } else { $this->redirect('Index/index'); } }
public function changePassword() { $status = 1; $model = new Model(); if (md5($_POST['oldpwd']) != $_SESSION['pwd']) { $msg = "输入密码不对"; $status = 0; } if ($status == 1) { //$sql="update user set pwd=".md5($_POST['newpwd1'])." where uid ='".$_SESSION['uid']."'"; //$model->execute("insert into tmp(col1) values('".$sql."')"); $model->execute("update user set pwd='" . md5($_POST['newpwd1']) . "' where uid ='" . $_SESSION['uid'] . "'"); } $returnData['status'] = $status; $returnData['msg'] = $msg; $this->ajaxReturn($returnData, 'JSON'); }
public function index() { //dump($_GET); $key1 = $_GET['key1']; $key2 = $_GET['key2']; $key3 = $_GET['key3']; $Form = new Model(); $r = $Form->query('select * from email_active where user_id = "%s"', $key1); //dump($r); if ($r) { $mesg; $record = $r[0]; //dump($record); //dump($record[mail_address]); if ($record[mail_address] != $key2) { $mesg = "请使用注册邮箱激活!"; //dump($this->mesg); } else { if ($record[active_code] != $key3) { $mesg = "激活码错误!"; //dump($this->mesg); } else { if (intval($record[over_time]) < time()) { $mesg = "激活码过期!"; //dump($this->mesg); } else { $res = $Form->execute('update email_active set active_status="1" where user_id="%s"', $key1); if ($res) { //dump($res); $mesg = " 激活成功!"; //dump($this->mesg); } } } } } else { $mesg = "激活失败!"; } $this->tip = $mesg; //dump($this->tip); $this->display(); }
function getMyPlanList() { $param = json_decode(file_get_contents('php://input'), true); $token = $param['xtoken']; init_verify_token($token); $uid = $param['uid']; //$uid = 1584; if (empty($uid)) { err_ret(-205, 'lack of param', '缺少参数'); } $model = new Model(); //查询是否有过期的,有过期就更新 $time = time(); $sql = "UPDATE my_plan SET status=4 WHERE uid={$uid} AND end_time<{$time}"; $model->execute($sql); $sql = "SELECT t.*, user_info.header,user_info.name,user_info.nicker FROM\n (\n SELECT DISTINCT pid,title,coverimg,type AS isfree,peoplenumber,coachid,status,begin_time,end_time from my_plan,plan where my_plan.pid = plan.id and uid={$uid} ORDER BY isfree desc\n ) AS t,user_info \n WHERE t.coachid=user_info.id"; $result = $model->query($sql); $data['errno'] = 0; $data['plan_list'] = $result; echo json_encode($data); }
public function messageDetail() { if (session('?userid') && session('?usertype') && ($_SESSION['usertype'] == 1 || $_SESSION['usertype'] == 3)) { $id = $_GET['key']; $Form = new Model(); $Form->execute("update messagebox set adminread=1 where id='%s'", $id); $msg = $Form->query("select * from messagebox where id = '%s'", $id); if ($msg) { $this->msg = $msg[0]; $type = $msg[0]['msg_type']; if ($type == '1') { $innovator = $Form->query('select user_id,name,email,phone from entrepreneur_personal where user_id="%s"', $msg[0]['from_id']); $this->from = $innovator[0]; $this->from_page = U('Home/User/innovator/val/' . $msg[0]['from_id']); $investor = $Form->query('select user_id,name,email,mobile as phone from investor_personal where user_id="%s"', $msg[0]['to_id']); $this->to_page = U('Home/User/investor/val/' . $msg[0]['to_id']); $this->to = $investor[0]; } else { if ($type == '2') { $innovator = $Form->query('select user_id,name,email,phone from entrepreneur_personal where user_id="%s"', $msg[0]['to_id']); $this->to = $innovator[0]; $this->to_page = U('Home/User/innovator/val/' . $msg[0]['to_id']); $investor = $Form->query('select user_id,name,email,mobile as phone from investor_personal where user_id="%s"', $msg[0]['from_id']); $this->from_page = U('Home/User/investor/val/' . $msg[0]['from_id']); $this->from = $investor[0]; } else { $innovator = $Form->query('select user_id,name,email,phone from entrepreneur_personal where user_id="%s"', $msg[0]['from_id']); $this->from = $innovator[0]; $this->from_page = U('Home/User/innovator/val/' . $msg[0]['from_id']); $innovator = $Form->query('select user_id,name,email,phone from entrepreneur_personal where user_id="%s"', $msg[0]['to_id']); $this->to = $innovator[0]; $this->to_page = U('Home/User/innovator/val/' . $msg[0]['to_id']); } } } $this->display(); } else { $this->redirect('Index/index'); } }
function docancle() { //如果该用户没投这个项目,那么他不能投票 $pid = I('pid'); $leader_id = I('leader_id'); $uid = is_login(); $countP = M('ProjLeader')->where(array('pid' => $pid, 'uid' => $uid))->count(); if (!$countP) { $retData['message'] = "你还没有投资该项目,因此你不能取消!"; $retData['status'] = false; } //如果已经对该项目投过票了则不能再投了 $uid = is_login(); $touziCount = $this->touziCount($pid, $uid); $Projectvote = M('ProjectVote'); $deleteVote = $Projectvote->where(array('project_id' => $pid, 'investor_id' => $uid))->save(array('marks' => 1)); $sqlstr = "UPDATE jm_proj_leader SET voit_count=voit_count-" . $touziCount . " WHERE pid=" . $pid . " AND uid=" . $leader_id . " "; $model = new Model(); $update = $model->execute($sqlstr); if ($update) { $retData['message'] = "取消成功!"; $retData['status'] = true; } $jsonstr = json_encode($retData); echo $jsonstr; }
public function import() { if (!IS_AJAX) { $this->error(L('_ERROR_ACTION_')); } if (I('get.file')) { $filename = base64_decode(I('get.file')); $file = C('BACKUP_PATH') . $filename; $sql = read_file($file); $db = new Model(); $res = $db->execute($sql); if ($res === FALSE) { $this->error(L('IMPORT_ERROR')); } else { $this->success(L('IMPORT_OK'), U('Database/recover', $this->vl)); } } else { $this->error(L('_ERROR_ACTION_')); } }
public function userSave() { $Form = new Model(); if (I('post.value') === 'investor') { $seed = rand(C(RANDOM_USER_MIN), C(RANDOM_USER_MAX)); $id = '1' . substr(date('Y'), 2) . $seed; $regTime = date('Y-m-d'); $exist = $Form->query('select user_id from investor_personal where user_id = "%s"', $id); while ($exist) { $seed = rand(C(RANDOM_USER_MIN), C(RANDOM_USER_MAX)); $id = '1' . substr(date('Y'), 2) . $seed; $exist = $Form->query('select user_id from investor_personal where user_id = "%s"', $id); } $result = $Form->execute('insert into investor_personal (user_id,name,mobile,email,company,title,user_type,reg_time,reg_status) values ("%s","%s","%s","%s","%s","%s",%d, "%s",%d)', $id, $_POST['key1'], encode($_POST['key2']), encode($_POST['key3']), $_POST['key4'], $_POST['key5'], $_POST['key6'], $regTime, 0); //感兴趣领域 $interests = $_POST['key9']; $interests = explode(',', $interests); for ($i = 0; $i < count($interests) - 1; $i++) { $temp = $Form->execute('replace into interest_investor (id, interest_field) values ("%s",%d)', $id, $interests[$i]); } //认证资料 if ($_POST['key6'] == 1) { $result1 = $Form->execute('insert into investor_company (user_id, company_name) values ("%s","%s")', $id, $_POST['key4']); } else { if ($_POST['key6'] == 2) { $result1 = $Form->execute('insert into investor_fi (user_id) values ("%s")', $id); } } if ($result) { $safety = $Form->execute('insert into investor_security (user_id,user_pwd) values ("%s","%s")', $id, $_POST['key7']); if ($safety) { echo 200; } else { echo 400; } } else { echo 400; } } else { if (I('post.value') === 'innovator') { $seed = rand(C(RANDOM_USER_MIN), C(RANDOM_USER_MAX)); $id = '2' . substr(date('Y'), 2) . $seed; $regTime = date('Y-m-d'); $exist = $Form->query('select user_id from entrepreneur_personal where user_id = "%s"', $id); while ($exist) { $seed = rand(C(RANDOM_USER_MIN), C(RANDOM_USER_MAX)); $id = '1' . substr(date('Y'), 2) . $seed; $exist = $Form->query('select user_id from entrepreneur_personal where user_id = "%s"', $id); } $result = $Form->execute('insert into entrepreneur_personal (user_id,name,email,phone,nickname,gender,birthday,city,reg_time,reg_status) values ("%s","%s","%s","%s","%s",%d,"%s",%d, "%s",%d)', $id, $_POST['key1'], encode($_POST['key2']), encode($_POST['key3']), $_POST['key4'], $_POST['key5'], $_POST['key6'], $_POST['key7'], $regTime, 0); //感兴趣领域 $interests = $_POST['key9']; $temp = $Form->execute('replace into interest_entrepreneur (id, interest_field) values ("%s",%d)', $id, $interests); if ($result) { $safety = $Form->execute('insert into entrepreneur_security (user_id,user_pwd) values ("%s","%s")', $id, $_POST['key11']); if ($safety) { echo 200; } else { echo 400; } } else { echo 400; } } else { echo 400; } } }
function send_find_mail($user_id, $objectid, $to_address) { $Form = new Model(); $name = ''; $pwd = ''; $active_code = ''; if ($objectid == 2) { $names = $Form->query('select name from investor_personal where user_id="%s"', $user_id); $pwds = $Form->query('select user_pwd from investor_security where user_id="%s"', $user_id); $name = $names[0][name]; $pwd = $pwds[0][user_pwd]; } else { $names = $Form->query('select name from entrepreneur_personal where user_id="%s"', $user_id); $pwds = $Form->query('select user_pwd from entrepreneur_security where user_id="%s"', $user_id); $name = $names[0][name]; $pwd = $pwds[0][user_pwd]; } $active_time = time(); $over_time = $active_time + 24 * 60 * 60; $active_code = md5($user_id . $name . $pwd . $active_time); $sqlstr = sprintf("replace into email_find_pwd (user_id,active_code,mail_address,over_time,active_status)\n values ('%s','%s','%s','%d','%d')", $user_id, $active_code, $to_address, $over_time, 0); $res = $Form->execute($sqlstr); if ($res) { $url = sprintf("http://localhost:8888/lcb/index.php/Home/Account/setting?key1=%s&key2=%s&key3=%s", $user_id, $to_address, $active_code); $body = sprintf("尊敬的用户 %s:请点击以下链接重置密码,如不能点击请将地址拷贝至浏览器栏。<br><a>%s</a>", $name, $url); return think_send_mail($to_address, $name, $subject = '来创科技重置密码', $body); } return 400; }
public function newAnswer() { //获取客户端发送的json $json = json_decode($GLOBALS['HTTP_RAW_POST_DATA']); $key = "access_token"; $jwt = $json->access_token; if ($json->access_token == null) { $log = "无access_token"; } else { $jwt = JWT::decode($jwt, $key, array('HS256')); $timenow = date("YmdHis", strtotime('now')); if (!($jwt->aud == $json->username && $timenow < $jwt->exp && $timenow > $jwt->iat)) { $log = "超时或名称不对称"; } } $arr = $json; $answer = $arr->answer; $id = $arr->id; $Model = new Model(); $adate = date("YmdHis", strtotime('now')); //创建投票开始的年月日时分秒 $sql = "select name from " . __PREFIX__ . "user where id=" . $json->username; $res = $Model->query($sql); $aname = $res[0]['name']; $sql = "update " . __PREFIX__ . "qa set aid={$json->username}, aname='{$aname}', answer='{$answer}', adate='{$adate}' where id=" . $id; /* echo $sql; die; */ if ($Model->execute($sql)) { $suc = 1; } else { $suc = 0; } $resjson = json_encode($res); $jsonsend = array("username" => $json->username, "suc" => $suc, "access_token" => $json->access_token); /** * IMPORTANT: * You must specify supported algorithms for your application. See * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 * for a list of spec-compliant algorithms. */ $json = json_encode($jsonsend); //echo $json; echo $json; // $this->display("./Background/Home/phyman-1/index.html"); // $this->assign($json); }
public function requestAuth() { //dump($_POST); $Form = new Model(); $id = I('post.p', 0); $result = $Form->execute('update project_info set status = 1 where project_id = "%s"', $id); if ($result) { echo 200; } else { echo 400; } }
public function saveIntro() { if (session('?userid') && session('?usertype') && ($_SESSION['usertype'] == 1 || $_SESSION['usertype'] == 3)) { $Form = new Model(); if (count($_POST['c']) > 0 && count($_POST['p']) > 0) { $result = $Form->execute('update project_info set project_intro="%s" where project_id="%s"', $_POST['c'], $_POST['p']); if ($result) { echo 200; } else { echo 400; } } } }
public function testDelete() { $config = $this->getConfig(); $order_model = new Model('order', $config); $order_model->id = 2; $flag = $order_model->delete(); $this->assertEquals(1, $flag); $flag = $order_model->delete('1'); $this->assertEquals(1, $flag); $address_model = new Model('user_address', $config); $flag = $address_model->delete(['1', '2']); $this->assertEquals(2, $flag); $user_model = new Model('user', $config); $flag = $user_model->using([''])->where('1=1')->delete(); $this->assertEquals(2, $flag); $ru_model = new Model('role_user', $config); $flag = $ru_model->delete(['1', '1']); $this->assertEquals(1, $flag); $sql = <<<EOF DROP TABLE IF EXISTS `tp_user`; DROP TABLE IF EXISTS `tp_order`; DROP TABLE IF EXISTS `tp_user_address`; DROP TABLE IF EXISTS `tp_role_user`; EOF; $model = new Model('', $this->getConfig()); $model->execute($sql); $flag = $model->db(0, null); $this->assertNull($flag); }
public function testoprions() { $key = "123"; $Model = new Model(); $voteid = 1; $sql = "select count(*) from __PREFIX__vote_options where vid=" . $voteid; $res = $Model->query($sql); $resultofvote = array('sum' => $res[0]['count(*)'], 'options' => array()); for ($i = 1; $i < 3; $i++) { $sql = "select id,content from __PREFIX__vote_options where vid=" . $voteid; $res = $Model->query($sql); $num = $temp[0]['count(*)']; $s = array('opt' => $res[$i]['id'], 'conten' => $res[$i]['content']); array_push($resultofvote['options'], $s); } $resss = json_encode($resultofvote); print_r($resss); echo "<br>"; $token = array('result' => $resss); // echo 'success'; /** * IMPORTANT: * You must specify supported algorithms for your application. See * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 * for a list of spec-compliant algorithms. */ //$token=json_encode($token); $token = json_encode($token); $jwt = JWT::encode($token, $key); echo $jwt; //向数据库中增加表 $this::insertuser($id); $decoded = JWT::decode($jwt, $key, array('HS256')); //json print_r($decoded); // echo $resultofvote['sum']; die; /* $sql="select uuid_short() Length=15;"; print_r($Model->query($sql)); */ /* $date=date("Ymd",strtotime('now')); echo $date; $datetime=date("Y-m-d H:i:s",strtotime($date)); echo $datetime; */ // print_r($res); $sql = "select uuid_short();"; $uuid = $Model->query($sql); // print_r( $uuid); $id = $uuid[0]['uuid_short()']; $title = 'wwwww'; $uid = 201522040840; $datesql = ''; $tid = 1; $body = 'dddddd.html'; $grade = 1; echo $id; $sql = "insert into __PREFIX__article(id,title,uid,date,tid,body,grade)\r\n values ({$id},'{$title}','{$uid}','{$datesql}','{$tid}','{$body}','{$grade}')"; // $sql='insert into __PREFIX__authority (id,name) values (uuid_short(),\'测试\')'; if ($id = $Model->execute($sql)) { echo '111'; } else { echo '33'; } /* $sql="select * from __PREFIX__authority LIMIT 1,10"; $res=$Model->query($sql); print_r($res); $datetime= date("YmdHis",strtotime('now')); $options=explode(";","我的家;在东北;松花江上"); //$decoded->options);//此处为投票具体内容 $count=count($options);//总共有多少个投票内容 for($i=0;$i<$count;$i++){ $optionids=$optionids.$datetime.$i.";"; } echo $optionids; */ /* $Model=new Model(); $sql="select options from __PREFIX__vote where id=123"; $res=$Model->query($sql); echo $sql; print_r($res); $optionid=explode(";", $res[0]['options']); print_r($optionid); $ph="phyman"; $sql="select content from ".__PREFIX__."vote_options where id=$optionid[0]"; $res2=$Model->query($sql); echo $sql; echo $res2; print_r($res2); */ }
public function helpDB() { $User = M('User'); // 动态的切换数据库,支持切换到相同和不同的数据库类型 //Model->db("数据库编号","数据库配置"); $User->db(1, "mysql://*****:*****@localhost:3306/test")->query("查询SQL"); $User->db(1)->query("查询SQL"); // select $User->where('status=1')->order('create_time')->limit(10)->select(); $User->select(array('order' => 'create_time', 'where' => 'status=1', 'limit' => '10')); // find and delete a record $User->where('id=1')->field('id,name,email')->find(); $User->where('status=1 and id=1')->delete(); // 配合预处理机制,确保更加安全 $User->where("id=%d and username='******' and xx='%f'", '$id', '$username', '$xx')->select(); // 多表进行操作 $User->field('user.name,role.title')->table('think_user user,think_role role')->limit(10)->select(); $Model = M('Model'); $Model->field('user.name,role.title')->table(array('think_user' => 'user', 'think_role' => 'role'))->limit(10)->select(); $Model = M('User'); $Model->alias('a')->join('__DEPT __ b ON b.user_id= a.id')->select(); // SELECT * FROM think_user a INNER JOIN think_dept b ON b.user_id= a.id // 调用save方法更新数据的时候 会自动判断当前的数据对象里面是否有主键值存在,如果有的话会自动作为更新条件 $Model = M('User'); $data['id'] = 8; $data['name'] = '流年'; $data['email'] = '*****@*****.**'; $Model->save($data); // 等效 $Model->data($data)->where('id=8')->save(); $Model->field('id,title,content as name')->select(); // SELECT id,title,content as name FROM table $Model->field('id,SUM(score)')->select(); // SELECT id,SUM(score) FROM table $Model->field(array('id', 'concat(name,' - ',id)' => 'truename', 'LEFT (title,7)' => 'sub_title'))->select(); // SELECT id,concat(name,'-',id) as truename,LEFT (title,7) as sub_title FROM table $Model->field('user_id,content', true)->select(); // 获取除了user_id, content之外的所有字段 $Article = M('Article'); $Article->page('1,10')->select(); // 查询第一页数据 $Article->page('2,10')->select(); // 查询第二页数据 // group方法只有一个参数,并且只能使用字符串 $this->field('username,max(score)')->group('user_id')->select(); // SELECT username,max(score) FROM think_score GROUP BY user_id $Model = M('Artist'); $Model->join('think_work ON think_artist.id = think_work.artist_id')->join('think_card ON think_artist.card_id = think_card.id')->select(); // UNION操作用于合并两个或多个 SELECT 语句的结果集。 $Model->field('name')->table('think_user_0')->union('SELECT name FROM think_user_1')->union('SELECT name FROM think_user_2')->select(); $Model->distinct(true)->field('name')->select(); // SELECT DIST INCT name FROM think_user // Lock方法是用于数据库的锁机制,如果在查询或者执行操作的时候使用:自动在生成的SQL语句最后加上 FOR UPDATE 或者FOR UPDATE NOWAIT (Oracle数据库)。 $Model->distinct(true)->field('name')->select() . lock(true); // cache方法用于查询缓存操作 cache 可以用于select 、find 和getField 在缓存有效期之内不会再次进行数据库查询操作 $Model = M('User'); $Model->cache(true, 60, 'xcache')->find(); // 对查询结果使用xcache缓存,缓存有效期60秒 // COMMENT方法 用于在生成的SQL语句中添加注释内容 $this->comment('查询考试前十名分数')->field('username,score')->limit(10)->order('score desc')->select(); // SELECT username,score FROM think_score ORDER BY score desc LIMIT 10 /* 查询考试前十名分数 */ // fetchSql用于直接返回SQL而不是执行查询,适用于任何的CURD操作方法 $result = M('User')->fetchSql(true)->find(1); // 输出result结果为: SELECT * FROM think_user where id = 1 // token方法可用于临时关闭令牌验证 即可在提交表单的时候临时关闭令牌验证(即使开启了T OKEN_ON参数) $Model->token(false)->create(); //读取数据是指读取数据表中的一行数据(或者关联数据),主要通过find 方法完成; 多行记录 用select $User = M("User"); // 实例化User对象 // 查找status值为1name值为think的用户数据 $data = $User->where('status=1 AND name="thinkphp"')->find(); dump($data); $this->getField('id,name', 5); // 限制返回5条记录 // 3.2.3版本开始,setInc和setDec方法支持延迟更新 $Article->where('id=5')->setInc('view', 1, 60); // 文章阅读数加1,并且延迟60秒更新(写入) //exp查询的条件不会被当成字符串,所以后面的查询条件可以使用任何SQL支持的语法,包括使用函数和字段名称。查询表达式不仅可用于查询条件,也可以用于数据更新,例如: $User = M("User"); // 实例化User对象 // 要修改的数据对象属性赋值 $data['name'] = 'ThinkPHP'; $data['score'] = array('exp', 'score+1'); // 用户的积分加1 $User->where('id=5')->save($data); // 根据条件保存修改的数据 //execute用于更新和写入数据的sql操作,如果数据非法或者查询错误则返回false ,否则返回影响的记录数。 $Model = new \Think\Model(); // 实例化一个model对象 没有对应任何数据表 $Model->execute("update think_user set name='thinkPHP' wherestatus=1"); // 如果你当前采用了分布式数据库,并且设置了读写分离的话,execute方法始终是在写服务器执行,因此execute方法对应的都是写操作,而不管你的SQL语句是什么。 //静态定义:在模型类里面预先定义好该模型的自动验证规则,我们称为静态定义。 }
public function helpDBOperation() { $User = M('User'); $User->getDbFields(); //获取当前数据字段 $User->findAll(); //查找所有记录 $User->findAll('1,3,8'); //查询主键为1,3,8的记录集 $User->count(); // 获取记录数 $User->max('score'); // 获取用户的最大积分 $User->min('score', 'score>0'); // 获取积分大于 0 的用户的最小积分 $User->avg('字段名'); // 获取所有记录的字段值的平均值 $User->sum('字段名'); // 统计字段值 $User->getN(2, 'score>80', 'score desc'); // 返回符合条件的第 2 条记录 $User->getN(2, 'score>80', 'score desc'); //还可以获取最后第二条记录 $User->first('score>80', 'score desc'); //如果要查询第一条记录,还可以使用 $User->last('score>80', 'score desc'); // 获取最后一条记录 $User->top(5, '', 'score desc'); // 获取积分最高的前 5 条记录 $User->getBy('name', 'liu21st'); //跟据字段的字段值来查询记录 $Model = new Model(); // 实例化一个 model 对象 没有对应任何数据表 $Model->query("select * from think_user where status=1"); $objrs = $Model->query("select * from think_user where status=1"); //自定义查询 $Model->execute("update think_user set name='thinkPHP' where status=1"); //用于更新和写入数据的 sql 操作,返回影响的记录数 $User->startTrans(); // 启动事务 $User->commit(); // 提交事务 $User->rollback(); // 事务回滚 }
public function delFloor() { $floorId = $_POST['floorId']; $model = new Model(); $model->execute("update floor set del_flag=1 where floor_id ='" . $floorId . "'"); $this->ajaxReturn($data, 'JSON'); }
function addOneDayCourse() { header('Access-Control-Allow-Origin:*'); //跨域 header("Content-type: text/html; charset=utf-8"); /* { "xtoken": "35dsakfsdjfcvjdsajfkdsf234", "coachid": 23, "uid": 333, "pid": 11, "time": "3825843", "action_list": [ { "actionid": 34, "group": 3, "count": 20, "order": 1, "type": 1, "duration": 34 }, { "actionid": 34, "group": 3, "count": 20, "order": 1, "type": 2, "duration": 54 } ] } */ $param = json_decode(file_get_contents('php://input'), true); // $str = '{ // "xtoken": "35dsakfsdjfcvjdsajfkdsf234", // "coachid": 34, // "uid": 76, // "pid": 2, // "time": "1448255875", // "action_list": [ // { // "actionid": 34, // "group": 3, // "count": 200, // "order": 1, // "type": 1, // "duration": 20 // }, // { // "actionid": 44, // "group": 3, // "count": 150, // "order": 1, // "type": 1, // "duration": 30 // } // ] // }'; // $param = json_decode($str, true); $token = $param['xtoken']; init_verify_token($token); $coachid = $param['coachid']; // $coachid = 34; if (!isset($coachid)) { err_ret(-205, 'lack of param', '缺少参数'); } $uid = $param['uid']; // $uid = 42; if (!isset($uid)) { err_ret(-205, 'lack of param', '缺少参数'); } $pid = $param['pid']; // $pid = 1; if (!isset($pid)) { err_ret(-205, 'lack of param', '缺少参数'); } //时间有可能是未来的某天的课程 $time = $param['time']; // $time = 1447257600; if (!isset($time)) { err_ret(-205, 'lack of param', '缺少参数'); } //先查询数据库中是否购买了课程 $model_my_plan = new Model('my_plan'); $condition['uid'] = $uid; $condition['pid'] = $pid; $condition['coachid'] = $coachid; $result = $model_my_plan->where($condition)->select(); if (count($result) <= 0) { err_ret(-206, 'user has no buy plan', '客户没有购买计划'); } $model_course_record = new Model('course_record'); $next_courseid = $model_course_record->max('courseid') + 1; //再查询用户在这一天是否有课程 $sql = "SELECT * FROM my_plan WHERE FROM_UNIXTIME(course_time,'%Y-%m-%d')=FROM_UNIXTIME({$time},'%Y-%m-%d') AND uid={$uid} AND pid={$pid} AND coachid={$coachid}"; $model = new Model(); $result = $model->query($sql); if (count($result) > 0) { //这一天已经有课程了,修改课程 $cur_courseid = $result[0]['courseid']; //根据cur_courseid删除原来的课程 $delete_course_sql = "DELETE FROM course_record WHERE courseid=" . $cur_courseid; $model->execute($delete_course_sql); //添加课程 $action_list = $param['action_list']; for ($i = 0; $i < count($action_list); $i++) { $action_list[$i]['courseid'] = $cur_courseid; $model_course_record->add($action_list[$i]); } //修改课程状态 $save_data['status'] = 3; $save_data['iscontacted'] = 1; $save_data['isfinished'] = 0; $save_data['tips'] = ''; $save_data['pay_time'] = $result[0]['pay_time']; $save_data['course_time'] = $time; $save_data['begin_time'] = $result[0]['begin_time']; $save_data['end_time'] = $result[0]['end_time']; $model_my_plan->where('id=' . $result[0]['id'])->save($save_data); //返回结果 $data['errno'] = 0; $data['courseid'] = $cur_courseid; echo json_encode($data); } else { //这一天没有课程 //添加课程 $action_list = $param['action_list']; for ($i = 0; $i < count($action_list); $i++) { $action_list[$i]['courseid'] = $next_courseid; $model_course_record->add($action_list[$i]); } //找到开始时间和结束时间 $result_my_plan = $model_my_plan->where($condition)->select(); $begin_time = $result_my_plan[0]['begin_time']; $end_time = $result_my_plan[0]['end_time']; $pay_time = $result_my_plan[0]['pay_time']; $course_time = $result_my_plan[0]['course_time']; if ($course_time == 1 || $course_time == 0) { $begin_time = time(); $end_time = $begin_time + 30 * 86400; } //把课程添加到计划 unset($condition); $condition['uid'] = $uid; $condition['pid'] = $pid; $condition['coachid'] = $coachid; $condition['courseid'] = 0; unset($result_my_plan); $result_my_plan = $model_my_plan->where($condition)->select(); if (count($result_my_plan) > 0) { $id = $result_my_plan[0]['id']; $save_data['uid'] = $uid; $save_data['pid'] = $pid; $save_data['coachid'] = $coachid; $save_data['courseid'] = $next_courseid; $save_data['status'] = 3; $save_data['iscontacted'] = 1; $save_data['isfinished'] = 0; $save_data['tips'] = ''; $save_data['pay_time'] = $pay_time; $save_data['course_time'] = $time; $save_data['begin_time'] = $begin_time; $save_data['end_time'] = $end_time; $model_my_plan->where('id=' . $id)->save($save_data); } else { $add_data['uid'] = $uid; $add_data['pid'] = $pid; $add_data['coachid'] = $coachid; $add_data['courseid'] = $next_courseid; $add_data['status'] = 3; $add_data['iscontacted'] = 1; $add_data['isfinished'] = 0; $add_data['tips'] = ''; $add_data['pay_time'] = $pay_time; $add_data['course_time'] = $time; $add_data['begin_time'] = $begin_time; $add_data['end_time'] = $end_time; $model_my_plan->add($add_data); } //返回数据 $data['errno'] = 0; $data['courseid'] = $next_courseid; echo json_encode($data); //通知用户 $sql = "SELECT id, name,nicker FROM user_info WHERE id IN({$uid},{$coachid})"; $model = new Model(); $result = $model->query($sql); foreach ($result as $value) { if ($value['id'] == $uid) { //用户 $userNicker = $value['nicker']; } else { if ($value['id'] == $coachid) { $coachName = $value['name']; } } } $strDate = timeToString($time); $strTicker = 'Hi,' . $userNicker . ' 你有新的计划啦,快点开看看吧'; $strTitle = 'Hi,' . $userNicker . ' 你有新的计划啦,快点开看看吧'; // $strText = 'Hi,'.$userNicker.' 你的教练'.$coachName.'给你安排了'.$time.'的训练计划啦 记得去查看哦~'; $strText = 'Hi,' . $userNicker . ' 你的教练' . $coachName . '给你安排了新的训练计划啦 记得去查看哦~'; //发通知 // sendDeviceUnicast($uid,$strTicker,$strTitle,$strText); getuiSendDeviceUnicast($uid, $strTitle, $strText); } }
public function articleUpdate() { if (session('?userid') && session('?usertype') && ($_SESSION[usertype] == 1 || $_SESSION[usertype] == 2)) { //dump($_POST); $Form = new Model(); $date = date("Y-m-d H:i:s"); $id = date("Ymdhis"); //'update project_info set status=%d where project_id="%s"' //生成缩略图 $info = htmlspecialchars_decode(I('post.key6')); $origin = getPic($info, C(EXP_PREFIX)); //dump($origin); if ($origin != null) { $thumb = substr($origin, 0, strlen($origin) - 4) . 'thumb.jpg'; //ThinkImage类方法 $image = new \Think\Image(); $image->open($origin); $unlink = $image->thumb(240, 135, \Think\Image::IMAGE_THUMB_CENTER)->water('./Public/pic/water.png', \Think\Image::IMAGE_WATER_NORTHWEST, 80)->text(' ' . C('MODULE_CODE')[I('post.key2', 0)], './Public/fonts/1.ttf', 12, '#FFFFFF', \Think\Image::IMAGE_WATER_NORTHWEST)->save($thumb); if ($unlink !== false) { $thumb = C(PREFIX) . substr($thumb, 1); } else { $thumb = ''; } } else { $thumb = ''; } $sqlstr = sprintf("update admin_articles set admin_id='%s',article_title='%s',article_type=%d,\n article_field=%d,article_object=%d,article_about=%d,article_content='%s',article_time='%s',\n article_abstract='%s', thumb='%s' \n where article_id='%s'", $_SESSION['userid'], $_POST['key1'], $_POST['key2'], $_POST['key3'], $_POST['key4'], $_POST['key5'], $_POST['key6'], $date, $_POST['key0'], $thumb, $_POST['key7']); $result = $Form->execute($sqlstr); if ($result) { echo $result; } else { echo $result; } } }
public function detail() { $Form = new Model(); $result = $Form->query('select admin_articles.*, admin_nickname from admin_articles inner join admin_personal on admin_articles.admin_id = admin_personal.admin_id where article_id="%s"', $_GET['p']); if ($result) { $result[0]['article_type'] = C('MODULE_CODE')[$result[0]['article_type']]; //dump($result[0]); if ($result[0]['article_about'] == C(PROJECT_CODE)) { $object = $Form->query('select project_name as name, project_logo as portrait from project_info where project_id = "%s"', $result[0]['article_object']); //dump($object); $this->obj = $object[0]; } else { if ($result[0]['article_about'] == C(INVESTOR_CODE)) { $object = $Form->query('select name, portrait from investor_personal where user_id = "%s"', $result[0]['article_object']); //dump($object); $this->obj = $object[0]; } else { if ($result[0]['article_about'] == C(INNOVATOR_CODE)) { $object = $Form->query('select name, portrait from entrepreneur_personal where user_id = "%s"', $result[0]['article_object']); //dump($object); $this->obj = $object[0]; } } } $this->p = $result[0]; } $update = $Form->execute('update admin_articles set article_visits=%d where article_id="%s"', $result[0]['article_visits'] + 1, $_GET['p']); $this->display(); }
public function saveProjects() { if (session('?userid') && session('?usertype')) { $ps = $_POST; $Form = new Model(); $Form->execute("delete from home_show where tag='%d'", C(PROJECT_CODE)); if ($_POST) { for ($i = 1; $i <= 12; $i++) { $tmp = $ps['key' . $i]; if ($tmp) { //dump($tmp."||||".$i); //$old[$i]=$tmp; $Form->execute("replace into home_show (content_id,tag) values ('%s','%d')", $tmp, C(PROJECT_CODE)); } } } echo 200; } }
public function saveChange() { //dump($_POST); $Form = new Model(); if ($_SESSION['type'] == 1) { if (check_mobile(I('post.key5'), I('post.key4')) == 200) { $check = $Form->query('select * from investor_security where user_id = "%s"', $_SESSION['id']); if ($check[0]['user_pwd'] === I('post.key1')) { $result = $Form->execute('update investor_security set user_pwd = "%s" where user_id = "%s"', I('post.key2'), $_SESSION['id']); if ($result) { echo 200; session('[destroy]'); exit; } else { echo 400; exit; } } else { echo 404; exit; } } else { echo 409; exit; } } else { if ($_SESSION['type'] == 2) { if (check_mobile(I('post.key5'), I('post.key4')) == 200) { $check = $Form->query('select * from entrepreneur_security where user_id = "%s"', $_SESSION['id']); if ($check[0]['user_pwd'] === I('post.key1')) { $result = $Form->execute('update entrepreneur_security set user_pwd = "%s" where user_id = "%s"', I('post.key2'), $_SESSION['id']); if ($result) { echo 200; session('[destroy]'); } else { echo 400; exit; } } else { echo 404; exit; } } else { echo 409; exit; } } else { echo 401; } } }
public function addUser() { //获取客户端发送的json $json = json_decode($GLOBALS['HTTP_RAW_POST_DATA']); print_r($json); $key = "access_token"; $jwt = $json->access_token; if ($json->access_token == null) { $log = "无access_token"; } else { $jwt = JWT::decode($jwt, $key, array('HS256')); $timenow = date("YmdHis", strtotime('now')); if (!($jwt->aud == $json->username && $timenow < $jwt->exp && $timenow > $jwt->iat)) { $log = "超时或名称不对称"; } } $arr = $json; $id = $arr->id; //用户名为学号,也是数据库中的ID $name = $arr->name; $mailbox = $arr->mailbox; $psw = $arr->id; $authority = $arr->authority; $grade = $arr->grade; $art = $arr->id; //文章的id号 if ($authority == "管理员") { $authority = "admin"; } else { $authority = "user"; } $Model = new Model(); $sql = "insert into " . __PREFIX__ . "user (id,name,mailbox,psw,authority,grade) values ({$id},'{$name}','{$mailbox}',{$psw},'{$authority}','{$grade}');"; if ($Model->execute($sql)) { $suc = 1; } else { $suc = 0; } $jsonsend = array("username" => $json->username, "suc" => $suc, "access_token" => $json->access_token); }
public function saveChange() { //dump($_POST); $Form = new Model(); $user_id = $_POST['key1']; $newpwd = $_POST['key2']; $pwds = $Form->query('select user_pwd from investor_security where user_id="%s"', $user_id); $pwd = $pwds[0]; if ($pwd) { $result = $Form->execute('update investor_security set user_pwd = "%s" where user_id = "%s"', I('post.key2'), $user_id); if ($result) { echo 200; } else { echo 404; } } else { $result = $Form->execute('update entrepreneur_security set user_pwd = "%s" where user_id = "%s"', I('post.key2'), $user_id); if ($result) { echo 200; } else { echo 404; } } session('[destroy]'); }
/** * 车辆驶离停车场 * * @param unknown $car_no * 车牌号 * @param unknown $berth_no * 车位机器编码 * @param unknown $money * 停车费 */ public function leave($car_no, $berth_no, $money) { $Model = new Model(); $now = time(); $sql = "select r.berth_id,r.id,r.park_id,u.id as user_id from px_parkrecord as r,px_car as c,px_berth as b,px_user as u,px_user_car as uc\r\n\t\t\t where c.no='" . $car_no . "' and b.no=" . $berth_no . " and r.start_time is not null and r.end_time is null and c.id=r.car_id and\r\n\t\t\t c.id=uc.car_id and uc.user_id=u.id and r.berth_id=b.id and b.no=" . $berth_no; /* /* $sql_id = "select px_parkrecord.berth_id,px_parkrecord.id,px_parkrecord.park_id,px_user.id as user_id, max(px_parkrecord.start_time) from px_parkrecord,px_car,px_berth,px_user,px_user_car where px_car.no='" . $car_no . "' and px_car.id=px_parkrecord.car_id and px_parkrecord.berth_id=px_berth.id and px_parkrecord.start_time is not null and px_parkrecord.end_time is null and px_car.id=px_user_car.car_id and px_user_car.user_id=px_user.id"; */ //var_dump($sql); */ $id = $Model->query($sql); if ($id[0]['id']) { $sql_update = "update px_parkrecord set end_time=" . $now . ",money=" . $money . " where id=" . $id[0]['id']; $result1 = $Model->execute($sql_update); $park_id = $id[0]['park_id']; $result2 = M('Park')->where('id=' . $park_id)->setInc('remain_num', 1); $berth_id = $id[0]['berth_id']; $sql_berth = "update px_berth set is_null=0 where id=" . $berth_id; $result3 = $Model->execute($sql_berth); $result4 = M('Park')->where('id=' . $park_id)->field('total_num,remain_num')->find(); $num = ($result4['total_num'] - $result4['remain_num']) / $result4[total_num]; $Target = A('Target'); $Target->add($park_id, $num); $User = A('User'); $User->cost($id[0]['user_id'], $money); echo "车牌号为" . $car_no . "的车驶离id为" . $park_id . "的停车场,驶离车位的id是" . $berth_id; } else { echo "车辆全部驶离停车场"; } }