afa 6 months ago
parent
commit
8fb62391ff

+ 2 - 0
application/api/controller/Home.php

@@ -44,6 +44,7 @@ class Home extends Api
             ->field('id,title as title,img_url,createtime')
             ->where('type_id', $announcement::Banner)
             ->where('status', $announcement::Normal)
+            ->where('is_show', $announcement::Normal)
             ->where('to_lang', $this->lan)
             ->limit(0,10)
             ->order('id DESC,weigh desc')
@@ -54,6 +55,7 @@ class Home extends Api
             ->field('id,title as title,img_url,createtime')
             ->where('type_id', $announcement::Announ)
             ->where('status', $announcement::Normal)
+            ->where('is_show', $announcement::Normal)
             ->where('to_lang', $this->lan)
             ->limit(0,10)
             ->order('id DESC,weigh desc')

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

@@ -118,7 +118,7 @@ class Order extends Api
 
 
     /**
-     * 订单寄售转让
+     * 添加订单寄售转让
      * @return void
      */
     public function transfer(ProductOrder $productOrder, MarketLogic $marketLogic)

+ 30 - 29
application/api/controller/Product.php

@@ -6,8 +6,7 @@ use think\Db;
 use think\Loader ;
 use app\common\controller\Api;
 use app\common\model\ProductLists;
-use app\common\model\ProductMarket;
-use app\common\model\ProductOrder;
+use app\common\model\ProductTransfer;
 use app\common\model\ProductsModel;
 use app\common\model\ProductPopular;
 use app\api\logic\OrderLogic;
@@ -64,23 +63,22 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferList(ProductTransfer $productTransfer, 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
+        $order = 'price ASC';
+        if($sort == 1) $order = 'price desc';
+        $map['a.status'] = $productTransfer::Normal;
+        if(!empty($type_id)) $map['a.type_id'] = $type_id;
+        if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
+     
+        $list = $productTransfer
             ->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)
