REmployeController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: north
  5. * Date: 2017/8/14
  6. * Time: 下午2:31
  7. */
  8. class REmployeController extends AdminController {
  9. public function actionIndex()
  10. {
  11. //$tmp = JEmploye::model()->findAll();
  12. //foreach ($tmp as $k => $v) {
  13. //$v->delete();
  14. //}
  15. $status = CommonFn::getComboboxData(JEmploye::$status_option, 100, true, 100);//人员状态
  16. $auth = CommonFn::getComboboxData(JEmploye::$auth_option, 1, true, 100);
  17. $this->render('index',array(
  18. 'status' => $status,
  19. 'auth' => $auth
  20. ));
  21. }
  22. public function actionList()
  23. {
  24. $pageParams = CommonFn::getPageParams();
  25. $status = intval(Yii::app()->request->getParam('status', 100));
  26. $criteria = new EMongoCriteria($pageParams);
  27. if ($status != 100 ) {
  28. $criteria->status('==',$status);
  29. }
  30. $cursor = JEmploye::model()->findAll($criteria);
  31. $rows = CommonFn::getRowsFromCursor($cursor);
  32. $parsedRows = JEmploye::model()->parse($rows);
  33. $total = $cursor->count();
  34. echo CommonFn::composeDatagridData($parsedRows, $total);
  35. }
  36. public function actionEdit()
  37. {
  38. $id = Yii::app()->request->getParam('id','');
  39. $status = intval(Yii::app()->request->getParam('status',100));
  40. $user_name = Yii::app()->request->getParam('user_name','');
  41. $mobile = Yii::app()->request->getParam('mobile','');
  42. $auth = intval(Yii::app()->request->getParam('auth',''));
  43. $owned_stores = Yii::app()->request->getParam('owned_stores','');
  44. $desc = Yii::app()->request->getParam('desc','');
  45. $flag1 = Yii::app()->request->getParam('flag','');
  46. if ($status == 100) {
  47. CommonFn::requestAjax(false,'状态没有修改');exit;
  48. }
  49. if ($auth == 100) {
  50. CommonFn::requestAjax(false,'角色没有修改');exit;
  51. }
  52. if (!CommonFn::isMongoId($id)) {
  53. CommonFn::requestAjax(false,'id错误');exit;
  54. }
  55. $flag = function () use ($owned_stores){
  56. $criteria = new EMongoCriteria();
  57. $criteria->store_id('==',intval($owned_stores));
  58. $store = Store::model()->find($criteria);
  59. if (empty($store)) {
  60. return true;
  61. } else {
  62. return false;
  63. }
  64. };
  65. if ($flag()) {
  66. CommonFn::requestAjax(false,'门店不存在');exit;
  67. }
  68. $employe = JEmploye::get(new MongoId($id));
  69. $employe->status = $status;
  70. $employe->user_name = $user_name;
  71. $employe->mobile = $mobile;
  72. $employe->auth = $auth;
  73. $employe->owned_stores = intval($owned_stores);
  74. $employe->desc = $desc;
  75. $employe->flag = intval($flag1);
  76. $employe->save();
  77. CommonFn::requestAjax(true,'保存成功');exit;
  78. }
  79. public function actionAdd()
  80. {
  81. $user_id = Yii::app()->request->getParam('user_id','');
  82. $user_name = Yii::app()->request->getParam('user_name','');
  83. $mobile = Yii::app()->request->getParam('mobile','');
  84. $auth = intval(Yii::app()->request->getParam('auth',''));
  85. $owned_stores = Yii::app()->request->getParam('owned_stores','');
  86. $desc = Yii::app()->request->getParam('desc','');
  87. $sex = Yii::app()->request->getParam('sex','');
  88. $status = intval(Yii::app()->request->getParam('status',100));
  89. if ($status == 100) {
  90. CommonFn::requestAjax(false,'状态没有修改');exit;
  91. }
  92. if (CommonFn::isMongoId($user_id)) {
  93. $user = RUser::get(new MongoId($user_id));
  94. if (empty($user)) {
  95. CommonFn::requestAjax(false,'id错误');exit;
  96. }
  97. }
  98. $employe = new JEmploye();
  99. $employe->user_id = $user->_id;
  100. $employe->user_name = $user_name;
  101. $employe->mobile = $mobile;
  102. $employe->auth = intval($auth);
  103. $employe->owned_stores = intval($owned_stores);
  104. $employe->desc = $desc;
  105. $employe->status = intval($status);
  106. $employe->sex = intval($sex);
  107. $employe->save();
  108. CommonFn::requestAjax(true,'保存成功');exit;
  109. }
  110. }