CommonAction.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class CommonAction extends AuthAction{
  10. public function index() {
  11. //列表过滤器,生成查询Map对象
  12. $map = $this->_search ();
  13. //追加默认参数
  14. if($this->get("default_map"))
  15. $map = array_merge($map,$this->get("default_map"));
  16. if (method_exists ( $this, '_filter' )) {
  17. $this->_filter ( $map );
  18. }
  19. $name=$this->getActionName();
  20. if($name=='WeiboUserLevel')
  21. {
  22. $name='UserLevel';
  23. }
  24. $model = D ($name);
  25. if (! empty ( $model )) {
  26. $this->_list ( $model, $map );
  27. }
  28. $list = $this->get("list");
  29. if($name == 'IndexImage'){
  30. foreach($list as $k=>$v){
  31. $list[$k]['image']= get_spec_image($v['image']);
  32. }
  33. }
  34. //等级列表分销比率显示or隐藏
  35. if(defined('OPEN_DISTRIBUTION')&&OPEN_DISTRIBUTION==1){
  36. $this->assign ( 'is_module', 1 );
  37. }else{
  38. $this->assign ( 'is_module', 0 );
  39. }
  40. //购买规则 游戏币显示or隐藏
  41. if(defined('OPEN_SEND_COINS_MODULE')&&OPEN_SEND_COINS_MODULE==1){
  42. $this->assign('is_coins_module',1);
  43. }else{
  44. $this->assign('is_coins_module',0);
  45. }
  46. $this->display ();
  47. return;
  48. }
  49. /**
  50. +----------------------------------------------------------
  51. * 根据表单生成查询条件
  52. * 进行列表过滤
  53. +----------------------------------------------------------
  54. * @access protected
  55. +----------------------------------------------------------
  56. * @param string $name 数据对象名称
  57. +----------------------------------------------------------
  58. * @return HashMap
  59. +----------------------------------------------------------
  60. * @throws ThinkExecption
  61. +----------------------------------------------------------
  62. */
  63. protected function _search($name = '') {
  64. //生成查询条件
  65. if (empty ( $name )) {
  66. $name = $this->getActionName();
  67. }
  68. //$name=$this->getActionName();
  69. $model = D ( $name );
  70. $map = array ();
  71. foreach ( $model->getDbFields () as $key => $val ) {
  72. if (isset ( $_REQUEST [$val] ) && $_REQUEST [$val] != '') {
  73. $map [$val] = $_REQUEST [$val];
  74. }
  75. }
  76. return $map;
  77. }
  78. /**
  79. +----------------------------------------------------------
  80. * 根据表单生成查询条件
  81. * 进行列表过滤
  82. +----------------------------------------------------------
  83. * @access protected
  84. +----------------------------------------------------------
  85. * @param Model $model 数据对象
  86. * @param HashMap $map 过滤条件
  87. * @param string $sortBy 排序
  88. * @param boolean $asc 是否正序
  89. +----------------------------------------------------------
  90. * @return void
  91. +----------------------------------------------------------
  92. * @throws ThinkExecption
  93. +----------------------------------------------------------
  94. */
  95. protected function _list($model, $map, $sortBy = '', $asc = false,$is_redis=0, $redis =array()) {
  96. //排序字段 默认为主键名
  97. if (isset ( $_REQUEST ['_order'] )) {
  98. $order = $_REQUEST ['_order'];
  99. } else {
  100. $order = ! empty ( $sortBy ) ? $sortBy : $model->getPk ();
  101. }
  102. //排序方式默认按照倒序排列
  103. //接受 sost参数 0 表示倒序 非0都 表示正序
  104. if (isset ( $_REQUEST ['_sort'] )) {
  105. $sort = $_REQUEST ['_sort'] ? 'asc' : 'desc';
  106. } else {
  107. $sort = $asc ? 'asc' : 'desc';
  108. }
  109. if ($sortBy == 'nosort'){
  110. $order =$model->getPk ();
  111. $sort = 'desc';
  112. }
  113. if($is_redis){
  114. //创建分页对象
  115. if (! empty ( $_REQUEST ['listRows'] )) {
  116. $listRows = $_REQUEST ['listRows'];
  117. } else {
  118. $listRows = '';
  119. }
  120. $p = new Page ( $redis['total_num'], $listRows );
  121. //分页跳转的时候保证查询条件
  122. foreach ( $map as $key => $val ) {
  123. if (! is_array ( $val )) {
  124. $p->parameter .= "$key=" . urlencode ( $val ) . "&";
  125. }
  126. }
  127. //分页显示
  128. $page = $p->show ();
  129. //列表排序显示
  130. $sortImg = $sort; //排序图标
  131. $sortAlt = $sort == 'desc' ? l("ASC_SORT") : l("DESC_SORT"); //排序提示
  132. $sort = $sort == 'desc' ? 1 : 0; //排序方式
  133. //模板赋值显示
  134. $this->assign ( 'list', $redis['list'] );
  135. $this->assign ( 'sort', $sort );
  136. $this->assign ( 'order', $order );
  137. $this->assign ( 'sortImg', $sortImg );
  138. $this->assign ( 'sortType', $sortAlt );
  139. $this->assign ( "page", $page );
  140. $this->assign ( "nowPage",$p->nowPage);
  141. }else{
  142. //取得满足条件的记录数
  143. $count = $model->where ( $map )->count ( '*' );
  144. if ($count > 0) {
  145. //创建分页对象
  146. if (! empty ( $_REQUEST ['listRows'] )) {
  147. $listRows = $_REQUEST ['listRows'];
  148. } else {
  149. $listRows = '';
  150. }
  151. $p = new Page ( $count, $listRows );
  152. //分页查询数据
  153. $voList = $model->where($map)->order( "`" . $order . "` " . $sort)->limit($p->firstRow . ',' . $p->listRows)->findAll ( );
  154. // echo $model->getlastsql();
  155. //分页跳转的时候保证查询条件
  156. foreach ( $map as $key => $val ) {
  157. if (! is_array ( $val )) {
  158. $p->parameter .= "$key=" . urlencode ( $val ) . "&";
  159. }
  160. }
  161. //分页显示
  162. $page = $p->show ();
  163. //列表排序显示
  164. $sortImg = $sort; //排序图标
  165. $sortAlt = $sort == 'desc' ? l("ASC_SORT") : l("DESC_SORT"); //排序提示
  166. $sort = $sort == 'desc' ? 1 : 0; //排序方式
  167. //模板赋值显示
  168. foreach($voList as $k=>$v){
  169. $voList[$k]['head_image'] = get_spec_image($v['head_image']);
  170. $voList[$k]['nick_name'] = emoji_decode($v['nick_name']);
  171. $voList[$k]['podcast_name'] = emoji_decode($v['podcast_name']);
  172. $voList[$k]['log_info'] = emoji_decode($v['log_info']);
  173. }
  174. $this->assign ( 'list', $voList );
  175. $this->assign ( 'sort', $sort );
  176. $this->assign ( 'order', $order );
  177. $this->assign ( 'sortImg', $sortImg );
  178. $this->assign ( 'sortType', $sortAlt );
  179. $this->assign ( "page", $page );
  180. $this->assign ( "nowPage",$p->nowPage);
  181. }
  182. }
  183. return;
  184. }
  185. /**
  186. * 上传图片的通公基础方法
  187. *
  188. * @return array
  189. */
  190. protected function uploadImage($thumb)
  191. {
  192. if(conf("WATER_MARK")!=""){
  193. $water_mark = get_real_path().conf("WATER_MARK"); //水印
  194. }
  195. else{
  196. $water_mark = "";
  197. }
  198. $alpha = conf("WATER_ALPHA"); //水印透明
  199. $place = conf("WATER_POSITION"); //水印位置
  200. $upload = new UploadFile();
  201. //设置上传文件大小
  202. $upload->maxSize = conf('MAX_IMAGE_SIZE') ; /* 配置于config */
  203. //设置上传文件类型
  204. $upload->allowExts = explode(',',conf('ALLOW_IMAGE_EXT')); /* 配置于config */
  205. $dir_name = to_date(get_gmtime(),"Ym");
  206. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  207. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  208. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  209. }
  210. $dir_name = $dir_name."/".to_date(get_gmtime(),"d");
  211. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  212. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  213. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  214. }
  215. $dir_name = $dir_name."/".to_date(get_gmtime(),"H");
  216. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  217. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  218. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  219. }
  220. $save_rec_Path = "/public/attachment/".$dir_name."/origin/"; //上传时先存放原图
  221. $savePath = APP_ROOT_PATH."public/attachment/".$dir_name."/origin/"; //绝对路径
  222. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name."/origin/")) {
  223. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name."/origin/");
  224. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name."/origin/", 0777);
  225. }
  226. $domain_path = get_domain().APP_ROOT.$save_rec_Path;
  227. $upload->saveRule = "uniqid"; //唯一
  228. $upload->savePath = $savePath;
  229. if($thumb==1){
  230. $upload->thumb = true;
  231. $upload->thumbMaxWidth = 40;
  232. $upload->thumbMaxHeight = 50;
  233. }
  234. if($upload->upload())
  235. {
  236. $uploadList = $upload->getUploadFileInfo();
  237. foreach($uploadList as $k=>$fileItem)
  238. {
  239. $file_name = $fileItem['savepath'].$fileItem['savename']; //上图原图的地址
  240. //水印图
  241. $big_save_path = str_replace("origin/","",$savePath); //大图存放图径
  242. $big_file_name = str_replace("origin/","",$file_name);
  243. // Image::thumb($file_name,$big_file_name,'',$big_width,$big_height);
  244. @file_put_contents($big_file_name,@file_get_contents($file_name));
  245. if(file_exists($water_mark))
  246. {
  247. Image::water($big_file_name,$water_mark,$big_file_name,$alpha,$place);
  248. }
  249. $big_save_rec_Path = str_replace("origin/","",$save_rec_Path); //上传的图存放的相对路径
  250. $uploadList[$k]['recpath'] = $save_rec_Path;
  251. $uploadList[$k]['bigrecpath'] = $big_save_rec_Path;
  252. $last_index = strrpos($save_rec_Path,'/')+1;
  253. $uploadList[$k]['thumbpath'] = substr($save_rec_Path,0,$last_index).'thumb_'.substr($save_rec_Path,$last_index);
  254. // if(app_conf("PUBLIC_DOMAIN_ROOT")!='')
  255. // {
  256. // $origin_syn_url = app_conf("PUBLIC_DOMAIN_ROOT")."/es_file.php?username=".app_conf("IMAGE_USERNAME")."&password=".app_conf("IMAGE_PASSWORD")."&file=".get_domain().APP_ROOT."/public/attachment/".$dir_name."/origin/".$fileItem['savename']."&path=attachment/".$dir_name."/origin/&name=".$fileItem['savename']."&act=0";
  257. // $big_syn_url = app_conf("PUBLIC_DOMAIN_ROOT")."/es_file.php?username=".app_conf("IMAGE_USERNAME")."&password=".app_conf("IMAGE_PASSWORD")."&file=".get_domain().APP_ROOT."/public/attachment/".$dir_name."/".$fileItem['savename']."&path=attachment/".$dir_name."/&name=".$fileItem['savename']."&act=0";
  258. // @file_get_contents($origin_syn_url);
  259. // @file_get_contents($big_syn_url);
  260. // }
  261. }
  262. return array("status"=>1,'data'=>$uploadList,'info'=>L("UPLOAD_SUCCESS"));
  263. }
  264. else
  265. {
  266. return array("status"=>0,'data'=>null,'info'=>$upload->getErrorMsg());
  267. }
  268. }
  269. /**
  270. * 上传文件公共基础方法
  271. *
  272. * @return array
  273. */
  274. protected function uploadFile()
  275. {
  276. $upload = new UploadFile();
  277. $ext_arr = array(
  278. 'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
  279. 'flash' => array('swf', 'flv'),
  280. 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
  281. 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'txt', 'zip', 'rar','pdf','mp4','swf', 'flv', 'mp3'),
  282. );
  283. //设置上传文件大小
  284. $upload->maxSize = conf('MAX_IMAGE_SIZE') ; /* 配置于config */
  285. //设置上传文件类型
  286. if(!empty($ext_arr[$_REQUEST['dir']]))
  287. {
  288. $upload->allowExts =$ext_arr[$_REQUEST['dir']];
  289. }else{
  290. $upload->allowExts = explode(',',conf('ALLOW_IMAGE_EXT')); /* 配置于config */
  291. }
  292. $dir_name = to_date(get_gmtime(),"Ym");
  293. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  294. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  295. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  296. }
  297. $dir_name = $dir_name."/".to_date(get_gmtime(),"d");
  298. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  299. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  300. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  301. }
  302. $dir_name = $dir_name."/".to_date(get_gmtime(),"H");
  303. if (!is_dir(APP_ROOT_PATH."public/attachment/".$dir_name)) {
  304. @mkdir(APP_ROOT_PATH."public/attachment/".$dir_name);
  305. @chmod(APP_ROOT_PATH."public/attachment/".$dir_name, 0777);
  306. }
  307. $save_rec_Path = "/public/attachment/".$dir_name."/"; //上传时先存放原图
  308. $savePath = APP_ROOT_PATH."public/attachment/".$dir_name."/"; //绝对路径
  309. $domain_path = get_domain().APP_ROOT.$save_rec_Path;
  310. $upload->saveRule = "uniqid"; //唯一
  311. $upload->savePath = $savePath;
  312. if($upload->upload())
  313. {
  314. $uploadList = $upload->getUploadFileInfo();
  315. foreach($uploadList as $k=>$fileItem)
  316. {
  317. $uploadList[$k]['recpath'] = $save_rec_Path;
  318. if(app_conf("PUBLIC_DOMAIN_ROOT")!='')
  319. {
  320. $syn_url = app_conf("PUBLIC_DOMAIN_ROOT")."/es_file.php?username=".app_conf("IMAGE_USERNAME")."&password=".app_conf("IMAGE_PASSWORD")."&file=".$domain_path.$fileItem['savename']."&path=attachment/".$dir_name."/&name=".$fileItem['savename']."&act=0";
  321. @file_get_contents($syn_url);
  322. }
  323. }
  324. return array("status"=>1,'data'=>$uploadList,'info'=>L("UPLOAD_SUCCESS"));
  325. }
  326. else
  327. {
  328. return array("status"=>0,'data'=>null,'info'=>$upload->getErrorMsg());
  329. }
  330. }
  331. public function _before_update()
  332. {
  333. $uname = $_REQUEST['uname'];
  334. if($uname&&trim($uname)!='')
  335. {
  336. $rs = M(MODULE_NAME)->where("uname='".$uname."' and id <> ".intval($_REQUEST['id']))->count();
  337. if($rs > 0)
  338. {
  339. $this->error(l("UNAME_EXISTS"));
  340. }
  341. }
  342. $py = $_REQUEST['py'];
  343. if($py&&trim($py)!='')
  344. {
  345. $rs = M(MODULE_NAME)->where("py='".$py."' and id <> ".intval($_REQUEST['id']))->count();
  346. if($rs > 0)
  347. {
  348. $this->error(l("UNAME_EXISTS"));
  349. }
  350. }
  351. }
  352. public function _before_insert()
  353. {
  354. $uname = $_REQUEST['uname'];
  355. if($uname&&trim($uname)!='')
  356. {
  357. $rs = M(MODULE_NAME)->where("uname='".$uname."' and id <> ".intval($_REQUEST['id']))->count();
  358. if($rs > 0)
  359. {
  360. $this->error(l("UNAME_EXISTS"));
  361. }
  362. }
  363. $py = $_REQUEST['py'];
  364. if($py&&trim($py)!='')
  365. {
  366. $rs = M(MODULE_NAME)->where("py='".$py."' and id <> ".intval($_REQUEST['id']))->count();
  367. if($rs > 0)
  368. {
  369. $this->error(l("UNAME_EXISTS"));
  370. }
  371. }
  372. }
  373. public function toogle_status()
  374. {
  375. $id = intval($_REQUEST['id']);
  376. $ajax = intval($_REQUEST['ajax']);
  377. $field = $_REQUEST['field'];
  378. $info = $id."_".$field;
  379. if(MODULE_NAME=='Finance'){
  380. $c_is_effect = M(FinanceCompany)->where("id=".$id)->getField($field); //当前状态
  381. }else{
  382. $c_is_effect = M(MODULE_NAME)->where("id=".$id)->getField($field); //当前状态
  383. }
  384. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  385. if(MODULE_NAME=='Finance'){
  386. M(FinanceCompany)->where("id=".$id)->setField($field,$n_is_effect);
  387. }else{
  388. M(MODULE_NAME)->where("id=".$id)->setField($field,$n_is_effect);
  389. }
  390. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  391. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  392. }
  393. /**
  394. +----------------------------------------------------------
  395. * 根据表单生成查询条件
  396. * 进行列表过滤
  397. +----------------------------------------------------------
  398. * @access protected
  399. +----------------------------------------------------------
  400. * @param Model $model 数据对象
  401. * @param string $sql_str Sql语句 不含排序字段的SQL语句
  402. * @param string $parameter 分页跳转的时候保证查询条件
  403. +----------------------------------------------------------
  404. * @return void
  405. +----------------------------------------------------------
  406. * @throws ThinkExecption
  407. +----------------------------------------------------------
  408. */
  409. function _Sql_list($model, $sql_str, $parameter='', $sortBy = '', $asc = false,$count_sql= false)
  410. {
  411. //排序字段 默认为主键名
  412. if (isset ( $_REQUEST ['_order'] )) {
  413. $order = $_REQUEST ['_order'];
  414. } else {
  415. $order = $sortBy;
  416. }
  417. if ($sortBy == 'nosort'){
  418. unset($order);
  419. }
  420. //排序方式默认按照倒序排列
  421. //接受 sost参数 0 表示倒序 非0都 表示正序
  422. if (isset ( $_REQUEST ['_sort'] )) {
  423. $sort = $_REQUEST ['_sort'] ? 'asc' : 'desc';
  424. } else {
  425. $sort = $asc ? 'asc' : 'desc';
  426. }
  427. //取得满足条件的记录数
  428. if($count_sql){
  429. $sql_tmp = $count_sql;
  430. }else{
  431. $sql_tmp = 'select count(*) as tpcount from ('.$sql_str.') as a';
  432. }
  433. //dump($sql_tmp);
  434. $rs = $model->query($sql_tmp, false);
  435. //dump($rs);
  436. $count = intval($rs[0]['tpcount']);
  437. //dump($count);
  438. if($count>0) {
  439. //创建分页对象
  440. if(!empty($_REQUEST['listRows'])) {
  441. $listRows = $_REQUEST['listRows'];
  442. }else {
  443. $listRows = '';
  444. }
  445. import ( "@.ORG.Page" );
  446. $p = new Page($count,$listRows);
  447. //分页跳转的时候保证查询条件
  448. //dump($parameter);
  449. if ((!empty($parameter)) && (substr($parameter,1,1) <> '&')){
  450. //add by chenfq 2010-06-19 添加分页条件连接缺少 & 问题
  451. $parameter = '&'.$parameter;
  452. }
  453. $p->parameter = $parameter;
  454. //排序
  455. if (!empty($order))
  456. $sql_str .= ' ORDER BY '.$order.' '.$sort;
  457. //分页查询数据
  458. $sql_str .= ' LIMIT '.$p->firstRow.','.$p->listRows;
  459. //dump($sql_str);
  460. $voList = $model->query($sql_str, false);
  461. //dump($voList);
  462. //分页显示
  463. $page = $p->show();
  464. $sortImg = $sort; //排序图标
  465. $sortAlt = $sort == 'desc' ? L('SORT_ASC') : L('SORT_DESC'); //排序提示
  466. $sort = $sort == 'desc' ? 1 : 0; //排序方式
  467. $this->assign ( 'sort', $sort );
  468. $this->assign ( 'order', $order );
  469. $this->assign ( 'sortImg', $sortImg );
  470. $this->assign ( 'sortType', $sortAlt );
  471. $this->assign('list', $voList);
  472. $this->assign("page", $page);
  473. }
  474. //Cookie::set ( '_currentUrl_', U($this->getActionName()."/index") );
  475. return $voList;
  476. }
  477. public function get_jx_json($info,$type='') {
  478. $year = array_keys($info);
  479. $price = array_values($info);
  480. $chart = new open_flash_chart();
  481. $chart->set_bg_colour( '#FFFFFF' );//flash背景颜色
  482. //$title = new title( 'UK Petrol price (pence) per Litre' );
  483. //$title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
  484. //$chart->set_title( $title );
  485. $d = new hollow_dot();
  486. $d->size(3)->halo_size(0)->colour('#8f8fbd');
  487. $area = new area();
  488. $area->set_width( 2);
  489. $area->set_default_dot_style( $d );
  490. $area->set_fill_colour( '#eaf6ff' );
  491. $area->set_fill_alpha( 0.4 );
  492. $area->set_colour('#8f8fbd');
  493. //$area->set_values($price);
  494. $area->set_values($price);
  495. $chart->add_element($area);
  496. $num=intval(count($year>=7?$year:7)/7);
  497. if($num==0){
  498. $num=intval(count($year));
  499. }
  500. $num=$num>0?$num:1;
  501. $x_labels = new x_axis_labels();
  502. $x_labels->set_steps($num);
  503. $x_labels->set_size(12);
  504. $x_labels->set_colour('#000000');
  505. $x_labels->set_labels($year);
  506. if(count($year)>0){
  507. $x_labels->set_vertical();
  508. }
  509. // // 插入数据
  510. $x = new x_axis();
  511. $x->set_colour('#000000');
  512. $x->set_grid_colour('#dadada');
  513. $x->set_offset(false);
  514. $x->set_steps($num);
  515. // Add the X Axis Labels to the X Axis
  516. //$x->set_labels($x_labels);
  517. $x->set_labels_from_array( $year );
  518. $chart->set_x_axis($x);
  519. $y = new y_axis();
  520. $y->labels = null;
  521. $max = $this->get_the_right_y(max($price));
  522. $max=$max>0?$max:1;
  523. $y->set_range(0, ($max/5+1)*5, ($max/5+1));
  524. // if ($max > 20 && $max <= 100) {
  525. //
  526. // $y->set_range(0, $max, 10);
  527. // }elseif($max >= 10&&$max<=20){
  528. // $y->set_range(0, $max, 5);
  529. // }
  530. // else {
  531. // $y->set_range(0, $max);
  532. // }
  533. $y->set_colour('#000000');
  534. $y->set_grid_colour('#dadada');
  535. if($type=='percent'){
  536. $y->set_label_text(" #val#%");
  537. }else{
  538. $y->set_label_text(" #val#");
  539. }
  540. $chart->add_y_axis($y);
  541. $info = $chart->toPrettyString();
  542. return $info;
  543. }
  544. public function get_jx_json_bar($info,$type='') {
  545. $year =array_keys($info);
  546. $price = array_values($info);
  547. $chart = new open_flash_chart();
  548. $chart->set_bg_colour( '#FFFFFF' );//flash背景颜色
  549. $x_labels = new x_axis_labels();
  550. $x_labels->set_steps(1);
  551. $x_labels->set_size(12);
  552. $x_labels->set_colour('#000000');
  553. if(count($year)>0){
  554. $x_labels->set_vertical();
  555. }
  556. $x_labels->set_labels($year);
  557. // // 插入数据
  558. $x = new x_axis();
  559. $x->set_colour('#000000');
  560. $x->set_grid_colour('#dadada');
  561. $x->set_offset(true);
  562. $x->set_steps(1);
  563. // Add the X Axis Labels to the X Axis
  564. $x->set_labels($x_labels);
  565. $x->set_offset(true);
  566. $chart->set_x_axis($x);
  567. // $bar = new bar_filled( '#74b1e0', '#9dc7e8' );
  568. // $bar->set_values( $price );
  569. $price_array=array();
  570. foreach($price as $k=>$v){
  571. $price_array[$k]=new bar_value($v);
  572. $price_array[$k]->set_colour('#74b1e0');
  573. if($type=='percent'){
  574. //$y->set_label_text("#val#%");
  575. $price_array[$k]->set_tooltip( $year[$k].'<br>'.''.number_format($v).'%' );
  576. }else{
  577. $price_array[$k]->set_tooltip( $year[$k].'<br>'.''.number_format($v) );
  578. }
  579. }
  580. $bar = new bar_glass();
  581. $bar->set_values( $price_array );
  582. $chart->add_element($bar);
  583. //
  584. // LOOK:
  585. //
  586. //$x_legend = new x_legend( '1983 to 2008' );
  587. //$x_legend->set_style( '{font-size: 20px; color: #778877}' );
  588. //$chart->set_x_legend( $x_legend );
  589. //
  590. // remove this when the Y Axis is smarter
  591. //
  592. $y = new y_axis();
  593. $max = $this->get_the_right_y(max($price));
  594. $max=$max>0?$max:1;
  595. $y->set_range(0, ($max/5+1)*5, ($max/5+1));
  596. // if ($max > 20 && $max <= 100) {
  597. //
  598. // $y->set_range(0, $max, 10);
  599. // }elseif($max >= 10&&$max<=20){
  600. // $y->set_range(0, $max, 5);
  601. // }
  602. // else {
  603. // $y->set_range(0, $max);
  604. // }
  605. $y->set_colour('#000000');
  606. $y->set_grid_colour('#dadada');
  607. if($type=='percent'){
  608. $y->set_label_text(" #val#%");
  609. }else{
  610. $y->set_label_text(" #val#");
  611. }
  612. $chart->add_y_axis($y);
  613. $info = $chart->toPrettyString();
  614. return $info;
  615. }
  616. public function check_day($start_time,$end_time){
  617. $start_time=strtotime($start_time);
  618. $end_time=strtotime($end_time);
  619. $left_time=$end_time-$start_time;
  620. if($left_time/3600>1){
  621. return true;
  622. }else{
  623. return false;
  624. }
  625. }
  626. public function get_value($value, $field,$y_field,$x_type='',$y_type='') {
  627. $info = array ();
  628. if($y_type=='percent'){
  629. foreach ($value as $k => $v) {
  630. if(!empty($v[$y_field])){
  631. if($x_type=='hour_time'){
  632. $v[$y_field]=substr($v[$y_field],0,5);
  633. }elseif($x_type=='day_time'){
  634. $v[$y_field]=substr($v[$y_field],0,10).' ';
  635. }
  636. if (isset ($info[$v[$y_field]])) {
  637. $info[$v[$y_field]] = ($v[$field]) +( $info[$v[$y_field]]);
  638. } else {
  639. $info[$v[$y_field]] = ($v[$field]);
  640. }
  641. //$info[$v[$y_field]] = ($info[$v['sdate']] > 0) ? $info[$v['sdate']] : 0;
  642. $info[$v[$y_field]] = ($info[$v[$y_field]] > 0) ? $info[$v[$y_field]] : '';
  643. }
  644. }
  645. foreach($info as $k=>$v){
  646. $info[$k]=$v*100;
  647. $info[$k]=$info[$k];
  648. }
  649. }else{
  650. foreach ($value as $k => $v) {
  651. if(!empty($v[$y_field])){
  652. if($x_type=='hour_time'){
  653. $v[$y_field]=substr($v[$y_field],0,5);
  654. }elseif($x_type=='day_time'){
  655. $v[$y_field]=substr($v[$y_field],0,10).' ';
  656. }
  657. if (isset ($info[$v[$y_field]])) {
  658. $info[$v[$y_field]] = intval($v[$field]) +intval( $info[$v[$y_field]]);
  659. } else {
  660. $info[$v[$y_field]] = intval($v[$field]);
  661. }
  662. //$info[$v[$y_field]] = ($info[$v['sdate']] > 0) ? $info[$v['sdate']] : 0;
  663. $info[$v[$y_field]] = ($info[$v[$y_field]] > 0) ? $info[$v[$y_field]] : 0;
  664. }
  665. }
  666. }
  667. return $info;
  668. }
  669. public function get_jx_json_all($value,$array){
  670. $data=array();
  671. foreach($array as $k=>$v){
  672. foreach($v as $k1=>$v1){
  673. if(isset($v1[3])&&!empty($v1[3])){
  674. $type=$v1[3];
  675. }else{
  676. $type='';
  677. }
  678. if(isset($v1[4])&&!empty($v1[4])){
  679. $type_y=$v1[4];
  680. }else{
  681. $type_y='';
  682. }
  683. $data[$k][$k1]['line'] = $this->get_jx_json($this->get_value($value, $v1[0],$v1[1],$type,$type_y),$type_y);
  684. $data[$k][$k1]['bar'] = $this->get_jx_json_bar($this->get_value($value, $v1[0],$v1[1],$type,$type_y),$type_y);
  685. $data[$k][$k1]['title']=$v1[2];
  686. }
  687. }
  688. return $data;
  689. }
  690. public function get_the_right_y($max){
  691. //$max=35;
  692. $max=intval($max);
  693. if($max>5&&$max<10){
  694. return 10;
  695. }else{
  696. $num=intval($max)/4;
  697. $num=($num*10-$num*10%10)/10;
  698. $num=($num*100-$num*100%100)/100;
  699. $num=$num>=1?$num:1;
  700. }
  701. return intval($num*5);
  702. }
  703. //时间段过滤搜索
  704. public function com_search(){
  705. $map = array ();
  706. $map['start_time'] = trim($_REQUEST['start_time']);
  707. $map['end_time'] = trim($_REQUEST['end_time']);
  708. if ($map['start_time'] == ''&&$map['end_time'] != ''){
  709. $this->error('开始时间 不能为空');
  710. exit;
  711. }
  712. if ($map['start_time'] != ''&&$map['end_time'] == ''){
  713. $this->error('结束时间 不能为空');
  714. exit;
  715. }
  716. if ($map['start_time'] != ''&&$map['end_time'] != '') {
  717. $d = explode('-',$map['start_time']);
  718. if (checkdate($d[1], $d[2], $d[0]) == false){
  719. $this->error("开始时间不是有效的时间格式:{$map['start_time']}(yyyy-mm-dd)");
  720. exit;
  721. }
  722. $d = explode('-',$map['end_time']);
  723. if (checkdate($d[1], $d[2], $d[0]) == false){
  724. $this->error("结束时间不是有效的时间格式:{$map['end_time']}(yyyy-mm-dd)");
  725. exit;
  726. }
  727. if (to_timespan($map['start_time']) > to_timespan($map['end_time'])){
  728. $this->error('开始时间不能大于结束时间:'.$map['start_time'].'至'.$map['end_time']);
  729. exit;
  730. }
  731. $q_date_diff = 32;
  732. $this->assign("q_date_diff",$q_date_diff);
  733. if ($q_date_diff > 0 && (abs(to_timespan($map['end_time']) - to_timespan($map['start_time'])) / 86400 + 1 > $q_date_diff)){
  734. $this->error("查询时间间隔不能大于 {$q_date_diff} 天");
  735. exit;
  736. }
  737. $map['start_time']=to_timespan($map['start_time']);
  738. $map['end_time']=to_timespan($map['end_time']);
  739. /*admin_ajax_return($map['start_time']);*/
  740. }else{
  741. $map = array ();
  742. }
  743. return $map;
  744. }
  745. }