Example #1
0
 /**
  * 添加数据
  */
 public function add_POST()
 {
     if (C('ADD')) {
         if (IS_AJAX) {
             if (PUT('clear')) {
                 $this->success('数据删除成功' . $this->truncate($this->model->getModelName()));
             }
             $key = PUT('key');
             $name = PUT('name');
             $content = PUT('content');
             if (!$key) {
                 $this->error('关键字不能为空');
             }
             if (!$name) {
                 $this->error('名称不能为空');
             }
             $data = array();
             $result = array();
             $data['key'] = $key;
             $data['name'] = $name;
             $data['content'] = $content;
             if ($this->model->add($data)) {
                 $result['key'] = $key;
                 $result['name'] = $name;
                 $this->success('添加成功', $result);
             } else {
                 $this->error('添加失败');
             }
         } else {
             $this->lists_post();
         }
     }
 }
Example #2
0
 public function buildModel_POST()
 {
     $name = PUT('name');
     if (!$name) {
         $this->error('模型名称不能为空');
     }
     \Think\Build::buildModel('Api', $name);
     $this->success('模型生成成功', $name);
 }
Example #3
0
 /**
  * 数据列表
  */
 public function lists()
 {
     if (IS_POST) {
         $title = PUT('title');
         $map = array();
         $map['parent_id'] = 0;
         parent::page(array('size' => PUT('size', 10), 'page' => PUT('p'), 'where' => $map, 'orderby' => 'sort desc,id desc'));
     } else {
         $this->display();
     }
 }
Example #4
0
 /**
  * 删除数据
  */
 public function delete()
 {
     if (IS_GET) {
         $map = array();
         $map['id'] = PUT('id');
         $result = $this->__delete($map);
         if ($result['success']) {
             $this->success('删除成功', U('index'));
         } else {
             $this->error('删除失败');
         }
     }
 }
Example #5
0
 public function version()
 {
     if (IS_POST) {
         $data = PUT();
         if ($data) {
             $key = $data['key'];
             unset($data['key']);
             $data['updated'] = NOW_TIME;
             $data['description'] = addcslashes($data['description'], "\r\n");
             $res = config($key, $data);
             $this->success('保存成功');
         } else {
             $this->error('表单提交错误');
         }
     } else {
         $this->display();
     }
 }
Example #6
0
 /**
  * 密码重置
  */
 public function reset()
 {
     if (IS_POST) {
         $id = PUT('id');
         //User_id
         $map = array();
         $map['id'] = $id;
         $user = $this->model->where($map)->find();
         $username = $user['username'];
         $password = md5(substr($username, -6));
         $res = $this->model->where($map)->setField('password', $password);
         if ($res) {
             $this->success('密码重置成功!');
         } else {
             $this->error('密码重置失败!');
         }
     }
 }
Example #7
0
 public function index_post()
 {
     $content = PUT('content');
     if (!empty($content)) {
         $model = M('Feedback');
         $data['content'] = $content;
         $data['created'] = NOW_TIME;
         $data['status'] = 1;
         $result = $model->add($data);
     } else {
         $this->error('反馈内容不能为空!');
     }
     if ($result) {
         $this->success('反馈提交成功!');
     } else {
         $this->error('反馈提交失败!');
     }
 }
Example #8
0
 private function _echo($result)
 {
     // file_put_contents('log.txt',json_encode(IS_AJAX));
     // file_put_contents('log.txt',json_encode(PUT('debug')==true),FILE_APPEND);
     if ($this->flag && PUT('dump') == true) {
         $filename = strtolower(CONTROLLER_NAME . ACTION_NAME);
         F($filename, json_encode_format($result));
         dump_json_format($result);
         exit;
     } elseif ($this->flag && PUT('debug') == true) {
         $this->flag = false;
         $filename = strtolower(CONTROLLER_NAME . ACTION_NAME);
         $string = F($filename);
         if (empty($string)) {
             $string = json_encode_format($result);
         }
         $this->success('AJAX', $string);
     } else {
         $this->response($result, $this->_type);
     }
 }
Example #9
0
 /**
  * 管理员登陆
  */
 public function login()
 {
     if (IS_POST) {
         $username = PUT('username');
         $password = PUT('password');
         $verify = PUT('verify');
         $result = array();
         //             if(!check_verify($verify)){
         //     $this->error('验证码输入错误!');
         // }else
         $err = Auth::login($username, $password);
         //             wlog('err', $err);
         if ($err < 5) {
             switch ($err) {
                 case 1:
                     $this->error('用户不存在');
                     break;
                 case 2:
                     $this->error('用户已禁用');
                     break;
                 case 3:
                     $this->error('角色已禁用');
                     break;
                 case 4:
                     $this->error('密码错误');
                     break;
             }
         } else {
             $user = $_SESSION['user_auth'];
             action_log('user_login', 'Admin', $user['id'], $user['id']);
             wlog('PUT', PUT());
             $this->success('登陆成功!', U('index'));
             //                 $this->redirect('Index/index','','','登陆成功!');
         }
     } else {
         layout('Common/layout');
         $this->display();
     }
 }
