afa 5 сар өмнө
parent
commit
6480b1a423

+ 4 - 4
application/admin/controller/Dashboard.php

@@ -8,7 +8,7 @@ use app\common\model\OfflineRechargeRecordModel;
 use app\common\model\OfflineWithdrawRecordModel;
 use app\admin\model\LedgerTokenChange;
 use app\common\controller\Backend;
-use app\common\model\Attachment;
+use app\common\model\UserPledge;
 use fast\Date;
 use Google\Service\Books\Offers;
 use think\Db;
@@ -70,9 +70,9 @@ class Dashboard extends Backend
             'all_in_usdt_num'   => OfflineRechargeRecordModel::where('status', OfflineRechargeRecordModel::StatusSuccess)->count(),
 
             'all_out_usdt'      => OfflineWithdrawRecordModel::where('status', 'in', [2,4])->sum('real_amount'),
-            //'all_in-out'         => OfflineRechargeRecord::where('status', 'in', [2,4])->count(),
-
-            'month_in_usdt'     => OfflineRechargeRecordModel::where('create_time', '>', strtotime($month_date))->where('status', OfflineRechargeRecordModel::StatusSuccess)->sum('amount'),
+     
+            //所有有效质押订单的日产量X数量的和
+            'month_in_usdt'     => UserPledge::getCountByTimeTeac(),
             'attachmentsize'    => 0,
             'picturenums'       => 0,
             'picturesize'       => 0,

+ 5 - 0
application/admin/controller/product/Lists.php

@@ -5,6 +5,7 @@ namespace app\admin\controller\product;
 use app\common\controller\Backend;
 use Exception;
 use think\Db;
+use app\common\model\ProductOrder;
 use app\common\model\ProductArea;
 use think\exception\DbException;
 use think\exception\PDOException;
@@ -50,12 +51,16 @@ class Lists extends Backend
         if ($this->request->request('keyField')) {
             return $this->selectpage();
         }
+
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
         $list = $this->model->with('products')
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);
+
+        $productOrder = new ProductOrder();    
         foreach ($list as &$item) {
+            $item['hold_num'] = $productOrder::where('product_id', $item->id)->where('status', 'in',[$productOrder::Paid, $productOrder::Transferred, $productOrder::Freeze])->count();//持有数量
             $item['total_num']= $this->productArea::where('product_id', $item->id)->count();
             $item['sell_num'] = $this->productArea::where('product_id', $item->id)->where('status', $this->productArea::Stop)->count();
         }

+ 7 - 6
application/admin/view/dashboard/index.html

@@ -186,21 +186,22 @@
                             </div>
                         </div>
                     </div>
+                
                     <div class="col-sm-3 col-xs-6">
                         <div class="sm-st clearfix">
-                            <span class="sm-st-icon st-blue"><i class="fa fa-leaf"></i></span>
+                            <span class="sm-st-icon st-green"><i class="fa fa-user"></i></span>
                             <div class="sm-st-info">
-                                <span>{$month_in_usdt}</span>
-                                本月报单金额
+                                <span>{$totaladmin}</span>
+                                {:__('Total admin')}
                             </div>
                         </div>
                     </div>
                     <div class="col-sm-3 col-xs-6">
                         <div class="sm-st clearfix">
-                            <span class="sm-st-icon st-green"><i class="fa fa-user"></i></span>
+                            <span class="sm-st-icon st-blue"><i class="fa fa-leaf"></i></span>
                             <div class="sm-st-info">
-                                <span>{$totaladmin}</span>
-                                {:__('Total admin')}
+                                <span>{$month_in_usdt} TeaC</span>
+                                统计当日最高产出
                             </div>
                         </div>
                     </div>

+ 8 - 5
application/admin/view/product/lists/add.html

