Esempio n. 1
0
 /**
 * 核销卡券记录
 * 
 */
 public function cancelCard(){
     //$openid = $this->getParam("openid");    
     //$cardid = $this->getParam("cardid"); 
     $code = $this->getParam("code"); 
     $str = $this->getParam("str"); 
     if($str != 123){
         printJson(null, 0, '验证失败');
         exit;   
     }
     $res = $this->_Model->listGetCodeLog($code);
     if(!$res){
         printJson(null, 0, '没有卡券');
         exit;    
     }
     if($res['state'] == 3){
         printJson(null, 3, '已被核销');
         exit;       
     }
     //根据code更新卡券为核销
     $ret = $this->_Model->upCancelCard($code);
     if(!$ret){
         printJson(null, 2, '核销失败');
         exit;       
     }
     printJson(null, 1, '核销成功');
     exit;
        
 }
Esempio n. 2
0
 /**
  * 做一个login
  */
 public function login()
 {
     if (IS_AJAX && 'submit' == I('post.submit')) {
         //login 操作
         $username = I('post.username');
         $userpass = I('post.userpass');
         //表单令牌
         if (token_check() == false) {
             printJson(array('tk' => form_token()), 1, '请求超时,请重试');
         }
         $mod = Factory::getModel('bt_user');
         $where = sprintf("username='******' AND deleted=0", $username);
         $row = $mod->field('id,userpass,salt')->where($where)->find();
         if (empty($row)) {
             printJson(array('tk' => form_token()), 1, '账号不存在');
         }
         if ($row['userpass'] != md5($userpass . $row['salt'])) {
             printJson(array('tk' => form_token()), 1, '账号或者密码不正确');
         }
         $row['username'] = $username;
         session_regenerate_id();
         $user_cls = load_class('UserModel');
         $user_cls->setSessionUser($row);
         printJson(1);
     }
     $turl = urldecode(I('get.url', url('DiskTop', 'index')));
     $this->assign('turl', $turl);
     $this->display();
 }
Esempio n. 3
0
/**
 * RestfulResponse
 * 
 * Simple response functions
 *
 * @author Philippe
 */
function sendFinalHttpResponse($code, $data = null)
{
    if ($data) {
        printJson($data);
    }
    http_response_code($code);
    exit(0);
}
Esempio n. 4
0
 /**
  * 列表
  */
 public function index()
 {
     if (IS_AJAX && !empty($_POST)) {
         $table = isset($_POST['table']) ? $_POST['table'] : '';
         if (empty($table)) {
             printJson("提交不合法");
         }
         $column = '';
         foreach ($table as $key => $val) {
             if (empty($val['name'])) {
                 continue;
             }
             if (in_array($val['type'], array('char', 'varchar', 'text'))) {
                 //string类型,0便是空字符串
                 $val['default'] = empty($val['default']) ? '' : $val['default'];
             }
             $val['default'] = " DEFAULT '" . $val['default'] . "' ";
             $type = $val['type'] . '(' . $val['length'] . ')';
             if ($val['type'] == 'decimal') {
                 //数值类型的长度有小数位
                 $type = $val['type'] . '(' . $val['length'] . ',' . $val['place'] . ')';
             } elseif (in_array($val['type'], array('text', 'mediumtext', 'longtext', 'datetime', 'date'))) {
                 //相关类型不需要默认值和长度设定
                 $type = $val['type'];
                 $val['default'] = '';
             }
             $null_str = $val['null'] ? 'NOT NULL' : '';
             //进行语句的拼接
             $col = "`%s` %s %s %s COMMENT '%s',";
             $col = sprintf($col, $val['name'], $type, $null_str, $val['default'], $val['comment']);
             $column .= $col . "\n";
         }
         $column = substr($column, 0, -1);
         $str = "CREATE TABLE `table_name` (\n`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'pk',\n{$column}\n`create_at` int(10) NOT NULL DEFAULT '0',\n`update_at` int(10) NOT NULL DEFAULT '0',\n`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0正常1删除',\nPRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ";
         printJson($str);
     }
     $this->display();
 }
