afa 7 bulan lalu
induk
melakukan
2dc8207f72

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

@@ -37,7 +37,7 @@ class Market extends Api
             $validate = \think\Loader::validate('Market');
             if(!$validate->scene('collect')->check($params)) $this->error($validate->getError());
      
-            $userCollect::setUserCollect($this->auth->id, $params['transfer_id']);
+            $userCollect::setUserCollect($this->auth->id, $params['market_id']);
             $this->success("ok");
       }
 

+ 0 - 3
application/api/controller/Order.php

@@ -105,9 +105,6 @@ class Order extends Api
             //扣除Rwa数量
             if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($order_info->user_id, $userModel::getByParentId($order_info->user_id), 1, '-');
 
-            //扣除运费
-            //if($order_info->freight > 0) $ledgerWalletModel->setChangeFrozen($this->auth->id, $order_info->freight, LedgerFrozenChangeModel::Freight, '-');
-  
             $order_info->status= $productOrder::Shipped; 
             $order_info->save();
             // 提交事务

+ 57 - 12
application/api/controller/Product.php

@@ -3,7 +3,7 @@
 namespace app\api\controller;
 
 use think\Db;
-use think\db\Expression;
+use think\Loader ;
 use app\common\controller\Api;
 use app\common\model\ProductLists;
 use app\common\model\ProductMarket;
@@ -11,10 +11,11 @@ use app\common\model\ProductOrder;
 use app\common\model\ProductsModel;
 use app\common\model\ProductPopular;
 use app\api\logic\OrderLogic;
