afa 8 månader sedan
förälder
incheckning
2cf894f04c

+ 33 - 15
application/api/controller/Airdrop.php

@@ -8,7 +8,7 @@ use app\common\model\UserModel;
 use app\common\controller\Api;
 use app\common\model\UserWelfare;
 use think\Db;
-use think\exception\DbException;
+use app\common\model\LedgerWalletModel;
 use app\common\model\ProductOrder;
 //空投
 class Airdrop extends Api
@@ -23,11 +23,14 @@ class Airdrop extends Api
         $this->lan = $this->request->getLan();
     }
 
-    //获取是否领取
-    public function getNewbieWeal(ProductOrder $productOrder)
+    //获取领取福利信息
+    public function getNewbieWeal(UserWelfare $userWelfare, ProductOrder $productOrder)
     {
-        $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
-        $this->success('', boolval($info));
+        $info    = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
+        $endTime = bcadd($info->create_time, 86400)?? 0;
+
+        $rows    = $userWelfare::getIsWelfare();
+        $this->success('', ['is_super'=>$this->auth->is_super, 'end_time'=>$endTime, 'chabao'=>$rows->frozen]);
     }
 
 
@@ -42,7 +45,7 @@ class Airdrop extends Api
         Db::startTrans();
         try {
             //添加Rwa茶记录
-            $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->new_product_id, $row->new_num, $this->lan);
+            $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->new_product_id, $row->new_num, $this->lan, $productOrder::Newbie);
             //添加茶数量
             $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $row->new_num, '+');
             Db::commit();
@@ -56,18 +59,33 @@ class Airdrop extends Api
 
 
     //超级福利
-    public function getSuperWeal()
+    public function setSuperWeal(UserWelfare $userWelfare, UserModel $userModel, ProductOrder $productOrder)
     {
-       
-        $this->success('', $info);
-    }
+        $row = $userWelfare::getIsWelfare();
+        if(empty($row->is_super)) $this->error(__('暂未开启'));
+        if(!empty($this->auth->is_super)) $this->error(__('您已领取'));
 
+        $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
+        if((time()-$info->create_time) >= 86400) $this->error(__('您已过期'));
+        Db::startTrans();
+        try {
+            //添加Rwa茶记录
+            $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->super_product_id, $row->super_num, $this->lan, $productOrder::Super);
 
-    //超级福利
-    public function setSuperWeal()
-    {
-    
-        $this->success('', $info);
+            //添加超级福利标识/上级
+            $userModel::updateUserSuper($this->auth->id, $this->auth->parent_id);
+
+            //标识为社区长
+            if($row->frozen > 0) LedgerWalletModel::sendUserSubFrozen($this->auth->id, $row->frozen, LedgerWalletModel::Super, '-'); 
+            
+            //添加茶数量
+            $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $row->super_num, '+');
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('', $result);
     }
 
 

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

@@ -34,5 +34,6 @@ return [
     '已提货'                                                                      => 'Gifted',
     '已取消'                                                                      => 'Cancelled',
     '物流运费'                                                                    => 'Logistics freight',
+    '茶宝标记激活'                                                                => 'Tea treasure mark activation',
     '暂未开启'                                                                    => 'Not yet enabled'   
 ]; 

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

