public function run($code) { if (Yii::app()->request->isAjaxRequest) { $user = User::model()->findByAttributes(array('id' => Yii::app()->user->id)); $result = Coding::isValidCode($code); $hasused = Coding::hasUsedCode($code); if ($result['code'] == 200 && $user->status >= 3 && !$hasused) { $code = Code::model()->findByAttributes(array('code' => $code)); $code->times--; $code->save(); $codeused = new CodeUsed(); $codeused->codeId = $code->id; $codeused->userId = Yii::app()->user->id; $codeused->createTime = date('YmdHis'); $codeused->save(); $user->status = 4; $user->save(); $ccode = new CCode(); $result = $ccode->getproduct($code->code); echo CJSON::encode(array('code' => 200, 'mes' => 'success', 'data' => $result['data'])); } else { echo CJSON::encode(array('code' => 500, 'mes' => 'fail')); } } }
public function run() { $this->controller->pageTitle = 'Book a Workspace'; $now = date('Y-m-d', time()); $date = Yii::app()->request->getParam('date'); $date = $date == '' ? $now : $date; $proxy = new CHub(); $result = $proxy->getHubList(); if (Yii::app()->request->isAjaxRequest) { $id = Yii::app()->request->getParam('id'); $hub = Yii::app()->request->getParam('hub'); $date = Yii::app()->request->getParam('date'); if ($id) { $date = date('Ymd', strtotime($date)); $record = Reservations::model()->findAll('startTime =' . date('Ymd', strtotime($date)) . '100000' . ' and userId=' . Yii::app()->user->id . ' and type=1 and status=1'); $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1)); if ($orderid) { foreach ($orderid as $list) { $order = OrderProduct::model()->find('endDate>=' . $date . ' and orderId=' . $list['id'] . ' and startDate<=' . $date); if ($order) { break; } } if ($order) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => $order['totalTimes'] - $order['usedTimes'], 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { $code = CodeUsed::model()->findAll('userId=' . Yii::app()->user->id); if ($code) { foreach ($code as $list) { $value = Code::model()->find('endDate>=' . $date . ' and id=' . $list['codeId'] . ' and startDate<=' . $date); if ($value) { break; } } if ($value) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 1, 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } } else { $proxy = new CReservation(); $result = $proxy->getNumber($date); if ($result['code'] == 200) { $data = array('code' => 200, 'data' => $result); echo CJSON::encode($data); } } } else { $this->controller->render('workspacelist', array('data' => $result['data'], 'date' => $date)); } }
public function run() { if (Yii::app()->request->isAjaxRequest) { try { $name = Yii::app()->request->getParam('name'); $mobile = Yii::app()->request->getParam('mobile'); $code = Yii::app()->request->getParam('code'); $email = Yii::app()->request->getParam('email'); $password = Yii::app()->request->getParam('password'); $actcode = Yii::app()->request->getParam('actcode'); $_code = Yii::app()->session['regist_code' . $mobile]; if ($_code && $_code == $code) { $item = Yii::app()->db->createCommand('select * from user where mobile=' . $mobile . ' and status=0')->queryRow(); if (!$item) { $user = new User(); $user->nickName = $name; $user->mobile = $mobile; $user->email = $email; $user->status = 4; if ($password) { $user->password = md5($password); } $wechat = Yii::app()->session['wechat']; if ($wechat) { // $user->nickName = $wechat['nickname']; $user->portrait = $wechat['headimgurl']; $user->gender = $wechat['sex']; } //邀请人公司赋值 $codedetail = Code::model()->findByAttributes(array('code' => $actcode)); $companyId = User::model()->findByAttributes(array('id' => $codedetail->userId))->company; $user->company = $companyId; $user->insert(); //消息系统初始化 EasemobHelper::initIM($user->id, array('username' => $user->id, 'password' => 'nakedim', 'nickname' => $name)); $user->type = 2; $user->isBindIM = 1; $user->save(); $codedetail->times--; $codedetail->save(); $codeused = new CodeUsed(); $codeused->codeId = $codedetail->id; $codeused->userId = $user->id; $codeused->createTime = date("Y-m-d"); $codeused->save(); Yii::app()->session['user'] = $user; } else { Yii::log(print_r($item, 1), CLogger::LEVEL_ERROR, 'info'); Yii::app()->session['user'] = $item; } //如果用户注册过了,没付款不生成新的用户,读取数据库里的用户信息 $identity = new UserIdentity(); $identity->registAuth($user); $duration = Yii::app()->getComponent('session')->getTimeout(); Yii::app()->user->login($identity, $duration); echo CJSON::encode(array('code' => 200, 'message' => 'success')); } else { echo CJSON::encode(array('code' => 500, 'message' => '验证码错误')); } } catch (CException $e) { Yii::log($e->getMessage(), CLogger::LEVEL_ERROR); echo CJSON::encode(array('code' => 500, 'message' => '注册失败')); } } }
public function run($id = null) { $this->controller->pageTitle = "Company"; if (!$id) { if (Yii::app()->request->isAjaxRequest) { $id = Yii::app()->request->getParam('id'); $name = Yii::app()->request->getParam('name'); $service = Yii::app()->request->getParam('service'); $result = Company::model()->findByAttributes(array('name' => $name)); if ($result && $result['ownerId'] != Yii::app()->user->id) { echo CJSON::encode(array('code' => 400, 'message' => 'HAVING')); die; } else { if (!$id) { $company = new Company(); $now = date('Y-m-d H:i:s'); $company->createTime = $now; $company->save(); $companyid = Company::model()->findByAttributes(array('createTime' => $now)); for ($i = 0; $i < count($service); $i++) { $proxy = new Service_company(); $proxy->serviceId = $service[$i]; $proxy->companyId = $companyid['id']; $proxy->save(); } } else { $company = Company::model()->findByAttributes(array('id' => $id)); $company->updateTime = date('Y-m-d H:i:s'); $proxy = Service_company::model()->findAllByAttributes(array('companyId' => $id)); foreach ($proxy as $list) { $list->status = 0; $list->save(); } for ($i = 0; $i < count($service); $i++) { $dp = new Service_company(); $dp->serviceId = $service[$i]; $dp->companyId = $company['id']; $dp->save(); } } $company->name = $name; $company->ownerId = Yii::app()->user->id; // FIXME $company->email = Yii::app()->request->getParam('email'); $company->phone = Yii::app()->request->getParam('phone'); $company->website = Yii::app()->request->getParam('website'); $company->logo = Yii::app()->request->getParam('logo'); $company->location = User::model()->findByAttributes(array('id' => Yii::app()->user->id))['location']; $company->background = Yii::app()->request->getParam('background'); $company->introduction = Assist::removeXSS(Yii::app()->request->getParam('introduction')); $company->facebookid = Yii::app()->request->getParam('facebookid'); $company->linkedinid = Yii::app()->request->getParam('linkedinid'); $company->save(); $user = User::model()->findByAttributes(array('id' => Yii::app()->user->id)); if ($user['type'] == 1) { $user->status = 4; } else { if ($user['type'] == 3) { $user->status = 4; } } $user->company = $company->id; $user->save(); //所有公司员工设置公司 $code = Code::model()->findAllByAttributes(array('userId' => Yii::app()->user->id, 'status' => 1)); if ($code) { foreach ($code as $list) { $user = CodeUsed::model()->findAll('codeId=' . $list['id']); if ($user) { foreach ($user as $value) { $item = User::model()->findByAttributes(array('id' => $value['userId'])); $item->company = $company->id; $item->save(); } } } } echo CJSON::encode(array('code' => 200, 'message' => 'SUCCESS', 'data' => array('status' => $status))); } } else { $firservice = Service::model()->findAll("parentId is null"); foreach ($firservice as $key) { $a[$key['name']] = Service::model()->findAllByAttributes(array('parentId' => $key['id'])); // array_push($a,$key['name']); } $this->controller->render('updateProfile', array('totalservice' => $a)); } } else { $id = Yii::app()->request->getParam('id'); $company = Company::model()->findByAttributes(array('id' => $id)); $myservice = Service_company::model()->findAllByAttributes(array('companyId' => $company['id'], 'status' => 1)); $user = User::model()->findByAttributes(array('id' => Yii::app()->user->id)); foreach ($myservice as $list) { $array[] = Service::model()->findByAttributes(array('id' => $list['serviceId'])); } $firservice = Service::model()->findAll("parentId is null"); foreach ($firservice as $key) { $a[$key['name']] = Service::model()->findAllByAttributes(array('parentId' => $key['id'])); // array_push($a,$key['name']); } // var_dump($a);die; $this->controller->render('updateProfile', array('company' => $company, 'status' => $user['status'], 'myservice' => $array, 'totalservice' => $a)); } }