+            ->group('a.product_id')
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,min(a.price) as price,a.product_id,b.type_id')
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
@@ -97,21 +95,23 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferCollectList(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferCollectList(ProductTransfer $productTransfer, 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['a.status'] = $productMarket::Normal;
+        $order = 'b.weigh desc';
+        if($sort == 1) $order = 'price DESC';
+        if($sort == 2) $order = 'price ASC';
+        $map['a.status'] = $productTransfer::Normal;
         if(!empty($type_id)) $map['a.type_id'] = $type_id;
         if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
-        $list = $productMarket->alias('a')
+        $list = $productTransfer->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")
-            ->join("user_collect c", "c.market_id = a.id and c.user_id = {$this->auth->id}")
-            ->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)
+            ->join("user_collect c", "c.product_id = a.product_id and c.user_id = {$this->auth->id}")
+            ->group('a.product_id')
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,min(a.price) as price,a.product_id,a.type_id')
+            ->where('a.status', $productTransfer::Normal)
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
@@ -128,18 +128,19 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferDetail(ProductLists $productLists, OrderLogic $orderLogic)
     {
-
+       
         $ids    = $this->request->post('ids/d', '');
-        $list = $productMarket->with('products,producttransfer,collect')
-            ->where('product_market.id',   $ids)
-            ->where('product_market.status', $productMarket::Normal)
+        $list = $productLists->with('producttransfer,collect')
+            ->where('product_list.id',   $ids)
+            ->where('product_list.status', $productLists::Normal)
+            ->field('id,'.$this->lan .'_name as name,thum,details')
             ->find();
         if(empty($list)) $this->error('数据不存在');
 
-        $list->issue       = $orderLogic::getProductIssue($list->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
-        $list->circulation = $orderLogic::getProductCirculation($list->product_id);  //流通: 所有用户的持有量  
+        $list->issue       = $orderLogic::getProductIssue($list->id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
+        $list->circulation = $orderLogic::getProductCirculation($list->id);  //流通: 所有用户的持有量  
         $this->success('', $list);
     }
  
@@ -158,7 +159,7 @@ class Product extends Api
         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();
+                if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('product_id', $item->product_id)->count();
                 $item['issue']       = $orderLogic::getProductIssue($item->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
                 $item['circulation'] = $orderLogic::getProductCirculation($item->product_id);  //流通: 所有用户的持有量    
             }

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

@@ -9,7 +9,7 @@ use think\Loader ;
 use app\common\model\ProductOrder;
 use app\common\model\ProductLists;
 use app\common\model\ProductTransfer;
-use app\common\model\ProductMarket;
+
 
 //自由市场
 class MarketLogic
@@ -18,32 +18,7 @@ class MarketLogic
       // 添加市场寄售订单
       public static function createTransferOrder(float $price, int $productId, int $areaId, string $orderNo, int $userId, array $params)
       {
-            //获取市场价
-            $minPrice = ProductTransfer::getTransferMinPrice($productId);
-            if($price < $minPrice || empty($minPrice)) $minPrice = $price;
-            //添加市场
-            $rows = ProductMarket::where('product_id', $productId)->find();
-            if(empty($rows)){
-                
-                  ProductMarket::create([
-                  'product_id' => $productId, 
-                  'type_id'    => ProductLists::getProductTypeById($productId), 
-                  'price'      => $minPrice,'status' => ProductMarket::Normal]);
-            }else{
-
-                  $isUpdate = false;    
-                  //更新市场状态
-                  if($rows->status != ProductMarket::Normal ){
-                        $rows->status = ProductMarket::Normal;
-                        $isUpdate = true;
-                  }
-                  //更新最低价
-                  if($rows->price != $minPrice){
-                        $rows->price = $minPrice;
-                        $isUpdate = true;
-                  }
-                  if($isUpdate) $rows->save();
-            }
+          
             //添加寄售订单
             $fee = getConfig('transfer_fee');
             $feeAmount = bcmul($price, $fee, 2) ;
@@ -52,30 +27,12 @@ class MarketLogic
 
 
 
-      //取消寄售更新最低价
+      //取消寄售更新
       public static function cancelTransferOrder(int $orderId, int $userId, $orderInfo)
       {
-            //市场
-            $market = ProductMarket::where('product_id', $orderInfo['product_id'])->find();
             //转让
             $rows  = ProductTransfer::where('order_id', $orderId)->find();
-            if($market){
-                  $isUpdate = false;
-                  //是否全部取消
-                  $count = ProductTransfer::where('product_id', $orderInfo['product_id'])->where('status', ProductTransfer::Normal)->count();
-                  if($count == 1){
-                        $isUpdate = true;
-                        $market->status = ProductMarket::Hidden;
-                  }else{
-                        //取消最小价格
-                        if($rows->price < $market->price){
-                              $isUpdate = true;
-                              $market->price = ProductTransfer::getTransferMinPriceByProduct($orderInfo['product_id'], $rows->price);
-                        }
-                  }
-                  //市场状态
-                  if($isUpdate) $market->save();
-            }
+           
             //转让列表取消
             $rows->status = ProductTransfer::Stop;
             $rows->save();

+ 24 - 1
application/common/model/ProductLists.php

@@ -3,7 +3,7 @@
 namespace app\common\model;
 
 use think\Model;
-
+use app\common\library\Auth;
 
 class ProductLists extends Model
 {
@@ -64,6 +64,29 @@ class ProductLists extends Model
     {
         return $this->hasOne('ProductPopular', 'product_id', 'id', [], 'INNER')->order('start_time')->setEagerlyType(0);
     }
+
+
+    //寄售
+    public function producttransfer()
+    {   
+        $map = [];
+        $transfer = input('post.transfer_id/d', 0);
+        if($transfer > 0) $map['id'] = $transfer;
+        $order = 'id desc';
+        if(input('post.sort') == 1) $order = 'price desc';
+        if(input('post.sort') == 2) $order = 'price asc';
+        return $this->hasMany('ProductTransfer', 'product_id', 'id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order);
+    }
+
+       
+    //收藏
+    public function collect()
+    {   
+        
+        return $this->hasOne('UserCollect', 'product_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']);
+    }
+
+        
     
     //获取产品分类
     public static function getProductTypeById(int $productId)

+ 0 - 95
application/common/model/ProductMarket.php

@@ -1,95 +0,0 @@
-<?php
-
-namespace app\common\model;
-
-use think\Model;
-use think\Request;
-use app\common\library\Auth;
-
-class ProductMarket extends Model
-{
-
-    // 表名
-    protected $table = 'product_market';
-
-    
-    // 自动写入时间戳字段
-    protected $autoWriteTimestamp = 'int';
-
-    // 定义时间戳字段名
-    protected $createTime = 'create_time';
-    protected $updateTime = 'update_time';
-    protected $deleteTime = false;
-
-
-    // 追加属性
-    protected $append = [
-        'create_time_text',
-        'update_time_text'
-    ];
-    
-    //状态 normal, hidden
-    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,details');
-    }
-
-
-    //寄售
-    public function producttransfer()
-    {   
-        $map = [];
-        $transfer = input('post.transfer_id/d', 0);
-        if($transfer > 0) $map['id'] = $transfer;
-        $order = 'price asc';
-        if(input('post.sort') == 1) $order = 'price desc';
-        return $this->hasMany('ProductTransfer', 'product_id', 'product_id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order);
-    }
-
-
-
-    public function getCreateTimeTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
-        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
-    }
-
-
-    public function getUpdateTimeTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
-        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
-    }
-
-
-    protected function setCreateTimeAttr($value)
-    {
-        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
-    }
-
-    protected function setUpdateTimeAttr($value)
-    {
-        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
-    }
-
-
-}

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

@@ -13,27 +13,27 @@ use think\Request;
 class UserCollect extends Model
 {
 
-      protected $name = "user_collect";
+    protected $name = "user_collect";
 
-  
-   
-      //设置用户收藏
-      public static function setUserCollect(int $uid, int $marketId)
-      {
-           $rows = self::where('user_id', $uid)->where('market_id', $marketId)->find();
-           if($rows){
-               return $rows->delete();
-           }else{
-               return self::create(['user_id'=>$uid, 'market_id'=>$marketId]);
-           }
-      }
-
-
-      //用户
-      public function users()
-      {
-          return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
-      }
+
+
+    //设置用户收藏
+    public static function setUserCollect(int $uid, int $marketId)
+    {
+        $rows = self::where('user_id', $uid)->where('product_id', $marketId)->find();
+        if($rows){
+            return $rows->delete();
+        }else{
+            return self::create(['user_id'=>$uid, 'product_id'=>$marketId]);
+        }
+    }
+
+
+    //用户
+    public function users()
+    {
+        return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
+    }
   
 
 }

+ 1 - 0
public/assets/js/backend/general/announcement.js

@@ -31,6 +31,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'img_url', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                         {field: 'weigh', title: __('Weigh'), operate: false},
                         {field: 'status', title: __('Status'), searchList: {"1":__('上架'),"2":__('下架')}, formatter: Table.api.formatter.toggle},
+                        {field: 'is_show', title: __('推荐'), searchList: {0:__('否'), 1:__('是')}, formatter: Table.api.formatter.toggle},
                         {field: 'to_lang', title: __('所属语言'), operate: false,  searchList: {'zh':__('中文'), 'en':__('英文')}, formatter: Table.api.formatter.flag},
                         {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'updatetime', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},