Example #10
0
 /**
  * 删除数据
  */
 public function delete_POST()
 {
     if (C('ADD')) {
         $name = PUT('username');
         if (!$name) {
             $this->error('手机号码不能为空');
         }
         $result = array();
         if ($this->model->delete($name)) {
             $result['phone'] = $name;
             $this->success('删除成功', $result);
         } else {
             $this->error('删除失败');
         }
     }
 }
Example #11
0
 /**
  * 注册一个新用户
  * @param  string $username 用户名
  * @param  string $password 用户密码
  * @return integer          注册成功-用户信息,注册失败-错误编号
  *	       错误编号:
  *	       		-1:手机号码不能为空
  *	       		-2:密码不能为空
  *	       		-3:手机号码已经注册
  *	       		 0:注册失败
  *	       		>0:注册成功
  */
 public function register(string $username, string $password)
 {
     if (empty($username)) {
         return -1;
     }
     if (empty($password)) {
         return -2;
     }
     if ($this->checkMobile($username)) {
         return -3;
     }
     $data['username'] = $username;
     $data['password'] = $password;
     $data['app_os'] = PUT('app_os');
     $data['register_ip'] = get_client_ip(1);
     $data['register_time'] = NOW_TIME;
     $data['updated'] = NOW_TIME;
     return IIF($this->add($data), 0);
 }
Example #12
0
 protected function uploadImage($options = array())
 {
     if (IS_POST) {
         $file = PUT('file');
         if (!empty($file) && is_file($file)) {
             unlink($file);
         }
         if (PUT('upload', false)) {
             $cfg = array_merge(array('path' => strtolower(CONTROLLER_NAME), 'key' => 'file', 'size' => 3, 'thumb' => false), $options);
             $res = upload_image($cfg['path'], $cfg['key'], $cfg['size']);
             if ($res['success']) {
                 if ($cfg['thumb']) {
                     $image = new \Think\Image();
                     $image->open($res['image']);
                     $w = $data['w'];
                     $h = $data['h'];
                     if (is_array($cfg['thumb'])) {
                         $w = $cfg['thumb'][0];
                         $h = $cfg['thumb'][1];
                     }
                     $image->thumb($w, $h, $image::IMAGE_THUMB_CENTER)->save($res['image']);
                 }
                 $this->success($res['image']);
             } else {
                 $this->error($res['msg']);
             }
         }
     }
 }
Example #13
0
 /**
  * 消息已读
  */
 public function hasRead_post()
 {
     $model = M('MsgRead');
     $data = array();
     $data['user_id'] = PUT('user_id');
     $data['msg_id'] = PUT('msg_id');
     $data['status'] = 1;
     if ($model->where($data)->select()) {
         $this->error('已读,勿重复提交');
     }
     $data['created'] = NOW_TIME;
     $result = $model->add($data);
     if ($result) {
         $this->success('数据提交成功!');
     } else {
         $this->error('数据提交失败!');
     }
 }
Example #14
0
 public function buildModel()
 {
     if (IS_POST) {
         $name = PUT('name');
         $module = PUT('module');
         if (!$name) {
             $this->error('模型名称不能为空');
         }
         if (!$module) {
             $this->error('模块名称不能为空');
         }
         \Think\Build::buildModel($module, $name);
         $this->success('模型生成成功', $name);
     }
 }
Example #15
0
 /**
  * 短信通知
  */
 public function smsNotify()
 {
     if (IS_POST) {
         $user_id = PUT('user_id');
         $msg_id = PUT('msg_id');
         $map = array();
         $map['id'] = $user_id;
         $user = D('User')->where($map)->find();
         $where['id'] = $msg_id;
         $message = D('Message')->where($where)->find();
         $title = $message['title'];
         //wlog('$title', $title);
         $telephone = $user['username'];
         //wlog('$username', $telephone);
         $msg = '111';
         $msg = "温馨提醒:请尽快完成《" . $title . "》消息的阅读。【洞头人才】";
         $res = Luosimao::send(3, $telephone, $msg);
         //wlog('sms', $res);
         if ($res['error'] == 0) {
             $this->success('短信通知完成');
         } else {
             $this->error($res['msg']);
         }
     }
 }
