afa 6 сар өмнө
parent
commit
254d1bff4a

+ 1 - 1
application/admin/view/general/announcement/add.html

@@ -21,7 +21,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('关联产品')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-product_id" data-rule="required" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="">
+            <input id="c-product_id"  data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="">
         </div>
     </div>
 

+ 1 - 1
application/admin/view/general/announcement/edit.html

@@ -20,7 +20,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('关联产品')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-product_id" data-rule="required" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
+            <input id="c-product_id" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
         </div>
     </div>
 

+ 33 - 16
application/api/controller/Teac.php

@@ -6,7 +6,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use app\api\logic\TeacLogin;
 use app\common\model\ParametersModel;
-use app\common\model\ProductOrder;
+use app\common\model\LedgerTokenChangeModel;
 use app\common\model\UserModel;
 use app\common\model\LedgerWalletModel;
 use fast\Action;
@@ -54,24 +54,26 @@ class Teac extends Api
     /*
      * 发布求购
      */
-    public function setBuying(TeacLogin $teacLogin)
+    public function setBuying(LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Teac');
         if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
         
         if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
+
+        $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
+        if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
         
         Db::startTrans();
         try{
             
             //新增求购信息
-            $order_info = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['user_id'], $params['from_user'], $params['order_no'], $params['fees'], $params['price']);
+            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock']);
+
+            //冻结资产
+            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
 
-            $order_id = (new ProductOrder)->insertGetId($order_info);
-            if(!$order_id){
-                throw new Exception('订单创建失败');
-            }
             Db::commit();
             $this->success('订单创建成功');
         }catch(Exception $e){
@@ -82,17 +84,32 @@ class Teac extends Api
     }
 
 
-   
+    //发布出售
+    public function setSell()
+    {
+        $validate = \think\Loader::validate('Teac');
+        if(!$validate->scene('sell')->check($params)) $this->error($validate->getError());
+        
+        if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
 
+        $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
+        if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
+        
+        Db::startTrans();
+        try{
+            
+            //新增求购信息
+            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock']);
 
-    //
-    public function updaetWallet()
-    {
-        $daoru_list = Db::table('ledger_wallet_1')
-            ->whereNotNull('address')
-            ->select();
-        $i = 0;
-        dump($i);
+            //冻结资产
+            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
+
+            Db::commit();
+            $this->success('订单创建成功');
+        }catch(Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
     }
 
 

+ 1 - 2
application/api/logic/MarketLogic.php

@@ -20,11 +20,10 @@ class MarketLogic
       {
             //获取市场价
             $minPrice = ProductTransfer::getTransferMinPrice($productId);
-            if($price < $minPrice || empty($minPrice)) $minPrice = $price;
-
             //添加市场
             $rows = ProductMarket::where('product_id', $productId)->find();
             if(empty($rows)){
+                  if($price < $minPrice || empty($minPrice)) $minPrice = $price;
                   ProductMarket::create([
                   'product_id' => $productId, 
                   'type_id'    => ProductLists::getProductTypeById($productId),