JWorkerController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/2/28
  6. * Time: 下午12:30
  7. * description :
  8. */
  9. class JWorkerController extends AdminController
  10. {
  11. protected $fileds = [
  12. 'user_id' => '用户ID',
  13. 'name' => '用户名',
  14. 'mobile' => '手机',
  15. 'phone' => '电话',
  16. 'email' => '邮箱',
  17. 'birth' => '生日',
  18. 'sex' => '性别',
  19. 'address1' => '户籍地址',
  20. 'address2' => '居住地址',
  21. 'address3' => '通信地址',
  22. 'address_number' => '邮编',
  23. 'card_number' => '身份证号',
  24. 'certificate' => '证书',
  25. 'people' => '居委会',
  26. 'care_institutions' => '护理机构',
  27. 'desc' => '备注',
  28. 'status' => '状态',
  29. ];
  30. public function actionIndex()
  31. {
  32. $status = CommonFn::getComboboxData(Worker::$status_options, 100, true, 100);
  33. $this->render('index',[
  34. 'fileds' => $this->fileds,
  35. 'status' => $status,
  36. ]);
  37. }
  38. public function actionList()
  39. {
  40. $pageParams = CommonFn::getPageParams();
  41. $search = Yii::app()->request->getParam('search', '');
  42. $status = Yii::app()->request->getParam('status', 0);
  43. $criteria = new EMongoCriteria($pageParams);
  44. if ($search) {
  45. $criteria->addCond('user_info.name','or',new MongoRegex('/' . $search . '/'));
  46. }
  47. if($status != 100 && $status > 0) {
  48. $criteria->status('==',(int)$status);
  49. }
  50. $cursor = Worker::model()->findAll($criteria);
  51. $rows = CommonFn::getRowsFromCursor($cursor);
  52. $parsedRows = Worker::model()->parse($rows);
  53. $total = $cursor->count();
  54. echo CommonFn::composeDatagridData($parsedRows, $total);
  55. }
  56. public function actionEdit()
  57. {
  58. $this->fileds['id'] = 'ID';
  59. $data = [];
  60. foreach ($this->fileds as $filed => $v) {
  61. $data[$filed] = Yii::app()->request->getParam($filed,'');
  62. if ($filed == 'status' && $data['status'] == 100) {
  63. CommonFn::requestAjax(false, '请选择状态', array(
  64. 'error' => $filed,
  65. ));
  66. }
  67. if (empty($data[$filed])) {
  68. CommonFn::requestAjax(false, '请填写完整数据', array(
  69. 'error' => $filed,
  70. ));
  71. }
  72. }
  73. if (!CommonFn::isMongoId($data['id'])) {
  74. CommonFn::requestAjax(false, '修改失败', array());
  75. }
  76. $worker = Worker::get(new MongoId($data['id']));
  77. $worker->user_id = $data['user_id'];
  78. $worker->user_info = [
  79. 'name' => $data['name'],
  80. 'mobile' => $data['mobile'],
  81. 'phone' => $data['phone'],
  82. 'email' => $data['email'],
  83. 'birth' => strtotime($data['birth']),
  84. 'sex' => (int)$data['sex'],
  85. ];
  86. $worker->status = (int)$data['status'];
  87. $worker->address = [
  88. 'address1' => $data['address1'],
  89. 'address2' => $data['address2'],
  90. 'address3' => $data['address3'],
  91. ];
  92. $worker->address_number = $data['address_number'];
  93. $worker->card_number = $data['card_number'];
  94. $worker->certificate = $data['certificate'];
  95. $worker->care_institutions = $data['care_institutions'];
  96. $worker->desc = $data['desc'];
  97. $worker->people = $data['people'];
  98. $worker->save();
  99. CommonFn::requestAjax(true,'修改成功');exit;
  100. }
  101. public function actionAdd()
  102. {
  103. $data = [];
  104. foreach ($this->fileds as $filed => $v) {
  105. $data[$filed] = Yii::app()->request->getParam($filed,'');
  106. if ($filed == 'status' && $data['status'] == 100) {
  107. CommonFn::requestAjax(false, '请选择状态', array(
  108. 'error' => $filed,
  109. ));
  110. }
  111. if (empty($data[$filed])) {
  112. CommonFn::requestAjax(false, '请填写完整数据', array($filed));
  113. }
  114. }
  115. $worker = new Worker();
  116. $worker->user_info = [
  117. 'name' => $data['name'],
  118. 'mobile' => $data['mobile'],
  119. 'phone' => $data['phone'],
  120. 'email' => $data['email'],
  121. 'birth' => strtotime($data['birth']),
  122. 'sex' => (int)$data['sex'],
  123. ];
  124. $worker->status = (int)$data['status'];
  125. $worker->address = [
  126. 'address1' => $data['address1'],
  127. 'address2' => $data['address2'],
  128. 'address3' => $data['address3'],
  129. ];
  130. $worker->address_number = $data['address_number'];
  131. $worker->user_id = $data['user_id'];
  132. $worker->register_time = time();
  133. $worker->card_number = $data['card_number'];
  134. $worker->certificate = $data['certificate'];
  135. $worker->people = $data['people'];
  136. $worker->care_institutions = $data['care_institutions'];
  137. $worker->desc = $data['desc'];
  138. $worker->save();
  139. CommonFn::requestAjax(true,'创建成功');exit;
  140. }
  141. }