Пример #1
0
 public function update($id)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $order = Order::model()->findByAttributes(array('id' => $id));
         $order->status = 1;
         $ordercompanyproduct = OrderCompany::model()->findAllByAttributes(array('orderId' => $id));
         if ($ordercompanyproduct) {
             foreach ($ordercompanyproduct as &$value) {
                 $code = Code::model()->findByAttributes(array('ordercompanyproductId' => $value->id));
                 $code->status = 1;
                 $value->status = 1;
                 if (!$value->save() || !$code->save()) {
                     throw new Exception("Error Processing Request", 1);
                 }
             }
         }
         $order->save();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         Yii::log('update fail', CLogger::LEVEL_ERROR, 'updatedb');
         return array('code' => 500, 'mes' => 'update fail');
     }
     return array('code' => 200, 'mes' => 'success');
 }
Пример #2
0
 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'));
         }
     }
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
 public static function checkCode($code)
 {
     $result = Code::model()->findByAttributes(array('code' => $code));
     if ($result) {
         $code = rand(10000000, 99999999);
         self::checkCode($code);
         return self::checkCode($code);
     } else {
         return true;
     }
 }
Пример #5
0
 public function run()
 {
     $this->controller->pageTitle = "Profile";
     if (Yii::app()->request->isAjaxRequest) {
         $id = Yii::app()->user->id;
         $user = User::model()->findByAttributes(array('id' => $id));
         $user->nickName = Yii::app()->request->getParam('nickName');
         $user->portrait = Yii::app()->request->getParam('portrait');
         Yii::app()->user->setState('portrait', Yii::app()->request->getParam('portrait'));
         $user->background = Yii::app()->request->getParam('background');
         $user->title = Yii::app()->request->getParam('title');
         $user->website = Yii::app()->request->getParam('website');
         $user->description = Assist::removeXSS(Yii::app()->request->getParam('description'));
         $user->birthday = Yii::app()->request->getParam('birthday');
         $user->gender = Yii::app()->request->getParam('gender');
         $user->location = Yii::app()->request->getParam('hub');
         $skills = preg_replace('/,+/', ',', Yii::app()->request->getParam('skills'));
         $skills = preg_replace('/,+/', ',', $skills);
         $user->skills = trim($skills, ',');
         $interests = preg_replace('/,+/', ',', Yii::app()->request->getParam('interests'));
         $interests = preg_replace('/,+/', ',', $interests);
         $user->interests = trim($interests, ',');
         //$user->wechatid = Yii::app()->request->getParam('wechatid');
         $user->facebookid = Yii::app()->request->getParam('facebookid');
         $user->twitterid = Yii::app()->request->getParam('twitterid');
         $user->linkedinid = Yii::app()->request->getParam('linkedinid');
         $user->instagramid = Yii::app()->request->getParam('instagramid');
         $status = Yii::app()->request->getParam('status');
         $code = Code::model()->findByAttributes(array('userId' => $id));
         if ($status == 1) {
             $user->status = 2;
         }
         $havecode = empty($code) ? 0 : 1;
         if ($user->save()) {
             echo CJSON::encode(array('code' => 200, 'message' => 'success', 'data' => $havecode));
         }
     } else {
         $id = Yii::app()->user->id;
         $user = User::model()->findByAttributes(array('id' => $id));
         $proxy = new CHub();
         $hub = $proxy->getHubList();
         $this->controller->render('updateProfile', array('user' => $user, 'hub' => $hub['data']));
     }
 }
Пример #6
0
foreach ($code_info as $_code_info_v) {
    $district_options[$_code_info_v->code_value] = $_code_info_v->code_meaning;
}
echo $form->dropDownList($addr_info, 'addr_district', $district_options);
?>
			</td>
		</tr>
		<tr>
			<td>
				<?php 
echo $form->label($cust_info, 'cust_source');
?>
			</td>
			<td>
				<?php 
