= 10000) { $num = sprintf('%.1f', round($num / 10000 * 100) / 100) . '万'; } elseif ($num >= 1000) { $num = sprintf('%.1f', round($num / 1000 * 100) / 100) . '千'; } return $num; } /** * 根据日期获得这周的周一 * @param $date * @param int $d * @param string $format * @return false|string */ public static function firstOfWeek($date, $d = 0, $format = 'Ymd') { $now = strtotime($date) - $d * 86400; //当时的时间戳 $number = date("w", $now); //当时是周几 $number = $number == 0 ? 7 : $number; //如遇周末,将0换成7 $diff_day = $number - 1; //求到周一差几天 return date($format, $now - ($diff_day * 60 * 60 * 24)); } /** * 老原创的签名 * @param $time * @return string */ public static function getOldYcSign($time): string { $privateKey = env('EXTERNAL_PRIVATE_KEY'); return md5(md5($time . $privateKey) . $privateKey); } /** * @param array $data * @param array $colHeaders * @param bool $asString * @return bool|string */ public static function toCSV(array $data, array $colHeaders = array(), $asString = false) { $stream = $asString ? fopen('php://temp/maxmemory', 'wb+') : fopen('php://output', 'wb'); if (!empty($colHeaders)) { fputcsv($stream, $colHeaders); } foreach ($data as $record) { fputcsv($stream, $record); } if ($asString) { rewind($stream); $returnVal = stream_get_contents($stream); fclose($stream); return $returnVal; } fclose($stream); return true; } /** * 设备信息 * @return string */ public static function getDeviceType(): string { //全部变成小写字母 $agent = strtolower(getProp($_SERVER, 'HTTP_USER_AGENT')); $type = 'other'; //分别进行判断 if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) { $type = 'ios'; } if (strpos($agent, 'android')) { $type = 'android'; } return $type; } /** * 是否在微信内打卡 * @return bool */ public static function isOpenedInWechat(): bool { //全部变成小写字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); //判断 if (strpos($agent, 'micromessenger')) { return true; } return false; } /** * 组装meta数据 * @param $page * @param $total * @param int $pageSize * @return array */ public static function buildMeta($page, $total, $pageSize = 15): array { $lastPage = (int)ceil($total / $pageSize); return [ 'current_page' => (int)$page, 'next_page' => ++$page, 'last_page' => $lastPage ?? 1, 'per_page' => (int)$pageSize, 'total' => (int)$total, 'next_page_url' => '', 'prev_page_url' => '' ]; } /** * 获取token保存的信息 * @param $token * @return mixed */ public static function getTokenData($token) { $tokenJson = Redis::get($token); return json_decode($tokenJson, true); } /** * 获取口令码 * @param $uid * @param $bid * @return int|mixed|null */ public static function getPasswordCode($uid, $bid) { $code = DB::table('user_book_code')->where(['uid'=>$uid, 'bid'=>$bid])->value('id'); if (!$code) { $code = DB::table('user_book_code')->insertGetId([ 'uid' => $uid, 'bid' => $bid, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); } return '请在抖音搜索“火猫小说”后搜索口令'.$code.',开始阅读吧!'; } }