afa 7 months ago
parent
commit
5bd09fccbe

+ 0 - 1
application/api/controller/Market.php

@@ -177,7 +177,6 @@ class Market extends Api
             return $this->error($e->getMessage());
         }
         $this->success('ok');
-
     }
 
     //取消求购

+ 40 - 128
application/api/controller/User.php

@@ -2,6 +2,8 @@
 
 namespace app\api\controller;
 
+use app\api\logic\OrderLogic;
+use app\api\logic\UserLogic;
 use app\common\controller\Api;
 use app\common\model\ProductOrder;
 use app\common\model\LedgerSmhChangeModel;
@@ -72,26 +74,14 @@ class User extends Api
      * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
      * @return void
      */
-    public function getNftList(ProductOrder $productOrder, ProductTransfer $productTransfer)
+    public function getNftList(ProductOrder $productOrder, ProductTransfer $productTransfer, UserLogic $userLogic)
     {
         $typeId = $this->request->post('type_id/d', 0);
         $productId = $this->request->post('product_id/d', 0);
-        $where = self::getNftWhere($typeId, $productId, $productOrder);
-        $list = $productOrder->alias('a')
-              ->join("product_list b", "b.id = a.product_id", "left")
-              ->join("products c", "c.id = b.type_id", "left")
-              ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
-              ->join("product_area d", "d.id = a.area_id", "left") //地区
-              ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.status,a.order_no,a.type_id,c.'.$this->lan.'_title as title,
-              z.price as transfer_price,d.address,b.min_transfer_fee,b.max_transfer_fee,b.gift_fee,b.freight,b.is_transfer,b.is_gift,b.is_freight,b.is_storage,b.is_buying')
-              ->where('a.user_id', $this->auth->id)
-              ->where($where)
-              ->order('a.id DESC')
-              ->paginate($this->pageSize);
-        //地板价格 
-        foreach ($list as &$item) {
-            if($item->price == 0) $item->floor_price = $productTransfer::getTransferMinPrice($item->product_id);
-        }      
+        //搜索条件
+        $where = $userLogic::getNftWhere($typeId, $productId, $productOrder);
+        //查询
+        $list = $userLogic::getUserNftList($productOrder, $productTransfer, $this->lan, $this->auth->id, $this->pageSize, $where);
         $this->success('', $list);
     }
 
@@ -100,18 +90,13 @@ class User extends Api
      * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
      * @return void
      */
-    public function getMyNftList(ProductOrder $productOrder)
+    public function getMyNftList(ProductOrder $productOrder, UserLogic $userLogic)
     {
         $typeId = $this->request->post('type_id/d', 0);
-        $where = self::getNftWhere($typeId, 0, $productOrder);
-        $list = $productOrder->alias('a')
-              ->join("product_list b", "b.id = a.product_id", "left")
-              ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id, count(a.num) as hold_num')
-              ->where('a.user_id', $this->auth->id)
-              ->group('a.product_id')
-              ->where($where)
-              ->order('a.id DESC')
-              ->paginate($this->pageSize);
+        //搜索条件
+        $where = $userLogic::getNftWhere($typeId, 0, $productOrder);
+        //查询
+        $list = $userLogic::getMyUserNftList($productOrder, $this->auth->id, $this->lan, $where, $this->pageSize);
         $this->success('', $list);
     }
 
@@ -119,28 +104,9 @@ class User extends Api
      * 余额记录信息
      * @return void
      */
