123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- /**
- * Created by north.Deng's MAC
- * User: north.Deng
- * Date: 2018/3/1
- * Time: 上午10:44
- * description :
- */
- class JgEmpolyerController extends JBaseController
- {
- public function actionRegister()
- {
- $store_id = Yii::app()->request->getParam('storeId','');
- if ($store_id == '') {
- CommonFn::requestAjax(false, 'store_id 错误', array());exit;
- }
- $isReg = Yii::app()->request->getParam('isReg',false);
- $user_id = Yii::app()->request->getParam('userId','');
- if (!CommonFn::isMongoId($user_id)) {
- CommonFn::requestAjax(false, 'user_id 错误', array());exit;
- }
- $c = new EMongoCriteria();
- $c->store_id('==',intval($store_id));
- $c->status('==',2);
- $store = Store::model()->find($c);
- if (empty($store)) {
- CommonFn::requestAjax(false, 'store_id 错误', array());exit;
- }
- if ($isReg) {
- $c = new EMongoCriteria();
- $c->user_id('==',new MongoId($user_id));
- $emp = JGEmploye::model()->find($c);
- if (empty($emp) ) {
- CommonFn::requestAjax(false, '未注册', array());exit;
- } else {
- CommonFn::requestAjax(false, '已注册', array());exit;
- }
- }
- $name = Yii::app()->request->getParam('userName','');
- $address1 = Yii::app()->request->getParam('address1','');
- $address2 = Yii::app()->request->getParam('address2','');
- $phone = Yii::app()->request->getParam('phone','');
- $work_type = Yii::app()->request->getParam('work_type','');
- $sex = Yii::app()->request->getParam('sex','');
- foreach ($work_type as &$value) {
- $value = intval($value);
- }
- sort($work_type);
- $skill = Yii::app()->request->getParam('skill','');
- foreach ($skill as &$value) {
- $value = intval($value);
- }
- sort($skill);
- $readme = Yii::app()->request->getParam('readme','');
- $emp = new JGEmploye();
- $emp->user_id = new MongoId($user_id);
- $emp->store_id = $store->store_id;
- $emp->name = $name;
- $emp->address = array($address1,$address2);
- $emp->phone = $phone;
- $emp->sex = intval($sex);
- $emp->work_type = $work_type;
- $emp->skill = $skill;
- $emp->readme = $readme;
- $emp->status = 0;
- $emp->reg_time = time();
- $emp->save();
- CommonFn::requestAjax(true, '注册成功', array());
- }
- public function actionInfo()
- {
- $user_id = Yii::app()->request->getParam('userId','');
- if (!CommonFn::isMongoId($user_id)) {
- CommonFn::requestAjax(false, 'user_id 错误', array());exit;
- }
- $c = new EMongoCriteria();
- $c->user_id('==',new MongoId($user_id));
- $emp = JGEmploye::model()->find($c);
- if (empty($emp)) {
- CommonFn::requestAjax(false, '查无此人', array());exit;
- } else {
- CommonFn::requestAjax(true, '成功', $emp);exit;
- }
- }
- public function actionIsEmp()
- {
- }
- public function actionEdit()
- {
- $id = Yii::app()->request->getParam('id','');
- $status = Yii::app()->request->getParam('status','');
- $name = Yii::app()->request->getParam('name','');
- $phone = Yii::app()->request->getParam('phone','');
- $cart_num = Yii::app()->request->getParam('cart_num','');
- $star = Yii::app()->request->getParam('star','');
- $readme = Yii::app()->request->getParam('readme','');
- $store_id = Yii::app()->request->getParam('store_id','');
- $desc = Yii::app()->request->getParam('desc','');
- $work_time_part = Yii::app()->request->getParam('work_time_part','');
- $birth_time = intval(Yii::app()->request->getParam('birth_time',''));
- $work_time = intval(Yii::app()->request->getParam('work_time',''));
- $address1 = Yii::app()->request->getParam('address1','');
- $address2 = Yii::app()->request->getParam('address2','');
- $skills = Yii::app()->request->getParam('skill');
- $work_types = Yii::app()->request->getParam('work_types');
- foreach ($work_types as &$value) {
- $value = intval($value);
- }
- sort($work_types);
- foreach ($skills as &$value) {
- $value = intval($value);
- }
- sort($skills);
- if (intval($star) > 5) {
- CommonFn::requestAjax(false,'星级评定最大为5星');exit;
- }
- if (!CommonFn::isMongoId($id)) {
- CommonFn::requestAjax(false,'id错误');exit;
- }
- $flag = function () use ($store_id){
- $criteria = new EMongoCriteria();
- $criteria->store_id('==',intval($store_id));
- $store = Store::model()->find($criteria);
- if (empty($store)) {
- return true;
- } else {
- return false;
- }
- };
- if ($flag()) {
- CommonFn::requestAjax(false,'门店不存在');exit;
- }
- $employe = JGEmploye::get(new MongoId($id));
- if (!empty($status)) {
- $employe->status = intval($status);
- }
- if (!empty($name)) {
- $employe->name = $name;
- }
- if (!empty($phone)) {
- $employe->phone = $phone;
- }
- if (!empty($cart_num)) {
- $employe->cart_num = $cart_num;
- }
- if (!empty($store_id)) {
- $employe->store_id = intval($store_id);
- }
- if (!empty($star)) {
- $employe->star = intval($star);
- }
- if (!empty($readme)) {
- $employe->readme = $readme;
- }
- if (!empty($birth_time)) {
- $employe->birth_time = $birth_time;
- }
- if (!empty($work_time)) {
- $employe->work_time = $work_time;
- }
- if (!empty($address1) ) {
- $employe->address[0] = $address1;
- }
- if (!empty($address2) ) {
- $employe->address[1] = $address2;
- }
- if (!empty($work_time_part) ) {
- $employe->work_time_part = json_decode($work_time_part,true);
- }
- if (!empty($skills) ) {
- $employe->skill = $skills;
- }
- if (!empty($work_types) ) {
- $employe->work_type = $work_types;
- }
- if (!empty($desc) ) {
- $employe->desc = $desc;
- }
- $employe->save();
- CommonFn::requestAjax(true,'保存成功');exit;
- }
- public function actionList()
- {
- $store_id = Yii::app()->request->getParam('storeId','');
- $work_time = Yii::app()->request->getParam('work_time','');
- $work_type = intval(Yii::app()->request->getParam('work_type',''));
- $skill = intval(Yii::app()->request->getParam('skill',''));
- $work_time_part = json_decode(Yii::app()->request->getParam('work_time_part',''),true);
- if ($store_id == '') {
- CommonFn::requestAjax(false, 'store_id 错误', array());exit;
- }
- $search = Yii::app()->request->getParam('search', '');
- $user_id = Yii::app()->request->getParam('userId','');
- if (!CommonFn::isMongoId($user_id)) {
- CommonFn::requestAjax(false, 'user_id 错误', array());exit;
- }
- $pageParams = CommonFn::getPageParams();
- $status = intval(Yii::app()->request->getParam('status', 100));
- $criteria = new EMongoCriteria($pageParams);
- $criteria->store_id('==',intval($store_id));
- if ($status != 100 ) {
- $criteria->status('==',$status);
- }
- if ($search != '' && !CommonFn::isMongoId($search)){
- $criteria->addCond('name','or', new MongoRegex('/' . $search . '/'));
- $criteria->addCond('phone','or', new MongoRegex('/' . $search . '/'));
- }
- if (!empty($work_type)) {
- $criteria->work_type('==',$work_type);
- }
- if (!empty($skill)) {
- $criteria->skill('==',$skill);
- }
- if ($work_time != '') {
- $criteria->work_time('<=',intval($work_time));
- }
- $criteria->sort('socre',EMongoCriteria::SORT_DESC);
- $cursor = JGEmploye::model()->findAll($criteria);
- $rows = CommonFn::getRowsFromCursor($cursor);
- $parsedRows = JGEmploye::model()->parse($rows);
- $total = $cursor->count();
- if (!empty($work_time_part)) {
- $data = array();
- foreach ($parsedRows as $value) {
- if (is_array($value['work_time_part'])) {
- $tmp = $value['work_time_part'];
- for ($i=0;$i<count($tmp);$i++) {
- $v = $tmp[$i];
- if ($v['start'] <= $work_time_part['start'] && $v['end'] >= $work_time_part['end']) {
- $data[] = $value;break;
- }
- }
- }
- }
- $total = count($data);
- echo CommonFn::composeDatagridData($data, $total);exit;
- }
- echo CommonFn::composeDatagridData($parsedRows, $total);
- }
- }
|