AssistHomeController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. class AssistHomeController extends AssistController
  3. {
  4. public function actionIndex()
  5. {
  6. $page=Req::get('page');
  7. if(!$page) $page=1;
  8. $pageLimit=10;
  9. $userModel=new AssistUser();
  10. $result = $userModel->getLesseeList($page,$pageLimit);
  11. return $this->render('index', array(
  12. 'dataList' => $result['dataList'],
  13. 'pages' => $result['pages'],
  14. 'page'=>$page
  15. ));
  16. }
  17. public function actionAdd()
  18. {
  19. if (Yii::app()->request->getIsPostRequest()) {
  20. $model = new AssistUser();
  21. $realName=Req::post('real_name');
  22. $userName=Req::post('user_name');
  23. $password=Req::post('password');
  24. $re_password=Req::post('re_password');
  25. $status=Req::post('status');
  26. $sex=Req::post('sex');
  27. $cutting_limit=Req::post('cutting_limit');
  28. $scan_limit=Req::post('scan_limit');
  29. if(!$realName || !$userName || !$password){
  30. Yii::app()->jump->error('请填写完整信息!');
  31. }
  32. $check=AssistUser::model()->find('user_name=:un ',array(':un'=>$userName));
  33. if($check){
  34. Yii::app()->jump->error('手机号已经被使用!');
  35. }
  36. $model->real_name=$realName;
  37. $model->user_name=$userName;
  38. $model->status=$status;
  39. $model->sex=$sex;
  40. $model->update_time=time();
  41. if($password){
  42. if($password!=$re_password){
  43. Yii::app()->jump->error('确认密码不一致!');
  44. }
  45. $model->password=$this->producePassword($password);
  46. }
  47. if($cutting_limit){
  48. $model->cutting_limit=1;
  49. }else{
  50. $model->cutting_limit=0;
  51. }
  52. if($scan_limit){
  53. $model->scan_limit=1;
  54. }else{
  55. $model->scan_limit=0;
  56. }
  57. if($model->save()){
  58. $this->redirect(array('assistHome/index'));
  59. }else{
  60. Yii::app()->jump->error('添加失败!');
  61. }
  62. }
  63. return $this->render('add');
  64. }
  65. public function actionEdit()
  66. {
  67. $lesseeId = (int)Req::get('lid');
  68. $model = new AssistUser();
  69. $model = $model->findByPk($lesseeId);
  70. if (Yii::app()->request->getIsPostRequest()) {
  71. $lesseeId = (int)Req::post('lid');
  72. $realName=Req::post('real_name');
  73. $userName=Req::post('user_name');
  74. $password=Req::post('password');
  75. $re_password=Req::post('re_password');
  76. $status=Req::post('status');
  77. $sex=Req::post('sex');
  78. $cutting_limit=Req::post('cutting_limit');
  79. $scan_limit=Req::post('scan_limit');
  80. if(!$realName || !$userName){
  81. Yii::app()->jump->error('请填写完整信息!');
  82. }
  83. $check=AssistUser::model()->find('user_name=:un and user_id<>:id',array(':un'=>$userName,':id'=>$lesseeId));
  84. if($check){
  85. Yii::app()->jump->error('手机号已经被使用!');
  86. }
  87. $updateArr=array();
  88. $updateArr['real_name']=$realName;
  89. $updateArr['user_name']=$userName;
  90. $updateArr['status']=$status;
  91. $updateArr['sex']=$sex;
  92. $updateArr['update_time']=time();
  93. if($password){
  94. if($password!=$re_password){
  95. Yii::app()->jump->error('确认密码不一致!');
  96. }
  97. $updateArr['password']=$this->producePassword($password);
  98. }
  99. if($cutting_limit){
  100. $updateArr['cutting_limit']=1;
  101. }else{
  102. $updateArr['cutting_limit']=0;
  103. }
  104. if($scan_limit){
  105. $updateArr['scan_limit']=1;
  106. }else{
  107. $updateArr['scan_limit']=0;
  108. }
  109. if(AssistUser::model()->updateAll($updateArr,'user_id=:uid',array(':uid'=>$lesseeId))){
  110. $this->redirect(array('assistHome/index'));
  111. }
  112. }
  113. return $this->render('edit', array(
  114. 'user' => $model
  115. ));
  116. }
  117. public function actionRemove()
  118. {
  119. $lesseeId = (int)Req::post('lesseeId');
  120. if (!$lesseeId) {
  121. exit(json_encode(array('status'=>0)));
  122. }
  123. $lessee = AssistUser::model()->findByPk($lesseeId);
  124. if ($lessee) {
  125. $examNum=ATask::model()->find("operator=:uid",array(':uid'=>$lesseeId));
  126. if ($examNum) {
  127. exit(json_encode(array('status'=>0,'msg'=>'当前账号已产生任务数据,禁止删除,谢谢!')));
  128. } else {
  129. if (AssistUser::model()->deleteAll('user_id=:uid',array(':uid'=>$lesseeId))) {
  130. exit(json_encode(array('status'=>1)));
  131. } else {
  132. exit(json_encode(array('status'=>0)));
  133. }
  134. }
  135. } else {
  136. exit(json_encode(array('status'=>0,'msg'=>'未找到用户信息')));
  137. }
  138. }
  139. }