Forráskód Böngészése

新增秒杀库存归还

luojianqun 1 éve
szülő
commit
022967402d

+ 6 - 13
App/Crontab/BalanceCrontab.php

@@ -146,8 +146,8 @@ class BalanceCrontab implements JobInterface
                 'first' => ['value'=>'尊敬的客户:您上月共消费了'.$sendData['consume_credit'].'积分'],
                 'keyword1' => ['value'=>$sendData['balance']],
                 'keyword2' => ['value'=>date('Y年m月d日',$sendData['end_time'])],
-//                'remark' => ['value'=>'欢迎登录「'.$sendData['operators_name'].'」小程序选购心仪的商品。'],
-                'remark' => ['value'=>'做最美的女神,点击领取走心好礼', 'color' => '#E3170D'],
+                'remark' => ['value'=>'欢迎登录「'.$sendData['operators_name'].'」小程序选购心仪的商品。'],
+//                'remark' => ['value'=>'做最美的女神,点击领取走心好礼', 'color' => '#E3170D'],
             ]);
             $status = $api_res['response']['errcode']!==0?2:1;  //0无响应 1成功 2失败
             
@@ -155,17 +155,10 @@ class BalanceCrontab implements JobInterface
         //手机短信推送
         if($sendData['push_type']==2){
             $sms = new Sms($sendData['operators_id']);
-            if ($sendData['operators_id'] == '17') {  //湘江银行
-                $api_res = $sms->send($sendData['mobile'],'SMS_271570466',[
-                    's_1' => $sendData['balance'],
-                ]);
-            } else {
-                $api_res = $sms->send($sendData['mobile'],'SMS_232170368',[
-                    's_1' => $sendData['consume_credit'],
-                    's_2' => $sendData['balance'],
-                ]);
-            }
-
+            $api_res = $sms->send($sendData['mobile'],'SMS_232170368',[
+                's_1' => $sendData['consume_credit'],
+                's_2' => $sendData['balance'],
+            ]);
             $status = $api_res['response']['Code']!='OK'?2:1;  //0无响应 1成功 2失败
         }
         //更新任务内容表

+ 60 - 0
App/Crontab/SeckillCrontab.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace App\Crontab;
+
+use EasySwoole\Crontab\JobInterface;
+use EasySwoole\Mysqli\QueryBuilder;
+use EasySwoole\ORM\DbManager;
+use App\Models\BalancePushSet;
+use App\Models\ShopGoods;
+use App\Models\SeckillGoods;
+
+
+class SeckillCrontab implements JobInterface
+{
+
+    protected $set; //秒杀库存归还
+
+    public function jobName(): string
+    {
+        // 定时任务的名称
+        return 'SeckillCrontab';
+    }
+
+    public function crontabRule(): string
+    {
+        // 定义执行规则 根据 Crontab 来定义
+        // 每分钟执行一次
+        return '*/1 * * * *';
+    }
+
+    public function run()
+    {
+        // 定时任务的执行逻辑
+        $this->set = BalancePushSet::create()->get()->toArray();
+        //是否启用
+        if($this->set['enable']!=1){
+            return;
+        }
+        $endTime = time();
+        $sql = "SELECT a.`name`,b.active_id,b.operators_id,b.goodsid,b.total FROM ims_superdesk_shop_seckill_active a LEFT JOIN ims_superdesk_shop_seckill_active_operators_goods b ON a.id=b.active_id WHERE a.endtime<{$endTime} AND b.total>0";
+        $queryBuild = new QueryBuilder();
+        $queryBuild->raw($sql);
+        $res_data = DbManager::getInstance()->query($queryBuild, true, 'default')->toArray();
+        foreach($res_data['result'] as $k=>$val){
+            ShopGoods::create()->update([
+                'total' => QueryBuilder::inc(intval($val['total'])),
+            ], ['id' => $val['goodsid']]);
+            SeckillGoods::create()->update([
+                'total' => 0,
+            ], ['active_id' => $val['active_id'], 'operators_id' => $val['operators_id'], 'goodsid' => $val['goodsid']]);
+        }
+    }
+
+    public function onException(\Throwable $throwable)
+    {
+        // 捕获 run 方法内所抛出的异常
+    }
+
+
+}

+ 18 - 0
App/Models/SeckillGoods.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Models;
+
+use EasySwoole\ORM\AbstractModel;
+
+/**
+ * 秒杀商品表
+ * Class WarningBody
+ */
+class SeckillGoods extends AbstractModel
+{
+     /**
+      * @var string 
+      */
+     protected $tableName = 'ims_superdesk_shop_seckill_active_operators_goods';
+     
+}

+ 18 - 0
App/Models/ShopGoods.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Models;
+
+use EasySwoole\ORM\AbstractModel;
+
+/**
+ * 主站商品表
+ * Class WarningBody
+ */
+class ShopGoods extends AbstractModel
+{
+     /**
+      * @var string 
+      */
+     protected $tableName = 'ims_superdesk_shop_goods';
+     
+}

+ 2 - 0
EasySwooleEvent.php

@@ -13,6 +13,7 @@ use EasySwoole\ORM\DbManager;
 use EasySwoole\ORM\Db\Connection;
 use EasySwoole\ORM\Db\Config;
 use App\Crontab\ElasticSearchGoodsCrontab;
+use App\Crontab\SeckillCrontab;
 
 class EasySwooleEvent implements Event
 {
@@ -65,6 +66,7 @@ class EasySwooleEvent implements Event
 
         // 注册定时任务
         $crontab->register(new BalanceCrontab());
+        $crontab->register(new SeckillCrontab());
         $crontab->register(new ElasticSearchGoodsCrontab());
         $crontab->attachToServer(ServerManager::getInstance()->getSwooleServer());