Ver Fonte

寄售转让详情

afa há 7 meses atrás
pai
commit
51944947b6

+ 28 - 255
application/api/controller/Market.php

@@ -1,32 +1,29 @@
 <?php
 
-
 namespace app\api\controller;
 
-use app\common\logic\BscApi;
-use app\common\logic\MyBscApi;
+
 use app\common\controller\Api;
 use app\common\model\AnnouncementModel;
 use app\common\model\UserCollect;
-use app\common\model\LedgerUsdtChangeModel;
 use app\common\model\ProductBuying;
 use app\common\model\ParametersModel;
 use app\common\model\ProductOrder;
 use app\common\model\UserModel;
-use app\common\model\UserPathModel;
 use app\common\model\LedgerWalletModel;
+use app\common\model\ProductTransfer;
+use app\api\logic\MarketLogic;
 use fast\Action;
 use fast\Asset;
 use fast\Http;
 use fast\RechargeStatus;
 use think\Db;
-use think\Log;
-use think\Model;
+use think\Exception;
 
 class Market extends Api
 {
 
-
+    const LockTime = 180; // 锁定时间 3分钟
     //用户收藏
     public function collect(UserCollect $userCollect)
     {
@@ -34,7 +31,6 @@ class Market extends Api
         $params = $this->request->post();
         $validate = \think\Loader::validate('Market');
         if(!$validate->scene('collect')->check($params)) $this->error($validate->getError());
-    
         $userCollect::setUserCollect($this->auth->id, $params['market_id']);
         $this->success("ok");
     }
@@ -68,6 +64,28 @@ class Market extends Api
     }
 
     
+    //锁定寄售
+    public function setTransferLock(ProductTransfer $productTransfer, MarketLogic $marketLogic)
+    {
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Market');
+        if(!$validate->scene('transferlock')->check($params)) $this->error($validate->getError());
+  
+        Db::startTrans();
+        try {
+
+            $marketLogic->setTransferLock($productTransfer, time() + self::LockTime, $params);
+          
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error($e->getMessage(), null, $e->getCode());
+        }
+        $this->success('ok');
+    }
+
 
     
     //求购
@@ -152,252 +170,7 @@ class Market extends Api
         }
     }
 
