Browse Source

转让中

afa 6 months ago
parent
commit
5de8b75368

+ 7 - 3
application/admin/view/product/lists/add.html

@@ -35,11 +35,15 @@
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Gift_fee')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <div class="col-xs-12 col-sm-2">
             <input id="c-gift_fee" data-rule="required" class="form-control" name="row[gift_fee]" type="text"  value="">
         </div>
-        <label class="control-label col-xs-12 col-sm-2">{:__('Freight')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-1">{:__('发行量')}:</label>
+        <div class="col-xs-12 col-sm-2">
+            <input id="c-issue_num" data-rule="required" class="form-control" name="row[issue_num]" type="text"  value="">
+        </div>
+        <label class="control-label col-xs-12 col-sm-1">{:__('Freight')}:</label>
+        <div class="col-xs-12 col-sm-2">
             <input id="c-freight" data-rule="required" class="form-control" name="row[freight]" type="text"  value="">
         </div>
     </div>

+ 7 - 3
application/admin/view/product/lists/edit.html

@@ -34,11 +34,15 @@
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Gift_fee')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <div class="col-xs-12 col-sm-2">
             <input id="c-gift_fee" data-rule="required" class="form-control" name="row[gift_fee]" type="text"  value="{$row.gift_fee|htmlentities}">
         </div>
-        <label class="control-label col-xs-12 col-sm-2">{:__('Freight')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-1">{:__('发行量')}:</label>
+        <div class="col-xs-12 col-sm-2">
+            <input id="c-issue_num" data-rule="required" class="form-control" name="row[issue_num]" type="text"  value="">
+        </div>
+        <label class="control-label col-xs-12 col-sm-1">{:__('Freight')}:</label>
+        <div class="col-xs-12 col-sm-2">
             <input id="c-freight" data-rule="required" class="form-control" name="row[freight]" type="text"  value="{$row.freight|htmlentities}">
         </div>
     </div>

+ 4 - 6
application/api/controller/Product.php

@@ -78,7 +78,7 @@ class Product extends Api
             ->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")
             ->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')
+            ->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,b.issue_num as issue')
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
@@ -110,7 +110,7 @@ class Product extends Api
             ->join("product_list b", "a.product_id = b.id", "left")
             ->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,b.type_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,b.issue_num as issue')
             ->where('a.status', $productTransfer::Normal)
             ->where($map)
             ->order($order)
@@ -135,11 +135,10 @@ class Product extends Api
         $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')
+            ->field('id,'.$this->lan .'_name as name,issue_num as issue,thum,details')
             ->find();
         if(empty($list)) $this->error('数据不存在');
-
-        $list->issue       = $orderLogic::getProductIssue($list->id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
+ 
         $list->circulation = $orderLogic::getProductCirculation($list->id);  //流通: 所有用户的持有量  
         $this->success('', $list);
     }
@@ -160,7 +159,6 @@ class Product extends Api
             $userCollect = Loader::model('UserCollect');
             foreach ($list as &$item) {
                 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);  //流通: 所有用户的持有量    
             }
         }

+ 13 - 10
application/api/controller/Teac.php

@@ -14,7 +14,7 @@ use fast\Asset;
 use Exception;
 use fast\RechargeStatus;
 use think\Db;
-use app\common\model\TeacTrade;
+use app\common\model\ProductTeac;
 
 //Teac交易
 class Teac extends Api
@@ -25,15 +25,15 @@ class Teac extends Api
     /*
      * 求购列表
      */
-    public function getTeacList(TeacTrade $teacTrade)
+    public function getTeacList(ProductTeac $productTeac)
     {
         
         $type_id = $this->request->post('type_id/d', 0);
-        if(!in_array($type_id, [TeacTrade::Buying, TeacTrade::Sell])) $this->error('类型错误');
+        if(!in_array($type_id, [ProductTeac::Buying, ProductTeac::Sell])) $this->error('类型错误');
            
-        $list = $teacTrade->where('status', TeacTrade::Normal)->where('type_id', $type_id )
-        ->order('create_time desc')
-        ->paginate($this->pageSize);
+        $list = $productTeac->where('status', ProductTeac::Normal)->where('type_id', $type_id)
+             ->order('create_time desc')
+             ->paginate($this->pageSize);
         
         $this->success('ok', $list);
     }
