afa 10 kuukautta sitten
vanhempi
sitoutus
4eb942bd43
2 muutettua tiedostoa jossa 18 lisäystä ja 16 poistoa
  1. 2 3
      application/api/controller/Home.php
  2. 16 13
      application/api/controller/Product.php

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

@@ -71,10 +71,9 @@ class Home extends Api
     {
         //更新库存
         $productPopular::setUpdateStatus();
-        // 热销
         $resp['product_list']  = $productPopular->with('productsList')->where('product_popular.status', '<', $productPopular::STOP)->limit(2)
-           ->order('start_time asc,weigh desc')->select();
-
+           ->order('weigh desc,start_time asc')->select();
+        
         // 转让 
         $resp['transfer_list'] = $productTransfer->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")

+ 16 - 13
application/api/controller/Product.php

@@ -29,20 +29,23 @@ class Product extends Api
     {
         $list = $productsModel->where('status', 1)->column('id,'.$this->lan.'_title as title');
         $resp = array();
-
-        foreach ($list as $kk =>$val) 
-        {
-            $pro= $productPopular->alias('a')
-                ->join("product_list b", "b.id=a.product_id", "LEFT")
-                ->field('a.id,'.'b.'.$this->lan.'_name as name,a.product_id,b.thum as img_url,price,cost_price,stock,num,start_time,end_time,a.status')
-                ->where('a.status', '<', $productPopular::STOP)
-                ->where('b.type_id', $kk)
-                ->order('a.status')
-                ->select();
-    
-            $resp[] = ['type_id'=>$kk,'title'=>$val, 'product'=>$pro];
+        foreach ($list as $kk =>$val) {
+            $list= $productLists->where('type_id', $kk)->field('id,thum as img_url,'.$this->lan.'_name as name')->select();
+            foreach ($list as $key => &$item) {
+                $pro =$productPopular
+                    ->field('id,product_id,price,cost_price,stock,num,start_time,end_time,status')
+                    ->where('product_id', $item->id)
+                    ->where('status', '<', $productPopular::STOP)
+                    ->order('start_time')
+                    ->find();
+                if(!empty($pro)){
+                    $item['pro'] = $pro;
+                }else{
+                    unset($list[$key]);
+                }    
+            }
+            $resp[] = ['type_id'=>$kk,'title'=>$val, 'product'=>$list];
         }
-
         $this->success('', $resp);
     }