afa 7 сар өмнө
parent
commit
ff4e4269a4

+ 1 - 25
application/api/controller/Home.php

@@ -118,31 +118,7 @@ class Home extends Api
         $this->success('',  compact('info', 'times', 'order'));
     }
 
-    /**
-     * 转让详情
-     * @param int $uid 
-     * @param string $fee
-     * @param string $txHsh
-     * @return void
-     */
-    public function getTransferInfo(ProductTransfer $productTransfer)
-    {
-        try {
-            $ids = $this->request->post('ids/d', 0);
-            if(empty($ids)) throw new Exception(__("Parameter error"));
-  
-            $info = $productTransfer->alias('a')
-                ->join("product_list b", "a.product_id = b.id", "left")
-                ->join("product_area d", "d.id = a.area_id", "left") //地区
-                ->field('a.id,a.product_id,a.area_id,'.'b.'.$this->lan.'_name as name,b.images as img_url,price,fees,b.details,d.address')
-                ->where('a.id', $ids)
-                ->find();
-         
-        } catch (Exception $e) {
-            $this->error( $e->getMessage());
-        }
-        $this->success('',  $info);
-    }
+   
     
     /**
      * 获取地址

+ 32 - 3
application/api/controller/Market.php

@@ -101,13 +101,11 @@ class Market extends Api
      */
     public function setBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying)
     {
-
         $params = $this->request->post();
         $validate = \think\Loader::validate('Market');
         if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
 
         if($productBuying::getProductBuyingCount($this->auth->id, $params['product_id']) > config('market_buying.max_buying_num')) $this->error('您的求购次数已达上限');
-
         $chabao     =  $ledgerWalletModel::getWalletChaBao($this->auth->id);
         $total      = bcmul($params['min_price'], $params['num'], 6); // 所需茶宝
         if($chabao < $total) $this->error('您的茶币不足');
@@ -130,8 +128,39 @@ class Market extends Api
             Db::rollback();
             return $e->getMessage();
         }
-
         $this->success('ok');
+    }
+
+
+    //出售求购
+    public function sellBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying)
+    {
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Market');
+        if(!$validate->scene('sellbuying')->check($params)) $this->error($validate->getError());
+        $buying = $productBuying::get($params['id']);
+        if(empty($buying)) $this->error('订单不存在');
+        if($buying->user_id!= $this->auth->id) $this->error('无权操作');
+        if($buying->status != ProductBuying::Normal) $this->error('订单已完成');
+        $total = bcmul($buying->min_price, $buying->num, 6); // 所需茶宝
+        $chabao =  $ledgerWalletModel::getWalletChaBao($this->auth->id);
+        if($chabao < $total) $this->error('您的茶币不足');
+        // 启动事务
+
+    }
+
+    //取消求购
+    public function cancelBuying(ProductBuying $productBuying)
+    {
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Market');
+        if(!$validate->scene('cancelbuying')->check($params)) $this->error($validate->getError());
+        $buying = $productBuying::get($params['id']);
+        if(empty($buying)) $this->error('订单不存在');
+        if($buying->user_id!= $this->auth->id) $this->error('无权操作');
+        if($buying->status != ProductBuying::Normal) $this->error('订单已完成');
+        $buying->status = ProductBuying::Close;
+        $buying->save();
 
     }
 

+ 8 - 0
application/api/controller/Product.php

@@ -143,6 +143,14 @@ class Product extends Api
         $this->success('', $list);
     }
  
+    //获取持有产品订单列表
+    public function getHoldList(OrderLogic $orderLogic)
+    {
+        $productId = $this->request->post('product_id/d', '');
+        if(empty($productId)) $this->error('参数错误');
+        $list = $orderLogic::getUserProductOrder($this->auth->id, $productId, $this->lan);
+        $this->success('', $list);
+    }
 
 
     private static function getProductOrderList(object $list, int $uid, bool $isCollect, OrderLogic $orderLogic): object

+ 13 - 1
application/api/logic/OrderLogic.php

@@ -45,7 +45,19 @@ class OrderLogic
       }
 
 
-      //
+      //获取产品有效的订单
+      public static function getUserProductOrder(int $uid, int $productId,string $lan): object
+      {     
+            return Loader::model('ProductOrder')->alias('a')
+                  ->join("product_list b", "a.product_id = b.id", "left")
+                  ->field('a.id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.order_no')
+                  ->where('a.product_id', $productId)
+                  ->where('a.user_id', $uid)
+                  ->where('a.status', ProductOrder::Paid)
+                  ->order('id desc')
+                  ->select();
+         
+      }
 
 
 

+ 0 - 1
application/common/model/ProductBuying.php

@@ -69,7 +69,6 @@ class ProductBuying extends Model
     {
        
         return self::where('product_id', $productId)->where('status', self::Normal)->field('id,min_price')->order('id desc')->select();
-    
     }
 
     public function getCreateTimeTextAttr($value, $data)

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

@@ -151,6 +151,8 @@ class ProductOrder extends Model
         return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->sum('num');
     }
 
+
+
     // 获取订单状态
     public static function getProductOrder($orderId, $status, string $field){
         return self::alias('a')->where('a.id', $orderId)