MasterController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. class MasterController extends AdminController{
  3. public function actionIndex()
  4. {
  5. $status_option = Master::$status_option;
  6. $status = CommonFn::getComboboxData($status_option, 100, true, 100);
  7. $this->render('index', array(
  8. 'status' => $status
  9. ));
  10. }
  11. public function actionList(){
  12. $params = CommonFn::getPageParams();
  13. $type = Yii::app()->request->getParam('type', 100);
  14. $id = Yii::app()->request->getParam('id', '');
  15. $status = intval(Yii::app()->request->getParam('status', 100));
  16. $search = Yii::app()->request->getParam('search', '');
  17. $criteria = new EMongoCriteria($params);
  18. if ($type != 100){
  19. $criteria->type('==', new MongoId($type));
  20. }
  21. if($status!=100){
  22. $criteria->status('==', $status);
  23. }
  24. if ($id != ''){
  25. $master_id = new MongoId($id);
  26. $criteria->_id('==', $master_id);
  27. }
  28. if ($search != ''){
  29. if (CommonFn::isMongoId($search)){
  30. $criteria->_id('==',new MongoId($search));
  31. } else {
  32. $criteria->name = new MongoRegex('/' . $search . '/');
  33. }
  34. }
  35. $cursor = Master::model()->findAll($criteria);
  36. $total = $cursor->count();
  37. $rows = CommonFn::getRowsFromCursor($cursor);
  38. $parsedRows = Master::model()->parse($rows);
  39. echo CommonFn::composeDatagridData($parsedRows, $total);
  40. }
  41. public function actionEdit(){
  42. $id = Yii::app()->request->getParam('id', '');
  43. $status = intval(Yii::app()->request->getParam('status', 1));
  44. $avatar = Yii::app()->request->getParam('avatar', '');
  45. $type = Yii::app()->request->getParam('type', 'beautician');
  46. $name = Yii::app()->request->getParam('name', '');
  47. $desc = Yii::app()->request->getParam('desc', '');
  48. $city_info = Yii::app()->request->getParam('city_info', array());
  49. $mobile = Yii::app()->request->getParam('mobile', '');
  50. $address = Yii::app()->request->getParam('address', '');
  51. $position = Yii::app()->request->getParam('position',array());
  52. $sex = intval(Yii::app()->request->getParam('sex',3));
  53. $pics = Yii::app()->request->getParam('pics',array());
  54. $coverage = Yii::app()->request->getParam('coverage',array());
  55. if($status == 100){
  56. CommonFn::requestAjax(false, '必须指定状态!');
  57. }
  58. if(!$avatar){
  59. CommonFn::requestAjax(false, '头像不能为空');
  60. }
  61. if(!$type){
  62. CommonFn::requestAjax(false, '类型不能为空');
  63. }
  64. if(!$mobile){
  65. CommonFn::requestAjax(false, '联系方式不能为空');
  66. }
  67. if(empty($position)){
  68. CommonFn::requestAjax(false, '位置不能为空');
  69. }
  70. if(empty($coverage)){
  71. CommonFn::requestAjax(false, '服务区域不能为空');
  72. }
  73. $cityArray = array();
  74. $zCity = new ZCityInfo();
  75. if(!$zCity->checkCity($city_info,$cityArray)){
  76. CommonFn::requestAjax(false, '请检查城市信息是否正确!');
  77. }
  78. if ($name == '' || mb_strlen($name, 'utf-8') < 2 ||mb_strlen($name, 'utf-8') > 10){
  79. CommonFn::requestAjax(false, '姓名至少2个字,最多10个字');
  80. }
  81. if (mb_strlen($desc, 'utf-8') > 500){
  82. CommonFn::requestAjax(false, '简介最多500个字!');
  83. }
  84. $cityArray = array();
  85. $zCity = new ZCityInfo();
  86. if(!$zCity->checkCity($city_info,$cityArray)){
  87. CommonFn::requestAjax(false, '请检查城市信息是否正确!');
  88. }
  89. if(!$id){
  90. $master = new Master();
  91. $op = 'insert';
  92. }else{
  93. $op = 'update';
  94. $criteria = new EMongoCriteria();
  95. $criteria->_id = new MongoId($id);
  96. $master = Master::model()->find($criteria);
  97. if (empty($master)){
  98. CommonFn::requestAjax(false, '此人不存在');
  99. }
  100. }
  101. $sex = $sex>1?1:$sex;
  102. $new_pics = array();
  103. foreach($pics as $picStr){
  104. $pic = json_decode($picStr,true);
  105. if(isset($pic) && $pic){
  106. $new_pics[] = $pic;
  107. }
  108. }
  109. $pics = $new_pics;
  110. $status=$status>1?1:$status;
  111. $master->name = $name;
  112. $master->desc = CommonFn::parse_break($desc);
  113. $master->avatar = $avatar;
  114. $master->status = $status;
  115. $master->type = $type;
  116. $master->city_info = $cityArray;
  117. //$master->user = $user;
  118. //$master->ruser = $ruser;
  119. $master->position = $position;
  120. $master->mobile = $mobile;
  121. $master->address = $address;
  122. $master->sex = $sex;
  123. $master->coverage = $coverage;
  124. $master->pics = $pics;
  125. $arr_addMaster = array('status','user','ruser','type','name','city_info','position','mobile','address','sex','avatar','desc','pics','coverage');
  126. $success = $master->save(true,$arr_addMaster);
  127. CommonFn::requestAjax($success, '', array());
  128. }
  129. }