促销价格 功能设计

原理 :  需要用到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

//活动后期后,价格恢复原价
	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!";
		
		
	}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蜗牛慢慢向上爬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值