瀏覽代碼

寄售详情

afa 7 月之前
父節點
當前提交
236e2d47b2
共有 3 個文件被更改,包括 26 次插入24 次删除
  1. 11 14
      application/api/controller/Product.php
  2. 1 1
      application/common.php
  3. 14 9
      application/common/model/ProductMarket.php

+ 11 - 14
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('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量    
+            $item['circulation'] = $productOrder::where('product_id', $list->product_id)->where('status', $productOrder::Paid)->count();  //流通: 所有用户的持有量    
         }
         $this->success('', $list);
     }
@@ -95,20 +95,17 @@ class Product extends Api
      */
     public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
     {
-        $sort    = $this->request->post('sort/d', '');
-        $order = 'a.price ASC';
-        if($sort == 1) $order = 'a.price DESC';
-        $map['a.status'] = $productMarket::Normal;
-        if(!empty($type_id)) $map['b.type_id'] = $type_id;
-        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')
-            ->where('a.status', $productMarket::Normal)
-            ->where($map)
-            ->order($order)
+    
+        $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();  //流通: 所有用户的持有量  
         $this->success('', $list);
     }
  

+ 1 - 1
application/common.php

@@ -549,6 +549,6 @@ if (!function_exists('paymentLog')) {
      */
     function getOrderSN(string $prefix = 'ORD'): string
     {  
-        return $prefix.time() . '_' . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
+        return $prefix.time() . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
     }
 }

+ 14 - 9
application/common/model/ProductMarket.php

@@ -3,7 +3,7 @@
 namespace app\common\model;
 
 use think\Model;
-
+use think\Request;
 
 class ProductMarket extends Model
 {
@@ -27,23 +27,28 @@ class ProductMarket extends Model
         'update_time_text'
     ];
     
-    //状态 normal','hidden')
+    //状态 normal, hidden
     const Hidden           = 0;
     const Normal           = 1;
 
+   
 
-
-    //分类表
+    //产品
     public function products()
-    {
-        return $this->hasOne('ProductsModel', 'id', 'type_id', [], 'LEFT')->setEagerlyType(0);
+    {   
+
+        $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');
     }
 
 
     //寄售
-    public function productlists()
-    {
-        return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0);
+    public function producttransfer()
+    {   
+        $order = 'price asc';
+        if(input('post.sort') == 1) $order = 'price desc';
+        return $this->hasMany('ProductTransfer', 'product_id', 'product_id', [], 'LEFT')->order($order)->where('status', self::Normal);
     }