-    //重算团队业绩和直推人数
-    public function reset_team()
-    {
-        set_time_limit(0);
-
-        //先清空
-        $update = Db::table('user')
-            ->where('id', '>', 0)
-            ->update([
-                'team_power' => 0,
-                'team_num'   => 0,
-                'direct_num' => 0
-            ]);
-
-        $up_power = Db::table('ledger_wallet')
-            ->field('u.id')
-            ->alias('w')
-            ->join('user u', 'w.user_id = u.id')
-            ->where('u.effective_time','>',0)
-            ->where('w.rental_power', 0)
-            ->select();
-        foreach ($up_power as $item){
-            $update = Db::table('ledger_wallet')
-                ->where('user_id', $item['id'])
-                ->update([
-                    'rental_power' => 0.01
-                ]);
-        }
-
-        $power_list = Db::table('ledger_wallet')
-            ->where('rental_power', '>', 0)
-            ->select();
-        $info_list  = 0;
-        $bad_list   = [];
-        foreach ($power_list as $key => $info) {
-            dump('正在处理ID:' . $info['user_id']);
-            $parent_ids = (new UserPathModel())
-                ->where('user_id',$info['user_id'])
-                ->order('distance')
-                ->select();
-            foreach ($parent_ids as $item) {
-                $data = [
-                    'team_power' => Db::raw('team_power + ' . $info['rental_power']),
-                    'team_num'   => Db::raw('team_num + 1'),
-                ];
-                if ($item['distance'] == 1) {
-                    $data['direct_num'] = Db::raw('direct_num+1');
-                }
-                $update = Db::table('user')
-                    ->where('id', $item['parent_id'])
-                    ->update($data);
-                if (!$update) {
-                    $bad_list[] = $info;
-                } else {
-                    $info_list++;
-                }
-            }
-        }
-        dump('成功数量');
-        dump($info_list);
-        dump('失败数量');
-        dump($bad_list);
-    }
-    //累加新增团队业绩
-    public function addTeamPower()
-    {
-        set_time_limit(0);
-
-        $uid = 100702;
-        $num = 1429;
-        $parentIDs = (new UserPathModel())->getAllParentIDs($uid);
-        $parentIDs[] = $uid;
-
-        dump($parentIDs, true, 'ID列表');
-
-        $update = (new UserModel())
-            ->where('id', 'in', $parentIDs)
-            ->update([
-                'team_power' => Db::raw('team_power + ' . $num)
-            ]);
-        dump($update, true, '影响行数');
+ 
 
-    }
-
-    public function resetUserPath()
-    {
-        $ratio = 0.05;//直推奖励
-
-        $info_list = (new OfflineRechargeRecordModel())
-            ->where('status', OfflineRechargeRecordModel::StatusFail)
-            ->order('id', 'ASC')
-            ->select();
-        dump('本次数据共有:' . count($info_list));
-        foreach ($info_list as $info) {
-            $user = (new UserModel())->get($info['user_id']);
-            if (empty($user) || $user['parent_id'] == 0) {
-                continue;
-            }
-
-            $check = (new LedgerUsdtChangeModel())
-                ->where('user_id', $user['parent_id'])
-                ->where('action', Action::UsdtShareBonus)
-                ->where('from_id', $info['user_id'])
-                ->count();
-
-            if($check == 0){
-                (new LedgerWalletModel())->changeWalletAccount($user['parent_id'], Asset::USDT, $info['amount'] * $ratio, Action::UsdtShareBonus, $info['user_id']);
-                dump('订单ID:' . $info['id'] . '处理成功,奖金:' . $info['amount'] * $ratio);
-            }else{
-                dump('订单ID:' . $info['id'] . '处理失败,奖金已存在');
-            }
-        }
-    }
 
-    /**
-     * 补发直推奖
-     * @return void
-     */
-    public function resetShareBonus()
-    {
-        $users = (new UserModel())->order('id', 'ASC')->select();
-        foreach ($users as $v) {
-            (new UserPathModel())->createPath($v['id'], $v['parent_id']);
-        }
-    }
-
-    /**
-     * @return string
-     *
-     * 返回结果
-     * {
-            "status": "1",
-            "message": "OK",
-            "result": {
-                "status": "1"
-            }
-        }
-     */
-    public function getStatusByHaxh()
-    {
-        $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus&txhash=0x30f4190a8237c7744a0981a2895728bab93acf4cb78b03c192ed5ac387405c54&apikey=VTCKIP346DCRWB6JNS4KDANUJJEQN9VAKW";
-
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return "状态api返回数据异常";
-        }
-
-        if ($rsArr['status'] != '1') {
-            return '状态api返回status不为1,错误信息:' . $rsArr['message'];
-        }
-
-        if ($rsArr['result']['status'] != 1) {
-            return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
-        }
-
-    }
-
-    public function AllocateEtc()
-    {
-        $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr[0][2]);
-
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return "状态api返回数据异常";
-        }
-
-        if ($rsArr['status'] != '1') {
-            return '状态api返回status不为1,错误信息:' . $rsArr['message'];
-        }
-
-        if ($rsArr['result']['status'] != 1) {
-            return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
-        }
-
-    }
-    public function debug()
-    {
-        $num =rand(9000,10000);
-        dump($num/10000/1000);
-        $body = (new MyBscApi())->getInfoByTransactionHash('0xc3fc59faa9a1a9ff4fa1516b7df10570876a87993c397f6cd33ce3446641b5b0');
-        dump($body);
-    }
-    public function resetAirdrop()
-    {
-        $order_list = (new ProductOrder())
-            ->where('type_id', 3)
-            ->group('user_id')
-            ->column('user_id');
-        dump($order_list);
-        $order_list_send = (new ProductOrder())
-            ->where('type_id', 4)
-            ->group('user_id')
-            ->column('user_id');
-        dump($order_list_send);
-        $order_list = array_diff($order_list, $order_list_send);
-        dump($order_list);
-        $rs = (new ProductOrder())
-            ->where('type_id', 3)
-            ->where('user_id', 'in', $order_list)
-            ->update([
-                'create_time' => 1745942400
-            ]);
-        dump($rs);
-    }
-
-    public function updateNews()
-    {
-        $en_news = DB::name('announcement_cope')->select();
-        foreach ($en_news as $info) {
-            if(strlen($info['en_title']) > 3){
-                $rs = (new AnnouncementModel())
-                    ->save([
-                        'type_id' => $info['type_id'],
-                        'title' => $info['en_body'],
-                        'introduction' => $info['en_introduction'],
-                        'body' => $info['en_body'],
-                        'img_url' => $info['img_url'],
-                        'to_lang' => 1,
-                        'status' => $info['status'],
-                        'created_by' => $info['created_by'],
-                        'createtime' => $info['createtime'],
-                    ]);
-            }
-        }
-        dump($rs);
-    }
 }