-    public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, LedgerWalletModel $ledgerWalletModel)
+    public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, UserLogic $userLogic)
     {
-        // 启动事务
-        Db::startTrans();
-        try {
-            $list['total'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
-                            ->where('action', $ledgerTokenChangeModel::Share)
-                            ->sum("change_amount");
-
-            $list['data']  = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
-                            ->where('action', $ledgerTokenChangeModel::Share)
-                            ->order('id desc')
-                            ->paginate($this->pageSize);
-
-            $list['statusList'] = $ledgerTokenChangeModel::getStatusList();
-            // 提交事务
-            Db::commit();
-        } catch (Exception $e) {
-            // 回滚事务
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
+        $list = $userLogic::getUserBalanceLog($ledgerTokenChangeModel, $this->auth->id, $this->pageSize);
         $this->success('',  $list);
     }
 
@@ -148,16 +114,9 @@ class User extends Api
      * 我的茶友
      * @return void
      */
-    public function getChaList(UserModel $userModel)
+    public function getChaList(UserModel $userModel, UserLogic $userLogic)
     {
-        // 总推荐数
-        $list['total'] = $userModel::where('parent_id', $this->auth->id)->count();
-    
-        // 直推列表 
-        $list['data'] = $userModel::where('parent_id', $this->auth->id)
-                    ->field("address,address_level,create_time,nickname,direct_super,REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
-                    ->order('id desc')
-                    ->paginate($this->pageSize);
+        $list = $userLogic::getUserChaList($userModel, $this->auth->id, $this->pageSize);
         $this->success('', $list);
     }
 
@@ -199,88 +158,41 @@ class User extends Api
      * 获取操作信息 购买、赠送、提货、转让
      * @return void
      */
-    public function getOperateLog(ProductOrder $productOrder)
+    public function getOperateLog(ProductOrder $productOrder, UserLogic $userLogic)
     {   
         $typeId = $this->request->post('type_id/d', 0);
         $status = $this->request->post('status/d', 0);
         $areaId = $this->request->post('area_id/s', 0);
-        $where = self::getOperateWhere($typeId, $status, $areaId);
-        $list['data'] = $productOrder->alias('a')
-                ->join("product_list b", "b.id = a.product_id", "left")
-                ->join("product_area d", "d.id = a.area_id", "left") //地区
-                ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id,a.create_time,d.province,d.city,d.area,d.county')
-                ->where('a.user_id', $this->auth->id)
-                ->where($where)
-                ->order('a.id DESC')
-                ->paginate($this->pageSize);
-        foreach ($list['data'] as &$item) {
-            $item->address_id = '';
-            if($item->province > 0) $item->address_id .= $item->province.'-';
-            if($item->city > 0) $item->address_id .= $item->city.'-';
-            if($item->area > 0) $item->address_id .= $item->area.'-';
-            if($item->county > 0) $item->address_id .= $item->county.'-';
-            $item->address_id = rtrim($item->address_id, '-');
-        }        
-        $list['statusList'] = $productOrder::getStatusAll();
+        //搜索条件
+        $where = $userLogic::getOperateWhere($typeId, $status, $areaId);
+        //查询
+        $list  = $userLogic::getUserOperateLog($productOrder, $this->lan, $this->auth->id, $this->pageSize, $where);
         $this->success('', $list);
     }
 
-    /**
-     * Nft搜索条件
-     * @return array
-     */
-    private static function getNftWhere(int $typeId, int $productId , object  $productOrder): array
-    {   
-        $where = [];
-        switch ($typeId) {
-            case 0:
-                $where['a.status'] = ['=' , $productOrder::Paid];
-                break;
-            case 1:
-                $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
-                break;
-            case 2:
-                $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
-                break;
-            case 3:
-                $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
-                break;
-            case 4:
-                $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
-                break;
-            case 5:
-                $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
-                break;
-        }
-        if($productId > 0) $where['a.product_id'] = ['=' , $productId];
-        return $where;
+    
+    //获取用户待支付订单数量
+    public function getWaitPayOrderCount(OrderLogic $orderLogic)
+    {
+        $count = $orderLogic::getWaitPayOrderCount($this->auth->id, config('market_transfer.lock_time'));
+        $this->success('', $count);
     }
 
-    /**
-     * 操作记录搜索条件
-     * @return array
-     */
-    private static function getOperateWhere(int $typeId, int $status, string $areaId)
+    //获取用户待支付订单
+    public function getWaitPayOrderList(OrderLogic $orderLogic)
     {
-        $where = [];
-        //类型
-        if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
-        //编号Id
-        if(!empty($areaId)){
-            $arr = explode('-', $areaId);
-            if(count($arr) > 0) {
-                if(isset($arr[0])) $where['d.province'] = ['=', $arr[0]];
-                if(isset($arr[1])) $where['d.city']     = ['=', $arr[1]];
-                if(isset($arr[2])) $where['d.area']     = ['=', $arr[2]];
-                if(isset($arr[3])) $where['d.county']   = ['=', $arr[3]];
-            }
-        }
-        return $where;
+        $list = $orderLogic::getWaitPayOrderList($this->auth->id, config('market_transfer.lock_time'), $this->pageSize, $this->lan);
+        $this->success('', $list);
     }
 
-
-
-
-    
+    //取消用户待支付订单
+    public function setCancelWaitPayOrder(OrderLogic $orderLogic)
+    {   
+        $transfer_id = $this->request->post('transfer_id/d', 0);
+        if(empty($transfer_id)) $this->error(__('Invalid parameters'));
+        $list = $orderLogic::setCancelWaitPayOrder($this->auth->id, $transfer_id);
+        $this->success('ok', $list);
+    }
+ 
      
 }

+ 2 - 4
application/api/logic/MarketLogic.php

@@ -89,11 +89,9 @@ class MarketLogic
             $time = time();
             $lockList = $productTransfer->whereIn('id', $transferId)->select();
             foreach ($lockList as &$item) {
-
                   if($item->user_id == $uid)  throw new Exception(__("不能锁自己的寄售单"));
-                  if($item->is_lock == $productTransfer::Lock && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
-                  
-                  $item->is_lock = $productTransfer::Lock;
+                  if($item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
+                  $item->lock_uid  = $uid;
                   $item->lock_time = $time;
                   $item->save();
             }            

+ 31 - 0
application/api/logic/OrderLogic.php

@@ -74,9 +74,13 @@ class OrderLogic
                   if(empty($order_info)) throw new Exception(__("订单不存在"));
             }
             $totalAmount = 0; //总金额
+            $time = time();
+            $endTime = config('market_transfer.lock_time');
             foreach ($result as $item) {
 
                   if($item->user_id == $uid) throw new Exception(__("不能购买自己寄售的商品"));
+                  if($item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
+
                   $totalAmount = bcadd($totalAmount, $item->price, 2);
                   //抢购订单
                   $popular_order = $productOrder->where('id', $item->order_id)->find();
@@ -112,4 +116,31 @@ class OrderLogic
             return true;
       }
 
+      //获取赠送产品订单数量
+      public static function getWaitPayOrderCount(int $uid, int $endTime): int
+      {     
+            return Loader::model('ProductTransfer')::where('lock_uid', $uid)->where('lock_time', '>', time()-$endTime)->where('status', ProductTransfer::Normal)->count();
+      }
+
+      //获取赠送产品订单列表
+      public static function getWaitPayOrderList(int $uid, int $endTime, int $page, string $lan): object
+      {     
+            $result =Loader::model('ProductTransfer')::alias('a')
+                  ->join("product_list b", "a.product_id = b.id", "left")
+                  ->where('a.lock_uid', $uid)
+                  ->where('a.lock_time', '>', time()-$endTime)
+                  ->where('a.status', ProductTransfer::Normal)
+                  ->field('a.id,a.order_id,a.price,a.fees,a.lock_time,b.thum,b.' . $lan . '_name as name')
+                  ->order('a.id desc')
+                  ->paginate($page);
+            return $result;
+      }
+
+      //取消赠送产品订单
+      public static function setCancelWaitPayOrder(int $uid, int $transfer_id): bool
+      {
+            return Loader::model('ProductTransfer')::where('id', $transfer_id)->where('lock_uid', $uid)->update(['lock_uid' => 0, 'lock_time' => 0]);
+      }
+
+
 }

+ 165 - 0
application/api/logic/UserLogic.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace app\api\logic;
+
+use Exception;
+use think\Env;
+use think\Cache;
+use think\Loader ;
+use fast\Asset;
+use app\common\model\ProductOrder;
+use app\common\model\LedgerTeacChangeModel;
+use app\common\model\ProductPopular;
+use app\common\model\ProductTransfer;
+
+//用户逻辑
+class UserLogic
+{
+
+
+      //获取用户分享余额记录信息
+      public static function getUserBalanceLog(object $ledgerTokenChangeModel, int $uid, int $pageSize): array
+      {
+            //总收益
+            $list['total'] = $ledgerTokenChangeModel::where('user_id', $uid)->where('action', $ledgerTokenChangeModel::Share)->sum("change_amount");
+
+            $list['data']  = $ledgerTokenChangeModel::where('user_id', $uid)
+                        ->where('action', $ledgerTokenChangeModel::Share)
+                        ->order('id desc')
+                        ->paginate($pageSize);
+
+            $list['statusList'] = $ledgerTokenChangeModel::getStatusList();
+            return $list;
+      }
+
+
+      //获取用户发行Nft列表
+      public static function getUserNftList(object $productOrder,  object $productTransfer, string $lan, int $uid, int $pageSize, array $where): object
+      {
+            $list = $productOrder->alias('a')
+              ->join("product_list b", "b.id = a.product_id", "left")
+              ->join("products c", "c.id = b.type_id", "left")
+              ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
+              ->join("product_area d", "d.id = a.area_id", "left") //地区
+              ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.order_no,a.type_id,c.'.$lan.'_title as title,
+              z.price as transfer_price,d.address,b.min_transfer_fee,b.max_transfer_fee,b.gift_fee,b.freight,b.is_transfer,b.is_gift,b.is_freight,b.is_storage,b.is_buying')
+              ->where('a.user_id', $uid)
+              ->where($where)
+              ->order('a.id DESC')
+              ->paginate($pageSize);
+            //地板价格 
+            foreach ($list as &$item) {
+                  if($item->price == 0) $item->floor_price = $productTransfer::getTransferMinPrice($item->product_id);
+            } 
+            return $list;
+      }
+
+
+
+      //获取自己发行的Nft列表
+      public static function getMyUserNftList(object $productOrder, int $uid, string $lan, array $where, int $pageSize): object
+      {     
+           return $productOrder->alias('a')
+            ->join("product_list b", "b.id = a.product_id", "left")
+            ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id, count(a.num) as hold_num')
+            ->where('a.user_id', $uid)
+            ->group('a.product_id')
+            ->where($where)
+            ->order('a.id DESC')
+            ->paginate($pageSize);
+      }
+
+
+      //获取我的茶友好列表
+      public static function getUserChaList(object $userModel, int $uid, int $pageSize): array
+      {     
+            // 总推荐数
+            $list['total'] = $userModel::where('parent_id', $uid)->count();
+      
+            // 直推列表 
+            $list['data'] = $userModel::where('parent_id', $uid)
+                        ->field("address,address_level,create_time,nickname,direct_super,REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
+                        ->order('id desc')
+                        ->paginate($pageSize);
+            return $list;            
+      }
+
+
+
+      public static function getUserOperateLog(object $productOrder, string $lan, int $uid, int $pageSize, array $where): array
+      {
+            $list['data'] = $productOrder->alias('a')
+                        ->join("product_list b", "b.id = a.product_id", "left")
+                        ->join("product_area d", "d.id = a.area_id", "left") //地区
+                        ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id,a.create_time,d.province,d.city,d.area,d.county')
+                        ->where('a.user_id', $uid)
+                        ->where($where)
+                        ->order('a.id DESC')
+                        ->paginate($pageSize);
+            foreach ($list['data'] as &$item) {
+                  $item->address_id = '';
+                  if($item->province > 0) $item->address_id .= $item->province.'-';
+                  if($item->city > 0) $item->address_id .= $item->city.'-';
+                  if($item->area > 0) $item->address_id .= $item->area.'-';
+                  if($item->county > 0) $item->address_id .= $item->county.'-';
+                  $item->address_id = rtrim($item->address_id, '-');
+            }        
+            $list['statusList'] = $productOrder::getStatusAll();
+            return $list;
+      }
+
+
+      /**
+       * Nft搜索条件
+       * @return array
+       */
+      public static function getNftWhere(int $typeId, int $productId , object  $productOrder): array
+      {   
+            $where = [];
+            switch ($typeId) {
+                  case 0:
+                  $where['a.status'] = ['=' , $productOrder::Paid];
+                  break;
+                  case 1:
+                  $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
+                  break;
+                  case 2:
+                  $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
+                  break;
+                  case 3:
+                  $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
+                  break;
+                  case 4:
+                  $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
+                  break;
+                  case 5:
+                  $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
+                  break;
+            }
+            if($productId > 0) $where['a.product_id'] = ['=' , $productId];
+            return $where;
+      }
+
+      /**
+       * 操作记录搜索条件
+       * @return array
+       */
+      public static function getOperateWhere(int $typeId, int $status, string $areaId)
+      {
+            $where = [];
+            //类型
+            if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
+            //编号Id
+            if(!empty($areaId)){
+                  $arr = explode('-', $areaId);
+                  if(count($arr) > 0) {
+                  if(isset($arr[0])) $where['d.province'] = ['=', $arr[0]];
+                  if(isset($arr[1])) $where['d.city']     = ['=', $arr[1]];
+                  if(isset($arr[2])) $where['d.area']     = ['=', $arr[2]];
+                  if(isset($arr[3])) $where['d.county']   = ['=', $arr[3]];
+                  }
+            }
+            return $where;
+      }
+
+}

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

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