|
|
@@ -32,91 +32,84 @@ class WelfareLoginc
|
|
|
* @param int $num 数量
|
|
|
* @param int $lan 语言
|
|
|
*/
|
|
|
- public static function setUserWelfareLos($uid, int $productId, $num, $lan, $typeId)
|
|
|
- {
|
|
|
- $tim = time();
|
|
|
+ public static function setUserWelfareLos($uid, int $productId, $num, $tim, $lan, $typeId)
|
|
|
+ {
|
|
|
$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, $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, $typeId);
|
|
|
- }
|
|
|
+ // if(empty($result->is_area)){
|
|
|
+ // ProductOrder::setPopularNoAreaOrder($num, $result->id, $result->price, $result->product_id, $uid, $typeId);
|
|
|
+ // }else{
|
|
|
+ // $areaArr = ProductArea::where('product_id', $productId)->where('status', ProductArea::NORMAL)->orderRaw('id desc')->limit($num)->column('id');
|
|
|
+ // ProductOrder::setPopularAreaOrder($areaArr, $result->id, $result->price, $result->product_id, $uid, $typeId);
|
|
|
+ // }
|
|
|
+ self::setUserProductOrder($num, $result->is_area, $result->id, $result->price, $productId, $uid, $typeId);
|
|
|
return ['start_time'=>$tim, 'name'=>$result->name, 'num'=>$num];
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取当日收益 Daily earnings
|
|
|
+ /*
|
|
|
+ 这个条件是
|
|
|
+ 向持有选定产品超过指定数量的用户空投指定数量/或比例/的指定产品,
|
|
|
+ 比如
|
|
|
+ 向持有A茶超过10套的用户,空投2套B茶
|
|
|
+ 或
|
|
|
+ 向持有A茶超过10套的用户,空投持有 数量X20%套B茶,数量取整
|
|
|
+ */
|
|
|
+ /** $mod 0指定数量 1比
|
|
|
+ * 获取用户Rwa数量
|
|
|
*/
|
|
|
- private static function getDayEarnings(string $date)
|
|
|
+ public static function getUserRwaNum(int $rwa_num, $mod, $num): int
|
|
|
{
|
|
|
- $between_time = [strtotime($date), strtotime($date) + 86400];
|
|
|
//读取当日新增数据
|
|
|
- return ProductOrder::where('type_id', ProductOrder::Popular)->where('status', ProductOrder::Paid)->whereBetween('create_time', $between_time)->sum('price');
|
|
|
+ $list = UserModel::where('rwa_num', '>=',$rwa_num)->column('id,rwa_num');
|
|
|
+ if(empty($list)) return 0;
|
|
|
+ $total = 0; //总数量
|
|
|
+ if($mod == 1 && $num > 0){
|
|
|
+ $num = bcdiv($num, 100, 2);
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $total += bcmul($item, $num);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $total = count($list) * $num;
|
|
|
+ }
|
|
|
+ return $total;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //空投Rwa发放
|
|
|
+ public static function setUserExRwaNum(int $rwa_num, $productId, $isArea, $orderId, $price, $mod, $num): int
|
|
|
+ {
|
|
|
+ //读取当日新增数据
|
|
|
+ //$list = UserModel::where('rwa_num', '>=',$rwa_num)->column('id,rwa_num');
|
|
|
+ $total = 0; //总数量
|
|
|
+ $div = bcdiv($num, 100, 2);
|
|
|
+ UserModel::where('rwa_num', '>=',$rwa_num)->chunk(100,function($users) use($mod,$div,$num,$isArea,$orderId,$price,$productId,&$total){
|
|
|
+ foreach($users as $user){
|
|
|
+ // 处理user模型对象
|
|
|
+ $num = ($mod == 1)? bcmul($user->rwa_num, $div) : $num;
|
|
|
+ if(!empty(self::setUserProductOrder($num, $isArea, $orderId, $price, $productId, $user->id, ProductOrder::Airdrop))){
|
|
|
+ // $user->rwa_num += $num;
|
|
|
+ // $total +=$user->save();
|
|
|
+ $user::updateForRwaNum($user->id, $user->parent_id, $num, '+');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return $total;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
|
|
- /**
|
|
|
- * 获取可用日期
|
|
|
- * @var array
|
|
|
- */
|
|
|
- protected function getExeDate($type_id = 1)
|
|
|
+ private static function setUserProductOrder(int $num, $isArea, $orderId, $price, $productId, $uid, $typeId)
|
|
|
{
|
|
|
- $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;
|
|
|
+ if(empty($isArea)){
|
|
|
+ $result = ProductOrder::setPopularNoAreaOrder($num, $orderId, $price, $productId, $uid, $typeId);
|
|
|
+ }else{
|
|
|
+ $areaArr = ProductArea::where('product_id', $productId)->where('status', ProductArea::NORMAL)->orderRaw('id desc')->limit($num)->column('id');
|
|
|
+ $result = ProductOrder::setPopularAreaOrder($areaArr, $orderId, $price, $productId, $uid, $typeId);
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 插入或更新收益统计信息
|
|
|
- * @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')
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|