wugg 1 year ago
parent
commit
c9508b8bbd
3 changed files with 110 additions and 0 deletions
  1. 14 0
      app/admin/model/CgdCaixiao.php
  2. 14 0
      app/admin/model/SaleCaixiao.php
  3. 82 0
      app/command/caixiao.php

+ 14 - 0
app/admin/model/CgdCaixiao.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class CgdCaixiao extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/SaleCaixiao.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class SaleCaixiao extends Model
+{
+    //
+}

+ 82 - 0
app/command/caixiao.php

@@ -0,0 +1,82 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use app\admin\model\CgdCaixiao;use app\admin\model\Platform;use app\admin\model\SaleCaixiao;use think\console\Command;use think\console\Input;use think\console\Output;use think\facade\Cache;use think\facade\Db;
+
+class caixiao extends Command
+{
+	protected $table = null;
+	protected $contect = null;
+	protected $hour = null;
+
+    protected function cgd(){
+    	$cgd=new CgdCaixiao();
+    	$where=[['updatetime','>=',$this->hour]];
+    	$list = $cgd->where($where)->cursor();
+    	$cgdArr=[];
+    	foreach ($list as $item){
+    		$unique = md5($item->cgdNo.$item->updatetime);
+           $temp=['order_type'=>2,'uniqkey'=>$unique,'status'=>1,'addtime'=>date('Y-m:d H:i:s')];
+           if($this->isInCfp($unique)){
+           	$item['cat_name'] = json_decode($item->cat_name);
+            $temp['data']= json_encode($item,JSON_UNESCAPED_UNICODE);
+            $cgdArr[]=$temp;
+           }
+    	}
+    	if(empty($cgdArr)==false) $this->table->insertAll($cgdArr);
+    }
+
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('caixiao')
+            ->setDescription('the caixiao command');
+    }
+    
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+        $key="caixiao_copy";
+        $rs = Cache::store('redis')->inc($key);
+        if ($rs!=1){
+            Cache::store('redis')->dec($key);
+            return true;
+        }
+        $this->hour=date('Y-m-d H:i:s',strtotime('-1 hours'));
+       $this->contect= Db::connect('mysql_cxinv');
+        $this->table =$this->contect->name("caixiao_data");
+        $this->sale();
+        $this->cgd();
+        Cache::store('redis')->dec($key);
+        $output->writeln('caixiao');
+    }
+    
+    protected  function getPay($plat_id=0){
+    	$plat =new Platform();
+    	return $plat->where("id",$plat_id)->value("platform_name","");
+    }
+    
+    protected function sale(){
+    	$sale=new SaleCaixiao();
+    	$where=[["updatetime",">=",$this->hour]];
+    	$list = $sale->where($where)->cursor();
+    	$qrd=[];
+    	foreach ($list as $item){
+           $unique = md5($item->orderCode.$item->updatetime);
+           $temp=["order_type"=>1,"uniqkey"=>$unique,"status"=>1,"addtime"=>date('Y-m:d H:i:s')];
+           if($this->isInCfp($unique)){
+           	$item['cat_name'] = json_decode($item->cat_name);
+            $temp["data"]= json_encode($item,JSON_UNESCAPED_UNICODE);
+            $qrd[]=$temp;
+           }
+    	}
+    	if(empty($qrd)==false) $this->table->insertAll($qrd);
+    }
+    
+    protected function isInCfp($unique){
+        $ist = $this->contect->name("caixiao_data")->where("uniqkey",$unique)->findOrEmpty();
+        return empty($ist);
+    }
+}