StockViewUserController.php 25 KB

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