+ 3 - 2
application/api/controller/Product.php

@@ -128,10 +128,11 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
+    public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic)
     {
+
         $ids    = $this->request->post('ids/d', '');
-        $list = $productMarket->with('products,producttransfer')
+        $list = $productMarket->with('products,producttransfer,collect')
             ->where('product_market.id',   $ids)
             ->where('product_market.status', $productMarket::Normal)
             ->find();

+ 14 - 1
application/api/logic/MarketLogic.php

@@ -86,9 +86,22 @@ class MarketLogic
       }
 
 
+      //判断是否锁定
+      public static function setTransferLock(object $productTransfer, int $endTime, array $params)
+      {
+            $time = time();
+            $lockCount = $productTransfer
+                        ->whereIn('id', $params['transfer_id'])
+                        ->where('is_lock', $productTransfer::Lock)
+                        ->whereTime('lock_time','>', - $endTime)
+                        ->count();
+        
+            if(!empty($lockCount)) throw new Exception(__("茶权已被他人锁定,无法操作"));
 
+            return $productTransfer->whereIn('id', $params['transfer_id'])
+                  ->update(['lock_time'=> $time, 'is_lock' => $productTransfer::Lock]);
 
 
-
+      }
 
 }

+ 7 - 7
application/api/validate/Market.php

@@ -10,9 +10,9 @@ class Market extends Validate
      * 验证规则
      */
     protected $rule = [
-      'market_id'  => 'require',
-      'product_id' => 'require',
-      'area_id'    => 'requireIf:type,1',
+      'market_id'     => 'require',
+      'product_id'    => 'require',
+      'transfer_id'   => 'require',
       'num'        => 'requireIf:type,2|gt:0',
       'name'       => 'require',
       'type'       => 'require|in:1,2',
@@ -26,9 +26,9 @@ class Market extends Validate
      */
     protected $message = [
 
-      'market_id.require'=> '订单ID有误',
-      'product_id.require' => '产品ID有误', //
-      'area_id.require'    => '位置ID有误',
+      'market_id.require'   => '订单ID有误',
+      'product_id.require'  => '产品ID有误', //
+      'transfer_id.require' => '参数ID有误',
       'area_id.require'    => '位置ID有误',
       'num.require'        => '数量有误',
       'type.require'       => '参数有误',
@@ -44,7 +44,7 @@ class Market extends Validate
     protected $scene = [
         'collect'      => ['market_id'],
         'announcement' => ['product_id'],
-        'tran' => ['price', 'order_id'],
+        'transferlock' => ['transfer_id'],
         'out'  => ['order_id'],
         'giv'  => ['order_id', 'address'],
     ];

+ 3 - 0
application/common/model/ProductTransfer.php

@@ -26,6 +26,9 @@ class ProductTransfer extends Model
     const Stop           = 0;
     const Normal         = 1;
 
+    const Lock           = 1; //锁定
+    const NotLock        = 0; //未锁定
+
     //状态
     public $status_list = [
         '-1'                    => '全部',