StationController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. class StationController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $status_option = Station::$status_option;
  6. $status = CommonFn::getComboboxData($status_option, 100, true, 100);
  7. $type = CommonFn::getComboboxData(Yii::app()->params['o2o_service'], 100, true, 100);
  8. $this->render('index', array(
  9. 'status' => $status,
  10. 'type' => $type
  11. ));
  12. }
  13. public function actionList(){
  14. $filter_status = intval(Yii::app()->request->getParam('status', 100));
  15. $search = Yii::app()->request->getParam('search', '');
  16. $id = Yii::app()->request->getParam('id', '');
  17. $params = CommonFn::getPageParams();
  18. $criteria = new EMongoCriteria($params);
  19. if ($id != ''){
  20. $station_id = new MongoId($id);
  21. $criteria->_id('==', $station_id);
  22. }
  23. if ($filter_status != 100){
  24. $criteria->status('==', $filter_status);
  25. }
  26. if ($search != ''){
  27. $criteria->name('or', new MongoId($search));
  28. }
  29. $cursor = Station::model()->findAll($criteria);
  30. $total = $cursor->count();
  31. $rows = CommonFn::getRowsFromCursor($cursor);
  32. $parsedRows = Station::model()->parse($rows);
  33. echo CommonFn::composeDatagridData($parsedRows, $total);
  34. }
  35. public function actionEdit(){
  36. $id = Yii::app()->request->getParam('id', '');
  37. $status = intval(Yii::app()->request->getParam('status', 1));
  38. $name = Yii::app()->request->getParam('name', '');
  39. $start_time = intval(Yii::app()->request->getParam('start_time', 9));
  40. $end_time = intval(Yii::app()->request->getParam('end_time', 20));
  41. $beauticians_count = intval(Yii::app()->request->getParam('beauticians_count', 1));
  42. $address = Yii::app()->request->getParam('address', array());
  43. $types = Yii::app()->request->getParam('types', array());
  44. $address = json_decode($address);
  45. $coverage = Yii::app()->request->getParam('coverage', array());
  46. $coverage = json_decode($coverage);
  47. if($status == 100){
  48. CommonFn::requestAjax(false, '必须指定状态!');
  49. }
  50. if($name == '' || empty($address) ){
  51. CommonFn::requestAjax(false, '必填内容为空');
  52. }
  53. if($start_time >= $end_time){
  54. CommonFn::requestAjax(false, '时间选择错误');
  55. }
  56. //$types_arr = array();
  57. //if(!empty($types)){
  58. //foreach ($types as $type) {
  59. //if($type != 100){
  60. // $types_arr[] = Yii::app()->params['o2o_service'][$type];
  61. //}else{
  62. //CommonFn::requestAjax(false, '服务项目不能为空');
  63. // }
  64. //}
  65. //}else{
  66. //CommonFn::requestAjax(false, '服务项目不能为空');
  67. //}
  68. $status=$status>1?1:$status;
  69. if(!$id){
  70. $station = new Station();
  71. }else{
  72. $criteria = new EMongoCriteria();
  73. $criteria->_id = new MongoId($id);
  74. $station = Station::model()->find($criteria);
  75. if (empty($station)){
  76. CommonFn::requestAjax(false, '服务点 不存在');
  77. }
  78. }
  79. $station->status = $status;
  80. $station->name = $name;
  81. $station->start_time = $start_time;
  82. $station->end_time = $end_time;
  83. $station->beauticians_count = $beauticians_count;
  84. $station->address = $address;
  85. $station->coverage = $coverage;
  86. //$station->types = $types;
  87. $arr_station = array('status','name','start_time','end_time','beauticians_count','address','coverage');
  88. $success = $station->save(true,$arr_station);
  89. CommonFn::requestAjax($success, '', array());
  90. }
  91. }