public function actionIndex() { $shop_id = Yii::app()->request->getParam('shop_id'); if (!$shop_id) { Error::output(Error::ERR_NO_SHOPID); } //查询出改商店的一些详细信息 $shopData = Shops::model()->findByPk($shop_id); if (!$shopData) { Error::output(Error::ERR_NO_SHOPID); } $shopData = CJSON::decode(CJSON::encode($shopData)); //根据店铺id查询出该店铺的菜单 $menuData = Menus::model()->with('food_sort', 'image', 'shops')->findAll(array('condition' => 't.shop_id=:shop_id AND t.status=:status', 'params' => array(':shop_id' => $shop_id, ':status' => 2))); $data = array(); foreach ($menuData as $k => $v) { $data[$k] = $v->attributes; $data[$k]['index_pic'] = $v->index_pic ? Yii::app()->params['img_url'] . $v->image->filepath . $v->image->filename : ''; $data[$k]['sort_name'] = $v->food_sort->name; $data[$k]['shop_name'] = $v->shops->name; $data[$k]['create_time'] = Yii::app()->format->formatDate($v->create_time); $data[$k]['status'] = Yii::app()->params['menu_status'][$v->status]; $data[$k]['price'] = $v->price; } Out::jsonOutput(array('shop' => $shopData, 'menus' => $data)); }
public function actionViewRoles($id) { $menus = Menus::model()->findByPk((int) $id); $model = new RolesMenus('search'); $model->unsetAttributes(); // clear any default values $model->menu_id = (int) $id; if (isset($_GET['RolesMenus'])) { $model->attributes = $_GET['RolesMenus']; } $this->render('viewRoles', array('model' => $model, 'id' => $id, 'menus' => $menus)); }
public function run() { $menus = Menus::model()->findAll(array('condition' => 'parent_id = 0 AND dynamic = 1','order' => 'position','limit'=>6)); $submenus = Menus::model()->findAll('parent_id > 0'); $menu_sub = array(); foreach($submenus as $submenu) { $menu_sub[$submenu->parent_id][] = $submenu; } $this->render('menu', array( 'menus'=> $menus, 'submenu'=>$menu_sub )); }
public static function getActionName($id) { $model = Menus::model()->findByPk((int) $id); $roles = $model->rolesMenus; $sRoles = ''; if (count($roles) > 0) { for ($i = 0; $i < count($roles); $i++) { if ($roles[$i]->role) { $sRoles .= $roles[$i]->role->role_name . ' (' . $roles[$i]->actions . ')<br/> '; } } $sRoles = substr($sRoles, 0, -2); } return $sRoles; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Menus::model()->findByPk($id); if ($model === null) { Yii::log('The requested page does not exist.'); throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function findchildLevel1($id) { if (!empty($id)) { return Menus::model()->findAll(array('condition' => 'parent_id=' . $id)); } return array(); }
public function showMenu() { if (Yii::app()->session['LOGGED_USER'] != null) { $userObj = new Users(); $userObj = Yii::app()->session['LOGGED_USER']; $value = ''; $userRoleId = $userObj->role_id; $appicationId = Roles::getAppicationIdByRoleId($userRoleId); if ($appicationId != BE) { Yii::app()->user->logout(); Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('admin/site/login')); } $userRoleMenu = RolesMenus::model()->findAll(array('condition' => 'role_id=' . $userRoleId)); $userRoleMenuId = array(); if ($userRoleMenu) { foreach ($userRoleMenu as $u) { $userRoleMenuId[] = $u->menu_id; } } $menusTemp = Menus::model()->findAll(array('condition' => 'show_in_menu="1"', 'order' => 'display_order asc')); // MAY 12, 2014 ANH DUNG ADD $menus = array(); foreach ($menusTemp as $menuTemp) { if ($menuTemp->menu_link == '') { $menus[] = $menuTemp; continue; } $aLinks = explode('/', $menuTemp->menu_link); $c = ''; // controller name $a = ''; // action name if (count($aLinks) == 2) { $c = $aLinks[1]; $a = 'Index'; } elseif (count($aLinks) == 3) { $c = $aLinks[1]; $a = ucfirst($aLinks[2]); } $aActionAllowed = ActionsUsers::getActionArrayAllowForCurrentUserByControllerName($c); $aActionAllowed = array_map('strtolower', $aActionAllowed); $aActionAllowed = array_map('trim', $aActionAllowed); // Now 14, 2014 ANH DUNG ADD if (in_array(strtolower($a), $aActionAllowed)) { $menus[] = $menuTemp; } } // MAY 12, 2014 ANH DUNG ADD $this->str = "<ul class='nav'>"; $this->str .= "<li class='nav_li'><a href='" . Yii::app()->createAbsoluteUrl('/admin') . "'>Home</a></li>"; if ($menus != NULL) { $this->findchild(0, $menus, $value, $userRoleMenuId); } $this->str .= "</ul>"; if (Yii::app()->user->id) { if (isset(Yii::app()->user->application_id) && Yii::app()->user->application_id == BE) { return $this->str; } else { return ''; } } else { return ''; } } return ''; }
public function actionLookMenu() { $shop_id = Yii::app()->request->getParam('shop_id'); if (!isset($shop_id)) { throw new CHttpException(404, Yii::t('yii', '请选择就餐类别')); } $resident_flag = Yii::app()->request->getParam('resident_flag'); if (isset($resident_flag)) { throw new CHttpException(404, Yii::t('yii', '常驻员工每天每餐仅每次仅允许订购一份!!')); } //查询出改商店的一些详细信息 $shopData = Shops::model()->findByPk($shop_id); if (!$shopData) { throw new CHttpException(404, Yii::t('yii', '您选择的餐类不存在!')); } $shopData = CJSON::decode(CJSON::encode($shopData)); //判断改商家有没有下市场 if (intval($shopData['status']) != 2) { throw new CHttpException(404, Yii::t('yii', '您选择的餐类已经下市!')); } //根据订单历史纪录查询当天是否已经存在同样的中餐、晚餐订单记录 //店铺->中餐、晚餐 //菜单->地点 //LCF $member_id = Yii::app()->user->member_userinfo['id']; $criteria = new CDbCriteria(); $today = strtotime(date('Y-m-d')); $criteria->order = 't.create_time DESC'; $criteria->select = '*'; $criteria->condition = 'food_user_id=:food_user_id AND shop_id = :shop_id AND create_time > :create_time AND status < :status'; $criteria->params = array(':food_user_id' => $member_id, ':shop_id' => $shop_id, ':create_time' => $today, ':status' => 3); //查询结果 $todayOrderCount = FoodOrder::model()->count($criteria); $memberInfo = Members::model()->find('id=:id', array(':id' => Yii::app()->user->member_userinfo['id'])); if ($memberInfo->resident == 1 && $todayOrderCount >= 1) { throw new CHttpException(404, Yii::t('yii', '你今天已经订过该餐了!!常驻员工每天每餐仅每次仅允许订购一份!!')); } //根据店铺id查询出该店铺的菜单 $menuData = Menus::model()->with('food_sort', 'image', 'shops')->findAll(array('condition' => 't.shop_id=:shop_id AND t.status=:status', 'params' => array(':shop_id' => $shop_id, ':status' => 2))); $data = array(); foreach ($menuData as $k => $v) { $data[$k] = $v->attributes; $data[$k]['index_pic'] = $v->index_pic ? Yii::app()->params['img_url'] . $v->image->filepath . $v->image->filename : ''; $data[$k]['sort_name'] = $v->food_sort->name; $data[$k]['shop_name'] = $v->shops->name; $data[$k]['create_time'] = Yii::app()->format->formatDate($v->create_time); $data[$k]['status'] = Yii::app()->params['menu_status'][$v->status]; $data[$k]['price'] = $v->price; } //获取该店的留言 $criteria = new CDbCriteria(); $criteria->order = 't.order_id DESC'; $criteria->condition = 't.shop_id=:shop_id AND t.status=:status'; $criteria->params = array(':shop_id' => $shop_id, ':status' => 1); $count = Message::model()->count($criteria); //构建分页 $pages = new CPagination($count); $pages->pageSize = Yii::app()->params['pagesize']; $pages->applyLimit($criteria); $messageMode = Message::model()->with('members', 'shops', 'replys')->findAll($criteria); $message = array(); foreach ($messageMode as $k => $v) { $message[$k] = $v->attributes; $message[$k]['shop_name'] = $v->shops->name; $message[$k]['user_name'] = $v->members->name; $message[$k]['create_time'] = date('Y-m-d H:i:s', $v->create_time); $message[$k]['status_text'] = Yii::app()->params['message_status'][$v->status]; $message[$k]['status_color'] = Yii::app()->params['status_color'][$v->status]; $_replys = Reply::model()->with('members')->findAll(array('condition' => 'message_id=:message_id', 'params' => array(':message_id' => $v->id))); if (!empty($_replys)) { foreach ($_replys as $kk => $vv) { $message[$k]['replys'][$kk] = $vv->attributes; $message[$k]['replys'][$kk]['create_time'] = date('Y-m-d H:i:s', $vv->create_time); $message[$k]['replys'][$kk]['user_name'] = $vv->user_id == -1 ? '行政MM说' : $vv->members->name; } } } $this->render('lookmenu', array('menus' => $data, 'shop' => $shopData, 'pages' => $pages, 'message' => $message)); }
public function actionUpdate($id) { if(Yii::app()->user->checkAccess('admin')){ $model=$this->loadModel($id); if(isset($_POST['Articles'])) { $model->attributes=$_POST['Articles']; $image = CUploadedFile::getInstance($model,'image'); $new_image = false; if (isset($image)) { $old_image = $model->image; if (isset($old_image)) { $old_image_full_name = explode('.',$old_image); $old_image_name = $old_image_full_name[0]; $old_image_extension = $old_image_full_name[1]; $old_origin_image_name = $old_image_name.'_origin'; unlink(Yii::app()->basePath."/../images/articles/".$old_image); unlink(Yii::app()->basePath."/../images/articles/".$old_origin_image_name.'.'.$old_image_extension); } $extension = $image->extensionName; $image_name = md5(time()); $file_name = $image_name.'.'.$extension; $file_name_origin = $image_name.'_origin'.'.'.$extension; $model->image = $file_name; $size = getimagesize($_FILES['Articles']['tmp_name']['image']); $x = (int) $_POST['x']; $y = (int) $_POST['y']; $w = (int) $_POST['w'] ? $_POST['w'] : $size[0]; $h = (int) $_POST['h'] ? $_POST['h'] : $size[1]; $data = file_get_contents($image->getTempName()); $vImg = imagecreatefromstring($data); //$nw = $nh = 200; $nw = $w; $nh = $h; $dstImg = imagecreatetruecolor($nw, $nh); # copy image imagecopyresampled($dstImg, $vImg, 0, 0, $x, $y, $nw, $nh, $w, $h); # save image imagejpeg($dstImg, Yii::app()->basePath. '/../images/articles/'.$file_name); # clean memory imagedestroy($dstImg); $new_image = true; } else { $image = $model->image; } if($model->save()) { if ($new_image) $image->saveAs(Yii::app()->basePath. '/../images/articles/'.$file_name_origin); $this->redirect(array('view','id'=>$model->id)); } } $menu_model = Menus::model()->findAll('dynamic=1'); $menus = array(); switch(Yii::app()->language) { case 'ru': foreach ($menu_model as $_menu_model) { $menus[$_menu_model->id] = $_menu_model->name_ru; } break; case 'ua': foreach ($menu_model as $_menu_model) { $menus[$_menu_model->id] = $_menu_model->name_ua; } break; case 'en': foreach ($menu_model as $_menu_model) { $menus[$_menu_model->id] = $_menu_model->name_en; } break; } $this->render('update',array( 'model'=>$model, 'menus' => $menus )); } else { $this->redirect('/admin/user/login'); } }
public function loadModel($id) { $model = Menus::model()->with('food_sort', 'image')->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionLookMenu() { $shop_id = Yii::app()->request->getParam('shop_id'); if (!isset($shop_id)) { throw new CHttpException(404, Yii::t('yii', '请选择一家餐厅')); } //查询出改商店的一些详细信息 $shopData = Shops::model()->findByPk($shop_id); if (!$shopData) { throw new CHttpException(404, Yii::t('yii', '您选择的这家餐厅不存在')); } $shopData = CJSON::decode(CJSON::encode($shopData)); //判断改商家有没有下市场 if (intval($shopData['status']) != 2) { throw new CHttpException(404, Yii::t('yii', '您选择的这家餐厅不存在或者已经倒闭了!')); } //根据店铺id查询出该店铺的菜单 $menuData = Menus::model()->with('food_sort', 'image', 'shops')->findAll(array('condition' => 't.shop_id=:shop_id AND t.status=:status', 'params' => array(':shop_id' => $shop_id, ':status' => 2))); $data = array(); foreach ($menuData as $k => $v) { $data[$k] = $v->attributes; $data[$k]['index_pic'] = $v->index_pic ? Yii::app()->params['img_url'] . $v->image->filepath . $v->image->filename : ''; $data[$k]['sort_name'] = $v->food_sort->name; $data[$k]['shop_name'] = $v->shops->name; $data[$k]['create_time'] = Yii::app()->format->formatDate($v->create_time); $data[$k]['status'] = Yii::app()->params['menu_status'][$v->status]; $data[$k]['price'] = $v->price; } //获取该店的留言 $criteria = new CDbCriteria(); $criteria->order = 't.order_id DESC'; $criteria->condition = 't.shop_id=:shop_id AND t.status=:status'; $criteria->params = array(':shop_id' => $shop_id, ':status' => 1); $count = Message::model()->count($criteria); //构建分页 $pages = new CPagination($count); $pages->pageSize = Yii::app()->params['pagesize']; $pages->applyLimit($criteria); $messageMode = Message::model()->with('members', 'shops', 'replys')->findAll($criteria); $message = array(); foreach ($messageMode as $k => $v) { $message[$k] = $v->attributes; $message[$k]['shop_name'] = $v->shops->name; $message[$k]['user_name'] = $v->members->name; $message[$k]['create_time'] = date('Y-m-d H:i:s', $v->create_time); $message[$k]['status_text'] = Yii::app()->params['message_status'][$v->status]; $message[$k]['status_color'] = Yii::app()->params['status_color'][$v->status]; $_replys = Reply::model()->with('members')->findAll(array('condition' => 'message_id=:message_id', 'params' => array(':message_id' => $v->id))); if (!empty($_replys)) { foreach ($_replys as $kk => $vv) { $message[$k]['replys'][$kk] = $vv->attributes; $message[$k]['replys'][$kk]['create_time'] = date('Y-m-d H:i:s', $vv->create_time); $message[$k]['replys'][$kk]['user_name'] = $vv->user_id == -1 ? '前台妹子说' : $vv->members->name; } } } $this->render('lookmenu', array('menus' => $data, 'shop' => $shopData, 'pages' => $pages, 'message' => $message)); }
public function actionConfirmOrder() { //检查在不在订餐时间内 if (!Yii::app()->check_time->isOnTime()) { Error::output(Error::ERR_NOT_IN_TIME); } //接收传递过来的订单 $menuInfo = Yii::app()->request->getParam('menu_info'); $menuInfo = json_decode($menuInfo, 1); if ($menuInfo) { $shop_id = 0; $totalPrice = 0; //记录总价 $orderData = array(); //根据传递过来的订单构造数据 foreach ($menuInfo as $k => $v) { $menu = Menus::model()->find('id = :id AND status = :status', array(':id' => $v['id'], ':status' => 2)); if (!$menu) { Error::output(Error::ERR_ORDER_DATA_WRONG); } if (!$shop_id) { $shop_id = $menu->shop_id; } elseif ($menu->shop_id != $shop_id) { Error::output(Error::ERR_MENU_NOT_SAME_SHOP); } $orderData[] = array('Id' => $menu->id, 'Name' => $menu->name, 'Count' => intval($v['nums']), 'Price' => $menu->price, 'smallTotal' => $menu->price * $v['nums']); $totalPrice += $menu->price * $v['nums']; } if (!$shop_id || empty($orderData)) { Error::output(Error::ERR_ORDER_DATA_WRONG); } //获取当前用户信息,查看用户账户余额够不够付款 if ($this->module->user['balance'] < $totalPrice && !in_array($this->module->user['id'], Yii::app()->params['allow_user_id'])) { Error::output(Error::ERR_BALANCE_NOT_ENOUGH); } //构建数据 $foodOrder = new FoodOrder(); $foodOrder->shop_id = $shop_id; $foodOrder->order_number = date('YmdHis', time()) . Common::getRandNums(6); $foodOrder->food_user_id = $this->module->user['id']; $foodOrder->total_price = $totalPrice; $foodOrder->create_time = time(); $foodOrder->product_info = serialize($orderData); if ($foodOrder->save()) { //记录订单动态 $foodOrderLog = new FoodOrderLog(); $foodOrderLog->food_order_id = $foodOrder->id; $foodOrderLog->create_time = time(); $foodOrderLog->save(); Out::jsonOutput(array('return' => 1)); //下单成功 } else { Error::output(Error::ERR_SAVE_FAIL); } } }
public function adminDelete() { // 1 delete foreign table Roles Roles::model()->deleteAllByAttributes(array('application_id' => $this->id)); // 2 delete foreign table Menus Menus::model()->deleteAllByAttributes(array('application_id' => $this->id)); // 3 delete foreign table Menus Users::model()->deleteAllByAttributes(array('application_id' => $this->id)); // 4 delete table Applications if ($this->delete()) { Yii::log("Delete record id = " . $model->id); } }
protected function checkControllerAccessRules($controller, $application) { if (empty($controller)) { $accessArray = array(); $accessArray[] = array('deny', 'users' => array('*')); } else { $menu = Menus::model()->findAll(array('condition' => 'controller_name = "' . $controller . '" AND application_id =' . $application)); if (!empty($menu)) { $list_menu_id = ''; for ($i = 0; $i < count($menu); ++$i) { $v = $menu[$i]; if ($i == count($menu) - 1) { $list_menu_id .= $v->id; } else { $list_menu_id .= $v->id . ','; } } //echo $list_menu_id; $list_menu = $list_menu_id; $list_menu_id = explode(",", $list_menu_id); $criteria = new CDbCriteria(); $criteria->addInCondition('t.menu_id', $list_menu_id, 'AND'); $criteria->group = 't.role_id'; $menu_role = RolesMenus::model()->findAll($criteria); $accessArray = array(); /* $accessArray[] = array('allow', // allow all users to perform 'index' and 'view' actions 'actions'=>array('index','view'), 'users'=>array('*') ); print_r($accessArray); */ if (!empty($menu_role)) { for ($i = 0; $i < count($menu_role); ++$i) { $v = $menu_role[$i]; //echo $v->role_id; $menuOfRole = RolesMenus::model()->findAll('menu_id IN (' . $list_menu . ') AND role_id=' . $v->role_id); $action_name = ''; for ($t = 0; $t < count($menuOfRole); ++$t) { $w = $menuOfRole[$t]; if ($t === count($menuOfRole) - 1) { $action_name .= $w->actions; } else { if (!empty($w->actions)) { $action_name .= $w->actions . ","; } } } $action_name = explode(",", trim($action_name)); $accessArray[] = array('allow', 'actions' => $action_name, 'users' => array('@'), 'expression' => 'isset($user->role_id) && (Yii::app()->user->role_id == ' . $v->role_id . ')'); } $accessArray[] = array('deny', 'users' => array('*')); //print_r($accessArray); } else { $accessArray = array(); $accessArray[] = array('allow', 'users' => array('*')); } } else { $accessArray = array(); $accessArray[] = array('allow', 'users' => array('*')); } } //print_r($accessArray); return $accessArray; }
<?php $this->breadcrumbs = array('Manage Menu' => array('index'), $model->menu_name); $menus = array(array('label' => 'List Menu', 'url' => array('index')), array('label' => 'Create Menu', 'url' => array('create')), array('label' => 'Update Menu', 'url' => array('update', 'id' => $model->id)), array('label' => 'Delete Menu', 'url' => 'delete', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?'))); $this->menu = ControllerActionsName::createMenusRoles($menus, $actions); ?> <h1>View Menu: <?php echo $model->menu_name; ?> </h1> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('menu_name', 'menu_link', 'controller_name', 'display_order', array('name' => 'show_in_menu', 'value' => !empty($model->show_in_menu) && $model->show_in_menu == 1 ? 'Yes' : 'No'), array('name' => 'place_holder_id', 'value' => $model->place_holder->position), array('name' => 'application', 'value' => $model->application->application_name), array('name' => 'roles', 'type' => 'raw', 'value' => $sRoles), array('name' => 'parent', 'value' => !is_null(Menus::model()->findByPk($model->parent_id)) ? Menus::model()->findByPk($model->parent_id)->menu_name : ''))));