浏览代码

Merge branch 'master' of http://124.222.171.90:10880/Teapay/RWACha-API

* 'master' of http://124.222.171.90:10880/Teapay/RWACha-API:
  热销产品
  库存
  抢购
  余额不足
  茶宝赠送
  缩略图
jason 10 月之前
父节点
当前提交
bac01007c8

+ 2 - 1
application/admin/lang/zh-cn/general/config.php

@@ -90,5 +90,6 @@ return [
     'Giveaway'                             => '赠送手续费',
     'Giveaway txt'                         => '赠送描述',
     'Pv rate'                              => '直推收益比例',
-    
+    'Chabao giveaway'                      => '茶宝赠送比例',
+    'Chabao giveaway txt'                  => '茶宝赠送描述',
 ];

+ 37 - 0
application/api/command/SendBonusRewards.php

@@ -0,0 +1,37 @@
+<?php
+
+
+namespace app\api\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use app\common\logic\BonusRewards;
+use app\common\model\TimedTaskLogModel;
+use think\Model;
+
+
+class SendBonusRewards extends Command
+{
+    protected function configure()
+    {
+        $this->setName('SendBonusRewards')->setDescription('Here is the remark ');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        /* 永不超时 */
+//        ini_set('max_execution_time', 0);
+
+        // 记录开始运行的时间
+        $GLOBALS['_beginTime'] = microtime(TRUE);
+        $output->writeln('定时任务开始执行:' . date('Y-m-d H:i:s', time()));
+
+        /*** 发放团队算力奖励 ***/
+        $output->writeln("开始发放团队算力奖励:");
+
+        $log_id = (new BonusRewards())->powerRewards();
+
+        $output->info("SendTeamRewards ok!");
+    }
+}

+ 0 - 131
application/api/command/SendTeamRewards.php