@@ -57,7 +57,7 @@ class Teac extends Api
         try{
             
             //新增求购信息
-            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock']);
+            $order_price = $teacLogin::setCreateTrade($this->auth->id, $params['price'],  $params['stock']);
 
             //冻结资产
             $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
@@ -89,7 +89,7 @@ class Teac extends Api
         try{
             
             //新增求购信息
-            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock'], TeacTrade::Sell);
+            $order_price = $teacLogin::setCreateTrade($this->auth->id, $params['price'],  $params['stock'], TeacTrade::Sell);
 
             //冻结资产
             $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TEAC, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
@@ -110,17 +110,20 @@ class Teac extends Api
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public function setSellOrder()
+    public function setSellOrder(ProductTeac $productTeac, LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
     {
       
         $params = $this->request->post();
         $validate = \think\Loader::validate('Teac');
         if(!$validate->scene('sell_order')->check($params)) $this->error($validate->getError());
+        $row = $productTeac::get($params['id']);
+        if(empty($row)) $this->error('订单不存在');
+        if($row['status'] != ProductTeac::Normal) $this->error('订单已完成');
         // 启动事务
         Db::startTrans();
         try {
          
-            
+
 
 
         

+ 45 - 55
application/api/logic/TeacLogin.php

@@ -2,10 +2,8 @@
 
 namespace app\api\logic;
 
-use app\api\controller\Teac;
-use app\common\model\ParametersModel;
-use app\common\model\ServersModel;
-use app\common\model\TeacTrade;
+
+use app\common\model\ProductTeac;
 use fast\Http;
 use think\Loader;
 use Exception;
@@ -21,76 +19,68 @@ class TeacLogin
 {
     
      
-
- 
-
     /**
-     * 发布求购信息
-     */
-    public static  function setCreateOrder(int $uid, float $price, int $stock, int $typeId = TeacTrade::Buying):float
+     * 发布求购出售信息
+    */
+    public static  function setCreateTrade(int $uid, float $price, int $stock, int $typeId = ProductTeac::Buying):float
     {
         
-        $rows = TeacTrade::where('status', TeacTrade::Normal)->find();
+        $rows = ProductTeac::where('status', ProductTeac::Normal)->find();
         if($rows)  throw new Exception(__("你有未完成的求购订单、不能重复发布"));
 
         //添加订单信息
-        return TeacTrade::setUserCreateOrder($uid, $typeId, $price, $stock, bcmul($price, $stock, 2));
-
-
+        return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, bcmul($price, $stock, 2));
     }
 
-      /**
-       * 发布出售
-       * @$address  查询地址
-       * @$from_to  是查询付款交易(from),还剩收款交易(to),默认from
-       */
-      public function setCreateSellOrder(string $from, string $to, int $start_block, int $end_block = 99999999)
-      {
+    /**
+     * 发布出售
+     * @$address  查询地址
+     * @$from_to  是查询付款交易(from),还剩收款交易(to),默认from
+     */
+    public function setCreateSellOrder(string $from, string $to, int $start_block, int $end_block = 99999999)
+    {
         if(empty($from) && empty($to)){
             return _error('钱包地址不能都为空');
         }
 
-     
-
+    }
 
- 
-      }
 
-      /**
-       * 获取哈希地址成功状态
-       * @param $orderInfo
-       * @return array|string
-       */
-      public function getHashStatus($tx_hash):array
-      {
-        if (empty($tx_hash)) {
-            return _error('hash值不能为空');
-        }
+    /**
+     * 获取哈希地址成功状态
+     * @param $orderInfo
+     * @return array|string
+     */
+    public function getHashStatus($tx_hash):array
+    {
+    if (empty($tx_hash)) {
+        return _error('hash值不能为空');
+    }
 
-        $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus";
-        $url .= "&apikey=" . $this->bsc_api_key;
-        $url .= "&txhash=" . $tx_hash;
+    $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus";
+    $url .= "&apikey=" . $this->bsc_api_key;
+    $url .= "&txhash=" . $tx_hash;
 
-        $body = Http::get($url);
-        if (empty($body)) {
-            return _error('状态api返回内容为空');
-        }
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return _error('状态api返回数据异常,json转换失败');
-        }
+    $body = Http::get($url);
+    if (empty($body)) {
+        return _error('状态api返回内容为空');
+    }
+    // 转成数组
+    $rsArr = json_decode($body, true);
+    if (empty($rsArr) || !is_array($rsArr)) {
+        return _error('状态api返回数据异常,json转换失败');
+    }
 
-        if ($rsArr['status'] != '1') {
-            return _error('状态api返回status不为1,当前值为:' . $rsArr['status']);
-        }
+    if ($rsArr['status'] != '1') {
+        return _error('状态api返回status不为1,当前值为:' . $rsArr['status']);
+    }
 
-        if ($rsArr['result']['status'] != 1) {
-            return _error('状态api返回result中的status不为1,当前值为:' . $rsArr['result']['status']);
-        }
+    if ($rsArr['result']['status'] != 1) {
+        return _error('状态api返回result中的status不为1,当前值为:' . $rsArr['result']['status']);
+    }
 
-        return _success();
-      }
+    return _success();
+    }
 
       /**
        * 根据时间戳获取最近的区块高度     

+ 1 - 1
application/api/logic/UserLogic.php

@@ -118,7 +118,7 @@ class UserLogic
             $where = [];
             switch ($typeId) {
                   case 0:
-                  $where['a.status'] = ['=' , $productOrder::Paid];
+                  $where['a.status'] = ['in' , [$productOrder::Paid, $productOrder::Transferred, $productOrder::Freeze]]; //抢购/转让中/存储
                   break;
                   case 1:
                   $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];

+ 18 - 17
application/api/validate/Teac.php

@@ -10,15 +10,16 @@ class Teac extends Validate
      * 验证规则
      */
     protected $rule = [
-      'market_id'     => 'require',
-      'product_id'    => 'require',
-      'transfer_id'   => 'require',
-      'price'     => 'require|number|gt:0',
+      'teac_id'         => 'require',
+      'price'           => 'require|number|gt:0',
       'stock'           => 'require|number|gt:0',
-      'buying_id'     => 'require|number|gt:0',
-      'order_id'      => 'require|number',
-      'address'    => 'require',
-      'price'      => 'require|number|gt:0',
+      'num'             => 'require|number|gt:0',
+      'buying_id'       => 'require|number|gt:0',
+      'order_id'        => 'require|number',
+      'address'         => 'require',
+      'product_id'      => 'require',
+      'transfer_id'     => 'require',
+     
     ];
     
     /**
@@ -26,15 +27,15 @@ class Teac extends Validate
      */
     protected $message = [
 
-      'market_id.require'   => '订单ID有误',
-      'product_id.require'  => '产品ID有误', //
-      'transfer_id.require' => '参数ID有误',
-      'price'           => '价格有误',
-      'stock'                 => '数量有误',
+      'teac_id.require'     => '订单ID有误',
+      'price'               => '价格有误',
+      'stock'               => '数量有误',
+      'num'                 => '数量有误',
       'buying_id'           => '参数有误',
       'order_id'            => '参数有误',
-      'phone.mobile'       => '手机号有误',
-      'address.require'    => '请填写地址',
+      'address.require'     => '请填写地址',
+      'product_id.require'  => '产品ID有误', //
+      'transfer_id.require' => '参数ID有误',
     ];
     
     /**
@@ -44,8 +45,8 @@ class Teac extends Validate
        
         'buying'     => ['price', 'stock'],
         'sell'       => ['price', 'stock'],
-        'sellbuying'   => ['buying_id', 'order_id'],
-        'cancelbuying' => ['buying_id'],
+        'sell_order' => ['teac_id', 'num'],
+        'buy_order'  => ['buying_id', 'order_id'],
     ];
   
 }

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

@@ -31,7 +31,7 @@ class ProductOrder extends Model
     const Shipped           = 3;
     const Cancelled         = 4; //取消
     const Closure           = 5; //关闭
-    const Freeze            = 6; //质押
+    const Freeze            = 6; //存储
 
 
     //类型
@@ -48,7 +48,7 @@ class ProductOrder extends Model
     public $order_status = [
         '-1'                    => '全部',
         self::Paid              => '已付款',
-        self::Transferred       => '转让',
+        self::Transferred       => '转让',
         self::Shipped           => '提货',
         self::Closure           => '关闭',
         self::Freeze            => '质押',

+ 2 - 2
application/common/model/TeacTrade.php → application/common/model/ProductTeac.php

@@ -6,10 +6,10 @@ use think\Model;
 
 
 //Teac求购
-class TeacTrade extends Model
+class ProductTeac extends Model
 {
 
-    protected $name = "teac_trade";
+    protected $name = "product_teac";
 
     // 自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';

+ 1 - 0
public/assets/js/backend/product/lists.js

@@ -61,6 +61,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area', 'vue', 'ELEME
                         { field: 'is_transfer', title: __('寄售'), searchList: { "1": __('开启'), "0": __('关闭') }, formatter: Table.api.formatter.toggle },
                         { field: 'is_gift', title: __('赠送'), searchList: { "1": __('开启'), "0": __('关闭') }, formatter: Table.api.formatter.toggle },
                         { field: 'is_freight', title: __('提货'), searchList: { "1": __('开启'), "0": __('关闭') }, formatter: Table.api.formatter.toggle },
+                        { field: 'issue_num', title: __('发行量'), operate: false },
                         { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                         { field: 'operate', title: __('Operate'),
                             buttons:[