123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- * Created by north.Deng's MAC
- * User: north.Deng
- * Date: 2018/2/28
- * Time: 下午12:30
- * description :
- */
- class JWorkerController extends AdminController
- {
- protected $fileds = [
- 'user_id' => '用户ID',
- 'name' => '用户名',
- 'mobile' => '手机',
- 'phone' => '电话',
- 'email' => '邮箱',
- 'birth' => '生日',
- 'sex' => '性别',
- 'address1' => '户籍地址',
- 'address2' => '居住地址',
- 'address3' => '通信地址',
- 'address_number' => '邮编',
- 'card_number' => '身份证号',
- 'certificate' => '证书',
- 'people' => '居委会',
- 'care_institutions' => '护理机构',
- 'desc' => '备注',
- 'status' => '状态',
- ];
- public function actionIndex()
- {
- $status = CommonFn::getComboboxData(Worker::$status_options, 100, true, 100);
- $this->render('index',[
- 'fileds' => $this->fileds,
- 'status' => $status,
- ]);
- }
- public function actionList()
- {
- $pageParams = CommonFn::getPageParams();
- $search = Yii::app()->request->getParam('search', '');
- $status = Yii::app()->request->getParam('status', 0);
- $criteria = new EMongoCriteria($pageParams);
- if ($search) {
- $criteria->addCond('user_info.name','or',new MongoRegex('/' . $search . '/'));
- }
- if($status != 100 && $status > 0) {
- $criteria->status('==',(int)$status);
- }
- $cursor = Worker::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = Worker::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 ($filed == 'status' && $data['status'] == 100) {
- CommonFn::requestAjax(false, '请选择状态', array(
- 'error' => $filed,
- ));
- }
- if (empty($data[$filed])) {
- CommonFn::requestAjax(false, '请填写完整数据', array(
- 'error' => $filed,
- ));
- }
- }
- if (!CommonFn::isMongoId($data['id'])) {
- CommonFn::requestAjax(false, '修改失败', array());
- }
- $worker = Worker::get(new MongoId($data['id']));
- $worker->user_id = $data['user_id'];
- $worker->user_info = [
- 'name' => $data['name'],
- 'mobile' => $data['mobile'],
- 'phone' => $data['phone'],
- 'email' => $data['email'],
- 'birth' => strtotime($data['birth']),
- 'sex' => (int)$data['sex'],
- ];
- $worker->status = (int)$data['status'];
- $worker->address = [
- 'address1' => $data['address1'],
- 'address2' => $data['address2'],
- 'address3' => $data['address3'],
- ];
- $worker->address_number = $data['address_number'];
- $worker->card_number = $data['card_number'];
- $worker->certificate = $data['certificate'];
- $worker->care_institutions = $data['care_institutions'];
- $worker->desc = $data['desc'];
- $worker->people = $data['people'];
- $worker->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));
- }
- }
- $worker = new Worker();
- $worker->user_info = [
- 'name' => $data['name'],
- 'mobile' => $data['mobile'],
- 'phone' => $data['phone'],
- 'email' => $data['email'],
- 'birth' => strtotime($data['birth']),
- 'sex' => (int)$data['sex'],
- ];
- $worker->status = (int)$data['status'];
- $worker->address = [
- 'address1' => $data['address1'],
- 'address2' => $data['address2'],
- 'address3' => $data['address3'],
- ];
- $worker->address_number = $data['address_number'];
- $worker->user_id = $data['user_id'];
- $worker->register_time = time();
- $worker->card_number = $data['card_number'];
- $worker->certificate = $data['certificate'];
- $worker->people = $data['people'];
- $worker->care_institutions = $data['care_institutions'];
- $worker->desc = $data['desc'];
- $worker->save();
- CommonFn::requestAjax(true,'创建成功');exit;
- }
- }
|