@@ -87,13 +87,16 @@
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Teac兑换')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-2">{:__('隐藏')}:</label>
+        <div class="col-xs-12 col-sm-2">
+            {:build_radios('row[is_show]', ['0'=>__('隐藏'), '1'=>__('显示')])}
+        </div>
+        <label class="control-label col-xs-12 col-sm-1">{:__('Teac兑换')}:</label>
+        <div class="col-xs-12 col-sm-2">
             {:build_radios('row[is_teac]', ['0'=>__('关闭'), '1'=>__('开启')])}
         </div>
-  
-        <label class="control-label col-xs-12 col-sm-2">{:__('Teac兑换价格')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-1">{:__('Teac兑换价')}:</label>
+        <div class="col-xs-12 col-sm-2">
             <input id="c-teac_price"  class="form-control" name="row[teac_price]" type="text"  value="">
         </div>
     </div>

+ 8 - 5
application/admin/view/product/lists/edit.html

@@ -86,13 +86,16 @@
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Teac兑换')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-2">{:__('隐藏')}:</label>
+        <div class="col-xs-12 col-sm-2">
+            {:build_radios('row[is_show]', ['0'=>__('隐藏'), '1'=>__('显示')], $row['is_show'])}
+        </div>
+        <label class="control-label col-xs-12 col-sm-1">{:__('Teac兑换')}:</label>
+        <div class="col-xs-12 col-sm-2">
             {:build_radios('row[is_teac]', ['0'=>__('关闭'), '1'=>__('开启')], $row['is_teac'])}
         </div>
-  
-        <label class="control-label col-xs-12 col-sm-2">{:__('Teac兑换价格')}:</label>
-        <div class="col-xs-12 col-sm-3">
+        <label class="control-label col-xs-12 col-sm-1">{:__('Teac兑换价格')}:</label>
+        <div class="col-xs-12 col-sm-2">
             <input id="c-teac_price"  class="form-control" name="row[teac_price]" type="text"  value="{$row.teac_price|htmlentities}">
         </div>
     </div>

+ 6 - 7
application/api/controller/Order.php

@@ -3,7 +3,6 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\model\ProductTransfer;
 use app\common\model\ProductOrder;
 use app\common\model\ProductPopular;
 use app\common\model\LedgerFrozenChangeModel;
@@ -69,7 +68,7 @@ class Order extends Api
             WelfareLoginc::setUserEcologyAirdrop($this->auth->id, $params['product_id'], $this->auth->parent_id);
 
             //更新Rwa持有数量
-            if($order_info->price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $areaNum, '+');
+            if(!empty($order_info->is_show) && $order_info->price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $areaNum, '+');
             //扣除库存
             if(($order_info->stock - $areaNum) == 0 || time() >= $order_info->end_time) $order_info->status= $productPopular::Stop;
             $order_info->num  += $areaNum;
@@ -94,7 +93,7 @@ class Order extends Api
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
         if(!$validate->scene('pick')->check($params)) $this->error($validate->getError());
-        $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.freight,b.is_freight');
+        $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.freight,b.is_freight,b.is_show');
         if(empty($order_info) || empty($order_info->is_freight)) $this->error( __("参数有误,无可用产品"));
         // 启动事务
         Db::startTrans();
@@ -107,7 +106,7 @@ class Order extends Api
             $userArea->create(['name'=>$params['name'], 'type_id'=>$userArea::TakeAdders, 'phone'=>$params['phone'],'address'=>$params['address'],'order_id'=>$params['order_id']]);
 
             //扣除Rwa数量
-            if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($order_info->user_id, $userModel::getByParentId($order_info->user_id), 1, '-');
+            if(!empty($order_info->is_show) && $order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($order_info->user_id, $userModel::getByParentId($order_info->user_id), 1, '-');
 
             $order_info->status= $productOrder::Shipped; 
             $order_info->save();
@@ -188,7 +187,7 @@ class Order extends Api
         Db::startTrans();
          try {
 
-            $order_info = $productOrder::getProductOrder($params['order_id'], $productOrder::Paid, 'b.is_gift,b.gift_fee');
+            $order_info = $productOrder::getProductOrder($params['order_id'], $productOrder::Paid, 'b.is_gift,b.gift_fee,b.is_show');
             if(empty($order_info) || empty($order_info->is_gift)) throw new Exception(__("参数有误,无可用产品"));
 
             $user = $userModel->getByAddress($params['address']);
@@ -203,13 +202,13 @@ class Order extends Api
             $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Giveaway, $user['id'], $this->auth->id, $order_info->order_no, $fees, $order_info->popular_price);
 
             //对方Rwa+1
-            if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($user['id'], $userModel::getByParentId($user['id']), 1, '+');
+            if(!empty($order_info->is_show) && $order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($user['id'], $userModel::getByParentId($user['id']), 1, '+');
 
             //扣除手续费
             $ledgerWalletModel->setChangeFrozen($this->auth->id, $fees, LedgerFrozenChangeModel::Giveaway, '-');
         
             //扣除Rwa有效-1
-            if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, 1, '-');
+            if(!empty($order_info->is_show) && $order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, 1, '-');
 
             //修改:类型状态
             $order_info->type_id= $productOrder::Giveaway; 

+ 9 - 10
application/api/logic/OrderLogic.php

@@ -9,7 +9,7 @@ use think\Cache;
 use think\Loader ;
 use fast\Asset;
 use app\common\model\ProductOrder;
-use app\common\model\LedgerTeacChangeModel;
+use app\common\model\ProductLists;
 use app\common\model\ProductPopular;
 use app\common\model\ProductTransfer;
 
@@ -51,6 +51,7 @@ class OrderLogic
             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('b.is_show', ProductLists::Normal)
                   ->where('a.product_id', $productId)
                   ->where('a.user_id', $uid)
                   ->where('a.status', ProductOrder::Paid)
@@ -64,23 +65,21 @@ class OrderLogic
       public static function getProductTransferOrder(string $orderId, int $uid, int $puid)//: array
       {     
             $productOrder = Loader::model('ProductOrder');
+            $productLists = Loader::model('ProductLists');
             $productTransfer = Loader::model('ProductTransfer');
             $userModel = Loader::model('UserModel');
             $ledgerWalletModel = Loader::model('LedgerWalletModel');
             $ledgerTokenChangeModel = Loader::model('LedgerTokenChangeModel');
             $result = $productTransfer::whereIn('id', $orderId)->where('status', ProductTransfer::Normal)->select();
-            if (count($result) !=  count(explode(",", $orderId))) {
-                  if(empty($order_info)) throw new Exception(__("订单不存在"));
-            }
-            //$totalAmount = 0; //总金额
+            if (count($result) !=  count(explode(",", $orderId)))  if(empty($order_info)) throw new Exception(__("订单不存在"));
+            
             $time = time();
             $endTime = config('market_transfer.lock_time');
             foreach ($result as $item) {
 
                   if($item->user_id == $uid) throw new Exception(__("不能购买自己寄售的商品"));
                   if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
-
-                  //$totalAmount = bcadd($totalAmount, $item->price, 2);
+           
                   //抢购订单
                   $popular_order = $productOrder->where('id', $item->order_id)->find();
 
@@ -95,7 +94,8 @@ class OrderLogic
                   //增加转让人余额
                   $amount = bcsub($item->price, $item->fees, 2);
                   $ledgerWalletModel->changeWalletAccount($item->user_id, Asset::TOKEN, $amount, $ledgerTokenChangeModel::Receive, $uid);
-                  if($popular_order->popular_price > config('min_rwa_price')) {
+                  $show = $productLists::where('id', $item->product_id)->value('is_show');
+                  if(!empty($show) && $popular_order->popular_price > config('min_rwa_price')) {
                         //扣除转让人Rwa有效  
                         $userModel::updateForRwaNum($item->user_id, $userModel::getByParentId($item->user_id), 1, '-');
                         //增加购买Rwa有效
@@ -110,8 +110,7 @@ class OrderLogic
                   $item->status = $productTransfer::Stop;
                   $item->save();
             }
-            //$chabao = $ledgerWalletModel::getWalletChaBao($uid);
-            //if(bccomp($totalAmount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+
             return true;
       }
 

+ 8 - 2
application/api/logic/PledgeLogic.php

@@ -8,7 +8,7 @@ use think\Cache;
 use think\Loader ;
 use fast\Asset;
 use app\common\model\LedgerTokenChangeModel;
-use app\common\model\LedgerWalletModel;
+use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
 use app\common\model\LedgerTeacChangeModel;
 use app\common\model\ProductPledges;
@@ -38,7 +38,13 @@ class PledgeLogic
     public static function getHoldProductList($user_id, $product_id)
     {
         $model  = Loader::model('ProductOrder');
-        return $model::where('user_id', $user_id)->where('product_id', $product_id)->where('status', $model::Paid)->field('id,order_no')->select();
+        return $model::alias('a')
+        ->join('product_lists b', 'a.product_id = b.id', 'left')
+        ->where('b.is_show', ProductLists::Normal)
+        ->where('a.user_id', $user_id)
+        ->where('a.product_id', $product_id)
+        ->where('a.status', $model::Paid)
+        ->field('a.id,a.order_no')->select();
     }
 
     //添加质抵押订单

+ 2 - 0
application/api/logic/UserLogic.php

@@ -9,6 +9,7 @@ use think\Loader ;
 use fast\Asset;
 use app\common\model\ProductOrder;
 use app\common\model\LedgerTeacChangeModel;
+use app\common\model\ProductLists;
 use app\common\model\ProductPopular;
 use app\common\model\ProductTransfer;
 
@@ -120,6 +121,7 @@ class UserLogic
                   case 0:
                   //持有= 抢购+转让中+存储
                   $where['a.status'] = ['in' , [$productOrder::Paid, $productOrder::Transferred, $productOrder::Freeze]];
+                  $where['b.is_show'] = ['=' , ProductLists::Normal];
                   break;
                   case 1:
                   $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];

+ 19 - 10
application/common/model/ProductOrder.php

@@ -55,7 +55,7 @@ class ProductOrder extends Model
         self::Closure           => '关闭',
         self::Freeze            => '质押',
     ];
-
+   
 
     //抢购下单:未选择地区购买
     public static function setPopularNoAreaOrder($num, $orderId, $price, $productId, $uid, $typeId):bool
@@ -90,13 +90,13 @@ class ProductOrder extends Model
   
 
     /**
-     * @param int   $orderId 订单id
+     * @param int   $orderId   订单id
      * @param array $orderInfo 订单详情
      * @param int   $typeId    订单类型
      * @param int   $userId    用户id
      * @param int   $fromUser  来源id
      * @param float $fees      手续费
-     * @param float $fees      抢购价
+     * @param float $price     抢购价
      */
     public static function setCreateOrder(int $orderId, $orderInfo, $typeId, $userId, $fromUser, string $orderNo, float $fees, float $price): object
     {   
@@ -123,7 +123,7 @@ class ProductOrder extends Model
         foreach ($productId as &$item) {
             $item['num'] = $num;
             $count = self::getUserOrderNum($uid, $item['id']);
-            if(empty($count)) $count = 0;
+            //if(empty($count)) $count = 0;
             $item['hold_num'] = $count;
         }
         return $productId;
@@ -131,23 +131,32 @@ class ProductOrder extends Model
 
     //空投产品向达到一定持有量的用户 total_num
     public static function getUserOrderByProductId(int $rwaProductId, int $rwaNum){
-        return ProductOrder::whereIn('status', [self::Paid, self::Transferred, self::Freeze])
-        ->where('product_id', $rwaProductId)
-        ->group('user_id')->having('total_num>='.$rwaNum)
-        ->field('id,user_id,count(num) as total_num')
+        return ProductOrder::alias('a')
+        ->join('product_list b', 'a.product_id = b.id', 'left')
+        ->where('b.is_show', ProductLists::Normal)
+        ->whereIn('a.status', [self::Paid, self::Transferred, self::Freeze])
+        ->where('a.product_id', $rwaProductId)
+        ->group('a.user_id')->having('a.total_num>='.$rwaNum)
+        ->field('a.id,a.user_id,count(a.num) as total_num')
         ->select();
     }
 
     //获取持有产品数量订单
     public static function getUserOrderByProductNum(int $uid, int $product_id, int $totalNum): array
     {
-        return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->limit($totalNum)->column('id');
+        return  self::where('user_id', $uid)->where('product_id', $product_id)->limit($totalNum)->column('id');
     }
 
     //获取持有产品数量
     private static function getUserOrderNum(int $uid, int $product_id): int
     {
-        return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->sum('num');
+        return  self::alias('a')
+        ->join('product_list b', 'a.product_id = b.id', 'left')
+        ->where('b.is_show', ProductLists::Normal)
+        ->where('a.user_id', $uid)
+        ->where('a.product_id', $product_id)
+        ->where('a.status', '=', self::Paid)
+        ->sum('a.num');
     }
 
     // 获取订单状态

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

@@ -60,6 +60,7 @@ class UserAirdrop extends Model
     }
 
 
+
     //product,rwaProduct
     public function product()
     {

+ 13 - 0
application/common/model/UserPledge.php

@@ -48,6 +48,19 @@ class UserPledge extends Model
         ]);
     }
 
