public function on_get_checkcode($mobile = '') { if (!$mobile || !preg_match("/^13[0-9]{1}[0-9]{8}\$|15[0189]{1}[0-9]{8}\$|18[0-9]{9}\$/", $mobile)) { die_json(array('error' => '手机号格式不正确')); } // session_start(); if (isset($_SESSION['checkcode'])) { $got_checkcode = $_SESSION['checkcode']; list($checkcode, $timestamp) = explode('_', $got_checkcode); $now = time(); //检查是否在一分钟内 if ($now - $timestamp <= 60) { die_json(array('error' => '一分钟后才能重发验证码')); } } $checkcode = rand(100000, 999999); //6位 $timestamp = time(); //当前时间,5分钟过期 $_SESSION['checkcode'] = $checkcode . '_' . $timestamp; //调用短信 $result = $this->sendTemplateSMS($mobile, array($checkcode, '5'), $debug = 1); //替换debug if (!$result) { die_json(array('error' => '发送故障,请稍候重试')); } else { die_json(array('success' => '已发送验证码,请在' . $mobile . '手机上查收验证码')); } return true; }
public function delete() { $game_id = $this->input->post('game_id'); $result = $this->load_model('game_model')->delete_game($game_id); if (isset($result['error'])) { die_json(array('error' => $result['error'])); } else { die_json(array('error' => 0)); } }
/** * 获取游戏结果 */ public function on_get_game_result() { $game_id = get_post('game_id'); if (!$game_id) { return false; } $game_config = $this->db->where('game_id', $game_id)->column('games', 'game_config'); $game_config = json_decode($game_config, true); $rid = $this->getRand($game_config['proba_arr']); if ($rid > 6) { $rid = 0; } die_json(array('rid' => $rid)); }
function on_barcode($number = '') { if (empty($number)) { die_json(array('error_code' => 10041, '条形码不能为空')); } include_once LIBS_DIR . 'barcode/class/BCGFontFile.php'; include_once LIBS_DIR . 'barcode/class/BCGColor.php'; include_once LIBS_DIR . 'barcode/class/BCGDrawing.php'; include_once LIBS_DIR . 'barcode/class/BCGcode39.barcode.php'; // 加载字体大小 $font = new BCGFontFile(LIBS_DIR . 'barcode/font/Arial.ttf', 18); //颜色条形码 $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode39(); $code->setScale(2); $code->setThickness(30); // 条形码的厚度 $code->setForegroundColor($color_black); // 条形码颜色 $code->setBackgroundColor($color_white); // 空白间隙颜色 $code->setFont($font); // $code->parse($number); // 条形码需要的数据内容 } catch (Exception $exception) { $drawException = $exception; } //根据以上条件绘制条形码 $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // 生成PNG格式的图片 header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
/** * 修改金币 */ public function _update_user_score($userinfo, $score) { // 修改金币 $data = array('score' => $userinfo['score'], 'modify_time' => date('Y-m-d H:i:s')); $res = $this->db->where('user_id', $this->user_id)->update('user', $data); if ($res === false) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10020, 'error' => '获取金币失败!')); } // 如果是余额支付 - 记录账户变动记录 $data = array('user_id' => $this->user_id, 'action' => 'user.score.add', 'action_name' => '增加金币' . $score, 'amount' => $score, 'create_time' => date('Y-m-d H:i:s')); $res = $this->db->insert('user_account', $data); if ($res === false) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10021, 'error' => '游戏金币记录失败!')); } return true; }
function on_cart() { $cart = $_REQUEST['cart']; // 判断 if (!$cart) { die_json(array('error_code' => 10012, 'error' => '购物车加入失败,购物车数据为空!')); } // 启动事务 $this->db->trans_start(); // 删除购物车之前记录的数据 $this->db->where('user_id', $this->user_id)->where('session_id', session_id()); $res = $this->db->delete('cart'); if ($res === false) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10013, 'error' => '购物车加入失败,删除数据失败!')); } // 添加购物车数据 $flag = true; foreach ($cart as $i) { $data = array('user_id' => $this->user_id, 'session_id' => session_id(), 'goods_id' => $i['goods_id'], 'goods_price' => $i['goods_price'], 'goods_score' => $i['goods_score'], 'cart_num' => $i['cart_num'], 'create_time' => date('Y-m-d H:i:s')); $res = $this->db->insert('cart', $data); if ($res === false) { $flag = true; break; } } // 判断 if (!$flag) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10014, 'error' => '购物车加入失败!')); } // 提交事务 $this->db->trans_commit(); // 返回成功信息 die_json(array('message' => 'ok.')); }
public function on_check_can_play() { $game_id = get_post('game_id'); if (!$game_id) { return false; } $key = 'user_play_game_times_' . $this->user_id . '_' . $game_id; // unset($_SESSION[$key]);die; $can_play = 1; if (isset($_SESSION[$key])) { echo $_SESSION[$key] . "\n"; //检查是否过期了 list($play_times, $expire) = explode(',', $_SESSION[$key]); if (time() <= $expire) { //没有过期 if ($play_times == 0) { //今天不能玩了 $can_play = 0; die_json(array('can_play' => $can_play)); } else { $play_times--; $_SESSION[$key] = $play_times . ',' . $expire; die_json(array('can_play' => $can_play)); } } //过期了 } //第一次玩 //获取play_times $game_config = $this->db->where('game_id', $game_id)->column('games', 'game_config'); $game_config_arr = json_decode($game_config, true); $play_times = $game_config_arr['play_times']; $play_times--; $expire = strtotime('+1 day', strtotime(date('Y-m-d'))); //明天000 $_SESSION[$key] = $play_times . ',' . $expire; die_json(array('can_play' => $can_play)); }
public function on_focus($goods_id = 0) { $focus_res = array('error' => 0, 'reg_status' => 1); // 检查注册 $user_mobile = $this->db->where('user_id', $this->user_id)->column('user', 'mobile'); if (!$user_mobile) { $focus_res['reg_status'] = 0; die_json($focus_res); } //检查是否已经关注 $goods_focus = $this->db->where('user_id', $this->user_id)->where('goods_id', $goods_id)->row('goods_focus'); if ($goods_focus) { $focus_res['error'] = '您已经关注过该商品了!'; die_json($focus_res); } $data = array('user_id' => $this->user_id, 'goods_id' => $goods_id, 'create_time' => date("Y-m-d H:i:s")); $focus_goods_res = $this->db->insert('goods_focus', $data); if (!$focus_goods_res) { $focus_res['error'] = '关注商品失败!'; die_json($focus_res); } die_json($focus_res); }
public function on_focus($code = '') { if (empty($code)) { die_json(array('error_code' => 1, 'error' => '参数错误')); } // 是否关注 $focusInfo = $this->db->where('user_id', $this->user_id)->where('code', $code)->row('focus_user'); if ($focusInfo) { die_json(array('message' => '已经关注')); } // 启动事务 $this->db->trans_start(); $freeData = array('code' => $code, 'user_id' => $this->user_id, 'create_time' => date('Y-m-d H:i:s')); $res = $this->db->insert("focus_user", $freeData); if (false === $res) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 3, 'error' => '关注失败')); } $userinfo = $this->db->where('user_id', $this->user_id)->row('user'); $score = $this->db->where('focus_id', $code)->column('focus', 'score'); $score = !empty($score) ? $score : 0; $data = array('score' => $userinfo['score'] + $score, 'modify_time' => date('Y-m-d H:i:s')); $res = $this->db->where('user_id', $this->user_id)->update('user', $data); if (false === $res) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 4, 'error' => '增加金币失败')); } // 记录账户变动记录 $data = array('user_id' => $this->user_id, 'action' => 'user.score.add', 'action_name' => '增加金币' . $score, 'amount' => $score, 'create_time' => date('Y-m-d H:i:s')); $this->db->insert('user_account', $data); // 提交事务 $this->db->trans_commit(); die_json(array('message' => '关注成功')); }
/** * 金币支付 */ public function _balance_of_score($userinfo, $score) { if ($userinfo['score'] < $score) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10022, 'error' => '金币不足!')); } // 扣除余额 $data = array('score' => $userinfo['score'] - $score, 'modify_time' => date('Y-m-d H:i:s')); $res = $this->db->where('user_id', $this->user_id)->update('user', $data); if ($res === false) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10020, 'error' => '下单失败,金币支付失败!')); } // 如果是余额支付 - 记录账户变动记录 $data = array('user_id' => $this->user_id, 'action' => 'user.score.lose', 'action_name' => '订单支付金币' . $score, 'amount' => $score, 'create_time' => date('Y-m-d H:i:s')); $res = $this->db->insert('user_account', $data); if ($res === false) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10021, 'error' => '下单失败,金币变动记录失败!')); } return true; }
/** * 上传图片 * 上传图片到本地:index.php/image/upload * 上传图片到图片服务器:index.php/image/upload/remote */ function upload() { $ufile = isset($_REQUEST['file_name']) ? trim($_REQUEST['file_name']) : 'ufile'; // 获取上传表单名字 $file_types_str = isset($_REQUEST['file_types']) ? trim($_REQUEST['file_types']) : ''; // 获取图片类型 $file_width = isset($_REQUEST['width']) ? trim($_REQUEST['width']) : ''; //get_post('width'); // 图片宽 $file_height = isset($_REQUEST['height']) ? trim($_REQUEST['height']) : ''; //get_post('height'); // 图片高 $file_size = isset($_REQUEST['size']) ? trim($_REQUEST['size']) : ''; //get_post('size'); // 图片大小 // 上传图片的信息 $filename = $_FILES[$ufile]['name']; $tmpfile = $_FILES[$ufile]['tmp_name']; $filesize = $_FILES[$ufile]['size']; $fileinfo = pathinfo($filename); $file_types = explode(',', $file_types_str); !$file_types && ($file_types = array('jpg', 'jpeg', 'png', 'gif')); // 判断文件格式 if (isset($fileinfo['extension']) && !in_array(strtolower($fileinfo['extension']), $file_types)) { return array('error' => "文件格式不正确!"); } // 判断文件大小 if ($file_size != '' && $file_size * 1024 < $filesize) { return array('error' => "文件大小不符合规范"); } if (!trim($tmpfile)) { return array("error" => "上传文件为不能空!"); } $imagesize = getimagesize($tmpfile); // 判断文件高宽 if ($file_width != '' && $file_width != $imagesize[0] || $file_height != '' && $file_height != $imagesize[1]) { return array("error" => "文件尺寸不符合规范"); } $file = FCPATH . 'upload/image/' . time() . rand(999, 1000) . "." . $fileinfo['extension']; @move_uploaded_file($tmpfile, $file); $data = array('message' => '上传成功!'); // 上传到本地 $data['filename'] = basename($file); $data['file'] = $data['file_url'] = site_url('image/index?src=' . $data['filename']); die_json($data); }
function store_entry($id, $data) { $file = DATA_DIR . '/' . $id; if (empty($data)) { return; } if (is_array($data)) { $data = json_encode($data); } // $data = stripslashes($data); file_put_contents($file, $data) or die_json("Can't read the file!"); }
private function _check_favorable($code) { $favorableInfo = $this->db->where('user_id', $this->user_id)->where('activity_code', $code)->row('activity'); if ($favorableInfo) { $this->db->trans_rollback(); // 回滚事务 die_json(array('error_code' => 10039, 'error' => '优惠卷已经领取过了!')); } return $favorableInfo; }
<?php include '../scat.php'; include '../lib/txn.php'; $type = $_REQUEST['type']; if (!in_array($type, array('correction', 'vendor', 'customer', 'drawer'))) { die_json("Requested type not understood."); } $type = $db->escape($type); $q = "START TRANSACTION;"; $r = $db->query($q); if (!$r) { die_query($db, $q); } $q = "SELECT 1 + MAX(number) AS number FROM txn WHERE type = '{$type}'"; $number = $db->get_one($q); $tax_rate = $type == 'customer' ? DEFAULT_TAX_RATE : 0; $person = (int) $_REQUEST['person']; if (!$person) { $person = 'NULL'; } $q = "INSERT INTO txn\n SET created= NOW(),\n type = '{$type}',\n number = {$number},\n person = {$person},\n tax_rate = {$tax_rate}"; $r = $db->query($q); if (!$r) { die_query($db, $q); } $txn_id = $db->insert_id; $r = $db->commit(); if (!$r) { die_query($db, "COMMIT"); }
<?php include '../scat.php'; include '../lib/item.php'; include '../lib/fpdf/alphapdf.php'; include '../lib/php-barcode.php'; if ($q = $_REQUEST['q']) { $items = item_find($db, $q, 0); if (!$items) { die_json("No items found."); } } else { $id = (int) $_REQUEST['id']; $items = array(item_load($db, $id)); if (!$items[0]) { die_json("No such item."); } } $trim = $_REQUEST['trim']; $left_margin = 0.2; $label_width = 2.0; $label_height = 0.75; $basefontsize = 9; $vmargin = 0.1; $dummy = new AlphaPDF('P', 'in', array($label_width, $label_height)); $pdf = new AlphaPDF('P', 'in', array($label_width, $label_height)); foreach ($items as $item) { $pdf->AddPage(); $pdf->Rotate(270); $pdf->SetFont('Helvetica', ''); $pdf->SetFontSize($size = $basefontsize);
/** * 裁剪图片 */ function crop() { $image_file = $_REQUEST['image']; $info = pathinfo($image_file); $image_crop_file = $info['filename'] . '_crop.' . $info['extension']; $image_thumb_file = $info['filename'] . '_thumb.' . $info['extension']; $crop_offset = $_REQUEST['crop_offset']; if (!is_array($crop_offset)) { $crop_offset = explode(',', $crop_offset); } $upload_path = FCPATH . 'upload/image/'; list($width, $height, $type, $attr) = getimagesize($upload_path . $image_file); // 判断 if (!file_exists($upload_path . $image_file)) { die_json(array('error' => '图片不存在!')); } $x = $crop_offset[0]; // 裁剪的x坐标 $y = $crop_offset[1]; // 裁剪的y坐标 $w = $crop_offset[2]; // 裁剪的相对宽度 $h = $crop_offset[3]; // 裁剪的相对高度 $bw = $crop_offset[4]; // 原图显示宽度 $bh = $crop_offset[5]; // 原图显示高度 $pw = $width / $bw; // 宽度比例 $ph = $height / $bh; // 高度比例 // 裁剪图 $config = array('image_library' => 'gd2', 'source_image' => $upload_path . $image_file, 'new_image' => $upload_path . $image_crop_file, 'maintain_ratio' => false, 'width' => $w * $pw, 'height' => $h * $ph, 'x_axis' => $x * $pw, 'y_axis' => $y * $ph); $this->load->library('image_lib', $config); $res = $this->image_lib->crop(); if (!$res) { die_json(array('error' => '图片裁剪失败!')); } // 缩略图 $config = array('image_library' => 'gd2', 'source_image' => $upload_path . $image_crop_file, 'new_image' => $upload_path . $image_thumb_file, 'maintain_ratio' => false, 'width' => 120, 'height' => 120); $this->image_lib->initialize($config); $res = $this->image_lib->resize(); if (!$res) { die_json(array('error' => '生成缩略图失败!')); } die_json(array('message' => '上传成功!', 'image' => $image_crop_file, 'thumb' => $image_thumb_file)); }