| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\api\logic;
- use app\api\controller\Product;
- use app\common\model\ProductArea;
- 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;
- use think\Db;
- use think\Log;
- use think\Exception;
- use think\console\Output;
- 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, $typeId)
- {
- $tim = time();
- $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);
- }
- return ['start_time'=>$tim, 'name'=>$result->name, 'num'=>$num];
- }
-
-
- /**
- * 获取当日收益 Daily earnings
- */
- private static function getDayEarnings(string $date)
- {
- $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');
- }
-
-
- /**
- * 获取可用日期
- * @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')
- ]);
- }
- }
- }
- }
|