@@ -1,131 +0,0 @@
-<?php
-
-
-namespace app\api\command;
-
-use think\console\Command;
-use think\console\Input;
-use think\console\Output;
-use app\common\logic\TeamRewards;
-use app\common\model\TimedTaskLogModel;
-use think\Model;
-
-
-class SendTeamRewards extends Command
-{
-    protected function configure()
-    {
-        $this->setName('SendTeamRewards')->setDescription('Here is the remark ');
-    }
-
-    protected function execute(Input $input, Output $output)
-    {
-        /* 永不超时 */
-//        ini_set('max_execution_time', 0);
-
-        // 记录开始运行的时间
-        $GLOBALS['_beginTime'] = microtime(TRUE);
-        $output->writeln('定时任务开始执行:' . date('Y-m-d H:i:s', time()));
-
-        /*** 发放团队算力奖励 ***/
-        $output->writeln("开始发放团队算力奖励:");
-
-        $log_id = (new TeamRewards())->powerRewards();
-
-        $time_total = round(microtime(true) - $GLOBALS['_beginTime'], 4);//计算耗时
-
-        $output->writeln('团队算力奖励发放结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-        //更新发放日志
-        if($log_id > 0){
-            (new TimedTaskLogModel())->update([
-                'id'            => $log_id,
-                'status'        => 1,
-                'end_time'      => date('Y-m-d H:i:s'),
-                'elapsed_time'  => $time_total
-            ]);
-        }
-
-        /*** 发放分红收益 ***/
-        $begin_usdt = microtime(TRUE);
-        $output->writeln("开始发放加权分红:");
-
-        $log_id_1 = (new TeamRewards())->usdtRewards();
-
-        $time_total = round(microtime(true) - $begin_usdt, 4);//计算耗时
-        $output->writeln('加权分红发放结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-        //更新发放日志
-        if($log_id_1 > 0){
-            (new TimedTaskLogModel())
-                ->where('id', $log_id_1)
-                ->update([
-                    'id'            => $log_id_1,
-                    'status'        => 1,
-                    'end_time'      => date('Y-m-d H:i:s'),
-                    'elapsed_time'  => $time_total
-                ]);
-        }
-
-        /*** 发放社区长、系统领导人加权分红 ***/
-        $begin_usdt = microtime(TRUE);
-        $output->writeln("开始发放社区长、系统领导人加权分红:");
-
-        $log_id_1 = (new TeamRewards())->marketRewards();
-
-        $time_total = round(microtime(true) - $begin_usdt, 4);//计算耗时
-        $output->writeln('社区长、系统领导人加权分红发放结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-        //更新发放日志
-        if($log_id_1 > 0){
-            (new TimedTaskLogModel())
-                ->where('id', $log_id_1)
-                ->update([
-                    'id'            => $log_id_1,
-                    'status'        => 1,
-                    'end_time'      => date('Y-m-d H:i:s'),
-                    'elapsed_time'  => $time_total
-                ]);
-        }
-
-        /*** 团队业绩分红 ***/
-        $begin_usdt = microtime(TRUE);
-        $output->writeln("团队业绩分红:");
-
-        $log_id_1 = (new TeamRewards())->teamRewards();
-
-        $time_total = round(microtime(true) - $begin_usdt, 4);//计算耗时
-        $output->writeln('团队业绩分红发放结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-        //更新发放日志
-        if($log_id_1 > 0){
-            (new TimedTaskLogModel())
-                ->where('id', $log_id_1)
-                ->update([
-                    'id'            => $log_id_1,
-                    'status'        => 1,
-                    'end_time'      => date('Y-m-d H:i:s'),
-                    'elapsed_time'  => $time_total
-                ]);
-        }
-
-        /*** 今日产出 ***/
-//        $begin_usdt = microtime(TRUE);
-//        $output->writeln("今日产出:");
-//
-//        $log_id_1 = (new TeamRewards())->AllocateEtc();
-//
-//        $time_total = round(microtime(true) - $begin_usdt, 4);//计算耗时
-//        $output->writeln('今日产出放结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-//        //更新发放日志
-//        if($log_id_1 > 0){
-//            (new TimedTaskLogModel())
-//                ->where('id', $log_id_1)
-//                ->update([
-//                    'id'            => $log_id_1,
-//                    'status'        => 1,
-//                    'end_time'      => date('Y-m-d H:i:s'),
-//                    'elapsed_time'  => $time_total
-//                ]);
-//        }
-
-        $time_total = round(microtime(true) - $GLOBALS['_beginTime'], 4);//计算耗时
-        $output->writeln('定时任务执行结束,总耗时' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
-    }
-}

+ 6 - 8
application/api/controller/Home.php

@@ -74,7 +74,7 @@ class Home extends Api
         // 热销
         $resp['product_list'] = $productPopular->alias('a')
            ->join("product_list b", "a.product_id = b.id", "left")
-           ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
+           ->field('a.id,'.'b.'.$this->lan.'_name as name,a.product_id,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
            ->limit(2)
            ->where('a.status', '<', $productPopular::STOP)
            ->order('a.weigh desc')
@@ -107,20 +107,18 @@ class Home extends Api
     {
         try {
             $ids = $this->request->post('ids/d', 0);
+            $product_id = $this->request->post('product_id/d', 0);
             if(empty($ids)) throw new Exception(__("Parameter error"));
             $times = array();
             $order = array();
-            $info = $productPopular->alias('a')
-                ->join("product_list b", "a.product_id = b.id", "left")
-                ->field('a.id,a.product_id,'.'b.'.$this->lan.'_name as name,b.images as img_url,price,cost_price,stock,num,start_time,end_time,b.details')
-                ->where('a.id', $ids)
-                ->order('a.weigh desc')
-                ->find();
+            //详情
+            $info = $productPopular::getProductInfo($product_id, $ids, $this->lan);
+        
             if(!empty($info)) {
                 $times = $productPopular
                 ->where('product_id', $info['product_id'])
                 ->field('title,price, start_time, end_time, status')
-                ->order('id desc')->limit(10)->select();
+                ->order('weigh desc')->limit(10)->select();
             }
             if(!empty($info)) {
                 $order = $productOrder->alias('a')

+ 38 - 24
application/api/controller/Ledger.php

@@ -6,7 +6,7 @@ use app\admin\model\LedgerDeclarationChange;
 use app\common\controller\Api;
 use app\common\model\LedgerPowerChangeModel;
 use app\common\model\LedgerQubicChangeModel;
-use app\common\model\LedgerServersPowerChangeModel;
+use app\common\model\UserModel;
 use app\common\model\LedgerSmhChangeModel;
 use app\common\model\LedgerTokenChangeModel;
 use app\common\model\LedgerUsdtChangeModel;
@@ -15,6 +15,9 @@ use app\common\model\OfflineWithdrawRecordModel;
 use fast\Action;
 use think\Log;
 use think\Env;
+use think\Db;
+use fast\Asset;
+use think\Exception;
 
 /**
  * 首页接口
@@ -162,40 +165,51 @@ class Ledger extends Api
     }
 
     /**
-     * 算力明细
+     * 茶宝赠送明细 
      * @return void
      */
-    public function powerList()
+    public function chabao()
     {
-        $type  = $this->request->post('query.action'); // 账变类型
-        $where = [
-            'user_id' => $this->auth->getTokenUserID(),
-        ];
-        if ($type != Action::All) {
-            $where['action'] = $type;
-        }
-        $paginator = (new LedgerPowerChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
-        $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
+      
+        $this->success('', ['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')]);
     }
 
     /**
-     * USDT明细
+     * 茶宝赠送
      * @return void
      */
-    public function usdtList()
+    public function chabaoGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
     {
-        $type  = $this->request->post('query.action'); // 账变类型
-        $where = [
-            'user_id' => $this->auth->getTokenUserID(),
-        ];
-        if ($type != Action::All) {
-            $where['action'] = $type;
+   
+        $amount = $this->request->post('amount'); // 茶宝
+        $address = $this->request->post('address'); // 地址
+        if(empty($amount) || empty($address)){
+            $this->error(__('Parameter error'));
         }
-        $paginator = (new LedgerUsdtChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
-        foreach ($paginator as $key => $item){
-            $paginator[$key]['action_name'] = Action::getText($item['action']);
+        $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
+
+        // 启动事务
+        Db::startTrans();
+        try {
+
+            $user = $userModel->getByAddress($address);
+            if(empty($user)) throw new Exception(__("赠送用户不存在"));    
+            if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
+            $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
+            if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+        
+            // 更新USDT和账变
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerWalletModel::GiftPay);
+
+            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerWalletModel::GiftReceipt);
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error($e->getMessage(), null, $e->getCode());
         }
-        $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
+        $this->success('ok');
     }
 
     /**

+ 50 - 27
application/api/controller/Order.php

@@ -26,48 +26,57 @@ class Order extends Api
     /**
      * 创建订单
      */
-    public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductArea $productArea, LedgerWalletModel $ledgerWalletModel)
+    public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductArea $productArea, LedgerWalletModel $ledgerWalletModel, UserModel $userModel)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
         if(!$validate->scene('add')->check($params)) $this->error($validate->getError());
         
         $order_info = $productPopular->where('id', $params['order_id'])->find();
-        if($order_info->num == $order_info->stock) $this->error(__("库存不足"));
         if(empty($order_info)) $this->error(__("参数有误,无可用产品"));
-        $order_data['order_id']  = $params['order_id'];
-        $order_data['product_id']= $params['product_id'];
-        $order_data['price']     = $order_info['price'];
-        $order_data['type_id']   = $productOrder::Popular;
-        $order_data['area_id']   = $params['area_id'];
-        $order_data['order_no']  = getOrderSN('R');
-        $order_data['user_id']   = $this->auth->id;
-        $order_data['status']    = $productOrder::Paid;
-        $order_data['num']       = 1;
+        $areaArr = explode(',', $params['area_id']);
+        $areaNum = count($areaArr);
+        if(($order_info->num + $areaNum) > $order_info->stock) $this->error(__("库存不足"));
+
         // 启动事务
         Db::startTrans();
         try {
             
             $amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
-            if(bccomp($order_info['price'], $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+            $totalPrice = bcmul($order_info['price'], $areaNum, 2);
+            if(bccomp($totalPrice, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+            if($order_info->start_time > time()) throw new Exception(__("抢购未开始"));
             if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
-
-            // 生成订单
-            $productOrder->create($order_data);
-            //修改区域状态
-            $productArea->where('id', $order_data['area_id'])->setField('status', ProductLists::STOP);
-
+            //批量地区添加
+            foreach ($areaArr as $item) {
+                       
+                $order_data['order_id']  = $params['order_id'];
+                $order_data['product_id']= $params['product_id'];
+                $order_data['price']     = $order_info['price'];
+                $order_data['type_id']   = $productOrder::Popular;
+                $order_data['area_id']   = $item;
+                $order_data['order_no']  = getOrderSN('R');
+                $order_data['user_id']   = $this->auth->id;
+                $order_data['status']    = $productOrder::Paid;
+                $order_data['num']       = 1;
+                // 生成订单
+                $productOrder->create($order_data);
+                //修改区域状态
+                $productArea->where('id', $item)->setField('status', ProductLists::STOP);
+            }
             //余额记录
-            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Popular, $this->auth->id);
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$totalPrice, $ledgerWalletModel::Popular, $this->auth->id);
 
             //直推收益: pv* ×10%
-            if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $productOrder::getEffectiveOrder($this->auth->parent_id) > 0){
+            if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $userModel::getUserRwaNum($this->auth->parent_id) > 0){
                 $pv = bcmul($order_info['pv'], getConfig('pv_rate'), 2);
                 $ledgerWalletModel->changeWalletAccount($this->auth->parent_id, Asset::TOKEN, $pv, $ledgerWalletModel::Direct, $this->auth->id);
             }
+            //更新Rwa持有数量
+            $userModel->updateForRwaNum($this->auth->id, $areaNum, '+');
             //扣除库存
-            if($order_info->stock == 1 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
-            $order_info->num  += 1;
+            if(($order_info->stock - $areaNum) == 0 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
+            $order_info->num  += $areaNum;
             $order_info->save();
             // 提交事务
             Db::commit();
@@ -83,7 +92,7 @@ class Order extends Api
     /**
      * 提货订单
      */
-    public function pickupOrder(UserArea $userArea, ProductOrder $productOrder)
+    public function pickupOrder(UserArea $userArea, ProductOrder $productOrder, UserModel $userModel)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
@@ -99,6 +108,9 @@ class Order extends Api
         try {
             // 生成订单
             $userArea->create($order_data);
+            //扣除Rwa数量
+            $userModel->updateForRwaNum($order_info->user_id, 1, '-');
+
             $order_info->status= $productOrder::Shipped; 
             $order_info->save();
             // 提交事务
@@ -116,7 +128,7 @@ class Order extends Api
      * 订单转让
      * @return void
      */
-    public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer)
+    public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer, UserModel $userModel)
     {   
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
@@ -133,6 +145,9 @@ class Order extends Api
             $feeAmount = bcmul($params['price'], $fee, 2) ;
             $productTransfer::setTransferOrder($this->auth->id, $order_info['product_id'], $order_info['area_id'], $feeAmount, $params);
 
+            //扣除Rwa有效
+            $userModel->updateForRwaNum($order_info['user_id'], 1, '-');
+
             //修改状态
             $order_info->status = $productOrder::Transferred;
             $order_info->save();
@@ -148,7 +163,7 @@ class Order extends Api
      * 转让订单购买
      * @return void
      */
-    public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer, LedgerWalletModel $ledgerWalletModel)
+    public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer, LedgerWalletModel $ledgerWalletModel, UserModel $userModel)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
@@ -179,11 +194,13 @@ class Order extends Api
             //扣除余额记录 
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Payment, $order_info['user_id']);
           
-
             //增加转让人余额
             $amount = bcsub($order_info['price'], $order_info['fees'], 2);
             $ledgerWalletModel->changeWalletAccount($order_info['user_id'], Asset::TOKEN, $amount, $ledgerWalletModel::Receive, $this->auth->id);
 
+            //增加Rwa有效
+            $userModel->updateForRwaNum($this->auth->id, 1, '+');
+
             //修改原订单状态
             $productOrder->where('id', $order_info['order_id'])->setField('status', $productOrder::Closure);    
             //修改状态
@@ -236,6 +253,9 @@ class Order extends Api
             //扣除手续费
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$fees, $ledgerWalletModel::Giveaway, $user['id']);
 
+            //扣除Rwa有效
+            $userModel->updateForRwaNum($this->auth->id, 1, '-');
+
             $order_info->status= $productOrder::Closure; 
             $order_info->save();
 
@@ -251,7 +271,7 @@ class Order extends Api
 
 
     //取消转让 
-    public function cancel(ProductOrder $productOrder, ProductTransfer $productTransfer)
+    public function cancel(ProductOrder $productOrder, ProductTransfer $productTransfer, UserModel $userModel)
     {
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
@@ -265,6 +285,9 @@ class Order extends Api
 
             //转让列表取消
             $productTransfer::where('order_id',$params['order_id'])->setField('status', $productTransfer::STOP);
+
+            //增加Rwa有效
+            $userModel->updateForRwaNum($order_info['user_id'], 1, '+');
             $order_info->status= $productOrder::Paid; 
             $order_info->save();
             // 提交事务

+ 1 - 1
application/api/controller/Product.php

@@ -29,7 +29,7 @@ class Product extends Api
         foreach ($list as $kk =>$val) {
             $pro = $productPopular->alias('a')
                 ->join("product_list b", "a.product_id = b.id", "left")
-                ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
+                ->field('a.id,'.'b.'.$this->lan.'_name as name,a.product_id,b.thum as img_url,price,cost_price,stock,num,start_time,end_time')
                 ->where('a.status', '<', $productPopular::STOP)
                 ->where('b.type_id', $kk)
                 ->order('a.weigh desc')

+ 2 - 71
application/api/controller/User.php

@@ -66,7 +66,7 @@ class User extends Api
     }
 
     /**
-     * 获取Nft列表
+     * 获取Nft列表   transfer_price
      * @return void
      */
     public function getNftList(ProductOrder $productOrder)
@@ -76,7 +76,7 @@ class User extends Api
               ->join("products c", "c.id = b.type_id", "left")
               ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
               ->join("product_area d", "d.id = a.area_id", "left") //地区
-              ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.images as img_url,a.price,a.status,a.type_id,c.'.$this->lan.'_title as title,z.price as transfer_price,d.address')
+              ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id,c.'.$this->lan.'_title as title,z.price as transfer_price,d.address')
               ->where('a.user_id', $this->auth->id)
               ->order('a.id DESC')
               ->paginate($this->pageSize);
@@ -156,75 +156,6 @@ class User extends Api
 
 
 
-    /**
-     * 报单算力互转
-     * @return void
-     */
-    public function declarationTransfer()
-    {
-        $amount = $this->request->post('amount'); // 金额
-        $sign = $this->request->post('sign'); // 签名信
-        $address = $this->request->post('address'); // 提现地址
-//        $sign = 'test';
-        if(empty($sign)){
-            $this->error('参数错误');
-        }
-
-        $real   = $amount; // 实际到账
-        $min    = (new ParametersModel)->getValue('declarationMinAmount') ?? '0';
-        if ($amount <= 0) {
-            $this->error('互转金额必须大于0');
-        } else if ($amount < $min) {
-            $this->error('互转金额不能小于' . $min);
-        }
-
-        $uid = $this->auth->getTokenUserID();
-
-        // 用户信息
-        $from_user = (new UserModel())->getById($uid);
-        if (empty($from_user)) {
-            $this->error('用户不存在');
-        }
-
-        $to_user = (new UserModel())
-            ->where('address', $address)
-            ->find();
-        if (empty($to_user)) {
-            $this->error('接收用户不存在');
-        }
-
-        $wallet = (new LedgerWalletModel())->getWallet($from_user['id']);
-        if (empty($wallet)) {
-            $this->error('用户不存在');
-        }
-
-        if($amount > $wallet['declaration']){
-            $this->error('余额不足');
-        }
-
-        // 验签
-        $signMsg = "DeclarationWithdraw"; // 与前端约定的固定值
-        if (!checkSign($signMsg, $sign, $from_user['address'])) {
-            $this->error('签名校验失败');
-        }
-
-        // 启动事务
-        Db::startTrans();
-        try {
-            // 更新USDT和账变
-            (new LedgerWalletModel())->changeWalletAccount($from_user['id'], Asset::DECLARATION, -$amount, Action::TransferOut);
-
-            (new LedgerWalletModel())->changeWalletAccount($to_user['id'], Asset::DECLARATION, $amount, Action::TransferIn);
-            // 提交事务
-            Db::commit();
-        } catch (Exception $e) {
-            // 回滚事务
-            Db::rollback();
-            $this->error('提交失败:' . $e->getMessage());
-        }
-
-        $this->success('提现申请已提交');
-    }
 
     /**
      * 获取smh出款信息

+ 3 - 0
application/api/lang/en.php

@@ -20,4 +20,7 @@ return [
     '赠送'                                   => 'Gift fee',
     '直推收益'                               => 'Direct income',
     '系统调整'                               => 'System Adjustments',
+    '赠送支出'                               => 'Gift Expenses',
+    '赠送收款'                                                                    => 'Gift Receipt',
+    '抢购未开始'                                                                  => 'The flash sale has not started yet',
 ]; 

+ 1 - 0
application/api/lang/en/user.php

@@ -45,4 +45,5 @@ return [
     '退回'                                   => 'Return',
     '赠送'                                   => 'Gift fee',
     '直推收益'                               => 'Direct income',
+    'Parameter error'                       => 'Parameter error',
 ];

+ 6 - 1
application/api/lang/zh-cn.php

@@ -107,5 +107,10 @@ return [
     'The withdrawal amount cannot be less than'                                  => '提现金额不能小于',
     'Withdrawal failed, please contact customer service.'                        => '提现失败,请联系客服。',
     'Signature verification failed'                                              => '签名校验失败',
-    '系统调整'                                                                    => '系统调整'
+    '系统调整'                                                                    => '系统调整',
+    '赠送支出'                                                                    => '赠送支出',
+    '赠送收款'                                                                    => '赠送收款',
+    '抢购未开始'                                                                  => '抢购未开始',
+
+
 ];

+ 1 - 0
application/api/lang/zh-cn/user.php

@@ -45,4 +45,5 @@ return [
     '退回'                                  => '退回',
     '赠送'                                  => '赠送手续费',
     '直推收益'                              => '直推收益',
+    'Parameter error'                      => '参数有误',
 ];

+ 1 - 1
application/command.php

@@ -21,6 +21,6 @@ return [
     'app\api\command\OrderPay',
     'app\api\command\Team',
     'app\api\command\RechargeTxHashVerify',
-    'app\api\command\SendTeamRewards',
+    'app\api\command\SendBonusRewards', //奖金
     'app\admin\command\Task',
 ];

+ 67 - 115
application/common/logic/TeamRewards.php → application/common/logic/BonusRewards.php

@@ -23,33 +23,25 @@ use fast\Http;
  * 团队奖励发放逻辑
  * 定时任务,定时发放,每天一次,一般在凌晨12一过开始
  */
-class TeamRewards
+class BonusRewards
 {
     /**
      * 奖励名称及类型ID
      * @var array
      */
     private array $rewards_type = [
-        'power' => [
+        'community' => [
             'type_id' => 1,
-            'type_name' => "团队算力奖励"
+            'type_name' => "社区建设津贴"
         ],
-        'usdt' => [
+        'service' => [
             'type_id' => 2,
-            'type_name' => "加权分红"
+            'type_name' => "服务津贴"
         ],
-        'market' => [
+        'together' => [
             'type_id' => 3,
-            'type_name' => "团队在、系统领导人加权分红"
-        ],
-        'team' => [
-            'type_id' => 4,
-            'type_name' => "社区长业绩分红"
-        ],
-        'allocate' => [
-            'type_id' => 5,
-            'type_name' => "算力拨币"
-        ],
+            'type_name' => "共创津贴"
+        ]
     ];
 
     /**
@@ -61,17 +53,15 @@ class TeamRewards
      */
     public function powerRewards()
     {
-        $date = $this->getExeDate($this->rewards_type['power']['type_id']);
-
-        if(empty($date)){
-            return "本次没有可用时间";
-        }
+        $date = $this->getExeDate($this->rewards_type['community']['type_id']);
+        if(empty($date))  return "本次没有可用时间";
+        
 
         //创建定时任务执行日志
         $TimedTaskLog = new TimedTaskLogModel();
         $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['power']['type_id'],
-            'type_name'     => $this->rewards_type['power']['type_name'],
+            'type_id'       => $this->rewards_type['community']['type_id'],
+            'type_name'     => $this->rewards_type['community']['type_name'],
             'date_time'     => $date,
             'create_time'   => date('Y-m-d H:i:s'),
 
@@ -142,61 +132,7 @@ class TeamRewards
         return $log_id;
     }
 
-    /**
-     * 获取可用日期
-     * @var array
-     */
-    protected function getExeDate($type_id = 1)
-    {
-        $today = date('Y-m-d',strtotime("-1day"));//当前时间减一天为最后一次可用时间
-
-        $dateInfo = DB::table('timed_task_log')
-            ->where('type_id' ,$type_id)
-            ->where('status', 1)
-            ->order('date_time', 'desc')
-            ->find();
-        if(empty($dateInfo)){//首次
-            return $today;
-        }
 
-        $new_date = date('Y-m-d',strtotime("+1day",strtotime($dateInfo['date_time'])));//最后一次发放日期+1天为本次执行时间
-
-        if($new_date > $today){//超过今天
-            return "";
-        }
-        return $new_date;
-    }
-
-    /**
-     * 插入或更新收益统计信息
-     * @var array
-     */
-    protected function createData($uids, $amount, $date)
-    {
-        foreach ($uids as $user_id) {
-            $check = DB::table('team_rewards')
-                ->field('id')
-                ->where('user_id', $user_id)
-                ->where('date_time', $date)
-                ->find();
-            if ($check) {//存在,则更新
-                DB::table('team_rewards')
-                    ->where('id', $check['id'])
-                    ->update([
-                        'today_power' => Db::raw('today_power+' . $amount),
-                        'update_time' => date('Y-m-d H:i:s')
-                    ]);
-            } else {//新增
-                DB::table('team_rewards')
-                    ->insert([
-                        'user_id' => $user_id,
-                        'date_time' => $date,
-                        'today_power' => Db::raw('today_power+' . $amount),
-                        'create_time' => date('Y-m-d H:i:s')
-                    ]);
-            }
-        }
-    }
 
     /**
      * 计算理论收益
@@ -236,19 +172,6 @@ class TeamRewards
                     'update_time'   => date('Y-m-d H:i:s')
                 ]);
 
-//            //更新所有上级的 team_commission
-//            $path = (new UserPathModel())
-//                ->where('user_id', $info['user_id'])
-//                ->column('parent_id');
-//
-//            DB::table('team_rewards')
-//                ->where('user_id', 'in', $path)
-//                ->where('date_time', $info['date_time'])
-//                ->update([
-//                    'team_commission' => DB::raw("team_commission+" . $amount),
-//                    'update_time'   => date('Y-m-d H:i:s')
-//                ]);
-
         }
     }
 
@@ -316,7 +239,6 @@ class TeamRewards
                 }else{
                     Log::info("分红等级" . $level['level_id'] . "在" . $date . "分红金额为0;当日新增业绩:" . $amount . ",分红比例:" . $level['weight_dividend']. ",分红人数" . dump($levels_info[$level['level_id']]));
                 }
-
             }
         }
         return $log_id;
@@ -538,30 +460,6 @@ class TeamRewards
             }
         }
 
-
-//        foreach ($community_user_list as $info) {
-//            //取该社区长下新增服务器算力
-//            $next_ids = (new UserPathModel())->where('parent_id', $info['id'])->column('user_id');
-//            $recharge_power = OfflineRechargeRecordModel::where('user_id', 'in', $next_ids)
-//                //->where('order_type', 2)
-//                ->where('status', 1)
-//                ->whereBetween('create_time', $between_time)
-//                ->sum('power');
-//            $recharge_power = $community_rewards_arr[0] * $recharge_power;//取新增业绩的8%
-//            if($recharge_power < 1){
-//                (new Output())->writeln("会员:" . $info['id'] . ",本次没有可用新增数据:" . $date);
-//                continue;
-//            }
-//            $reward_power = $recharge_power * $community_rewards_arr[1];
-//            $reward_usdt = $recharge_power * $community_rewards_arr[2] * 8;//算力折算成U
-//            dump(['用户ID:' . $info['id'],'新增业绩:' . $recharge_power, '算力收益:' . $reward_power, 'U收益:' . $reward_usdt]);
-//
-//            //发放分红
-//            (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::POWER, $reward_power, Action::PowerCommunityBonusAward);
-//
-//            (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::USDT, $reward_usdt, Action::UsdtCmmunityBonus);
-//        }
-
         return $log_id;
     }
 
@@ -619,4 +517,58 @@ class TeamRewards
 
         return $log_id;
     }
+
+    /**
+     * 获取可用日期
+     * @var array
+     */
+    protected function getExeDate($type_id = 1)
+    {
+        $today = date('Y-m-d',strtotime("-1day"));//当前时间减一天为最后一次可用时间
+
+        $dateInfo = DB::table('timed_task_log')
+            ->where('type_id' ,$type_id)
+            ->where('status', 1)
+            ->order('date_time', 'desc')
+            ->find();
+        if(empty($dateInfo)){//首次
+            return $today;
+        }
+        $new_date = date('Y-m-d',strtotime("+1day",strtotime($dateInfo['date_time'])));//最后一次发放日期+1天为本次执行时间
+        if($new_date > $today){//超过今天
+            return "";
+        }
+        return $new_date;
+    }
+
+    /**
+     * 插入或更新收益统计信息
+     * @var array
+     */
+    protected function createData($uids, $amount, $date)
+    {
+        foreach ($uids as $user_id) {
+            $check = DB::table('team_rewards')
+                ->field('id')
+                ->where('user_id', $user_id)
+                ->where('date_time', $date)
+                ->find();
+            if ($check) {//存在,则更新
+                DB::table('team_rewards')
+                    ->where('id', $check['id'])
+                    ->update([
+                        'today_power' => Db::raw('today_power+' . $amount),
+                        'update_time' => date('Y-m-d H:i:s')
+                    ]);
+            } else {//新增
+                DB::table('team_rewards')
+                    ->insert([
+                        'user_id' => $user_id,
+                        'date_time' => $date,
+                        'today_power' => Db::raw('today_power+' . $amount),
+                        'create_time' => date('Y-m-d H:i:s')
+                    ]);
+            }
+        }
+    }
 }

+ 5 - 2
application/common/model/LedgerWalletModel.php

@@ -35,7 +35,8 @@ class LedgerWalletModel extends Model
     const Giveaway          = 7;
     const Direct            = 8;
     const System            = 9;
-
+    const GiftPay           = 10; //Gift Expenses
+    const GiftReceipt       = 11;
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
@@ -52,6 +53,8 @@ class LedgerWalletModel extends Model
         self::Giveaway          => '赠送手续费',
         self::Direct            => '直推收益',
         self::System            => '系统调整',
+        self::GiftPay           => '赠送支出',
+        self::GiftReceipt       => '赠送收款',
     ];
 
     public static function getWalletChaBao($userID)
@@ -80,7 +83,7 @@ class LedgerWalletModel extends Model
     {
         return [self::Popular => __('热销支付'), self::Payment  => __('转让支付'), self::Receive => __('转让收款'), self::Recharge => __('充值'), 
         self::Withdraw  => __('提现'), self::Share => __('分享'), self::Return => __('退回'), self::Giveaway => __('赠送'), self::Direct => __('直推收益'),
-        self::System => __('系统调整')];
+        self::System => __('系统调整'),self::GiftPay => __('赠送支出'),self::GiftReceipt => __('赠送收款')];
     }
 
     /**

+ 3 - 8
application/common/model/ProductOrder.php

@@ -33,9 +33,9 @@ class ProductOrder extends Model
     const Cancelled         = 4;
     const Closure           = 5;
 
-    const Popular           = 0;
-    const Transfer          = 1;
-    const Giveaway          = 2;
+    const Popular           = 0; //热销
+    const Transfer          = 1; //转让
+    const Giveaway          = 2; //赠送
     /* 
      *  订单状态 '已下单', 1=>'已付款', 2=>'已转让', 3=>'提货', 4=>'已取消', 5=>'完成'];
      */
@@ -50,11 +50,6 @@ class ProductOrder extends Model
     ];
 
 
-    //获取有效订单
-    public static function getEffectiveOrder(int $uid)
-    {
-        return self::where('user_id', $uid)->where('status', '<', self::Shipped)->count();
-    }
 
 
     public static function getStatusList()

+ 28 - 3
application/common/model/ProductPopular.php

@@ -2,6 +2,7 @@
 
 namespace app\common\model;
 
+use fast\Arr;
 use think\Model;
 
 
@@ -45,7 +46,12 @@ class ProductPopular extends Model
         $count =0;
         $time = time();
         $list = self::where('status', '<', self::STOP)->select();
-        foreach ($list as $item) {
+        foreach ($list as $item) 
+        {
+            //未开始
+            if ( $item->start_time > $time)  {
+                $count += $item->allowField(true)->isUpdate(true)->save(['status'=>self::NOTSTOP]);
+            }
             //进行中
             if ($time >= $item->start_time && $time < $item->end_time)  {
                 $count += $item->allowField(true)->isUpdate(true)->save(['status'=>self::NORMAL]);
@@ -59,6 +65,27 @@ class ProductPopular extends Model
     }
 
 
+    //获取热销详情
+    public static function getProductInfo(int $product_id, int $ids, string $lan): object
+    {
+        $info = self::alias('a')
+            ->join("product_list b", "a.product_id = b.id", "left")
+            ->field('a.id,a.product_id,'.'b.'.$lan.'_name as name,b.images as img_url,price,cost_price,stock,num,start_time,end_time,b.details')
+            ->where('a.product_id', $product_id)
+            ->where('a.status', self::NORMAL)
+            ->find();
+        if (empty($info)) {
+            $info = self::alias('a')
+                ->join("product_list b", "a.product_id = b.id", "left")
+                ->field('a.id,a.product_id,'.'b.'.$lan.'_name as name,b.images as img_url,price,cost_price,stock,num,start_time,end_time,b.details')
+                ->where('a.id', $ids)
+                ->order('a.weigh desc')
+                ->find();
+        }
+        return $info;
+    }
+
+
 
     //分类
     public function productsList()
@@ -77,8 +104,6 @@ class ProductPopular extends Model
 
     
 
-
-
     public function getStartTimeTextAttr($value, $data)
     {
         $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');

+ 23 - 1
application/common/model/UserModel.php

@@ -47,13 +47,35 @@ class UserModel extends Model
         return $arr;
     }
 
-    //获取用户余额 冻结金额 和 折合金额   frozen_amount  convert_mount
+    //获取用户余额 冻结金额 和 折合金额
     public static function getUserAmount(int $uid): float
     {   
         return self::where('id', $uid)->sum("balance-frozen_amount");
     }
     
 
+    //获取用户RWA
+    public static function getUserRwaNum(int $uid): int
+    {   
+        return self::where('id', $uid)->value("rwa_num");
+    }
+
+    
+    /**
+     * RWA更新数据
+     * @param int $uid
+     * @param string $power
+     * @return void
+     */
+    public static function updateForRwaNum(int $uid, string $score, string $action)
+    {
+        if($action == '+'){
+            return self::where('id', $uid)->setInc('rwa_num', $score);
+        }else{
+            return self::where('id', $uid)->setDec('rwa_num', $score);
+        }
+    }
+
     /**
      * 余额更新数据
      * @param int $uid

+ 11 - 2
application/extra/site.php

@@ -37,7 +37,16 @@ return array (
     'category2' => '分类二',
     'custom' => '自定义',
   ),
-  'direct_income' => '0.05',
+  'direct_income' => '10',
   'transfer_fee' => '0.8',
-  'recharge_address' => 'xxddddss',
+  'recharge_txt' => 'xxddddss',
+  'chabao_rate' => '0.7',
+  'withdrawal_fee' => '0.1',
+  'withdraw_min_amount' => '100',
+  'convert_rate' => '7.2',
+  'giveaway' => '0.12',
+  'giveaway_txt' => '赠送订单xxxx',
+  'pv_rate' => '0.1',
+  'chabao_giveaway' => '0.3',
+  'chabao_giveaway_txt' => '茶宝赠送xxxxx',
 );

+ 2 - 0
public/assets/js/backend/ledger/ledger_token_change.js

@@ -44,6 +44,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 7: '赠送手续费',
                                 8: '直推收益',
                                 9: '系统赠送',
+                                10: '赠送支出',
+                                11: '赠送收款'
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]