Esempio n. 5
0
   public function updateData() {
       $id = $this->getParam('id');
       $num = $this->getParam('tosup_num');
       $openid = $this->getParam('openid');
       $cardid = $this->getParam('cardid');
       $cardcount = $this->_Model->listCardCount($cardid);
       
       if($num > $cardcount){
           printJson(0, 2, '卡券库存不足,剩余'.$cardcount.'张!');
           exit();   
       }
       
       $param = array(
           'sub_status' => 1,
           'sup_time' => time(),
           'tosup_num' => $num,
       );
       $list = $this->_Model->updateData($id, $param);
       if ($list) {
           $this->_Model->addPartnerCodeData($openid, $cardid, $num);   
 
           //合伙人卡券统计
           $cardStu = $this->_IndexModel->checkPartnerCard($cardid, $openid); 
            
           $st = array(
               //'card_supplement' => $cardStu['card_supplement']+1,   //不是允许补充才算补充次数
               'card_number' => $cardStu['card_number']+$num,
               'card_issue' => $cardStu['card_issue']+$num
           );  
           //更改合伙人卡券统计发放数
           $this->_IndexModel->upPartnerCardStatistics($cardid, $openid, $st);
           //合伙人统计
           $partnerSta = $this->_IndexModel->listPartnerStatisticsOne($openid);
           $arrto = array(
               //'par_supplement' => $partnerSta['par_supplement']+1, 
               'par_number' => $partnerSta['par_number']+$num, 
           );
           //更改合伙人统计发放数
           $this->_IndexModel->upPartnerStatistics($openid, $arrto);
           
           $this->_CommonModel->insertOneMessage($openid, '卡包审核成功');
           printJson(0, 1, '补充成功!');
           exit();
       } 
       printJson(0, 0, '补充失败!');
           exit();
   }
Esempio n. 6
0
 /**
  * 获取卡券列表
  * status 参数 
  * “CARD_STATUS_NOT_VERIFY”,待审核;
  * “CARD_STATUS_VERIFY_FALL”,审核失败;
  * “CARD_STATUS_VERIFY_OK”,通过审核;
  * “CARD_STATUS_USER_DELETE”,卡券被用户删除;
  * “CARD_STATUS_USER_DISPATCH”,在公众平台投放过的卡券 
  */
 public function getCardList() {
     $data = array(
         'offset' => 0,
         'count' => 100,
         'status_list' => array($this->getParam("status")),
     );
     $card_list = $this->_admin_model->getCardList($data);
     //var_dump($card_list);
     printJson($card_list);
 }
Esempio n. 7
0
 /**
 Route Methods
 */
 public function levelObjectives($level)
 {
     //this one is publically accessiable through a route.
     //outputs json
     printJson($this->getLevelObjectives($level));
 }
Esempio n. 8
0
 public function ajaxCardCheck() {
     $openid = $this->_openId;
     $cardid = $this->getParam('cardid');
     $cardinfo = $this->_Model->checkCardSend($cardid);
     if (!$cardinfo) {
         printJson(null, 0, '主银,此卡劵的有效期已过!');
         exit();
     }
     if ($cardinfo['status'] == 2) {
         printJson(null, 0, '主银,此卡劵不能发放噢!');
         exit();
     }
     printJson(null, 1, '可以发放!');
     exit();
 }
Esempio n. 9
0
 public function ajaxdealwithrebate(){
     $id = $this->_id;
     $status = $this->_status;
     if(empty($id)){
         printJson('6','FAILED','id为空');
         exit;
     }
     
     if($status == 1){
         if($this->_model->agreegetcash($id)){
             printJson('1','OK','操作成功');
             exit;
         }else{
             printJson('2','FAILED', $this->_model->getError());
             exit;
         }
     }elseif($status == 2){
         if($this->_model->refusegetcash($id)){
             printJson('3','OK','操作成功');
             exit;
         }else{
             printJson('4','FAILED','系统错误,操作异常');
             exit;
         }
     }else{
         printJson('5','FAILED','status 有误');
     }
 }
Esempio n. 10
0
 /**
  * 获取用户已领取卡券
  */
 public function getUserCardList() {
     $data = array('openid' => $this->_openid, 'card_id' => $this->_card_id);
     $card_list = $this->_admin_model->getCardApi($data);
     if ($this->getParam('debug')) {
         echo '<pre>';
         print_r($card_list);
         echo '</pre>';
         exit;
     }
     printJson($card_list);
 }
