StockViewStationController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /**
  3. * 库存操作统计控制器(根据服务点)
  4. * @author 2015-10-08
  5. */
  6. class StockViewStationController extends AdminController {
  7. /**
  8. * 首页
  9. * 默认显示本周内数据统计及图表
  10. */
  11. public function actionIndex () {
  12. $station = Yii::app()->request->getParam('station', '');
  13. if ($station != '') {
  14. $station = new MongoId($station);
  15. $date_end = strtotime(date('Y-m-d', strtotime('+1 day', time())));
  16. $date_start = strtotime(date('Y-m-d', strtotime('-6 day', time())));
  17. $data = $this->getDataByStation($date_start, $date_end, $station);
  18. $data_str = $this->getDataStr($data);
  19. $criteria_station = new EMongoCriteria();
  20. $criteria_station->_id('==', $station);
  21. $cursor = Station::model()->find($criteria_station);
  22. $stationName = $cursor->name;
  23. $date_arr = $this->getDateArr($date_start, $date_end);
  24. $date_str = $this->getTimeStr($date_arr);
  25. $date_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
  26. } else {
  27. $date_range = '';
  28. $date_str = '';
  29. $data_str = array('price_count'=>'', 'operate_count'=>'');
  30. $station = '';
  31. $stationName = '';
  32. }
  33. $station_data = $this->getStationComboboxData();
  34. $this->render('index', array(
  35. 'date_range' => $date_range,
  36. 'date_str' => $date_str,
  37. 'price_count' => $data_str['price_count'],
  38. 'operate_count' => $data_str['operate_count'],
  39. 'station' => (string)$station,
  40. 'stationName' => $stationName,
  41. 'station_data' => $station_data
  42. ));
  43. }
  44. /**
  45. * 显示所有服务点在时间范围内的领取情况
  46. * @param string date_start | 开始的时间
  47. * @param string date_end | 结束的时间
  48. * @param string date_range | 时间范围,用于前端显示
  49. * @param array data | 时间范围内服务点、总价统计、操作统计
  50. */
  51. public function actionAll () {
  52. $date_start = Yii::app()->request->getParam('date_start', '');
  53. $date_end = Yii::app()->request->getParam('date_end', '');
  54. // 默认查询当天数据
  55. if (empty($date_start) || empty($date_end)) {
  56. $date_range = date('Y-m-d', time());
  57. $date_start = strtotime(date('Y-m-d', time()));
  58. $date_end = strtotime('+1 day', $date_start);
  59. } else {
  60. $date_range = $date_start == $date_end ? $date_start : $date_start.'至'.$date_end;
  61. $date_start = strtotime($date_start);
  62. $date_end = strtotime('+1 day', strtotime($date_end));
  63. }
  64. $data = $this->getAll($date_start, $date_end);
  65. $data = $data['data'];
  66. $price_count_arr = array();
  67. $stationName_str = '';
  68. foreach ($data as $key => $value) {
  69. $stationName_str .= '"'.$value['stationName'].'",';
  70. $price_count_arr[$value['stationName']] = $value['price_count'];
  71. }
  72. $stationName_str = substr($stationName_str, 0, mb_strlen($stationName_str)-1);
  73. $station_data = $this->getStationComboboxData();
  74. $this->render('all', array(
  75. 'date_start' => $date_start,
  76. 'date_end' => $date_end,
  77. 'date_range' => $date_range,
  78. 'stationNames' => $stationName_str,
  79. 'price_count_arr' => $price_count_arr,
  80. 'station' => '',
  81. 'station_data' => $station_data
  82. ));
  83. }
  84. /**
  85. * 左边列表显示
  86. */
  87. public function actionList () {
  88. $merge_data_days = Yii::app()->request->getParam('merge_data_days', false);
  89. $merge_data_weeks = Yii::app()->request->getParam('merge_data_weeks', false);
  90. $merge_data_months = Yii::app()->request->getParam('merge_data_months', false);
  91. $stationName = Yii::app()->request->getParam('stationName', '');
  92. $date_start = Yii::app()->request->getParam('date_start', '');
  93. $date_end = Yii::app()->request->getParam('date_end', '');
  94. // 时间为空则查询所有数据
  95. if (!empty($date_start) && !empty($date_end)) {
  96. $date_start = strtotime($date_start);
  97. $date_end = strtotime('+1 day', strtotime($date_end));
  98. }
  99. $data = $this->getAll($date_start, $date_end, $stationName, true, $merge_data_days, $merge_data_weeks, $merge_data_months);
  100. $total = $data['total'];
  101. $data = $data['data'];
  102. echo CommonFn::composeDatagridData($data, $total);
  103. }
  104. /**
  105. * 根据服务点ID查询本月领取情况
  106. */
  107. public function actionFindByWeeks () {
  108. $station = Yii::app()->request->getParam('station', '');
  109. // 默认日期已设,二次开发已预留根据时间调整范围的代码
  110. $date_end = strtotime('monday', time());
  111. if (strtotime(date('Y-m-d', time())) == $date_end) {
  112. $date_end = strtotime('+7 day', $date_end);
  113. }
  114. $date_start = strtotime('-35 day', $date_end);
  115. if ($station != '') {
  116. $station = new MongoId($station);
  117. $criteria_station = new EMongoCriteria();
  118. $criteria_station->_id = $station;
  119. $cursor = Station::model()->find($criteria_station);
  120. $stationName = $cursor->name;
  121. $week_arr = $this->getWeekArr($date_start, $date_end);
  122. $week_str = $this->getTimeStr($week_arr);
  123. $data_temp = $this->getDataByStation($date_start, $date_end, $station);
  124. $data = $this->parseDataByWeeks($data_temp, $date_start, $date_end);
  125. $data_str = $this->getDataStr($data);
  126. $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
  127. } else {
  128. $date_range = '';
  129. $week_str = '';
  130. $data_str = array('price_count'=>'', 'operate_count'=>'');
  131. $station = '';
  132. $stationName = '';
  133. }
  134. $station_data = $this->getStationComboboxData();
  135. $this->render('findByWeeks', array(
  136. 'date_range' => $date_range,
  137. 'weeks' => $week_str,
  138. 'price' => $data_str['price_count'],
  139. 'operate' => $data_str['operate_count'],
  140. 'station' => (string)$station,
  141. 'stationName' => $stationName,
  142. 'station_data' => $station_data
  143. ));
  144. }
  145. /**
  146. * 根据用户ID及月份范围查询领取情况
  147. */
  148. public function actionFindByMonths () {
  149. $station = Yii::app()->request->getParam('station', '');
  150. $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
  151. $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
  152. if ($station != '') {
  153. $data_temp = $this->getDataByStation($date_start, $date_end, $station);
  154. $data = $this->parseDataByMonths($data_temp, $date_start, $date_end, $station);
  155. $station = new MongoId($station);
  156. $criteria_station = new EMongoCriteria();
  157. $criteria_station->_id = $station;
  158. $cursor = Station::model()->find($criteria_station);
  159. $stationName = $cursor->name;
  160. $data_str = $this->getDataStr($data);
  161. $month_arr = $this->getMonthArr($date_start, $date_end);
  162. $month_str = $this->getTimeStr($month_arr);
  163. $month_range = date('Y-m', $date_start).'至'.date('Y-m', strtotime('-1 month', $date_end));
  164. } else {
  165. $month_range = '';
  166. $month_str = '';
  167. $data_str = array('price_count'=>'', 'operate_count'=>'');
  168. $station = '';
  169. $stationName = '';
  170. }
  171. $station_data = $this->getStationComboboxData();
  172. $this->render('findByMonths', array(
  173. 'month_range' => $month_range,
  174. 'month' => $month_str,
  175. 'price' => $data_str['price_count'],
  176. 'operate' => $data_str['operate_count'],
  177. 'station' => (string)$station,
  178. 'stationName' => $stationName,
  179. 'station_data' => $station_data
  180. ));
  181. }
  182. /**
  183. * ----------------------------------
  184. *
  185. * 私有方法,对数据进行整理
  186. *
  187. * ----------------------------------
  188. */
  189. /**
  190. * 获取所有数据的统计
  191. * @param boolean $empty_data : 查询的stock结果为空时是否记录
  192. * @param boolean $merge_data_days : 是否在结果中记录时间范围内(按照天)的单服务点数据
  193. * @param boolean $merge_data_weeks : 是否在结果中记录时间范围内(按照周)的单服务点数据
  194. * @param boolean $merge_data_months : 是否在结果中记录时间范围内(按照月)的单服务点数据
  195. */
  196. private function getAll($date_start = '', $date_end = '', $stationName = '', $empty_data = false, $merge_data_days = false, $merge_data_weeks = false, $merge_data_months = false) {
  197. $params = CommonFn::getPageParams();
  198. $data = array();
  199. $criteria_station = new EMongoCriteria($params);
  200. $criteria_station->name = new MongoRegex('/'.$stationName.'/');
  201. $cursor = Station::model()->findAll($criteria_station);
  202. $total = count($cursor);
  203. $stations = CommonFn::getRowsFromCursor($cursor);
  204. if (empty($stations)) {
  205. return $data;
  206. }
  207. foreach ($stations as $key => $value) {
  208. $criteria_stock = new EMongoCriteria();
  209. $criteria_stock->station = $value['_id'];
  210. // 时间为空则查询所有数据
  211. if (!empty($date_start) && !empty($date_end)) {
  212. $criteria_stock->time('>=', intval($date_start));
  213. $criteria_stock->time('<', intval($date_end));
  214. }
  215. $criteria_stock->sort('time', EMongoCriteria::SORT_ASC);
  216. $cursor = Stock::model()->findAll($criteria_stock);
  217. $stock = CommonFn::getRowsFromCursor($cursor);
  218. // 若查询数据为空则continue
  219. if (empty($stock)) {
  220. // 若$empty_data 及$merge_data_days 为真,则加入空数据(针对列表及默认柱状图)
  221. if ($empty_data) {
  222. $data_temp = array(
  223. 'price_count' => 0,
  224. 'operate_count' => 0,
  225. 'station' => (string)$value['_id'],
  226. 'stationName' => $value['name'],
  227. );
  228. // 按照每天整合数据
  229. if ($merge_data_days) {
  230. $date_range = date('Y-m-d', $date_start);
  231. $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
  232. $date_arr = $this->getDateArr($date_start, $date_end);
  233. $price_count_arr = array();
  234. $operate_count_arr = array();
  235. foreach ($date_arr as $k => $v) {
  236. array_push($price_count_arr, 0);
  237. array_push($operate_count_arr, 0);
  238. }
  239. $data_temp['data']['date_range'] = $date_range;
  240. $data_temp['data']['price_count'] = $price_count_arr;
  241. $data_temp['data']['operate_count'] = $operate_count_arr;
  242. $data_temp['data']['date_arr'] = $date_arr;
  243. // 按照每周整合数据
  244. } else if ($merge_data_weeks) {
  245. $date_end = strtotime('monday', time());
  246. if (strtotime(date('Y-m-d', time())) == $date_end) {
  247. $date_end = strtotime('+7 day', $date_end);
  248. }
  249. $date_start = strtotime('-35 day', $date_end);
  250. $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
  251. $week_str = $this->getWeekArr($date_start, $date_end);
  252. $price_count_arr = array();
  253. $operate_count_arr = array();
  254. foreach ($week_arr as $k => $v) {
  255. array_push($price_count_arr, 0);
  256. array_push($operate_count_arr, 0);
  257. }
  258. $data_temp['data']['price_count'] = $price_count_arr;
  259. $data_temp['data']['operate_count'] = $operate_count_arr;
  260. $data_temp['data']['week_arr'] = $week_arr;
  261. $data_temp['data']['date_range'] = $date_range;
  262. // 按照每月整合数据
  263. } else if ($merge_data_months) {
  264. $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
  265. $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
  266. $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
  267. $month_arr = $this->getMonthArr($date_start, $date_end);
  268. $price_count_arr = array();
  269. $operate_count_arr = array();
  270. foreach ($month_arr as $k => $v) {
  271. array_push($price_count_arr, 0);
  272. array_push($operate_count_arr, 0);
  273. }
  274. $data_temp['data']['price_count'] = $price_count_arr;
  275. $data_temp['data']['operate_count'] = $operate_count_arr;
  276. $data_temp['data']['month_arr'] = $month_arr;
  277. $data_temp['data']['month_range'] = $month_range;
  278. }
  279. $data[] = $data_temp;
  280. }
  281. continue;
  282. }
  283. $data_temp = array();
  284. $data_temp['price_count'] = 0;
  285. $data_temp['operate_count'] = 0;
  286. foreach ($stock as $k => $v) {
  287. $data_temp['price_count'] += $v['tot_price'];
  288. $data_temp['operate_count']++;
  289. }
  290. $data_temp['station'] = (string)$value['_id'];
  291. $data_temp['stationName'] = $value['name'];
  292. // 判断并加入每个服务点时间范围内的统计情况(按照天)
  293. if ($merge_data_days) {
  294. $date_range = date('Y-m-d', $date_start);
  295. $date_range .= '至'.date('Y-m-d', strtotime('-1 day', $date_end));
  296. $data_station_temp_days = $this->parseDataByDays($stock, $date_start, $date_end);
  297. $date_arr = $this->getDateArr($date_start, $date_end);
  298. $data_temp['data']['date_range'] = $date_range;
  299. $price_count_arr = array();
  300. $operate_count_arr = array();
  301. foreach ($data_station_temp_days as $key => $value) {
  302. array_push($price_count_arr, $value['price_count']);
  303. array_push($operate_count_arr, $value['operate_count']);
  304. }
  305. $data_temp['data']['price_count'] = $price_count_arr;
  306. $data_temp['data']['operate_count'] = $operate_count_arr;
  307. $data_temp['data']['date_arr'] = $date_arr;
  308. } else if ($merge_data_weeks) {
  309. // 默认查询近一个月数据
  310. $date_end = strtotime('monday', time());
  311. if (strtotime(date('Y-m-d', time())) == $date_end) {
  312. $date_end = strtotime('+7 day', $date_end);
  313. }
  314. $date_start = strtotime('-35 day', $date_end);
  315. $date_range = $date_range = $month_range = date('Y-m-d', $date_start).'至'.date('Y-m-d', strtotime('-1 day', $date_end));
  316. $data_station_temp = $this->parseDataByDays($stock, $date_start, $date_end);
  317. $data_station_temp_weeks = $this->parseDataByWeeks($data_station_temp, $date_start, $date_end);
  318. $week_arr = $this->getWeekArr($date_start, $date_end);
  319. $price_count_arr = array();
  320. $operate_count_arr = array();
  321. foreach ($data_station_temp_weeks as $key => $value) {
  322. array_push($price_count_arr, $value['price_count']);
  323. array_push($operate_count_arr, $value['operate_count']);
  324. }
  325. $data_temp['data']['price_count'] = $price_count_arr;
  326. $data_temp['data']['operate_count'] = $operate_count_arr;
  327. $data_temp['data']['week_arr'] = $week_arr;
  328. $data_temp['data']['date_range'] = $date_range;
  329. // 判断并加入每个服务点时间范围内的统计情况(按照月)
  330. } else if ($merge_data_months) {
  331. // 默认查询最近半年数据
  332. $date_end = strtotime(date('Y-m', strtotime('+1 month', time())));
  333. $date_start = strtotime(date('Y-m', strtotime('-5 month', time())));
  334. $month_range = date('Y-m', $date_start).'至'.date(date('Y-m', strtotime('-1 month', $date_end)));
  335. $data_station_temp = $this->parseDataByDays($stock, $date_start, $date_end);
  336. $data_station_temp_months = $this->parseDataByMonths($data_station_temp, $date_start, $date_end);
  337. $month_arr = $this->getMonthArr($date_start, $date_end);
  338. $price_count_arr = array();
  339. $operate_count_arr = array();
  340. foreach ($data_station_temp_months as $key => $value) {
  341. array_push($price_count_arr, $value['price_count']);
  342. array_push($operate_count_arr, $value['operate_count']);
  343. }
  344. $data_temp['data']['price_count'] = $price_count_arr;
  345. $data_temp['data']['operate_count'] = $operate_count_arr;
  346. $data_temp['data']['month_arr'] = $month_arr;
  347. $data_temp['data']['month_range'] = $month_range;
  348. }
  349. $data[] = $data_temp;
  350. }
  351. $data = array('data' => $data, 'total' => $total);
  352. return $data;
  353. }
  354. /**
  355. * 获取单服务点时间范围内所有数据(Y轴数据)
  356. * 按照日期归类
  357. * @param timestamp $date_start : 开始时间
  358. * @param timestamp $date_end : 结束时间
  359. * @param MongoID $station : 服务点ID
  360. */
  361. private function getDataByStation ($date_start, $date_end, $station) {
  362. $data = array();
  363. $date_index = $date_start;
  364. $criteria = new EMongoCriteria();
  365. $criteria->time('>=', $date_start);
  366. $criteria->time('<', $date_end);
  367. $criteria->station('==', $station);
  368. $criteria->sort('time', EMongoCriteria::SORT_ASC);
  369. $cursor = Stock::model()->findAll($criteria);
  370. $rows = CommonFn::getRowsFromCursor($cursor);
  371. $rows_count = count($rows);
  372. $rows_index = 0;
  373. while ($date_index < $date_end) {
  374. $data_temp = array(
  375. 'date' => $date_index,
  376. 'price_count' => 0,
  377. 'operate_count'=> 0
  378. );
  379. while ($rows_index < $rows_count) {
  380. if ($date_index <= $rows[$rows_index]['time'] &&
  381. $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
  382. $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
  383. $data_temp['operate_count']++;
  384. } else {
  385. break;
  386. }
  387. $rows_index++;
  388. }
  389. $data[] = $data_temp;
  390. $date_index = strtotime('+1 day', $date_index);
  391. }
  392. return $data;
  393. }
  394. /**
  395. * 根据查询Stock表获得的Rows整理数据,按照每天分类
  396. * 减少与Mongo的交互,提高性能
  397. * @param array $rows : 从Stock表查询的单服务点数据
  398. * @param timestamp $date_start : 开始的时间
  399. * @param timestamp $date_end : 结束的时间
  400. * @return array $data : 返回的数据
  401. */
  402. private function parseDataByDays ($rows, $date_start, $date_end) {
  403. $date_index = $date_start;
  404. $rows_count = count($rows);
  405. $rows_index = 0;
  406. while ($date_index < $date_end) {
  407. $data_temp = array(
  408. 'date' => $date_index,
  409. 'price_count' => 0,
  410. 'operate_count'=> 0
  411. );
  412. while ($rows_index < $rows_count) {
  413. if ($date_index <= $rows[$rows_index]['time'] &&
  414. $rows[$rows_index]['time'] < strtotime('+1 day', $date_index)) {
  415. $data_temp['price_count'] += $rows[$rows_index]['tot_price'];
  416. $data_temp['operate_count']++;
  417. } else {
  418. break;
  419. }
  420. $rows_index++;
  421. }
  422. $data[] = $data_temp;
  423. $date_index = strtotime('+1 day', $date_index);
  424. }
  425. return $data;
  426. }
  427. /**
  428. * 按照每周整理单服务点数据
  429. */
  430. private function parseDataByWeeks ($rows='', $date_start, $date_end, $station='') {
  431. if (empty($rows) && $station != '') {
  432. $station = new MongoId($station);
  433. $rows = $this->getDataByStation($date_start, $date_end, $station);
  434. }
  435. $range = ($date_end - $date_start)/3600/24/7;
  436. $data = array();
  437. $rows_index = 0;
  438. $day_count = 1;
  439. for ($data_index=0; $data_index < $range; $data_index++) {
  440. $data_temp = array(
  441. 'price_count' => 0,
  442. 'operate_count' => 0,
  443. );
  444. while ($day_count%8 != 0) {
  445. $data_temp['price_count'] += $rows[$rows_index]['price_count'];
  446. $data_temp['operate_count'] += $rows[$rows_index]['operate_count'];
  447. $rows_index++;
  448. $day_count++;
  449. }
  450. $data[] = $data_temp;
  451. $day_count = 1;
  452. }
  453. return $data;
  454. }
  455. /**
  456. * 按照月份整理单用户数据
  457. * @param $date_start timestamp : 开始时间
  458. * @param $date_end timestamp : 结束时间
  459. * @param $station MongoID : 服务点ID
  460. */
  461. private function parseDataByMonths ($rows='', $date_start, $date_end, $station='') {
  462. if (empty($rows) && $station != '') {
  463. $station = new MongoId($station);
  464. $rows = $this->getDataByStation($date_start, $date_end, $station);
  465. }
  466. $range = intval(date('m', $date_end)) - intval(date('m', $date_start));
  467. $num_of_days = array();
  468. for ($i=0; $i<$range; $i++) {
  469. $num_of_days[$i] = (strtotime('+'.($i+1).' month', $date_start) - strtotime('+'.$i.' month', $date_start))/3600/24;
  470. }
  471. $data = array();
  472. $data_index = 0;
  473. $day_count = 0;
  474. foreach ($num_of_days as $key => $value) {
  475. $day_count += $value;
  476. $data_temp = array(
  477. 'price_count' => 0,
  478. 'operate_count' => 0
  479. );
  480. while ($data_index < $day_count) {
  481. $data_temp['price_count'] += $rows[$data_index]['price_count'];
  482. $data_temp['operate_count'] += $rows[$data_index]['operate_count'];
  483. $data_index++;
  484. }
  485. $data[] = $data_temp;
  486. }
  487. return $data;
  488. }
  489. /**
  490. * 将数据转换为字符串
  491. * @param $data array : 需要转换为字符串的数据
  492. */
  493. private function getDataStr ($data) {
  494. $data_str = array(
  495. 'price_count' => '',
  496. 'operate_count' => ''
  497. );
  498. $price_count = '';
  499. $operate_count = '';
  500. foreach ($data as $key => $value) {
  501. $price_count .= '"'.$value['price_count'].'",';
  502. $operate_count .= '"'.$value['operate_count'].'",';
  503. }
  504. $price_count = substr($price_count, 0, strlen($price_count)-1);
  505. $operate_count = substr($operate_count, 0, strlen($operate_count)-1);
  506. $data_str['price_count'] = $price_count;
  507. $data_str['operate_count'] = $operate_count;
  508. return $data_str;
  509. }
  510. /**
  511. * 将时间范围数组转换为字符串
  512. * @param array $data : 待转换数据
  513. * @return string $data_str : 转换后数据
  514. */
  515. private function getTimeStr ($data) {
  516. $data_str = '';
  517. foreach ($data as $key => $value) {
  518. $data_str .= '"'.$value.'",';
  519. }
  520. $data_str = substr($data_str, 0, strlen($data_str)-1);
  521. return $data_str;
  522. }
  523. /**
  524. * 获取日期数组
  525. */
  526. private function getDateArr ($date_start, $date_end) {
  527. $date_arr = array();
  528. $date_index = $date_start;
  529. while ($date_index < $date_end) {
  530. $date_arr[] = date('m-d', $date_index);
  531. $date_index = strtotime('+1 day', $date_index);
  532. }
  533. return $date_arr;
  534. }
  535. /**
  536. * 获取周数组
  537. */
  538. private function getWeekArr ($date_start, $date_end) {
  539. $week_arr = array();
  540. $date_index = $date_start;
  541. do {
  542. $week_temp = date('m-d', $date_index);
  543. $date_index = strtotime('+7 day', $date_index);
  544. $week_temp .= '至'.date('m-d', strtotime('-1 day', $date_index));
  545. $week_arr[] = $week_temp;
  546. } while ($date_index < $date_end);
  547. return $week_arr;
  548. }
  549. /**
  550. * 获取月份数组
  551. */
  552. private function getMonthArr ($date_start, $date_end) {
  553. $month_arr = array();
  554. $date_index = $date_start;
  555. while ($date_index < $date_end) {
  556. $month_arr[] = intval(date('m', $date_index)).'月';
  557. $date_index = strtotime('+1 month', $date_index);
  558. }
  559. return $month_arr;
  560. }
  561. /**
  562. * 获取station的combobox数据
  563. */
  564. private function getStationComboboxData () {
  565. $criteria = new EMongoCriteria();
  566. $cursor = Station::model()->findAll($criteria);
  567. $rows = CommonFn::getRowsFromCursor($cursor);
  568. $parsedRows = Station::model()->parse($rows);
  569. $station_data = array();
  570. foreach ($parsedRows as $key => $v) {
  571. $station_data = array_merge($station_data, array($v['name'] => array('name' => $v['name'])));
  572. }
  573. $station = CommonFn::getComboboxData($station_data, '全部', true, '');
  574. return $station;
  575. }
  576. }
  577. ?>