123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * Created by north.Deng's MAC
- * User: north.Deng
- * Date: 2018/2/28
- * Time: 下午12:30
- * description :
- */
- class JCommunityController extends AdminController
- {
- protected $fileds = [
- 'user_id' => '用户ID',
- 'name' => '用户名',
- 'mobile' => '手机',
- 'phone' => '电话',
- 'email' => '邮箱',
- 'birth' => '生日',
- 'sex' => '性别',
- 'address' => '地址',
- 'address_number' => '邮编',
- 'street' => '街道',
- 'card_number' => '身份证号',
- 'desc' => '备注',
- ];
- public function actionIndex()
- {
- $status = [];
- $this->render('index',[
- 'fileds' => $this->fileds,
- 'status' => $status,
- ]);
- }
- public function actionList()
- {
- $pageParams = CommonFn::getPageParams();
- $search = Yii::app()->request->getParam('search', '');
- $criteria = new EMongoCriteria($pageParams);
- if ($search) {
- $criteria->addCond('user_info.name','or',new MongoRegex('/' . $search . '/'));
- }
- $cursor = Community::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = Community::model()->parse($rows);
- $total = $cursor->count();
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- public function actionEdit()
- {
- $this->fileds['id'] = 'ID';
- $data = [];
- foreach ($this->fileds as $filed => $v) {
- $data[$filed] = Yii::app()->request->getParam($filed,'');
- if (empty($data[$filed])) {
- CommonFn::requestAjax(false, '请填写完整数据', array(
- 'error' => $filed,
- ));
- }
- }
- if (!CommonFn::isMongoId($data['id'])) {
- CommonFn::requestAjax(false, '修改失败', array());
- }
- $community = Community::get(new MongoId($data['id']));
- $community->user_id = $data['user_id'];
- $community->user_info = [
- 'name' => $data['name'],
- 'mobile' => $data['mobile'],
- 'phone' => $data['phone'],
- 'email' => $data['email'],
- 'birth' => strtotime($data['birth']),
- 'sex' => (int)$data['sex'],
- ];
- $community->address_number = $data['address_number'];
- $community->address = $data['address'];
- $community->street = $data['street'];
- $community->card_number = $data['card_number'];
- $community->desc = $data['desc'];
- $community->save();
- CommonFn::requestAjax(true,'修改成功');exit;
- }
- public function actionAdd()
- {
- $data = [];
- foreach ($this->fileds as $filed => $v) {
- $data[$filed] = Yii::app()->request->getParam($filed,'');
- if ($filed == 'status' && $data['status'] == 100) {
- CommonFn::requestAjax(false, '请选择状态', array(
- 'error' => $filed,
- ));
- }
- if (empty($data[$filed])) {
- CommonFn::requestAjax(false, '请填写完整数据', array($filed));
- }
- }
- $community = new Community();
- $community->user_id = $data['user_id'];
- $community->user_info = [
- 'name' => $data['name'],
- 'mobile' => $data['mobile'],
- 'phone' => $data['phone'],
- 'email' => $data['email'],
- 'birth' => strtotime($data['birth']),
- 'sex' => (int)$data['sex'],
- ];
- $community->register_time = time();
- $community->address_number = $data['address_number'];
- $community->address = $data['address'];
- $community->street = $data['street'];
- $community->card_number = $data['card_number'];
- $community->desc = $data['desc'];
- $community->address = $data['address'];
- $community->save();
- CommonFn::requestAjax(true,'创建成功');exit;
- }
- }
|