Esempio n. 11
0
                break;
            case 'logout':
                printJson($session->logout());
                break;
            case 'send':
                $message = stripslashes(isset($_POST['message']) ? $_POST['message'] : '');
                printJson($session->send($message));
                break;
            case 'getUpdates':
                printJson($session->getUpdates());
                break;
            case 'getInitialUsers':
                printJson($session->getInitialUsers());
                break;
            default:
                printJson("InvalidActionException");
                break;
        }
    } catch (Exception $ex) {
        if (!isset($ex->jsontype)) {
            error_log("Exception: " . $ex);
            $ex->jsontype = "Exception";
        }
        printJson($ex);
    }
} else {
    $ex = new Exception("Error starting the PHP session");
    $ex->jsontype = "Exception";
    error_log($ex->getMessage());
    printJson($ex);
}
Esempio n. 12
0
 /**
  * 投票
  */
 private function voteOne($bb_id)
 {
     //判断bb_id是否存在
     $sql = sprintf("SELECT 1 FROM " . $this->baseTab . " WHERE id='%u' AND deleted=0", $bb_id);
     $bb = M("Const")->_db()->getOne($sql, $bb_id);
     if (empty($bb)) {
         Logger::debug("投票的宝宝不存在", $bb_id);
         return false;
     }
     //判断是否是第一次投票.
     $sql = "SELECT create_at FROM " . $this->voteTab . " WHERE " . sprintf("openid='%s' AND bb_id='%u' AND deleted=0 ", $this->openid, $bb_id) . ' ORDER BY id DESC ';
     $num = M("Const")->_db()->getOne($sql);
     $time = time();
     if ($time - $num < 3600) {
         //数据库也做一层判断
         printJson(null, 1, '请间隔1小时后再来投');
     }
     /*
     if($num>=strtotime(date("Y-m-d"))){
     	printJson(null,1,"每人每天对同一个萌娃仅限投1票");
     }
     */
     $set = ['openid' => $this->openid, 'bb_id' => $bb_id, 'create_at' => $time, 'update_at' => $time, 'deleted' => 0];
     $id = M("Const")->add($this->voteTab, $set);
     if (empty($id)) {
         Logger::debug("晒娃活动投票失败", $set);
     } else {
         //投票.
         $sql = "UPDATE " . $this->baseTab . " SET vote_times=vote_times+1 ";
         //次数
         if (empty($num)) {
             $sql .= ",vote_nums=vote_nums+1";
             //人次
             //记录投票的人数
             $cache = Factory::getCacher();
             method_exists($cache, 'getRedis') && $cache->getRedis()->lPush(self::VOTE_KEY, $bb_id);
         }
         $sql .= " WHERE " . sprintf("id='%u'", $bb_id);
         M("Const")->_db()->query($sql);
     }
     return $id;
 }
Esempio n. 13
0
/**
 * Get ALL the info about an addon, you will need addon id
 */
function addonInfo()
{
    global $url_params;
    if (isset($url_params['id'])) {
        $addon = new Addon();
        $addon_data = $addon->getAddonData($url_params['id']);
        printJson(json_encode($addon_data));
    }
}
 /**
 * ajax成功领取卡券
 * 
 */
 public function successCard(){
     $code = $this->getParam("code"); 
     $id = $this->getParam("id"); 
     $usopenid = $this->getParam('usopenid');
     $cardid = $this->getParam('cardid');
     $openid = $this->_openid;   
     //更改卡券状态
     $up = $this->_Model->upCardDrawfl($code,$openid,$usopenid);
     if (!$up) {
         printJson(null, 2, '参数错误');
         exit();
     }  
     
     $cardStu = $this->_Model->checkPartnerCard($cardid, $usopenid);
     $arr = array(
         'card_receiv' => $cardStu['card_receiv']+1,
         //'card_number' => $cardStu['card_number']-1
     );  
     //更改合伙人卡券统计发放数
     $this->_Model->upPartnerCardStatistics($cardid, $usopenid, $arr);
     $partnerSta = $this->_Model->listPartnerStatisticsOne($usopenid);
     
     //更改合伙人卡券发放数据
     $this->_Model->upParCardSend($id);
     
     
     $arrto = array(
         //'par_number' => $partnerSta['par_number']-1, 
         'par_receiv' => $partnerSta['par_receiv']+1
     );
     //更改合伙人统计发放数
     $this->_Model->upPartnerStatistics($usopenid, $arrto);
         
     printJson(0, 0, '修改成功');
     exit;
 }
 /**
  * 我的返利按日期查询
  */
 public function searchInfo(){
     $params           = $this->getParam();
     $params['openid'] = $this->_openId;
     $result = $this->model->searchInfodata($params);
     printJson($result, 0, 'ok');
 }
Esempio n. 16
0
    public function ajaxapplyfor() {
        $cash = $this->getParam('cash');

        if (!is_numeric($cash)) {
            printJson('5', 'FAILED', '提现金额输入错误');
            exit;
        }

        //检查是否可以提现申请
        if ($this->_Model->ispartnerHascashapply($this->_openId)) {
            printJson('4', 'FAILED', '不可以重复提交提现申请');
            exit;
        }
        //获取可提现金额
        $result = $this->_Model->getrebateall($this->_openId);
        $rebate = $result['rebate_money'];
        if ($cash <= $rebate) {
            if ($this->_Model->getcashapply($cash, $this->_openId, $rebate)) {
                printJson('0', 'OK', '提交成功');
                exit;
            } else {
                printJson('1', 'FAILED', 'system error');
                exit;
            }
        } else {
            printJson('2', 'FAILED', '提交金额,超过可提现金额');
            exit;
        }
    }