$code_model = Code::model();
$query = 'select * from tbl_code where code_tbl_name = "tbl_customer" and code_name = "cust_source"';
$code_info = $code_model->findAllBySql($query);
$cust_source_options = array();
foreach ($code_info as $_code_info_v) {
    $cust_source_options[$_code_info_v->code_value] = $_code_info_v->code_meaning;
}
echo $form->dropDownList($cust_info, 'cust_source', $cust_source_options);
?>
			</td>
		</tr>
		<tr class="alt">
			<td>
				<?php 
echo $form->label($cust_info, 'cust_in_time');
?>
Пример #7
0
 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' => '注册失败'));
         }
     }
 }
Пример #8
0
 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));
     }
 }
Пример #9
0
 /**
  * 按照选定的日期和美疗师来显示预约(包括普通预约和1元预约),用以计算金额
  * @throws CException
  */
 public function actionSelectAptmByDay()
 {
     define('APTM_ID', 0);
     define('COMM_NAME', 1);
     define('CUST_NAME', 2);
     define('PRICE', 3);
     if (isset($_POST['beau_id']) && $_POST['beau_id'] != 0 && isset($_POST['from_date_year']) && isset($_POST['from_date_month']) && isset($_POST['from_date_day']) && isset($_POST['to_date_year']) && isset($_POST['to_date_month']) && isset($_POST['to_date_day'])) {
         //整理日期
         $from_date = $_POST['from_date_year'] . '-' . $_POST['from_date_month'] . '-' . $_POST['from_date_day'];
         $to_date = $_POST['to_date_year'] . '-' . $_POST['to_date_month'] . '-' . $_POST['to_date_day'];
         $from_date = date("Y-m-d H:i:s", strtotime("{$from_date}"));
         $to_date = date('Y-m-d H:i:s', strtotime("{$to_date} +1 day"));
         if ($from_date > $to_date) {
             echo "<script>alert('起始日期应该早于或等于终了日期!');</script>";
         }
         //TODO:金额信息较复杂,应该需要再建一张表来计算,需要讨论
         //传递形式:
         /*
         xxxx-xx-xx
         ------------------------------------------
         |aptmid|aaaa                             |
         |项目名 |aaaa                             |
         |客户名 |bbbb                             |
         |金额: |111                              |
         ------------------------------------------
         xxxx-xx-xx
         ------------------------------------------
         |aptmid|aaaa                             |
         |项目名 |aaaa                             |
         |客户名 |bbbb                             |
         |金额: |111                              |
         ------------------------------------------
         |aptmid|aaaa                             |
         |项目名 |aaaa                             |
         |客户名 |bbbb                             |
         |金额: |111                              |
         ------------------------------------------
         */
         //定义数组
         $day_count = $this->countDays($from_date, $to_date);
         $aptm_info_by_day = array($day_count);
         //查询普通预约
         //(从tbl_appointment的预约日期入手,包括关联的tbl_order_item,tbl_commodity以获取客户名,项目名等信息)
         $aptm_model = Aptm::model();
         $query = 'select * from tbl_appointment where aptm_beau_id = ' . $_POST['beau_id'] . ' and aptm_time >= "' . $from_date . '"' . ' and aptm_time < "' . $to_date . '"';
         $aptm_info = $aptm_model->findAllBySql($query);
         if (isset($aptm_info)) {
             for ($cnt_day = 0; $cnt_day < $day_count; $cnt_day++) {
                 $counter_by_day = 0;
                 foreach ($aptm_info as $_v_aptm_info) {
                     $day_selected = date('Y-m-d', strtotime("{$from_date}" . ' +' . $cnt_day . ' day'));
                     $day_compare = date('Y-m-d', strtotime($_v_aptm_info->aptm_time));
                     if ($day_selected == $day_compare) {
                         //                            $info_by_day[APTM_ID] = $_v_aptm_info->pk_aptm_id;
                         //                            $info_by_day[CUST_NAME] = $_v_aptm_info->aptm_cust_name;
                         //                            $info_by_day[COMM_NAME] = '未取得';
                         //                            $info_by_day[PRICE] = 0;
                         $info_by_day = new InfoByDay();
                         $info_by_day->aptm_id = $_v_aptm_info->pk_aptm_id;
                         $info_by_day->cust_name = $_v_aptm_info->aptm_cust_name;
                         //查询tbl_order_item表以取得commodity_id
                         $order_item_model = Order_Item::model();
                         $order_item_info = $order_item_model->findByPk($_v_aptm_info->aptm_ord_item_id);
                         if (isset($order_item_info)) {
                             $comm_model = Commodity::model();
                             $comm_info = $comm_model->findByPk($order_item_info->ord_item_comm_id);
                             if (isset($comm_info)) {
                                 //                                    $info_by_day[COMM_NAME] = $comm_info->comm_name;
                                 $info_by_day->comm_name = $comm_info->comm_name;
                             }
                             //TODO:此处为暂定处理,在修改金额的时候需要修改!
                             //                                $info_by_day[PRICE] = $order_item_info->ord_item_price;
                             $info_by_day->price = $order_item_info->ord_item_price;
                         }
                         $aptm_info_by_day[$cnt_day][$counter_by_day] = $info_by_day;
                         $counter_by_day++;
                     }
                 }
             }
         }
         //查询1元特殊预约
         $contact_model = Contact::model();
         $query = 'select * from tbl_contact where con_beau_id = ' . $_POST['beau_id'] . ' and con_time >="' . $from_date . '"' . ' and con_time <"' . $to_date . '"';
         $contact_info = $contact_model->findAllBySql($query);
         $contact_info_by_day = array($day_count);
         if (isset($contact_info)) {
             for ($cnt_day = 0; $cnt_day < $day_count; $cnt_day++) {
                 $counter_by_day = 0;
                 foreach ($contact_info as $_v_contact_info) {
                     //                        $info_by_day[APTM_ID] = $_v_contact_info->pk_contact_id;
                     //                        $info_by_day[CUST_NAME] = $_v_contact_info->con_name;
                     //                        $info_by_day[COMM_NAME] = '未取得';
                     //                        //TODO:此处为暂定处理,在修改金额的时候需要修改!
                     //                        $info_by_day[PRICE] = 0;
                     $info_by_day = new InfoByDay();
                     $info_by_day->aptm_id = $_v_contact_info->pk_contact_id;
                     $info_by_day->cust_name = $_v_contact_info->con_name;
                     //查询tbl_code表以获取COMM_NAME
                     $code_model = Code::model();
                     $query = 'select * from tbl_code where code_tbl_name="tbl_contact" and code_name="con_prefer" and code_value=' . $_v_contact_info->con_prefer;
                     $code_info = $code_model->findBySql($query);
                     if (isset($code_info)) {
                         //                            $info_by_day[COMM_NAME] = $code_info->code_meaning;
                         $info_by_day->comm_name = $code_info->code_meaning;
                     }
                     $contact_info_by_day[$cnt_day][$counter_by_day] = $info_by_day;
                     //TODO:此处的三维数组改为自定义类试试看
                     $counter_by_day++;
                 }
             }
         }
         //获取美疗师姓名
         $beau_model = Beautician::model();
         $beau_info = $beau_model->findByPk($_POST['beau_id']);
         $beau_name = '没名字';
         if (isset($beau_info)) {
             $beau_name = $beau_info->beau_realname;
         }
         //            //转向列表显示页面
         //            $this->redirect('./index.php?r=aptm/showAptmByDay&beau_name='.$beau_name.
         //                            'from_date='.$from_date.
         //                            'to_date='.$to_date.
         //                            'day_count='.$day_count.
         //                            'aptm_info_by_day='.$aptm_info_by_day.
         //                            'contact_info_by_day='.$contact_info_by_day);
         $this->actionShowAptmByDay($beau_name, $from_date, $to_date, $day_count, $aptm_info_by_day, $contact_info_by_day);
         return;
     }
     //有东西没有选择的话,依旧描绘当前的选择视图
     //TODO:需要将已经选择的内容回传给视图以便修改
     $this->renderPartial('selectAptmByDay');
 }