2 @set dbname=sterp
3 @set tmp_db_file="G:\databack\erp\%date:~0,10%.sql"
4 @set db_back_file="G:\databack\erp\%date:~0,10%.rar"
5
6 rem 设置ftp服务器登录参数
7 @set ftp_server=116.141.145.79
8 @set ftp_user=upload
9 @set ftp_password=159357
10
11 rem 备份数据库,以日期为命名
12 mysqldump %dbname% >%tmp_db_file%
13 c:\progra~1\winrar\winrar a -k -r -s %db_back_file% %tmp_db_file%
14 del %tmp_db_file% /S /Q
15
16 rem 通过FTP上传到远处服务器
17 @echo off
18 echo open %ftp_server%>ftp.txt
19 echo %ftp_user%>>ftp.txt
20 echo %ftp_password%>>ftp.txt
21 echo cd erp>>ftp.txt
22 echo put %db_back_file%>>ftp.txt
23 echo bye>>ftp.txt
24 ftp -s:ftp.txt
25 echo 上传成功!
26
27 rem 关鸡
28 shutdown -s -f
一:为什么要做分类多属性?
1、网站架构的清爽性,可维护性,分类搜索
在一些比较大型的B2C网站,会发现不同的类目下面都会有一些不同的选项
例如进入了红酒柜类目,我可以选择是 多少瓶的 ,电子的还是压缩机的 ,价格范围等
如果进入了搅拌机的类目,我可以选择多少转的,功率,产量多少等
但如果是传统的属性表结构的话,将是这样储存
产品表:
名称,产品编码,型号,瓶数,压缩机类型,价格,转速,功率,产量
这样做的话 每一个产品都记录着这么多的信息,而且很多信息都不是自己想要的
例如红酒柜的时候不需要转速的数据,搅拌机不需要压缩机类型的数据
则存在十分多的数据冗余,更可怕的是,我们的产品分类几百种,如果都按传统的设计方式去实现的话,则难以管理
而且在前台设计的时候也不好做,十分每一个分类的都要有一个专门的class ?明显这种设计不大科学
从系统的维护性来说是不可取的
2、数据对比的实现:
在太平洋电脑网里面有个很好的功能,就是导购对比功能,如图
在我们圣托的产品不同于凡客,和京东
我们更多的是属于非标准的产品,还不属于家喻户晓的大品牌,
那如何才能让顾客快速的选择出符合自己的产品呢?
我们也许可以定下一些行业标准,例如什么参数的产品质量更好,更合适哪类人群使用···
这里如果有一个如太平洋的对比功能就好很多了
二、如何实现分类多属性
1、数据结构:
我们知道,我们的产品可以进行分类,从面向对象的角度来说,我们的子类应该是继承于父类的,例如男人继承于人类所以,男人应该拥有人类所有的属性。
so:
分类表中可以添加一个字段,记录在这分类中的属性名,用JSON序列化储存到表字段中,子级分类亦然。
如{'转速' ,'刀片工艺'}
因为 json可以转换为array,所以我们的属性集将成为array的格式,最终所属类目的产品的属性则为所属类目以及其所有父级分类的并集。
如果从数据结构来说,我们可能会考虑得更严谨一些,不是转化为array而是一个tree里面
并在产品表中添加一个命名为ex_attr的字段名,对应属性集中的每一个属性,并以json的格式进行储存入表中。
例如{'转速':'10000/m','刀片工艺':'0.5mm'}
当然如果我们的类目想更多的功能,显示的更独特性的话 我们的json格式就可以储存为
[{"type":"int","display_style":"bar","title":"转速"},{"type":"string","display_style":"string","title":"刀片工艺"}]
json可以直接转化为tree 和 tree_item
发到园区,也是为了大家能拍拍砖,给点意见 谢谢
当然,这种设计还是一种思想。希望这种思想能在下一版的系统改进中实现出来
Mysql自动备份:
建立要备份存放目录。如:E:\Data\db_bak\sterp
找到数据库文件所在目录的文件夹。如:E:\Data\data\sterp
在备份目录下,建立db_back_sterp.bat文件,输入
net stop mysql
xcopy E:\Data\data\sterp\*.* E:\Data\db_bak\sterp\%date:~0,10%\ /y
c:\progra~1\winrar\winrar a -k -r -s E:\Data\db_bak\sterp\%date:~0,10%.rar E:\Data\db_bak\sterp\%date:~0,10%\
rd E:\Data\db_bak\sterp\%date:~0,10%\ /S /Q
net start mysql
其中:
net stop mysql 代表停止mysql
xcopy E:\Data\data\sterp\*.* E:\Data\db_bak\sterp\%date:~0,10%\ /y 将目录文件复制到备份目录,并以日期命名
c:\progra~1\winrar\winrar a -k -r -s E:\Data\db_bak\sterp\%date:~0,10%.rar E:\Data\db_bak\sterp\%date:~0,10%\ 将刚刚复制过来的目录压缩。
rd E:\Data\db_bak\sterp\%date:~0,10%\ /S /Q 删除刚刚的临时目录,保留了压缩文件
net start mysql 开启服务。
保存bat文件。
打开任务计划,将刚刚的bat放入里面,并设置执行周期,什么时候执行
建议在凌晨执行
最近需要做到交叉表,而公司的需求比较复杂,一般的交叉表工具都不适合用
如果使用sql语句做的话 工作量太大了,于是尝试自己写一个交叉表的类,好二话不说,我们看看代码
代码
* 基本交叉表
* @author hugh
*
*/
class Pivot
{
private $HORIZONTAL_TOTAL_FIELD = 'total';
private $VERTICAL_TOTAL_FIELD = 'total';
private $data;
private $topPivot;
private $leftPivot;
private $measure;
private $horizontalColumn = array ();
private $verticalColumn = array ();
private $pivotValue = array ();
private $isHorizontalTotal = true;
private $isVerticalTotal = true;
private $horizontalTotal = null;
private $verticalTotal = null;
private $title = 'PivotTab';
/**
* 初始化交叉表
*/
private function InitPivot()
{
$this->topPivot;
foreach ( $this->data as $d )
{
$this->horizontalColumn [] = $d [$this->leftPivot];
$this->verticalColumn [] = $d [$this->topPivot];
}
$this->horizontalColumn = array_unique ( $this->horizontalColumn );
$this->verticalColumn = array_unique ( $this->verticalColumn );
$reasult = array ();
foreach ( $this->horizontalColumn as $h )
{
foreach ( $this->verticalColumn as $v )
{
$this->pivotValue [$h] [$v] = 0;
}
}
}
/**
* 填充数据
*/
private function fillData()
{
foreach ( $this->data as $row )
{
$this->pivotValue [$row [$this->leftPivot]] [$row [$this->topPivot]] += $row [$this->measure];
}
if ($this->isHorizontalTotal)
{
$this->setHorizontalTotal ();
}
if ($this->isVerticalTotal)
{
$this->setVerticalTotal ();
}
}
/**
* 设置纵向合计
*/
private function setVerticalTotal()
{
$this->verticalColumn [] = $this->VERTICAL_TOTAL_FIELD;
foreach ( $this->horizontalColumn as $i )
{
$rowsum = 0;
foreach ( $this->verticalColumn as $j )
{
$rowsum += $this->pivotValue [$i] [$j];
}
$this->pivotValue [$i] [$this->TOTAL_FIELD] = $rowsum;
}
}
/**
* 设置横向合计
*/
private function setHorizontalTotal()
{
$this->horizontalColumn [] = $this->HORIZONTAL_TOTAL_FIELD;
foreach ( $this->verticalColumn as $i )
{
$rowsum = 0;
foreach ( $this->horizontalColumn as $j )
{
$rowsum += $this->pivotValue [$j] [$i];
}
$this->pivotValue [$this->HORIZONTAL_TOTAL_FIELD] [$i] = $rowsum;
}
}
/**
* 渲染
*/
function Render()
{
echo '<pre>';
print_r ( $this->pivotValue );
}
/**
* 渲染为table
*/
function RenderToTable()
{
$resault = "<table border='1' width='250'>\n";
$resault .= "<tr><td>$this->title</td>\n";
foreach ( $this->verticalColumn as $value )
{
$resault .= "<td>$value</td>\n";
}
$resault .= "</tr>\n";
foreach ( $this->horizontalColumn as $i )
{
$resault .= "<tr><td>$i</td>\n";
foreach ( $this->pivotValue [$i] as $value )
{
$resault .= "<td>$value</td>\n";
}
$resault .= "</tr>\n";
}
$resault .= "</table>";
return $resault;
}
/**
* 构造交叉表
* @param $data 数据源
* @param $topPivot 头栏目字段
* @param $leftPivot 左栏目字段
* @param $measure 计算量
*/
function __construct(array $data, $topPivot, $leftPivot, $measure)
{
$this->data = $data;
$this->leftPivot = $leftPivot;
$this->topPivot = $topPivot;
$this->measure = $measure;
$this->horizontalColumn = array ();
$this->verticalColumn = array ();
$this->InitPivot ();
$this->fillData ();
}
}
重点在于InitPivot方法及fillData方法。
InitPivot里面保证了所有的item都会有值(默认为0)
fillData方法使用选择填充添加的方法,将数据填充入我们装数据的$pivotValue里面。
然后喜欢怎么输出都可以了