@@ -123,6 +123,7 @@ return [
     '已提货'                                                                      => '已提货',
     '已取消'                                                                      => '已取消',
     '物流运费'                                                                    => '物流运费',
+    '茶宝标记激活'                                                                => '茶宝标记激活',
     '不能购买自己寄售的商品'                                                       => '不能购买自己寄售的商品',
     '转让支付'                                                                    => '寄售支付',
     '转让收款'                                                                    => '寄售收款',

+ 8 - 209
application/api/logic/WelfareLoginc.php

@@ -9,6 +9,7 @@ use app\common\controller\Api;
 use app\common\model\UserWelfare;
 use app\common\model\ProductPopular;
 use app\common\model\ProductOrder;
+use app\common\model\UserModel;
 use fast\Action;
 use fast\Asset;
 use fast\MembershipLevel;
@@ -24,234 +25,32 @@ use fast\Http;
 class WelfareLoginc
 {
  
+
     /** 添加新人福利
      * @param int   $uid       用户id
      * @param array $productId 产品ID
      * @param int   $num       数量
      * @param int   $lan       语言
      */
-    public static function setUserWelfareLos($uid, int $productId, $num, $lan)
+    public static function setUserWelfareLos($uid, int $productId, $num, $lan, $typeId)
     {
         $tim = time();
-        $result = ProductPopular::alias('a')->where('a.start_time', '<=', $tim)->where('a.end_time', '>=', $tim)
-                ->join('product_list b', "a.product_id = b.id", "left")
-                ->field('a.*,b.is_area,'.$lan.'_name as name')
-                ->where('a.product_id', $productId)->find();
+        $result = ProductPopular::getPopularByTime($productId, $lan, $tim);
         if(!$result || $num > $result->stock) throw new Exception(__('库存不足'));
         if(empty($result->is_area)){
-            ProductOrder::setPopularNoAreaOrder($num, $result->id, $result->price, $result->product_id, $uid, ProductOrder::Newbie);
+            ProductOrder::setPopularNoAreaOrder($num, $result->id, $result->price, $result->product_id, $uid, $typeId);
         }else{
             $areaArr = ProductArea::where('product_id', $productId)->where('status', ProductArea::NORMAL)->orderRaw('RAND()')->limit($num)->column('id');
-            ProductOrder::setPopularAreaOrder($areaArr, $result->id, $result->price, $result->product_id, $uid, ProductOrder::Newbie);
+            ProductOrder::setPopularAreaOrder($areaArr, $result->id, $result->price, $result->product_id, $uid, $typeId);
         }
         return ['start_time'=>$tim, 'name'=>$result->name, 'num'=>$num];
     }
 
 
 
-    /**
-     * 计算理论收益
-     * @var array
-     */
-    protected function calculateRewards($info, $team_level_config)
-    {
-        $user = DB::table('user')
-            ->where('id', $info['user_id'])
-            ->find();
-        $level_info = [];
-        foreach ($team_level_config as $level) {
-            if ($user['team_power'] >= $level['compute_require']) {
-                $level_info['id'] = $level['level_id'];
-                $level_info['rate'] = $level['compute_incentive'];
-            }
-        }
-        if(isset($level_info['id']) && $level_info['id'] > 0){
-            //团队等级大于0,才发放收益
-            $amount = $info['today_power'] * $level_info['rate'];
-
-            DB::table('team_rewards')
-                ->where('id', $info['id'])
-                ->update([
-                    'team_power'    => $user['team_power'],
-                    'level_id'      => $level_info['id'],
-                    'rate'          => $level_info['rate'],
-                    'commission'    => $amount,
-                    'update_time'   => date('Y-m-d H:i:s')
-                ]);
-            //累计上级的团队收益
-            DB::table('team_rewards')
-                ->where('user_id', $user['parent_id'])
-                ->where('date_time', $info['date_time'])
-                ->update([
-                    'team_commission' => DB::raw("team_commission + " . $amount),
-                    'update_time'   => date('Y-m-d H:i:s')
-                ]);
-
-        }
-    }
-
-
-
-
-    /**
-     * 发放团队加权分红
-     * 1.提取各个等级的会员列表
-     * 2.再计算当日新增业绩
-     * 3.根据每个等级现存的人数,按比例平分佣金
-     */
-    public function usdtRewards()
-    {
-        $date = $this->getExeDate($this->rewards_type['usdt']['type_id']);
-
-        if(empty($date)){
-            return "本次没有可用时间";
-        }
-
-        //创建定时任务执行日志
-        $TimedTaskLog = new TimedTaskLogModel();
-        $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['usdt']['type_id'],
-            'type_name'     => $this->rewards_type['usdt']['type_name'],
-            'date_time'     => $date,
-            'create_time'   => date('Y-m-d H:i:s'),
-        ]);
-
-        $between_time = [strtotime($date), strtotime($date) + 86400];
-
-        //读取当日新增数据,按用户分组统计
-        $recharge_amount = DB::table('offline_recharge_record')
-            ->whereBetween('create_time', $between_time)
-            ->where('order_type', 1)
-            ->where('status', 1)
-            ->sum('amount');
-
-        if($recharge_amount < 1){
-            (new Output())->writeln("本次没有可用新增数据:" . $date);
-            return $log_id;
-        }
-
-        //1.查找有等级的会员
-        $level_user_list = DB::table('user')
-            ->field('id,team_level_id')
-            ->where('team_level_id', '>', 0)
-            ->select();
-        $levels_info = [];
-        //整理数据格式,以team_level_id为键名,存放该等级下的会员id数组
-        foreach ($level_user_list as $info) {
-            $levels_info[$info['team_level_id']][] = $info['id'];
-        }
-        //读取团队等级配置
-        $team_level_config = DB::table('team_level')
-            ->field('level_id, weight_dividend')
-            ->select();
-        foreach ($team_level_config as $level) {
-            if(isset($levels_info[$level['level_id']])){//存在当前等级的会员
-                //计算当前等级平分佣金金额:当日新增业绩 * 分红比例 / 当前等级人数
-                $amount = $recharge_amount * $level['weight_dividend'] / count($levels_info[$level['level_id']]);
-                if($amount > 0){
-                    foreach ($levels_info[$level['level_id']] as $user_id){
-                        //发放佣金
-                        (new LedgerWalletModel)->changeWalletAccount($user_id, Asset::USDT, $amount, Action::UsdtWeightDividend);
-                    }
-                }else{
-                    Log::info("分红等级" . $level['level_id'] . "在" . $date . "分红金额为0;当日新增业绩:" . $amount . ",分红比例:" . $level['weight_dividend']. ",分红人数" . dump($levels_info[$level['level_id']]));
-                }
-            }
-        }
-        return $log_id;
-    }
-
-    /**
-     * 发放社区长、系统领导人加权分红
-     * 1.提取社区长等级的会员列表
-     * 2.再计算当日新增业绩
-     * 3.根据每个等级现存的人数,按比例平分佣金
-     * 5.提取系统领导人等级的会员列表
-     * 6.再计算当日新增业绩
-     * 7.根据每个等级现存的人数,按比例平分佣金
-     */
-    public function marketRewards()
-    {
-        $date = $this->getExeDate($this->rewards_type['market']['type_id']);
-
-        if(empty($date)){
-            return "本次没有可用时间";
-        }
-
-        //创建定时任务执行日志
-        $TimedTaskLog = new TimedTaskLogModel();
-        $log_id = $TimedTaskLog->insertGetId([
-            'type_id'       => $this->rewards_type['market']['type_id'],
-            'type_name'     => $this->rewards_type['market']['type_name'],
-            'date_time'     => $date,
-            'create_time'   => date('Y-m-d H:i:s'),
-        ]);
-
-        $between_time = [strtotime($date), strtotime($date) + 86400];
-
-        //读取当日新增数据
-        $recharge_power = DB::table('offline_recharge_record')
-            ->whereBetween('create_time', $between_time)
-            ->where('status', 1)
-            ->sum('power');
-
-        if($recharge_power < 1){
-            (new Output())->writeln("本次没有可用新增数据:" . $date);
-            return $log_id;
-        }
-
-        //团队长分红
-        //查找有团队长等级的会员
-        $community_user_list = DB::table('user')
-            ->field('id,market_level_id')
-            ->where('market_level_id', MembershipLevel::CommunityLeader)
-            ->select();
-
-        $community_rewards = (new ParametersModel())->getValue('communityRewards'); //社区长分红参数 数据格式为:0.02:0.5:0.5
-        $usdt_rate = (new ParametersModel())->getValue('usdtToPowerRate');
-        $community_rewards_arr = explode(':', $community_rewards);
-
-        $reward = $recharge_power * $community_rewards_arr[0] / count($community_user_list);//新增业绩 * 分红比例 / 人数
-        if($reward > 0) {
-            $reward_power = $reward * $community_rewards_arr[1];
-            $reward_usdt = $reward * $community_rewards_arr[2] / $usdt_rate;//算力折算成U
-
-            foreach ($community_user_list as $info) {
-                //发放分红
-                (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::POWER, $reward_power, Action::PowerBonusAward);
-
-                (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::USDT, $reward_usdt, Action::UsdtWeightDividend);
-            }
-        }else {
-            Log::info("社区长分红在" . $date . "分红金额为0;当日新增业绩:" . $recharge_power . ",分红比例:" . $community_rewards_arr[0] . ",分红人数" . count($community_user_list));
-        }
-
-        //领导人分红
-        //查找有团队长等级的会员
-        $sys_leader_user_list = DB::table('user')
-            ->field('id,market_level_id')
-            ->where('market_level_id', MembershipLevel::SystemLeader)
-            ->select();
-
-        $sys_leade_rewards = (new ParametersModel())->getValue('sysLeaderRewards'); //系统领导人分红参数 数据格式为:0.02:0.5:0.5
-        $sys_leade_rewards_arr = explode(':', $sys_leade_rewards);
-
-        $reward = $recharge_power * $sys_leade_rewards_arr[0] / count($sys_leader_user_list);//新增业绩 * 分红比例 / 人数
-        if($reward > 0) {
-            $reward_power = $reward * $sys_leade_rewards_arr[1];
-            $reward_usdt = $reward * $sys_leade_rewards_arr[2] * 8;//算力折算成U
-
-            foreach ($sys_leader_user_list as $info) {
-                //发放分红
-                (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::POWER, $reward_power, Action::PowerBonusAward);
+  
 
-                (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::USDT, $reward_usdt, Action::UsdtWeightDividend);
-            }
-        }else {
-            Log::info("系统领导人分红在" . $date . "分红金额为0;当日新增业绩:" . $recharge_power . ",分红比例:" . $community_rewards_arr[0] . ",分红人数" . count($community_user_list));
-        }
-        return $log_id;
-    }
+ 
 
 
     /**

+ 38 - 35
application/common/model/LedgerWalletModel.php

@@ -40,7 +40,8 @@ class LedgerWalletModel extends Model
     const Community         = 12; //社区津贴
     const Service           = 13; //服务津贴
     const Together          = 14; //共创津贴
-    const Freight           = 15; //物流运费 
+    const Freight           = 15; //物流运费
+    const Super             = 16; //茶宝标记激活 
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
@@ -63,6 +64,7 @@ class LedgerWalletModel extends Model
         self::Service           => '服务津贴',
         self::Together          => '共创津贴',
         self::Freight           => '物流运费',
+        self::Super             => '茶宝标记激活',
     ];
 
     public static function getWalletChaBao($userID)
@@ -96,7 +98,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::GiftPay => __('转账支出'),self::GiftReceipt => __('转账收款'), self::Community => __('社区津贴'), 
-        self::Service => __('服务津贴'), self::Together => __('共创津贴'), self::Freight => __('物流运费')];
+        self::Service => __('服务津贴'), self::Together => __('共创津贴'), self::Freight => __('物流运费'), self::Super => __('茶宝标记激活')];
     }
 
     /**
@@ -156,6 +158,39 @@ class LedgerWalletModel extends Model
         }
     }
  
+    /**
+     * 发放代数收益
+     * @param int $uid 服务器算力的用户ID
+     * @param string $usdt 报单金额
+     * @return void
+     * @throws Exception
+     */
+    public function sendUserSubFrozen(int $uid,  string $amount, int $action, string $icn)
+    {
+        $available = $this->getWallet($uid);
+        $ledgerWalletModel  = new LedgerWalletModel();
+        if (empty($available)) $ledgerWalletModel->insertGetId(['user_id' => $uid]);  // 创建钱包
+
+        $newAmount = $available->token;
+        // 创建账变记录
+        $insertRs = $ledgerWalletModel->update(['token' => bcsub($newAmount, $amount, 6), 'frozen' => bcadd($available->frozen, $amount, 6)]);
+
+        // 创建账变记录
+        $insertRs = $ledgerWalletModel->insert([
+            'user_id'        => $uid,
+            'from_id'        => 0,
+            'change_amount'  => $icn.$amount,
+            'present_amount' => $newAmount,
+            'create_time'    => time(),
+            'action'         => $action
+        ]);
+
+        if (empty($insertRs)) {
+            throw new Exception('创建账变记录失败');
+        }
+       
+
+    }
 
     /**
      * 仅更新钱包余额,没有账变
@@ -261,39 +296,7 @@ class LedgerWalletModel extends Model
         // 上级算力的账变
     }
 
-    /**
-     * 发放代数收益
-     * @param int $uid 服务器算力的用户ID
-     * @param string $usdt 报单金额
-     * @return void
-     * @throws Exception
-     */
-    public function sendGenerateProfit(int $uid, string $usdt)
-    {
-        //上上级ID
-        $parentID = (new UserPathModel())->getParentID($uid, 2);
-        if(empty($parentID)){
-            return;
-        }
-        // 查询代数收益比例
-        $directProfit = (new ParametersModel)->getValue('generateProfitRate');
-        $rateArr      = explode(',', $directProfit);
-        if (empty($rateArr) || count($rateArr) != 2) {
-            throw new Exception('获取代数收益比例失败');
-        }
-        $genRate2 = explode(':', $rateArr[0]); // 上上级人数和比例
-        $genRate3 = explode(':', $rateArr[1]); // 上上上级人数和比例
-
-        // 上上级的发放
-        $amount = bcmul($genRate2[1], $usdt, 6);
-        if ($amount > 0) {
-            $parent1 = (new UserModel())->getById($parentID);
-            if (!empty($parent1) && $parent1['direct_num'] >= $genRate2[0]) { // 有效直推人数达标
-                (new LedgerWalletModel())->changeWalletAccount($parentID, Asset::USDT, $amount, Action::UsdtGenerateProfit, $uid);
-            }
-        }
-
-    }
+ 
 
     /**
      * 发放见点奖

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

@@ -124,7 +124,8 @@ class ProductOrder extends Model
     public static function getUserWelfare($uid, $typeId){
         return self::where('user_id', $uid)
                 ->where('type_id', $typeId)
-                ->select();
+                ->order('create_time desc')
+                ->find();
     }
 
     public static function getStatusList()

+ 10 - 0
application/common/model/ProductPopular.php

@@ -3,6 +3,7 @@
 namespace app\common\model;
 
 use fast\Arr;
+use Google\Service\Dfareporting\ObaIcon;
 use think\Model;
 
 
@@ -85,6 +86,15 @@ class ProductPopular extends Model
         return $info;
     }
 
+    //获取当前抢购产品
+    public static function getPopularByTime(int $productId, string $lan, $tim): object
+    {   
+       return self::alias('a')->where('a.start_time', '<=', $tim)->where('a.end_time', '>=', $tim)
+        ->join('product_list b', "a.product_id = b.id", "left")
+        ->field('a.*,b.is_area,'.$lan.'_name as name')
+        ->where('a.product_id', $productId)->find();  
+    }
+
  
     //分类
     public function productsList()

+ 10 - 8
application/common/model/UserModel.php

@@ -25,6 +25,11 @@ class UserModel extends Model
 //        'url',
 //    ];.
 
+    //0未开始 1进行中 2已结束 Not started
+    const NOTSTOP        = 0;
+    const NORMAL         = 1;
+    const STOP           = 2;
+
     protected $name = 'user';
 
 
@@ -87,18 +92,15 @@ class UserModel extends Model
 
 
     /**
-     * 余额更新数据
+     * 添加用户上级标识
      * @param int $uid
-     * @param string $power
+     * @param string $parentId
      * @return void
      */
-    public static function updateForRBalance(int $uid, string $score, string $action)
+    public static function updateUserSuper(int $uid, int $parentId)
     {
-        if($action == '+'){
-            return self::where('id', $uid)->setInc('balance', $score);
-        }else{
-            return self::where('id', $uid)->setDec('balance', $score);
-        }
+        self::where('id', $uid)->update(['is_super'=>self::NORMAL]);
+        return self::where('id', $parentId)->setInc('direct_super', self::NORMAL);
     }
 
 

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

@@ -50,6 +50,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 13: '服务津贴',
                                 14: '共创津贴',
                                 15: '物流运费',
+                                16: '茶宝标记激活'
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]