/** * 查询所有触摸屏名、id * @return 查询成功返回结果集 * 查询失败返回false */ public static function touchSelectForAllName() { $ret = array('status' => 0, 'msg' => ''); try { $cache = Yii::app()->cache->get(CacheName::getCacheName('touch_name_list')); //获取搭配屏名称列表缓存 if ($cache === false) { $sele_zd = 'touch_config.id,touch_config.name'; $sql = Yii::app()->db->createCommand()->select($sele_zd)->from('touch_config')->where('touch_config.lock<>1')->order('touch_config.id desc'); $newstypelist = $sql->queryAll(); if (count($newstypelist) == 0) { throw new Exception('查询触摸屏名称列表失败!'); } $ret['data'] = $newstypelist; $ret['status'] = 1; Yii::app()->cache->set(CacheName::getCacheName('touch_name_list'), $ret, 0); //设置搭配屏名称列表缓存 } else { $ret = $cache; } } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }
/** * 查询所有品牌 * @return array('status'=>0,'msg'=>'','data'=>array()) 成功status为1 有data数据 */ public static function brandSelectAll() { $ret = array('status' => 0, 'msg' => ''); try { $cache = Yii::app()->cache->get(CacheName::getCacheName('brand_name_list_all')); //获取所有品牌名列表缓存 if ($cache === false) { //查询可显示的品牌 不显示及其删除品牌不查询 $brandidarr = Yii::app()->db->createCommand()->select('id,name,englishname')->from("beu_brand")->where('status=10')->queryAll(); if (count($brandidarr) == 0) { throw new Exception('品牌列表为空!'); } $ret['data'] = $brandidarr; $ret['status'] = 1; Yii::app()->cache->set(CacheName::getCacheName('brand_name_list_all'), $ret, 0); //设置所有品牌名列表缓存 永不过期 } else { $ret = $cache; } } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }
/** *用户登录 * @param $username用户名 * @param $password密码 * 返回"true"为成功,不为true返回失败信息 */ public static function userLogin($username = NULL, $password = NULL) { $ret = array('status' => 0, 'msg' => ''); $ret_num = 2; try { if (!empty($_SESSION['user_id'])) { } if (empty($username) || empty($password)) { throw new Exception("用户名或密码输入有误"); } $password = md5("beubeu" . md5($password)); $users = self::userSelectByParm("", $username, $password); //查询用户表用户名和密码是否正确 if (empty($users)) { //大于0说明数据库查询有数据 $ret_num = 2; //用户名密码错误 throw new Exception('用户名密码错误'); } $currenttime = time(); ///echo $currenttime." ".$users['endtime'];exit(); if ($currenttime > strtotime($users['endtime'])) { //如果当前时间大于到期时间说明已过期 $ret_num = 3; throw new Exception('帐号过期'); } self::usermodelUpdateByUserid($users['id'], 2); //$ret_status=self::userSeleteStatus($users['id']); //print_r($ret_status);exit(); //if($ret_status['status']==1){//说明可登录 // $ret_num=8; // throw new Exception('帐号已登陆'); //} //设置seesion和cookie if (!empty($users["type"]) && $users["type"] == Yii::app()->params['sub_type']) { $ret_num = 6; throw new Exception('用户访问权限不够'); } //用户需要进行IP验证的就验证 if ($users['ip_limit'] == 1) { $sel = Yii::app()->db->createCommand(); $ipp2 = $sel->select('IP')->from('beu_user_ip_limit')->where('status=1 and userid=' . $users['id'])->queryAll(); if (count($ipp2) == 0) { $ret_num = 5; throw new Exception('IP未设置'); } $is_bool = false; foreach ($ipp2 as $value) { if ($value['IP'] == Comm::getSourceIp()) { $is_bool = true; break; } } if (!$is_bool) { $ret_num = 5; throw new Exception('当前访问IP不在设置范围内'); } } $users['type'] = self::userTypeChange($users['type'], $users['ERP3_status']); //权限转换 if ($users['type'] > 70 || $users['type'] < 51) { //用户权限级别不再范围表示其权限不可访问后台 $ret_num = 6; throw new Exception('用户访问权限不够'); } //$_SESSION ['type'] = $users['type']; //$_SESSION ['touchid'] = json_decode ( $userinfo ['touchid'], true ); //$_SESSION ['permissions'] = json_decode ( $userinfo ['permissions'], true ); $_SESSION['user_id'] = $users['id']; $_SESSION['userid'] = $users['id']; $_SESSION['user'] = $users['username']; //用户名 $_SESSION['type'] = $users['type']; //用户类型,2为管理员,5为品牌,10为普通用户 $_SESSION['istotalaccount'] = $users['istotalaccount']; //是非品牌总管理 1.是 0.否 $_SESSION['account'] = isset($users['account']) && !empty($users['account']) ? $users['account'] : 0; //对应的账户类型 beu_useraccount.id $_SESSION['touchidd'] = isset($users['touchid']) && !empty($users['touchid']) ? implode(',', json_decode($users['touchid'], true)) : ''; $_SESSION['xiazai_v'] = 1; //是有可下载图片 $_SESSION['brandid'] = isset($users['brandid']) && !empty($users['brandid']) ? $users['brandid'] : 0; /************* 总分屏配置 start ********************/ $_SESSION['clothes_table'] = 'touch_clothes'; $_SESSION['table_where'] = ''; $_SESSION['is_push'] = 0; $_SESSION['sub_id'] = 0; /************* 总分屏配置 end ********************/ Yii::app()->cache->delete(CacheName::getCacheName('user_action_Info') . $users['id']); //清除用户的可访问页面列表缓存 usercookie::userSet($users['id'], $username, $password); //删除该用户临时数据 //self::usermodeDeleteByUserid($users['id']); //将该用户添加到临时表中 //self::usermodeForAdd($users['id']); $ret_num = 4; $ret['status'] = 1; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } $ret['data'] = $ret_num; return $ret; }
/** * 根据ID获取当前用户 **/ public static function getusersById($id) { $ret = array('status' => 0, 'msg' => ''); try { if (empty($id) || !is_numeric($id) || intval($id) != $id) { throw new Exception('用户ID必须是整数'); } $cache = Yii::app()->cache->get(CacheName::getCacheName('user_info') . $id); //获取用户信息缓存 if ($cache === false) { $user = beu_users::model()->findByPk($id); if ($user == null) { throw new Exception('查询用户数据为空'); } $ret['status'] = 1; $ret['data'] = $user; Yii::app()->cache->set(CacheName::getCacheName('user_info') . $id, $ret, 0); //设置用户信息缓存 } else { $ret = $cache; } } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }
/** * 获取用户可访问的权限 * @return array('status'=>0,'msg'=>'','data'=>array(),'user_type'=>0) 成功status为1 有data数据,用户权限 */ static function getPowerAll() { $ret = array('status' => 0, 'msg' => ''); try { if (!isset($_SESSION['user_id'])) { throw new Exception('用户ID不能为空'); } $userid = $_SESSION['user_id']; $ret_judge_bool = permission::judgeUserIP(); //获取用户是否需要判断来源IP if ($ret_judge_bool['status'] == 0) { throw new Exception($ret_judge_bool['msg']); } if ($ret_judge_bool['is_bool_ip']) { //需要判断来源IP $ret_ip = self::getIpLimit($userid); //获取用户的IP白名单 if ($ret_ip['status'] == 0 && !isset($ret_ip['data'])) { throw new Exception($ret_ip['msg']); } $is_bool = false; foreach ($ret_ip['data'] as $value) { if ($value['IP'] == Comm::getSourceIp()) { $is_bool = true; break; } } if (!$is_bool) { //未在IP白名单里找到来源IP throw new Exception('来源IP未添加到用户的IP白名单里'); } } $user_type = $ret_judge_bool['user_type']; //用户权限级别 if ($user_type != 1) { //不为超级管理员时才查询其访问权限 $cache = Yii::app()->cache->get(CacheName::getCacheName('user_action_Info') . $userid . $user_type); if ($cache === false) { $ret_Action = self::getActionInfoByUser($userid, $user_type); if ($ret_Action['status'] == 0) { throw new Exception($ret_Action['msg']); } Yii::app()->cache->set(CacheName::getCacheName('user_action_Info') . $userid . $user_type, $ret_Action, 300); //设置用户的可访问页面列表缓存 } else { $ret_Action = $cache; } if ($user_type == Yii::app()->params['main_type'] && $_SESSION['sub_id'] != 0) { //当期帐号权限为总屏权限时,并且切换到了子屏 $ret_Action = self::getActionInfoByUser($_SESSION['sub_id'], Yii::app()->params['sub_type']); //获取子屏访问权限 } $ret['data'] = $ret_Action['data']; } $ret['status'] = 1; $ret['user_type'] = $user_type; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }
/** * 根据类型编号查询所有分类信息 * @param $styleid:int 类型id 默认0 或者为数组 * @return array('status'=>0,'msg'=>'','data'=>array()) 成功status为1 有data数据 */ public static function categorySelectForAll($styleid = 0) { $ret = array('status' => 0, 'msg' => ''); try { if ($styleid != 0 && !is_array($styleid)) { $styleid = trim($styleid); $styleid = array($styleid); } $newlist = Yii::app()->cache->get(CacheName::getCacheName('touch_Category_list')); //获取分类列表缓存 if ($newlist === false) { $data = Yii::app()->db->createCommand()->select('*')->from('beu_category')->where('status=1')->order('id')->queryAll(); if (count($newlist) == 0) { throw new Exception('类型为空!'); } $ret['data'] = $data; $ret['status'] = 1; Yii::app()->cache->set(CacheName::getCacheName('touch_Category_list'), $ret, 0); //设置分类列表缓存 永不过期 } else { $ret = $newlist; } if (is_array($styleid)) { foreach ($ret['data'] as $key => $value) { if (!in_array($value['style'], $styleid)) { unset($ret['data'][$key]); } } if (count($ret['data']) == 0) { $ret['status'] = 0; throw new Exception('查询类型为空!'); } sort($ret['data']); } } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }
/** * 将单品添加到搭配屏 **/ static function clothesAddTouchByTouchid($tid, $cid) { $ret = array('status' => 0, 'msg' => ''); try { if (empty($tid)) { throw new Exception('搭配屏编号有误!'); } if (empty($cid)) { throw new Exception('衣服编号有误!'); } $ret['text'] = ''; //获取要复制的搭配屏ID $tid_arr = explode(',', $tid); //单品ID数据 $cid_arr = explode(',', $cid); $touch_clothes_modelgender = array(); //需要添加到屏里的衣服所对应的模特数组 //获取需要添加的衣服的部分信息 $beu_clothes_obj = Yii::app()->db->createCommand()->select('status,modelgender,id')->from('beu_clothes')->where('id in(' . $cid . ')')->queryAll(); //将衣服id提取出来 $beu_clothes_id_arr = array(); foreach ($beu_clothes_obj as $key => $value) { if ($value['status'] >= 8) { $beu_clothes_id_arr[$key] = $value['id']; } else { $ret['text'] .= '编号为' . $value['id'] . '的衣服当前状态暂时不能复制<br/>'; } } for ($i = 0; $i < count($tid_arr); $i++) { $touch_clothes_modelgender[$tid_arr[$i]] = array(); //获取需要添加的衣服是否存在当前屏里 $cidd = Yii::app()->db->createCommand()->select('clothesid')->from('touch_clothes')->where('clothesid in(' . $cid . ') and touchid=' . $tid_arr[$i])->queryAll(); //如果需要添加的衣服都存在于当前屏,就不执行添加 if (count($cidd) == count($cid_arr)) { $ret['text'] .= '这些衣服都已存在' . $tid_arr[$i] . '屏里<br/>'; continue; } //将当前屏里已存在的衣服ID提取出来 $touch_clothes_id_arr = array(); foreach ($cidd as $key => $value) { $touch_clothes_id_arr[$key] = $value['clothesid']; } //循环遍历需要添加到当前屏的衣服 foreach ($beu_clothes_id_arr as $key_j => $value_j) { $clothes_id_key = array_search($value_j, $touch_clothes_id_arr); //获取当前衣服是否存在于当前屏内 if ($clothes_id_key !== false) { //如果当前衣服存在于屏里就不添加 $ret['text'] .= '编号为' . $value_j . '的衣服已存在' . $tid_arr[$i] . '屏里<br/>'; continue; } //判断当前衣服的模特类型是否在数组里已添加过 $clothes_modelgender_key = array_search($beu_clothes_obj[$key_j]['modelgender'], $touch_clothes_modelgender[$tid_arr[$i]]); if ($clothes_modelgender_key === false) { //如果未添加过 就添加 $touch_clothes_modelgender[$tid_arr[$i]][] = $beu_clothes_obj[$key_j]['modelgender']; } //将衣服添加到当前屏 $tc = new touch_clothes(); $tc->clothesid = $value_j; $tc->touchid = $tid_arr[$i]; $tc->trycount = 0; //试穿数 $tc->status = 12; $tc->acquiescetry = 0; //默认穿着1 $tc->recommend = 0; //是否推荐 $tc->createdate = date('Y-m-d H:i:s'); $tc->sort = 9999; $tc->save(); } } //清除搭配屏下的时间列表缓存 foreach ($tid_arr as $value) { Yii::app()->cache->delete(CacheName::getCacheName('touch_clothes_adddate_cache') . $value); foreach ($touch_clothes_modelgender[$value] as $modelgender_value) { //当前屏添加过衣服,清除其所对应模特的缓存 Yii::app()->cache->delete(CacheName::getCacheName('touch_Clothes_Category_list') . $modelgender_value . '_' . $value); //清除一级品类缓存 Yii::app()->cache->delete(CacheName::getCacheName('touch_Clothes_Category2_list') . $modelgender_value . '_' . $value); //清除二级品类缓存 } } $ret['status'] = 1; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } return $ret; }