common.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 通用页面
  4. *
  5. *
  6. ***/
  7. defined('InShopNC') or exit('Access Invalid!');
  8. class commonControl extends SystemControl{
  9. public function __construct(){
  10. parent::__construct();
  11. }
  12. /**
  13. * 图片上传
  14. *
  15. */
  16. public function pic_uploadOp(){
  17. if (chksubmit()){
  18. //上传图片
  19. $upload = new UploadFile();
  20. $upload->set('thumb_width', 500);
  21. $upload->set('thumb_height',499);
  22. $upload->set('thumb_ext','_small');
  23. $upload->set('max_size',C('image_max_filesize')?C('image_max_filesize'):1024);
  24. $upload->set('ifremove',true);
  25. $upload->set('default_dir',$_GET['uploadpath']);
  26. if (!empty($_FILES['_pic']['tmp_name'])){
  27. $result = $upload->upfile('_pic');
  28. if ($result){
  29. exit(json_encode(array('status'=>1,'url'=>UPLOAD_SITE_URL.'/'.$_GET['uploadpath'].'/'.$upload->thumb_image)));
  30. }else {
  31. exit(json_encode(array('status'=>0,'msg'=>$upload->error)));
  32. }
  33. }
  34. }
  35. }
  36. /**
  37. * 图片裁剪
  38. *
  39. */
  40. public function pic_cutOp(){
  41. Language::read('admin_common');
  42. $lang = Language::getLangContent();
  43. import('function.thumb');
  44. if (chksubmit()){
  45. $thumb_width = $_POST['x'];
  46. $x1 = $_POST["x1"];
  47. $y1 = $_POST["y1"];
  48. $x2 = $_POST["x2"];
  49. $y2 = $_POST["y2"];
  50. $w = $_POST["w"];
  51. $h = $_POST["h"];
  52. $scale = $thumb_width/$w;
  53. $src = str_ireplace(UPLOAD_SITE_URL,BASE_UPLOAD_PATH,$_POST['url']);
  54. if (strpos($src, '..') !== false || strpos($src, BASE_UPLOAD_PATH) !== 0) {
  55. exit();
  56. }
  57. if (!empty($_POST['filename'])){
  58. // $save_file2 = BASE_UPLOAD_PATH.'/'.$_POST['filename'];
  59. $save_file2 = str_ireplace(UPLOAD_SITE_URL,BASE_UPLOAD_PATH,$_POST['filename']);
  60. }else{
  61. $save_file2 = str_replace('_small.','_sm.',$src);
  62. }
  63. $cropped = resize_thumb($save_file2, $src,$w,$h,$x1,$y1,$scale);
  64. @unlink($src);
  65. $pathinfo = pathinfo($save_file2);
  66. exit($pathinfo['basename']);
  67. }
  68. $save_file = str_ireplace(UPLOAD_SITE_URL,BASE_UPLOAD_PATH,$_GET['url']);
  69. $_GET['resize'] = $_GET['resize'] == '0' ? '0' : '1';
  70. Tpl::output('height',get_height($save_file));
  71. Tpl::output('width',get_width($save_file));
  72. Tpl::showpage('common.pic_cut','null_layout');
  73. }
  74. /**
  75. * 查询每月的周数组
  76. */
  77. public function getweekofmonthOp(){
  78. import('function.datehelper');
  79. $year = $_GET['y'];
  80. $month = $_GET['m'];
  81. $week_arr = getMonthWeekArr($year, $month);
  82. echo json_encode($week_arr);
  83. die;
  84. }
  85. /**
  86. * AJAX查询品牌
  87. */
  88. public function ajax_get_brandOp() {
  89. $initial = trim($_GET['letter']);
  90. $keyword = trim($_GET['keyword']);
  91. $type = trim($_GET['type']);
  92. if (!in_array($type, array('letter', 'keyword')) || ($type == 'letter' && empty($initial)) || ($type == 'keyword' && empty($keyword))) {
  93. echo json_encode(array());die();
  94. }
  95. // 实例化模型
  96. $model_type = Model('type');
  97. $where = array();
  98. // 验证类型是否关联品牌
  99. if ($type == 'letter') {
  100. switch ($initial) {
  101. case 'all':
  102. break;
  103. case '0-9':
  104. $where['brand_initial'] = array('in', array(0,1,2,3,4,5,6,7,8,9));
  105. break;
  106. default:
  107. $where['brand_initial'] = $initial;
  108. break;
  109. }
  110. } else {
  111. $where['brand_name|brand_initial'] = array('like', '%' . $keyword . '%');
  112. }
  113. $brand_array = Model('brand')->getBrandPassedList($where, 'brand_id,brand_name,brand_initial', 0, 'brand_initial asc, brand_sort asc');
  114. echo json_encode($brand_array);die();
  115. }
  116. }