REmployeController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if ($status == 100) {
  46. CommonFn::requestAjax(false,'状态没有修改');exit;
  47. }
  48. if ($auth == 100) {
  49. CommonFn::requestAjax(false,'角色没有修改');exit;
  50. }
  51. if (!CommonFn::isMongoId($id)) {
  52. CommonFn::requestAjax(false,'id错误');exit;
  53. }
  54. $flag = function () use ($owned_stores){
  55. $criteria = new EMongoCriteria();
  56. $criteria->store_id('==',intval($owned_stores));
  57. $store = Store::model()->find($criteria);
  58. if (empty($store)) {
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. };
  64. if ($flag()) {
  65. CommonFn::requestAjax(false,'门店不存在');exit;
  66. }
  67. $employe = JEmploye::get(new MongoId($id));
  68. $employe->status = $status;
  69. $employe->user_name = $user_name;
  70. $employe->mobile = $mobile;
  71. $employe->auth = $auth;
  72. $employe->owned_stores = intval($owned_stores);
  73. $employe->desc = $desc;
  74. $employe->save();
  75. CommonFn::requestAjax(true,'保存成功');exit;
  76. }
  77. public function actionAdd()
  78. {
  79. $user_id = Yii::app()->request->getParam('user_id','');
  80. $user_name = Yii::app()->request->getParam('user_name','');
  81. $mobile = Yii::app()->request->getParam('mobile','');
  82. $auth = intval(Yii::app()->request->getParam('auth',''));
  83. $owned_stores = Yii::app()->request->getParam('owned_stores','');
  84. $desc = Yii::app()->request->getParam('desc','');
  85. $sex = Yii::app()->request->getParam('sex','');
  86. $status = intval(Yii::app()->request->getParam('status',100));
  87. if ($status == 100) {
  88. CommonFn::requestAjax(false,'状态没有修改');exit;
  89. }
  90. if (CommonFn::isMongoId($user_id)) {
  91. $user = RUser::get(new MongoId($user_id));
  92. if (empty($user)) {
  93. CommonFn::requestAjax(false,'id错误');exit;
  94. }
  95. }
  96. $employe = new JEmploye();
  97. $employe->user_id = $user->_id;
  98. $employe->user_name = $user_name;
  99. $employe->mobile = $mobile;
  100. $employe->auth = intval($auth);
  101. $employe->owned_stores = intval($owned_stores);
  102. $employe->desc = $desc;
  103. $employe->status = intval($status);
  104. $employe->sex = intval($sex);
  105. $employe->save();
  106. CommonFn::requestAjax(true,'保存成功');exit;
  107. }
  108. }