objCustomerCache = new CustomerCache(); $this->objDVipCardOrder = new DVipCardOrder('default'); } //删除redis中一个月前注册的客户 public function delCustomerOfOneMonthAgo() { $result = $this->objCustomerCache->delCustomerOfOneMonthAgo(); if ($result) { echo "删除30天前注册的客户--成功"; die; } echo "删除30天前注册的客户--失败"; } //删除redis中7天前有加购行为的客户 public function delInterestCustomerOfSevenDaysAgo() { $result = $this->objCustomerCache->delInterestCustomerOfSevenDaysAgo(); if ($result) { echo "删除7天有加购行为的客户--成功"; die; } echo "删除7天有加购行为的客户--失败"; } //每半小时执行一次,把下单超过半小时仍未支付的订单删掉 public function AutoDelNoPayVipCardOrder() { $sql = "show tables like 'qianniao_vip_card_order_%';"; $tables = $this->objDVipCardOrder->query($sql); if (empty($tables)) { echo "无会员卡订单表"; die; } $vipCardOrderTables = []; foreach ($tables as $tableArr) { foreach ($tableArr as $table) { if (strpos($table,'qianniao_vip_card_order_') !== false) { $vipCardOrderTables[] = $table; } } } if (empty($vipCardOrderTables)) { echo "无会员卡订单表"; die; } $this->objDVipCardOrder->beginTransaction(); foreach ($vipCardOrderTables as $vipCardOrderTable) { $enterpriseId = substr($vipCardOrderTable,strlen('qianniao_vip_card_order_')); $endTime = time()- 30 * 60; $sql = 'SELECT * FROM '.$vipCardOrderTable.' WHERE payStatus='.StatusCode::$delete.' AND createTime <='.$endTime; $orders = $this->objDVipCardOrder->query($sql); if ($orders === false) { $this->objDVipCardOrder->rollBack(); file_put_contents('/www/wwwroot/cron.log',date('Y-m-d H:i:s').'查询会员卡订单表失败'.var_export($orders,true).PHP_EOL,FILE_APPEND); } //循环处理订单 把会员卡销售数量减1,并删除订单 if (!empty($orders)) { foreach ($orders as $order) { $sql = "UPDATE qianniao_vip_card_".$enterpriseId.' SET num=num -1 where id='.$order['vipCardId']; $result = $this->objDVipCardOrder->query($sql); if ($result === false) { $this->objDVipCardOrder->rollBack(); file_put_contents('/www/wwwroot/cron.log',date('Y-m-d H:i:s').'修改会员卡销售数量失败'.var_export($result,true).PHP_EOL,FILE_APPEND); } $sql = "DELETE FROM ".$vipCardOrderTable.' where id='.$order['id']; $dbResult = $this->objDVipCardOrder->query($sql); if ($dbResult === false) { $this->objDVipCardOrder->rollBack(); file_put_contents('/www/wwwroot/cron.log',date('Y-m-d H:i:s').'删除会员卡订单失败'.var_export($result,true).PHP_EOL,FILE_APPEND); } } } } $this->objDVipCardOrder->commit(); } }