'SMH拨币', 2 => 'Qubic拨币', ]; /** * 空投发放 */ public function setAirdropRewards() { //查找会员资产列表 $info_list = UserAirdrop::where('type_id', UserAirdrop::typeRwa)->where('status', UserAirdrop::NORMAL)->find(); if(empty($info_list)){ (new Output())->writeln("本次没有空投发放数据:"); return false; } $result = ProductPopular::getPopularByTime($info_list['product_id'], 'zh', $info_list->start_time); if(!$result || $info_list->total_num > $result->stock) { (new Output())->writeln("本次执行库存不足:"); return false; } WelfareLoginc::setUserExRwaNum( $info_list['rwa_num'], $info_list['product_id'], $result->is_area, $result->id, $result->price, $info_list['rwa_mod'], $info_list['num']); $info_list->status = UserAirdrop::STOP; $info_list->remark = '总发放'.$info_list->total_num.'套'; return $info_list->save(); } /** * 拨币 * 向会员发放qubic * 每一万算力每天收益14-15万个币 */ public function AllocateQubic() { $type_id = 2; $date = $this->getExeDate($type_id); if(empty($date)){ (new Output())->writeln("本次没有可用时间:" . $date); return ; } //创建定时任务执行日志 $log_id = (new TimedTaskLogModel())->insertGetId([ 'type_id' => $type_id, 'type_name' => $this->rewards_type[$type_id], 'date_time' => $date, 'create_time' => date('Y-m-d H:i:s'), ]); //查找会员资产列表 $info_list = DB::table('ledger_wallet') ->alias('w') ->join('user u','u.id = w.user_id') ->field('user_id,power') ->where('power', '>', 0) ->where('effective_time', '>', 0) //报单有收益 ->select(); if(empty($info_list)){ (new Output())->writeln("本次没有可用会员数据:" . $date); return $log_id; } $num =rand(120000,130000); $power_price = $num/10000;//每算力每日获得SMH的数量,算法为每一万算力每日产15万个Qubic foreach ($info_list as $info) { $amount = ($info['power']) * $power_price; $check = (new LedgerQubicChangeModel()) ->where('user_id', $info['user_id']) ->where('action', LedgerQubicChangeModel::SysSend) ->where('from_id', strtotime($date)) ->count(); if($check){ dump('用户ID:' . $info['user_id'] . '已拨过,拨币量为:' . $amount); }else{ dump(['用户ID:' . $info['user_id'],'拨币量为:' . $amount]); //发放 (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::QUBIC, $amount, LedgerQubicChangeModel::SysSend); } } return $log_id; } /** * 拨币 * 向会员发放qubic * 每一万算力每天收益14-15万个币 */ public function AllocateAleo() { $type_id = 11; $date = $this->getExeDate($type_id); if(empty($date)){ (new Output())->writeln("本次没有可用时间:" . $date); return ; } //创建定时任务执行日志 $log_id = (new TimedTaskLogModel())->insertGetId([ 'type_id' => $type_id, 'type_name' => $this->rewards_type[$type_id], 'date_time' => $date, 'create_time' => date('Y-m-d H:i:s'), ]); //查找会员资产列表 $info_list = DB::table('ledger_wallet') ->alias('w') ->join('user u','u.id = w.user_id') ->field('user_id,power') ->where('power', '>', 0) ->where('effective_time', '>', 0) //报单有收益 ->select(); if(empty($info_list)){ (new Output())->writeln("本次没有可用会员数据:" . $date); return $log_id; } $num = mt_rand(4030,4080) / 1000;//每一万算力每日获得Aleo的数量,算法为每一万算力每日产6.5个币,并从2024-9-20开始,每天递减5% // $date1 = '2024-9-26'; // $date2 = date('Y-m-d'); // $diff = strtotime($date2) - strtotime($date1); // // 将时间戳差转换为天数 // $days = floor($diff / (60 * 60 * 24)); // if($days > 0){ // //每日递减3% // $num = $num * pow((1-0.03), $days); // } // if($num < 4){ // $num = $num = mt_rand(3500,4500) / 1000;//每一万算力保底3个币 // } $power_price = $num/10000;//每算力每日获得Aleo的数量,算法为每一万算力每日产6.5个币,并从2024-9-20开始,每天递减5% foreach ($info_list as $info) { $amount = ($info['power']) * $power_price; $check = (new LedgerQubicChangeModel()) ->where('user_id', $info['user_id']) ->where('action', LedgerTokenChangeModel::SysSend) ->where('from_id', strtotime($date)) ->count(); if($check){ dump('用户ID:' . $info['user_id'] . '已拨过,拨币量为:' . $amount); }else{ dump(['用户ID:' . $info['user_id'],'拨币量为:' . $amount]); //发放 (new LedgerWalletModel)->changeWalletAccount($info['user_id'], Asset::TOKEN, $amount, LedgerTokenChangeModel::SysSend); } } 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; } }