<?php
/**
* 任务计划 - 秒杀商品库存同步
*
*
*
*
* @copyright Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
* @license http://www.shopnc.net
* @link http://www.shopnc.net
* @since File available since Release v1.1
*/
defined('InShopNC') or exit('Access Invalid!');
PHP_SAPI == 'cli' or exit ( 'Cli Access Invalid!' );
class rush_goods_storageControl {
public $exception = true;
public $title_msg = '';
/**
* 初始化对象
*/
public function __construct(){
register_shutdown_function(array($this,"shutdown"));
}
/**
* 乐县域商品分类
*/
public function indexOp() {
try{
$res = $this->get_rush_list();
}catch (Exception $e){
$this->exception = false;
}
}
/**
* 秒杀商品库存同步
*/
public function get_rush_list() {
//秒杀商品
$model_rush = Model('rush');
$rush_condition = array(
'rush_activity.status' => array('neq', '4'),
/*'rush_goods.rush_start_time' => array('lt', time()),
'rush_goods.rush_end_time' => array('gt', time()),*/
);
$rush_info = $model_rush->getRushGoodsList($rush_condition);
if(!empty($rush_info)){
foreach ($rush_info as $v){
if($v['rush_goods_storage']>0){
$rush_start_time = date('YmdHis',$v['rush_start_time']);
$rush_end_time = date('YmdHis',$v['rush_end_time']);
$k='rush_'.$v['rush_id'].'_quantity_spu_'.$v['common_id'].'_'.$rush_start_time.'_'.$rush_end_time;
$redis = new Redis();
$redis->connect(C('rush_redis_host'),C('rush_redis_port'));
$storage = $redis->get($k);
if($storage){
if($storage!=$v['rush_goods_storage']){
$condition = [];
$data = [];
$condition['rush_id'] =$v['rush_id'];
$data['rush_goods_storage'] = $storage ;
$request = Model()->table('rush_goods')->where($condition)->update($data);
if(!$request){
LogManager::log_error(array('logKey'=>'update_rush_goods','message'=>'更新秒杀库存失败','condition'=>$condition,'data'=>$data),'get_rush_storage');
}
}
}else{
LogManager::log_error(array('logKey'=>'get_rush_goods_key','message'=>'秒杀商品查询key失败','KEY'=>$k),'get_rush_storage');
}
}
}
}else{
$this->title_msg = '没有查询到秒杀信息';
}
}
/**
* 执行完成提示信息
*
*/
public function shutdown()
{
if($this->exception) {
$caption = '秒杀库存更新成功--';
if($this->title_msg){
$title = $this->title_msg;
}else {
$title = '秒杀库存更新成功';
}
$this->lxy_sendmail($title,$caption);
exit("success at ". date('Y-m-d H:i:s', TIMESTAMP)."\n");
}else{
$caption = '秒杀库存更新失败--';
$title = '秒杀库存更新失败';
$this->lxy_sendmail($title,$caption);
exit("failure at" . date('Y-m-d H:i:s', TIMESTAMP)."\n");
}
}
//sendmail
public function lxy_sendmail($title,$caption){
$content = nl2br($caption);
//发送邮件
$to = 'hejp@lecuntao.com';
sendmail($to, 'update_rush_goods@163.com', $title, $content);
}
}
PHP 秒杀商品库存同步
最新推荐文章于 2023-12-02 15:39:16 发布