+    //所有有效质押订单的日产量X数量的和
+    public static function getCountByTimeTeac():int
+    {
+        $productPledges = new ProductPledges();
+        $list = self::where('status', self::Ongoing)->column('pledge_id,num');
+        $count = 0;
+        foreach ($list as $key=>$item) {
+            $day_num = $productPledges::where('id',$key)->value('day_num');
+            $count += bcmul($item, $day_num, 2);
+        }
+        return $count;
+    }
+
     //用户
     public function users()
     {

+ 11 - 5
public/assets/js/backend/product/lists.js

@@ -46,9 +46,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area',  ], function
                                 };
                             }
                         },
-                        { field: 'total_num', title: __('总设置数量'), operate: false },
-                        { field: 'sell_num', title: __('已出售数量'), operate: false },
-                        { field: 'min_transfer_fee', title: __('寄售转让费'), operate: false, formatter: function (value, row, index, field) {
+                        {field: 'total_num', title: __('总设置数量'), operate: false },
+                        {field: 'sell_num', title: __('已出售数量'), operate: false },
+                        {field: 'hold_num', title: __('持有数量'), operate: false },
+                        {field: 'min_transfer_fee', title: __('寄售转让费'), operate: false, formatter: function (value, row, index, field) {
                             return row.min_transfer_fee+ "~"+ row.max_transfer_fee;
                         }},
                         { field: 'gift_fee', title: __('Gift_fee'), operate: false },
@@ -66,7 +67,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area',  ], function
                         { field: 'operate', title: __('Operate'),
                             buttons:[
                                 {
-                                    icon: 'fa fa-cog',
                                     classname: 'btn btn-xs btn-info btn-dialog',
                                     name: '区域设置',
                                     text: __('区域设置'),
@@ -74,10 +74,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area',  ], function
                                     url: 'product/areas/index',
                                     extend:'data-area=["90%","85%"]',
                                     visible: function (row) {
-                                        // 自定义按钮 动态是否显示
                                         return row.is_area ==1;
                                     }
                                     //refresh:true,
+                                },{
+                                    classname: 'btn btn-xs btn-danger btn-dialog',
+                                    name: '产品统计',
+                                    text: __('产品统计'),
+                                    title: __('产品统计'),
+                                    url: 'product/areas/index',
+                                    extend:'data-area=["90%","85%"]',
                                 },
                               ],
                             table: table, events: Table.api.events.operate,