'用户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; } }