afa 6 сар өмнө
parent
commit
2bd1799a1c

+ 0 - 6
application/admin/controller/product/Products.php

@@ -33,12 +33,6 @@ class Products extends Backend
 
 
 
-    /**
-     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
-     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
-     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
-     */
-
     /**
      * 查看
      *

+ 52 - 1
application/admin/controller/product/Teacs.php

@@ -3,7 +3,12 @@
 namespace app\admin\controller\product;
 
 use app\common\controller\Backend;
-
+use Exception;
+use think\Db;
+use app\api\logic\TeacLogin;
+use think\exception\DbException;
+use think\exception\PDOException;
+use think\exception\ValidateException;
 /**
  * Teac交易管理
  *
@@ -49,4 +54,50 @@ class Teacs extends Backend
     }
 
 
+
+
+    /**
+     * 取消
+     * @param $ids
+     * @return string
+     * @throws DbException
+     * @throws \think\Exception
+     */
+    public function cancel($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch();
+        }
+        $result = false;
+        Db::startTrans();
+        try {
+            //是否采用模型验证
+            if ($this->modelValidate) {
+                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                $row->validateFailException()->validate($validate);
+            }
+
+            TeacLogin::setUserReturnOrder($row->user_id, $row['type_id'], $row['frozen']);
+
+            $result = $row->allowField(true)->save(['frozen'=>0,'status'=> $this->model::Closure]);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
 }

+ 2 - 2
application/api/controller/Teac.php

@@ -143,7 +143,7 @@ class Teac extends Api
 
 
     // 求购出售
-    public function setBuyOrder(ProductTeac $productTeac, LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin, UserTeac $userTeac)
+    public function setBuyOrder(ProductTeac $productTeac, TeacLogin $teacLogin, UserTeac $userTeac)
     {   
         $params = $this->request->post();
         $validate = \think\Loader::validate('Teac');
@@ -202,7 +202,7 @@ class Teac extends Api
 
             //返回相应茶宝Teac
             $teacLogin::setUserReturnOrder($this->auth->id, $row['type_id'], $row['frozen']);
-  
+            $row->frozen = 0;
             $row->status = ProductTeac::Closure;
             $row->save();
             // 提交事务

+ 15 - 6
application/api/logic/TeacLogin.php

@@ -27,13 +27,22 @@ class TeacLogin
     /**
      * 发布求购出售信息
     */
-    public static  function setCreateTrade(int $uid, float $price, int $stock, int $typeId, float $frozen):object
+    public static  function setCreateTrade(int $uid, float $price, int $stock, int $typeId, float $frozen)//:object
     {
-        // $rows = ProductTeac::where('user_id', $uid)->where('type_id', $typeId)->where('status', ProductTeac::Normal)->find();
-        // if($rows)  throw new Exception(__("你有未完成的求购订单、不能重复发布"));
-
-        //添加订单信息
-        return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, config('teac_trade.'. self::$feeList[$typeId]), $frozen);
+        $rows = ProductTeac::where('user_id', $uid)->where('trade_id', $typeId)->where('price', $price)->where('status', ProductTeac::Normal)->find();
+        $fee = config('teac_trade.'. self::$feeList[$typeId]);
+        if($rows)  {
+            $total_price = bcmul($price, $stock, 4);
+            $rows->fee   += bcmul($total_price, $fee, 4);
+            $rows->frozen += $frozen;
+            $rows->stock += $stock;
+            return $rows->save();
+        }else{
+            //添加订单信息
+            return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, $fee, $frozen);
+        }
+
+    
     }
 
     /**

+ 1 - 1
application/config.php

@@ -349,7 +349,7 @@ return [
         'sell_min_num'           => 100,   //最小出售数量
         'sell_serve_fee'         => 0.05,  //出售服务费
         'buy_min_price'          => 0.01,  //最小求购价格
-        'buy_max_price'          => 0.2,  //最大求购价格
+        'buy_max_price'          => 0.2,   //最大求购价格
         'buy_min_num'            => 100,   //最小求购数量
         'buy_serve_fee'          => 0.05,  //求购服务费
         'sell_desc'              => "

+ 11 - 0
public/assets/js/backend/product/teacs.js

@@ -47,6 +47,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     url: 'user/teacs/index',
                                     extend:'data-area=["90%","85%"]',
                                     //refresh:true,
+                                },{
+                                    classname: 'btn btn-xs btn-danger btn-ajax',
+                                    name: '取消记录',
+                                    text: __('取消记录'),
+                                    title: __('取消记录'),
+                                    url: 'product/teacs/cancel',
+                                    visible: function (row) {
+                                        // 自定义按钮 动态是否显示
+                                        return row.status ==1;
+                                    },
+                                    refresh:true,
                                 },
                               ],
                             table: table, events: Table.api.events.operate,