+use app\common\model\UserCollect;
 
 class Product extends Api
 {
-    protected array $noNeedLogin = ['*'];
+    protected array $noNeedLogin = ['getPopularList'];
     protected string $lan = '';
 
     public function _initialize()
@@ -62,7 +63,40 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
+    public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic)
+    {
+
+        $sort    = $this->request->post('sort/d', '');
+        $type_id = $this->request->post('type_id/s', '');
+        $key_val = $this->request->post('key_val/s', '');
+        $order = 'a.price ASC';
+        if($sort == 1) $order = 'a.price DESC';
+        $map['product_market.status'] = $productMarket::Normal;
+        if(!empty($type_id)) $map['product_market.type_id'] = $type_id;
+        if(!empty($key_val)) $map['product_list.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
+
+        $list = $productMarket
+            ->alias('a')
+            ->join("product_list b", "a.product_id = b.id", "left")
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
+            ->where('a.status', $productMarket::Normal)
+            ->where($map)
+            ->order($order)
+            ->paginate($this->pageSize);
+
+        $list = $this->getProductOrderList($list, $this->auth->id, true, $orderLogic);
+        $this->success('', $list);
+    }
+
+
+    
+    /**
+     * 寄售转让收藏列表
+     * sort: 0 默认排序 1价格从高到低 2价格从低到高
+     * type_id 分类
+     * key_val 商品名称搜索
+     */
+    public function getTransferCollectList(ProductMarket $productMarket, OrderLogic $orderLogic)
     {
         $sort    = $this->request->post('sort/d', '');
         $type_id = $this->request->post('type_id/s', '');
@@ -74,20 +108,20 @@ class Product extends Api
         if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
         $list = $productMarket->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")
-            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
+            ->join("user_collect c", "c.market_id = a.id", "left")
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id, count(c.market_id) as collect')
             ->where('a.status', $productMarket::Normal)
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
 
-        foreach ($list as &$item) {
-            $item['issue']       = $orderLogic::getProductIssue($item->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
-            $item['circulation'] = $productOrder::where('product_id', $item->product_id)->where('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量    
-        }
+        $list = $this->getProductOrderList($list, $this->auth->id, false, $orderLogic);
         $this->success('', $list);
     }
+
+
  
-     /**
+    /**
      * 寄售转让详情
      * sort: 0 默认排序 1价格从高到低 2价格从低到高
      * type_id 分类
@@ -95,22 +129,33 @@ class Product extends Api
      */
     public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
     {
-    
         $ids    = $this->request->post('ids/d', '');
         $list = $productMarket->with('products,producttransfer')
             ->where('product_market.id',   $ids)
             ->where('product_market.status', $productMarket::Normal)
             ->find();
-        
         if(empty($list)) $this->error('数据不存在');
 
         $list->issue       = $orderLogic::getProductIssue($list->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
-        $list->circulation = $productOrder::where('product_id', $list->product_id)->where('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量  
+        $list->circulation = $orderLogic::getProductCirculation($list->product_id);  //流通: 所有用户的持有量  
         $this->success('', $list);
     }
  
 
 
+    private static function getProductOrderList(object $list, int $uid, bool $isCollect, OrderLogic $orderLogic): object
+    {
+        if($list){
+            $userCollect = Loader::model('UserCollect');
+            foreach ($list as &$item) {
+                if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('market_id', $item->id)->count();
+                $item['issue']       = $orderLogic::getProductIssue($item->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
+                $item['circulation'] = $orderLogic::getProductCirculation($item->product_id);  //流通: 所有用户的持有量    
+            }
+        }
+        return $list;
+    }
+
     
     //获取分类
     public function getPopularType()

+ 12 - 2
application/api/logic/OrderLogic.php

@@ -11,7 +11,7 @@ use app\common\model\ProductOrder;
 use app\common\model\LedgerTeacChangeModel;
 use app\common\model\ProductPopular;
 
-//订单 product_popular
+//订单
 class OrderLogic
 {
 
@@ -30,13 +30,23 @@ class OrderLogic
       //获取产品发行量
       public static function getProductIssue(int $productId): int
       {
+      
             $popularNum = ProductPopular::where('product_id', $productId)->sum('stock-num');
-            
             $holdNum = ProductOrder::where('product_id', $productId)->where('status', ProductOrder::Paid)->sum('num');
             return bcadd($popularNum, $holdNum);
       }
 
 
+      //获取产品流通量
+      public static function getProductCirculation(int $productId): int
+      {     
+         
+            return Loader::model('ProductOrder')::where('product_id', $productId)->where('status', ProductOrder::Paid)->count();
+      }
+
+
+      //
+
 
 
 }

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

@@ -10,7 +10,7 @@ class Market extends Validate
      * 验证规则
      */
     protected $rule = [
-      'transfer_id'=> 'require',
+      'market_id'=> 'require',
       'product_id' => 'require',
       'area_id'    => 'requireIf:type,1',
       'num'        => 'requireIf:type,2|gt:0',
@@ -25,7 +25,7 @@ class Market extends Validate
      */
     protected $message = [
 
-      'transfer_id.require'=> '订单ID有误',
+      'market_id.require'=> '订单ID有误',
       'product_id.require' => '产品ID有误', //
       'area_id.require'    => '位置ID有误',
       'area_id.require'    => '位置ID有误',
@@ -41,7 +41,7 @@ class Market extends Validate
      * 验证场景
      */
     protected $scene = [
-        'collect'  => ['transfer_id'],
+        'collect'  => ['market_id'],
         'pick' => ['order_id'],
         'tran' => ['price', 'order_id'],
         'out'  => ['order_id'],

+ 12 - 1
application/common/model/ProductMarket.php

@@ -4,6 +4,7 @@ namespace app\common\model;
 
 use think\Model;
 use think\Request;
+use app\common\library\Auth;
 
 class ProductMarket extends Model
 {
@@ -31,12 +32,22 @@ class ProductMarket extends Model
     const Hidden           = 0;
     const Normal           = 1;
 
+
+ 
+
+    //收藏
+    public function collect()
+    {   
+     
+        return $this->hasOne('UserCollect', 'market_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']);
+    }
+ 
+
    
 
     //产品
     public function products()
     {   
-
         $header = Request::instance()->header('Accept-Language');
         $lan    = !empty($header)? substr($header, 0, 2):'zh' ;
         return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->field('id,'.$lan .'_name as name,thum');

+ 3 - 3
application/common/model/UserCollect.php

@@ -18,13 +18,13 @@ class UserCollect extends Model
   
    
       //设置用户收藏
-      public static function setUserCollect(int $uid, int $transferId)
+      public static function setUserCollect(int $uid, int $marketId)
       {
-           $rows = self::where('user_id', $uid)->where('transfer_id', $transferId)->find();
+           $rows = self::where('user_id', $uid)->where('market_id', $marketId)->find();
            if($rows){
                return $rows->delete();
            }else{
-               return self::create(['user_id'=>$uid, 'transfer_id'=>$transferId]);
+               return self::create(['user_id'=>$uid, 'market_id'=>$marketId]);
            }
       }