Browse Source

rwa发放

afa 6 months ago
parent
commit
b22fdcd84d

+ 2 - 1
application/admin/controller/offline/RwaExchangeRecord.php

@@ -17,6 +17,7 @@ class RwaExchangeRecord extends Backend
      * @var \app\admin\model\offline\RwaExchangeRecord
      */
     protected $model = null;
+    protected $relationSearch = true;
 
     public function _initialize()
     {
@@ -44,7 +45,7 @@ class RwaExchangeRecord extends Backend
             return $this->selectpage();
         }
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        $list = $this->model->with('users,products')
+        $list = $this->model->with('users,welfarereda')
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);

+ 7 - 8
application/api/controller/Exchange.php

@@ -60,7 +60,7 @@ class Exchange extends Api
                   $this->error(__('Parameter error'));
             }
             //检查区块链地址是否合法
-            if(!(isErc20AddressValid($coin_from_address) && isErc20AddressValid($usdt_from_address))){
+           if(!(isErc20AddressValid($coin_from_address) && isErc20AddressValid($usdt_from_address))){
                   $this->error(__('Invalid parameters'));
             }
             //福利兑换记录
@@ -149,7 +149,7 @@ class Exchange extends Api
                   $this->error('未识别到新USDT转入记录');
             }
             Log::info($usdt_list, 'USDT可用入记录');
-
+           
             //记录
             $inster_data[] = [
                   'order_no' => $order_no,
@@ -165,16 +165,15 @@ class Exchange extends Api
                   'create_time' => time()
             ];
             Log::info($inster_data, '插入数据');
-            $product_id = $welfare_config['product_id'];
-            $product_info =  (new ProductLists())->where('id', $product_id)->find();
-            if (empty($product_info))  $this->error('产品不存在');
+            
             try {
                   Db::startTrans();
-                  $rs = Db::name('rwa_exchange_record')->fetchSql(false)->insertAll($inster_data);
+                  Db::name('rwa_exchange_record')->fetchSql(false)->insertAll($inster_data);
                   //添加标记茶宝记录
                   $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, $usdt_data['amount'], LedgerFrozenChangeModel::RwaExchangeRecord, 0);
-                  //发放产品
-                  $rs = WelfareLoginc::setUserProductOrder(1, false, $order_no, 0, $product_info['id'], $this->auth->id, ProductOrder::RwaExchange);
+                  
+                  //发放产品奖励
+                  $rs =WelfareLoginc::setUserWelfareProduct($this->auth->id, $welfare_config['product_id'], $order_no, ProductOrder::RwaExchange);
                   Db::commit();
                   $this->success('ok', $order_no);
             } catch (Exception $e) {

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

@@ -32,7 +32,6 @@ class OrderLogic
       //获取产品发行量
       public static function getProductIssue(int $productId): int
       {
-      
             $popularNum = ProductPopular::where('product_id', $productId)->sum('stock-num');
             $holdNum = ProductOrder::where('product_id', $productId)->where('status', ProductOrder::Paid)->sum('num');
             return bcadd($popularNum, $holdNum);

+ 13 - 3
application/api/logic/WelfareLoginc.php

@@ -82,7 +82,6 @@ class WelfareLoginc
         // 使用bcdiv函数进行高精度除法运算,$num除以100,保留两位小数
         $div = bcdiv($num, 100, 2);
         $list = ProductOrder::getUserOrderByProductId($rwaProductId, $rwa_num);
-
         $user = new UserModel();
         foreach($list as $order){
                 //根据$mod的值决定是否需要对用户的rwa_num进行乘以$div的运算
@@ -174,12 +173,23 @@ class WelfareLoginc
             }
         }
 
-   
         //发放标记茶宝
         Loader::model('LedgerWalletModel')->changeWalletAccount($uid, Asset::FROZEN, $ecology['frozen'], LedgerFrozenChangeModel::Ecology, 0);
-
         //修改生态节点标识
         $user->is_ecology  = 1;
         return $user->save();
     }
+
+    //添加Rwa兑换福利产品
+    public static function setUserWelfareProduct(int $uid, string $productId, string $orderNo, int $typeId)
+    {
+        $productOrder = Loader::model('ProductOrder');
+        $productList = explode(',', $productId);
+        $result = [];
+        foreach ($productList as $item) {
+            $result[] = $productOrder::setCreateOrder(0, ['product_id'=> $item, 'area_id'=>0, 'price'=>0], $typeId, $uid, 0, $orderNo, 0, 0);
+        }
+        return $result;
+    }
+
 }

+ 6 - 0
application/common/model/RwaExchangeRecordModel.php

@@ -44,6 +44,12 @@ class RwaExchangeRecordModel extends Model
         return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0);
     }
  
+    
+    //兑换
+    public function welfarereda()
+    {
+        return $this->hasOne('ProductWelfareRede', 'id', 'welfare_id', [], 'LEFT')->setEagerlyType(0);
+    }
 
     public function getCreateTimeTextAttr($value, $data)
     {

+ 20 - 1
public/assets/js/backend/offline/rwa_exchange_record.js

@@ -24,12 +24,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     [
                         {checkbox: true},
                         {field: 'id', title: __('Id'), operate: false},
+                        {
+                            field: 'welfarereda.title', 
+                            title: __('福利兑换'), 
+                            operate: false,
+                            formatter : function(value, row, index, field){
+                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.title + "'>" + value + "</span>";
+                            },
+                            cellStyle : function(value, row, index, field){
+                                return {
+                                    css: {
+                                        "white-space": "nowrap",
+                                        "text-overflow": "ellipsis",
+                                        "overflow": "hidden",
+                                        "max-width":"150px"
+                                    }
+                                };
+                            }
+                        },
+                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                         {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                         {field: 'tx_hash', title: __('Tx_hash'), operate: 'LIKE'},
                         {field: 'users.address', title: __('User_id'),operate: 'LIKE'},
                         {field: 'symbol', title: __('Symbol'), operate: false},
                         {field: 'amount', title: __('Amount'), operate:false},
-                        {field: 'products.zh_name', title: __('Product_id'), operate:'LIKE'},
+                        {field: 'product_id', title: __('发放产品ID'), operate:'LIKE'},
                         {field: 'from_address', title: __('From_address'), operate: 'LIKE'},
                         {field: 'to_address', title: __('To_address'), operate: 'LIKE'},
                         {field: 'status', title: __('Status'), searchList: {