原理 : 需要用到cron计划任务, 访问变动的url (即类名下的方法)
在专家需要进行一场活动时, 首先填写 未来时间段的开始时间、结束时间以及这时间段的商品价格。记录到活动表中
同时 ,将商品表中的act_price进行填写活动价
在活动开始前,一切以原价展示,进行中将原价和活动价交换,(因为页面始终显示的是原价的字段,为了统一)。 活动结束后,再将 原价和活动价交换。
表:
1、商品表 、活动表
其中活动表有一个记录状态,为方便价格相互交换
字段 status int 10 默认为0 【注释:活动状态:0 未开始 1进行中 2活动已结束】
定时 访问 http://xxx/index.php?s=/addon/Activity/Activity/endactivity
http://xxx//index.php?s=/addon/Activity/Activity/startactivity
http://xxx//index.php?s=/addon/Activity/Activity/startactivity
//活动后期后,价格恢复原价
public function endactivity(){
$current_time = time();
//var_dump($current_time);exit();
//$act=M('activity')->where('act_starttime EGT '.$zuotian.' and act_starttime ELT ' .$mingtian)->select();
//$act=M('activity')->where('act_starttime >= '.$zuotian.' and act_starttime <= ' .$mingtian)->select();
$act=M('activity')->where('act_endtime <= ' .$current_time.' and status <>2')->select();
var_dump(M('activity')->getlastsql());exit();
foreach($act as $val){
$act_shopid=explode(',',$val['act_shopid']);
M('activity')->where('id = ' .$val['id'])->setField('status',2);
//var_dump(M('activity')->getlastsql());
//var_dump($act_shopid);exit();
foreach($act_shopid as $val){
if($val){
$shopdate=M('goodsshop')->where('id='.$val)->find();
$date=array('price'=>$shopdate['act_price'],'act_price'=>$shopdate['price']);
M('goodsshop')->where('id='.$val)->save($date);
}
}
}
echo "update activity is over!";
}
//活动由未开始,变为进行中, 活动价为当前价
public function startactivity(){
$current_time = time();
//$act=M('activity')->where('act_endtime ELT '.$zuotian.' and act_endtime EGT ' .$mingtian)->select();
$act=M('activity')->where('act_starttime <= '.$current_time.' and act_endtime >= ' .$current_time.' and status=0')->select();
//var_dump(M('activity')->getlastsql());exit();
foreach($act as $val){
$act_shopid=explode(',',$val['act_shopid']);
M('activity')->where('id = ' .$val['id'])->setField('status',1);
foreach($act_shopid as $val){
if($val){
$shopdate=M('goodsshop')->where('id='.$val)->find();
$date=array('price'=>$shopdate['act_price'],'act_price'=>$shopdate['price']);
M('goodsshop')->where('id='.$val)->save($date);
}
var_dump(M('goodsshop')->getlastsql());
}
}
echo "update activity is over!";
}