Example #16
0
 /**
  * 获取返回数据的关联记录
  * @access protected
  * @param mixed $result  返回数据
  * @param string|array $name  关联名称
  * @param boolean $return 是否返回关联数据本身
  * @return array
  */
 protected function getRelation(&$result, $name = '', $return = false)
 {
     if (!empty($this->_link)) {
         foreach ($this->_link as $key => $val) {
             $mappingName = !empty($val['mapping_name']) ? $val['mapping_name'] : $key;
             // 映射名称
             if (empty($name) || true === $name || $mappingName == $name || is_array($name) && in_array($mappingName, $name)) {
                 $mappingType = !empty($val['mapping_type']) ? $val['mapping_type'] : $val;
                 //  关联类型
                 $mappingClass = !empty($val['class_name']) ? $val['class_name'] : $key;
                 //  关联类名
                 $mappingFields = !empty($val['mapping_fields']) ? $val['mapping_fields'] : '*';
                 // 映射字段
                 $mappingCondition = !empty($val['condition']) ? $val['condition'] : '1=1';
                 // 关联条件
                 if (!empty($val['condition'])) {
                     $mappingCondition = preg_replace_callback('/{(\\w+)}/', function ($match) {
                         return PUT($match[1]);
                     }, $mappingCondition);
                 }
                 $mappingKey = !empty($val['mapping_key']) ? $val['mapping_key'] : $this->getPk();
                 // 关联键名
                 if (strtoupper($mappingClass) == strtoupper($this->name)) {
                     // 自引用关联 获取父键名
                     $mappingFk = !empty($val['parent_key']) ? $val['parent_key'] : 'parent_id';
                 } else {
                     $mappingFk = !empty($val['foreign_key']) ? $val['foreign_key'] : strtolower($this->name) . '_id';
                     //  关联外键
                 }
                 // 获取关联模型对象
                 $model = D($mappingClass);
                 switch ($mappingType) {
                     case self::HAS_ONE:
                         $pk = $result[$mappingKey];
                         $mappingCondition .= " AND {$mappingFk}='{$pk}'";
                         $relationData = $model->where($mappingCondition)->field($mappingFields)->find();
                         if (!empty($val['relation_deep'])) {
                             $model->getRelation($relationData, $val['relation_deep']);
                         }
                         break;
                     case self::BELONGS_TO:
                         if (strtoupper($mappingClass) == strtoupper($this->name)) {
                             // 自引用关联 获取父键名
                             $mappingFk = !empty($val['parent_key']) ? $val['parent_key'] : 'parent_id';
                         } else {
                             $mappingFk = !empty($val['foreign_key']) ? $val['foreign_key'] : strtolower($model->getModelName()) . '_id';
                             //  关联外键
                         }
                         $fk = $result[$mappingFk];
                         $mappingCondition .= " AND {$model->getPk()}='{$fk}'";
                         $relationData = $model->where($mappingCondition)->field($mappingFields)->find();
                         // dump($mappingCondition);exit;
                         if (!empty($relationData) && !empty($val['relation_deep'])) {
                             $model->getRelation($relationData, $val['relation_deep']);
                         }
                         break;
                     case self::HAS_MANY:
                         $pk = $result[$mappingKey];
                         $mappingCondition .= " AND {$mappingFk}='{$pk}'";
                         $mappingOrder = !empty($val['mapping_order']) ? $val['mapping_order'] : '';
                         $mappingLimit = !empty($val['mapping_limit']) ? $val['mapping_limit'] : '';
                         // 延时获取关联记录
                         $relationData = $model->where($mappingCondition)->field($mappingFields)->order($mappingOrder)->limit($mappingLimit)->select();
                         if (!empty($relationData) && !empty($val['relation_deep'])) {
                             foreach ($relationData as $key => $data) {
                                 $model->getRelation($data, $val['relation_deep']);
                                 $relationData[$key] = $data;
                             }
                         }
                         break;
                     case self::MANY_TO_MANY:
                         $pk = $result[$mappingKey];
                         $prefix = $this->tablePrefix;
                         $mappingCondition = " {$mappingFk}='{$pk}'";
                         $mappingOrder = $val['mapping_order'];
                         $mappingLimit = $val['mapping_limit'];
                         $mappingRelationFk = $val['relation_foreign_key'] ? $val['relation_foreign_key'] : $model->getModelName() . '_id';
                         if (isset($val['relation_table'])) {
                             $mappingRelationTable = preg_replace_callback("/__([A-Z_-]+)__/sU", function ($match) use($prefix) {
                                 return $prefix . strtolower($match[1]);
                             }, $val['relation_table']);
                         } else {
                             $mappingRelationTable = $this->getRelationTableName($model);
                         }
                         $sql = "SELECT b.{$mappingFields} FROM {$mappingRelationTable} AS a, " . $model->getTableName() . " AS b WHERE a.{$mappingRelationFk} = b.{$model->getPk()} AND a.{$mappingCondition}";
                         if (!empty($val['condition'])) {
                             $sql .= ' AND ' . $val['condition'];
                         }
                         if (!empty($mappingOrder)) {
                             $sql .= ' ORDER BY ' . $mappingOrder;
                         }
                         if (!empty($mappingLimit)) {
                             $sql .= ' LIMIT ' . $mappingLimit;
                         }
                         $relationData = $this->query($sql);
                         if (!empty($relationData) && !empty($val['relation_deep'])) {
                             foreach ($relationData as $key => $data) {
                                 $model->getRelation($data, $val['relation_deep']);
                                 $relationData[$key] = $data;
                             }
                         }
                         break;
                 }
                 if (!$return) {
                     if (isset($val['as_fields']) && in_array($mappingType, array(self::HAS_ONE, self::BELONGS_TO))) {
                         // 支持直接把关联的字段值映射成数据对象中的某个字段
                         // 仅仅支持HAS_ONE BELONGS_TO
                         $fields = explode(',', $val['as_fields']);
                         foreach ($fields as $field) {
                             if (strpos($field, ':')) {
                                 list($relationName, $nick) = explode(':', $field);
                                 $result[$nick] = $relationData[$relationName];
                             } else {
                                 $result[$field] = $relationData[$field];
                             }
                         }
                     } else {
                         $result[$mappingName] = $relationData;
                     }
                     unset($relationData);
                 } else {
                     return $relationData;
                 }
             }
         }
     }
     return $result;
 }
