JCommunityController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 JCommunityController extends AdminController
  10. {
  11. protected $fileds = [
  12. 'user_id' => '用户ID',
  13. 'name' => '用户名',
  14. 'mobile' => '手机',
  15. 'phone' => '电话',
  16. 'email' => '邮箱',
  17. 'birth' => '生日',
  18. 'sex' => '性别',
  19. 'address' => '地址',
  20. 'address_number' => '邮编',
  21. 'street' => '街道',
  22. 'card_number' => '身份证号',
  23. 'desc' => '备注',
  24. ];
  25. public function actionIndex()
  26. {
  27. $status = [];
  28. $this->render('index',[
  29. 'fileds' => $this->fileds,
  30. 'status' => $status,
  31. ]);
  32. }
  33. public function actionList()
  34. {
  35. $pageParams = CommonFn::getPageParams();
  36. $search = Yii::app()->request->getParam('search', '');
  37. $criteria = new EMongoCriteria($pageParams);
  38. if ($search) {
  39. $criteria->addCond('user_info.name','or',new MongoRegex('/' . $search . '/'));
  40. }
  41. $cursor = Community::model()->findAll($criteria);
  42. $rows = CommonFn::getRowsFromCursor($cursor);
  43. $parsedRows = Community::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. $community = Community::get(new MongoId($data['id']));
  63. $community->user_id = $data['user_id'];
  64. $community->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. $community->address_number = $data['address_number'];
  73. $community->address = $data['address'];
  74. $community->street = $data['street'];
  75. $community->card_number = $data['card_number'];
  76. $community->desc = $data['desc'];
  77. $community->save();
  78. CommonFn::requestAjax(true,'修改成功');exit;
  79. }
  80. public function actionAdd()
  81. {
  82. $data = [];
  83. foreach ($this->fileds as $filed => $v) {
  84. $data[$filed] = Yii::app()->request->getParam($filed,'');
  85. if ($filed == 'status' && $data['status'] == 100) {
  86. CommonFn::requestAjax(false, '请选择状态', array(
  87. 'error' => $filed,
  88. ));
  89. }
  90. if (empty($data[$filed])) {
  91. CommonFn::requestAjax(false, '请填写完整数据', array($filed));
  92. }
  93. }
  94. $community = new Community();
  95. $community->user_id = $data['user_id'];
  96. $community->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. $community->register_time = time();
  105. $community->address_number = $data['address_number'];
  106. $community->address = $data['address'];
  107. $community->street = $data['street'];
  108. $community->card_number = $data['card_number'];
  109. $community->desc = $data['desc'];
  110. $community->address = $data['address'];
  111. $community->save();
  112. CommonFn::requestAjax(true,'创建成功');exit;
  113. }
  114. }