afa 7 mesiacov pred
rodič
commit
304ac685d1

+ 30 - 24
application/admin/command/Task.php

@@ -2,12 +2,15 @@
 
 namespace app\admin\command;
 
+use app\admin\controller\user\User;
 use think\console\Command;
 use think\console\Input;
 use app\admin\model\Importregion;
+use app\common\model\ProductOrder;
 use think\console\Output;
 use think\Exception;
 use app\common\model\Region;
+use app\common\model\UserPledge;
 
 class Task extends Command
 {
@@ -65,30 +68,33 @@ class Task extends Command
       //地区导出格式 140213  平城区   140214  云冈区
       public function execute(Input $input, Output $output){
 
-        
-            $reg  =  new Region();
-            $imreg=  new Importregion();
-            $list = $reg::where('parent_id', '=', 140214)->chunk(1000, function($users) use($reg, $imreg) {
-                  foreach ($users as $user) {
-
-                        switch ($user->level) {
-                    
-                              case 4:
-                                    $san = $reg::where('id',  $user->parent_id)->find();
-                                    $two = $reg::where('id',  $san->parent_id)->find();
-                                    $one = $reg::where('id',  $two->parent_id)->find(); 
-                                    $imreg::insert(['name'=> $one->name.'-'.$two->name.'-'.$san->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$two->id.'-'.$san->id.'-'.$user->id, 'level'=>4]);
-                                    break;
-                              // 更多的 case 语句
-                              default:
-                                   echo "level error";
-                                   break;
-
-                          }
-                        //
-                  };
-
-            });
+            //
+            $rows = UserPledge::where('status', '>', 0)->select();
+            $model = new ProductOrder();
+            foreach ($rows as $row) {
+
+                  //修改详情
+                  $detail = json_decode($row['details'], true);
+              
+                  foreach ($detail as &$item) {
+                        $item['id'] = $model::where('order_no', '=', $item['order_no'])->value('id');
+
+                        //修改订单状态
+                        if($row['user_id'] == 1073 && $row['status'] == UserPledge::Remove){
+
+                              $model::where('id', '=', $item['id'])->setField('status', ProductOrder::Paid);
+                        }
+                      
+                  }
+                  $row->details = json_encode($detail, JSON_UNESCAPED_UNICODE);
+                  $row->save();
+
+
+              
+      
+                  
+            }
+            
 
       }
 

+ 1 - 1
application/api/controller/Product.php

@@ -82,7 +82,7 @@ class Product extends Api
 
         foreach ($list as &$item) {
             $item['issue']       = $orderLogic::getProductIssue($item->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
-            $item['circulation'] = $productOrder::where('product_id', $list->product_id)->where('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量    
+            $item['circulation'] = $productOrder::where('product_id', $item->product_id)->where('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量    
         }
         $this->success('', $list);
     }

+ 1 - 1
application/api/logic/PledgeLogic.php

@@ -116,7 +116,7 @@ class PledgeLogic
 
         //修改状态
         $detail =json_decode($rows->details, true);
-        Loader::model('ProductOrder')::whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
+        Loader::model('ProductOrder')::where('user_id', $user_id)->whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
 
         $rows->status    = $model::Remove;
         $rows->last_time = $time;

+ 77 - 0
extend/fast/Snowflake.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace fast;
+
+class Snowflake
+{
+    private int $datacenterId; // 数据中心ID
+    private int $machineId;    // 机器ID
+    private int $sequence = 0; // 序列号
+    private int $lastTimestamp = -1; // 上一个时间戳
+
+    private const DATA_CENTER_ID_BITS = 5; // 数据中心ID所占位数
+    private const MACHINE_ID_BITS = 5;      // 机器ID所占位数
+    private const SEQUENCE_BITS = 12;        // 序列号所占位数
+
+    private const MAX_DATA_CENTER_ID = -1 ^ (-1 << self::DATA_CENTER_ID_BITS);
+    private const MAX_MACHINE_ID = -1 ^ (-1 << self::MACHINE_ID_BITS);
+    
+    private const TIMESTAMP_LEFT_SHIFT = self::SEQUENCE_BITS + self::MACHINE_ID_BITS + self::DATA_CENTER_ID_BITS;
+    private const SEQUENCE_LEFT_SHIFT = self::MACHINE_ID_BITS + self::DATA_CENTER_ID_BITS;
+
+    private int $epoch; // 起始时间戳
+
+    public function __construct(int $datacenterId, int $machineId)
+    {
+        if ($datacenterId < 0 || $datacenterId > self::MAX_DATA_CENTER_ID) {
+            throw new \Exception("数据中心ID超出范围");
+        }
+
+        if ($machineId < 0 || $machineId > self::MAX_MACHINE_ID) {
+            throw new \Exception("机器ID超出范围");
+        }
+
+        $this->datacenterId = $datacenterId;
+        $this->machineId = $machineId;
+        $this->epoch = 1609430400000; // 自定义起始时间(例如2021年1月1日)
+    }
+
+    public function nextId(): int
+    {
+        $timestamp = $this->currentTimeMillis();
+
+        if ($timestamp < $this->lastTimestamp) {
+            throw new \Exception("错误:系统时钟发生回拨");
+        }
+
+        if ($this->lastTimestamp === $timestamp) {
+            $this->sequence = ($this->sequence + 1) & ((1 << self::SEQUENCE_BITS) - 1);
+            if ($this->sequence === 0) {
+                $timestamp = $this->waitNextMillis($timestamp);
+            }
+        } else {
+            $this->sequence = 0;
+        }
+
+        $this->lastTimestamp = $timestamp;
+
+        return (($timestamp - $this->epoch) << self::TIMESTAMP_LEFT_SHIFT) |
+               ($this->datacenterId << self::SEQUENCE_LEFT_SHIFT) |
+               ($this->machineId << self::SEQUENCE_BITS) |
+               $this->sequence;
+    }
+
+    private function waitNextMillis(int $lastTimestamp): int
+    {
+        $timestamp = $this->currentTimeMillis();
+        while ($timestamp <= $lastTimestamp) {
+            $timestamp = $this->currentTimeMillis();
+        }
+        return $timestamp;
+    }
+
+    private function currentTimeMillis(): int
+    {
+        return (int)(microtime(true) * 1000);
+    }
+}