JWorkerController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 ChBaseController
  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. ];
  29. public function actionList()
  30. {
  31. $pageParams = CommonFn::getPageParams();
  32. $search = Yii::app()->request->getParam('search', '');
  33. $status = Yii::app()->request->getParam('status', 0);
  34. $criteria = new EMongoCriteria($pageParams);
  35. if ($search) {
  36. $criteria->addCond('user_info.name','or',new MongoRegex('/' . $search . '/'));
  37. }
  38. if($status != 100 && $status > 0) {
  39. $criteria->status('==',(int)$status);
  40. }
  41. $cursor = Worker::model()->findAll($criteria);
  42. $rows = CommonFn::getRowsFromCursor($cursor);
  43. $parsedRows = Worker::model()->parse($rows);
  44. $total = $cursor->count();
  45. echo CommonFn::composeDatagridData($parsedRows, $total);
  46. }
  47. public function actionEdit()
  48. {
  49. $this->fileds['id'] = 'ID';
  50. $data = [];
  51. foreach ($this->fileds as $filed => $v) {
  52. $data[$filed] = Yii::app()->request->getParam($filed,'');
  53. if (empty($data[$filed])) {
  54. CommonFn::requestAjax(false, '请填写完整数据', array(
  55. 'error' => $filed,
  56. ));
  57. }
  58. }
  59. if (!CommonFn::isMongoId($data['id'])) {
  60. CommonFn::requestAjax(false, '修改失败', array());
  61. }
  62. $worker = Worker::get(new MongoId($data['id']));
  63. $worker->user_id = $data['user_id'];
  64. $worker->user_info = [
  65. 'name' => $data['name'],
  66. 'mobile' => $data['mobile'],
  67. 'phone' => $data['phone'],
  68. 'email' => $data['email'],
  69. 'birth' => strtotime($data['birth']),
  70. 'sex' => (int)$data['sex'],
  71. ];
  72. $worker->address = [
  73. 'address1' => $data['address1'],
  74. 'address2' => $data['address2'],
  75. 'address3' => $data['address3'],
  76. ];
  77. $worker->address_number = $data['address_number'];
  78. $worker->card_number = $data['card_number'];
  79. $worker->certificate = $data['certificate'];
  80. $worker->care_institutions = $data['care_institutions'];
  81. $worker->desc = $data['desc'];
  82. $worker->people = $data['people'];
  83. $worker->save();
  84. CommonFn::requestAjax(true,'修改成功');exit;
  85. }
  86. public function actionAdd()
  87. {
  88. $data = [];
  89. foreach ($this->fileds as $filed => $v) {
  90. $data[$filed] = Yii::app()->request->getParam($filed,'');
  91. if (empty($data[$filed])) {
  92. CommonFn::requestAjax(false, '请填写完整数据', array($filed));
  93. }
  94. }
  95. $worker = new Worker();
  96. $worker->user_info = [
  97. 'name' => $data['name'],
  98. 'mobile' => $data['mobile'],
  99. 'phone' => $data['phone'],
  100. 'email' => $data['email'],
  101. 'birth' => strtotime($data['birth']),
  102. 'sex' => (int)$data['sex'],
  103. ];
  104. $worker->status = 2;
  105. $worker->address = [
  106. 'address1' => $data['address1'],
  107. 'address2' => $data['address2'],
  108. 'address3' => $data['address3'],
  109. ];
  110. $worker->address_number = $data['address_number'];
  111. $worker->user_id = $data['user_id'];
  112. $worker->register_time = time();
  113. $worker->card_number = $data['card_number'];
  114. $worker->certificate = $data['certificate'];
  115. $worker->people = $data['people'];
  116. $worker->care_institutions = $data['care_institutions'];
  117. $worker->desc = $data['desc'];
  118. $worker->save();
  119. CommonFn::requestAjax(true,'创建成功');exit;
  120. }
  121. }