Example #17
0
 public function check()
 {
     if (IS_POS) {
         wlog('check', PUT());
     }
 }
Example #18
0
 /**
  * 删除数据
  */
 public function delete()
 {
     if (IS_POST) {
         $map = array();
         $map['id'] = PUT('id');
         $result = $this->__delete($map, true, 'info.portrait');
         if ($result['success']) {
             $this->success('删除成功');
         } else {
             $this->error('删除失败');
         }
     }
 }
Example #19
0
 /**
  * 修改密码
  */
 public function modify()
 {
     if (IS_POST) {
         $oldpassword = PUT('oldpassword');
         $password = PUT('password');
         if (empty($password)) {
             $this->error('新密码不能为空');
         }
         if ($password == $oldpassword) {
             $this->error('新密码不能和旧密码相同');
         }
         if ($password != PUT('repassword')) {
             $this->error('确认密码不一致');
         }
         $user = $this->model->field('id,username,password')->find(PUT('id'));
         if ($user && $user['password'] == md5(PUT('oldpassword'))) {
             $data = array();
             $data['id'] = PUT('id');
             $data['password'] = $password;
             $result = $this->__validate($data);
             if (!$result['success']) {
                 $this->error($result['msg']);
             } elseif ($this->__update()) {
                 $this->success('新密码设置成功');
             } else {
                 $this->error('新密码设置失败');
             }
         } else {
             $this->error('旧密码错误');
         }
     } elseif (IS_GET && PUT('get.id')) {
         $this->model->field('id,username,role_id');
         $res = $this->__find(PUT('get.id'));
         $this->ajaxReturn($res);
     } else {
         $this->display();
     }
 }
Example #20
0
function img_output()
{
    preg_match("/([^_]+)_(\\d+)x(\\d+)/", PUT('file'), $res);
    $url = base64_decode($res[1]);
    $w = (int) $res[2];
    $h = (int) $res[3];
    $path = pathinfo($url);
    // $dir        = sprintf('Uploads/_thumb/%s/w%s',date('Y-m-d'),$w);
    $dir = sprintf('Uploads/_thumb/w%s', $w);
    // $name       = md5($path['filename']);
    $name = md5_file($url);
    $filename = sprintf('%s/%s_%dx%d.%s', $dir, $name, $w, $h, $path['extension']);
    if (!is_file($filename)) {
        if (!is_dir($dir)) {
            @mkdir($dir, 0777, true);
        }
        $image = new \Common\Util\GD($url);
        $image->thumb($w, $h);
        // $image->text('乐乐派');
        $image->save($filename);
    }
    return $filename;
    // header("Content-Disposition: Attachment;filename=".$path['filename'].'_'.$w.'.'.$path['extension']);
    // header("Content-Type: image/$path[extension]");
    // $fp = fopen($filename,'rb');
    // fpassthru($fp);
}