if ($set && $file_id && $user_id) {
    $setUser = sql_query("UPDATE resource SET created_by='{$user_id}' WHERE ref='{$file_id}'");
    $newUser = array('new_user' => $user_id, 'file' => $file_id);
    printJson($newUser);
}
// set file size : no size set when file uploaded by API
// execute after file upload
if ($set && $update_file_size && $file_id) {
    update_disk_usage($file_id);
}
// rename a file
if ($set && $file_id && $new_file_name) {
    $new_file_name = urldecode($new_file_name);
    $renameFile = sql_query("UPDATE resource_data SET value=\"{$new_file_name}\" WHERE resource_type_field=51 AND resource='{$file_id}'");
    $newFileName = array('new_file_name' => $new_file_name, 'file' => $file_id);
    printJson($newFileName);
}
// rename a collection
if ($set && $collection_id && $new_collection_name) {
    $new_collection_name = urldecode($new_collection_name);
    $new_collection_name = str_replace('_', ' ', $new_collection_name);
    $renameCollection = sql_query("UPDATE collection SET name=\"{$new_collection_name}\" WHERE ref='{$collection_id}'");
    $newCollectionName = array('new_folder_name' => $new_collection_name);
    printJson($newCollectionName);
}
// move file to another collection
if ($set && $move_to_collection && $collection_id && $file_id) {
    $moveToCollection = sql_query("UPDATE collection_resource SET collection='{$move_to_collection}' WHERE collection='{$collection_id}' AND resource='{$file_id}'");
    $data = array('old_collection' => $collection_id, 'new_collection' => $move_to_collection, 'file' => $file_id);
    printJson($data);
}
Esempio n. 18
0
File: data.php Progetto: perrr/svada
function uploadUserOrChatImage($file, $uploader, $savePath, $maxSize, $type)
{
    $originalFileName = $file["name"][0];
    $uploadTime = time();
    $fileSize = $file["size"][0];
    //Create unique id for file
    $fileIdresult = getQuery("SELECT * FROM file WHERE id=(SELECT MAX(id) FROM file)");
    $newFileIdAssoc = $fileIdresult->fetch_assoc();
    $newFileId = $newFileIdAssoc["id"] + 1;
    //check if file is an image:
    $mime = mime_content_type($file['tmp_name'][0]);
    if (!strstr($mime, "image/")) {
        printJson('{"status": "failure", "message": " ' . $originalFileName . ' ' . getString('notAnImage') . '."}');
        return;
    }
    //Format for filename 'id.fileExtension'
    $newFileName = $newFileId . substr($originalFileName, strrpos($originalFileName, '.'));
    if ($fileSize > $maxSize) {
        printJson('{"status": "failure", "message": " ' . $originalFileName . ' ' . getString('fileIsTooLarge') . '."}');
        return;
    }
    //Add to database
    setQuery("INSERT INTO file (path, uploader, name, mime_type, timestamp) VALUES ('{$newFileName}', '{$uploader}', '{$originalFileName}','{$mime}', '{$uploadTime}')");
    $success = move_uploaded_file($file['tmp_name'][0], $savePath . $newFileName);
    if ($success && $type == "userImage") {
        setUserImage($uploader, $newFileId);
        printJson('{"status": "success", "message": " ' . getString('theFile') . ' ' . $originalFileName . ' ' . getString('wasUploaded') . '."}');
    } elseif ($success && $type == "chatImage") {
        setChatImage($newFileId, $uploader);
        printJson('{"status": "success", "message": " ' . getString('theFile') . ' ' . $originalFileName . ' ' . getString('wasUploaded') . '."}');
    } else {
        printJson('{"status": "success", "message": "' . getString('uploadFailed') . '."}');
    }
}
Esempio n. 19
0
 public function setchannelstatus() {
     $param = array(
         'status' => $this->_status,
         'ids' => $this->_id
     );
     if ($param['status'] != 1 && $param['status'] != 2) {
         printJson(3, 'FAILED', '状态参数获取错误');
         exit;
     }
     if (strlen($param['ids']) == 0) {
         printJson(4, 'FAILED', '未获取到id');
         exit;
     }
     $idarray = explode(',', $param['ids']);
     $flag = true;
     unset($param['ids']);
     for ($i = 0; $i <= count($idarray) - 1; $i++) {
         $id = $idarray[$i];
         if (!$this->_Model->update($id, $param)) {
             $flag = false;
         }
     }
     if ($flag) {
         printJson(1, 'OK', '添加成功');
     } else {
         printJson(2, 'FAILED', '有数据添加失败');
     }
 }