123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/11/14
- * Time: 15:45
- */
- namespace JinDouYun\Controller\Cron;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Cache\CustomerCache;
- use JinDouYun\Dao\Market\DVipCardOrder;
- use Mall\Framework\Core\StatusCode;
- class CustomerCron
- {
- private $objCustomerCache;
- private $objDVipCardOrder;
- public function __construct()
- {
- $this->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();
- }
- }
|