limit(12000)->get(); foreach ($users as $userItem) { $uid = $userItem->uid; $created_at = $userItem->created_at; $created_at_timestamp = strtotime($created_at); $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400)]; $recharge_amount_in_24h = OrderService::getAmount($params); $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 3)]; $recharge_amount_in_72h = OrderService::getAmount($params); $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 7)]; $recharge_amount_in_7d = OrderService::getAmount($params); $params = ['uid' => $uid, 'begin_time' => $created_at, 'end_time' => date('Y-m-d H:i:s', $created_at_timestamp + 86400 * 30)]; $recharge_amount_in_30d = OrderService::getAmount($params); $params = ['uid' => $uid]; $recharge_amount = OrderService::getAmount($params); $template_type = $userItem->template_type; $data = ['uid' => $uid, 'book_id' => $book_id, 'book_name' => $book_name, 'template_tye' => $template_type, 'distribution_channel_id' => $distribution_channel_id, 'recharge_amount_in_24h' => $recharge_amount_in_24h, 'recharge_amount_in_72h' => $recharge_amount_in_72h, 'recharge_amount_in_7d' => $recharge_amount_in_7d, 'recharge_amount_in_30d' => $recharge_amount_in_30d, 'recharge_amount' => $recharge_amount, 'created_at' => $created_at]; DB::table('charge_template_stat')->insert($data); } DB::update("UPDATE charge_template_stat a join users b on a.uid=b.id set a.distribution_channel_id=b.distribution_channel_id"); } }