4 Star 1 Fork 0

Gitee 极速下载/tipask

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/sdfsky/tipask
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
helpers.php 12.47 KB
一键复制 编辑 原始数据 按行查看 历史
songdengfeng 提交于 4年前 . fixed str_contains bug
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
<?php
/**
* Created by PhpStorm.
* User: sdf_sky
* Date: 15/10/27
* Time: 下午7:11
*/
if (!function_exists('trans_common_bool')) {
function trans_common_bool($value)
{
$map = [
0 => '否',
1 => '是',
];
if ($value === 'all') {
return $map;
}
if (isset($map[$value])) {
return $map[$value];
}
return '';
}
}
/*商品类型字段定义*/
if (!function_exists('trans_goods_post_type')) {
function trans_goods_post_type($post_type)
{
$map = [
0 => '不需要',
1 => '需要',
];
if ($post_type === 'all') {
return $map;
}
if (isset($map[$post_type])) {
return $map[$post_type];
}
return '';
}
}
if (!function_exists('trans_gender_name')) {
function trans_gender_name($post_type)
{
$map = [
0 => '保密',
1 => '男',
2 => '女',
];
if ($post_type === 'all') {
return $map;
}
if (isset($map[$post_type])) {
return $map[$post_type];
}
return '';
}
}
/*行家认证状态文字定义*/
if (!function_exists('trans_authentication_status')) {
function trans_authentication_status($status)
{
$map = [
0 => '待审核',
1 => '审核通过',
4 => '审核失败',
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*公告状态文字定义*/
if (!function_exists('trans_exchange_status')) {
function trans_exchange_status($status)
{
$map = [
0 => '未处理',
1 => '已处理',
4 => '兑换失败',
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*公告状态文字定义*/
if (!function_exists('trans_common_status')) {
function trans_common_status($status)
{
$map = [
0 => '待审核',
1 => '已审核',
-1 => '已禁言'
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*草稿类型定义*/
if (!function_exists('trans_draft_type')) {
function trans_draft_type($type)
{
$map = [
'question' => '提问',
'answer' => '回答',
'article' => '文章'
];
if ($type === 'all') {
return $map;
}
if (isset($map[$type])) {
return $map[$type];
}
return '';
}
}
/*举报状态定义*/
if (!function_exists('trans_report_status')) {
function trans_report_status($status)
{
$map = [
0 => '待处理',
1 => '已处理',
4 => '已忽略'
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*举报原因类型定义*/
if (!function_exists('trans_report_type')) {
function trans_report_type($type)
{
// 读取定义的配置信息
$map = config('tipask.report_type');
if ($type === 'all') {
return $map;
}
if (isset($map[$type])) {
return $map[$type]['subject'];
}
return '';
}
}
/*公告状态文字定义*/
if (!function_exists('trans_pay_status')) {
function trans_pay_status($status)
{
$map = [
0 => '待支付',
1 => '已支付',
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*问题状态文本描述定义*/
if (!function_exists('trans_question_status')) {
function trans_question_status($status)
{
$map = [
-1 => '待支付',
0 => '待审核',
1 => '待解决',
2 => '已解决',
];
if ($status === 'all') {
return $map;
}
if (isset($map[$status])) {
return $map[$status];
}
return '';
}
}
/*问题状态文本描述定义*/
if (!function_exists('trans_day_of_week')) {
function trans_day_of_week($day)
{
$map = [
0 => '星期天',
1 => '星期一',
2 => '星期二',
3 => '星期三',
4 => '星期四',
5 => '星期五',
6 => '星期六',
];
if ($day === 'all') {
return $map;
}
if (isset($map[$day])) {
return $map[$day];
}
return '';
}
}
if (!function_exists('trans_question_price')) {
function trans_question_price($price = 'all')
{
$map = [0, 5, 10, 15, 20, 30, 50, 80, 100];
return $map;
}
}
/*数据库setting表操作*/
if (!function_exists('Setting')) {
function Setting()
{
return app('App\Models\Setting');
}
}
/*数据库Category表操作*/
if (!function_exists('load_categories')) {
function load_categories($type = 'all')
{
return app('App\Models\Category')->loadFromCache($type);
}
}
/*数据库Category表操作*/
if (!function_exists('make_option_tree')) {
function make_option_tree($type = 'all', $select_id = 0)
{
$categories = app('App\Models\Category')->loadFromCache($type);
return app('App\Models\Category')->makeOptionTree($categories, $select_id);
}
}
/*生成分类Tab下拉数据格式*/
if (!function_exists('get_category_tab_data')) {
function get_category_tab_data($type = 'all', $size = 6)
{
$categories = app('App\Models\Category')->loadFromCache($type);
$rootCategories = [];
foreach ($categories as $category) {
if ($category->parent_id == 0) {
$rootCategories[] = $category;
}
}
$tabData['out_tabs'] = array_slice($rootCategories,0,$size);
$tabData['in_tabs'] = array_slice($rootCategories,$size);
return $tabData;
}
}
/*数据库area地区表操作*/
if (!function_exists('Area')) {
function Area()
{
return app('App\Models\Area');
}
}
/**
* 将正整数转换为带+,例如 10 装换为 +10
* 用户积分显示
*/
if (!function_exists('integer_string')) {
function integer_string($value)
{
if ($value >= 0) {
return '+' . $value;
}
return $value;
}
}
if (!function_exists('get_credit_message')) {
function get_credit_message($credits, $coins)
{
$messages = [];
if ($credits != 0) {
$messages[] = '经验 ' . integer_string($credits);
}
if ($coins != 0) {
$messages[] = '金币 ' . integer_string($coins);
}
return implode(",", $messages);
}
}
if (!function_exists('timestamp_format')) {
function timestamp_format($timestamp, $showDateTime = true)
{
$carbon = \Carbon\Carbon::instance(new DateTime($timestamp));
$time_format_string = Setting()->get('date_format');
if ($showDateTime) {
$time_format_string .= ' ' . Setting()->get('time_format');
}
if (Setting()->get('time_friendly') == 1) {
return $carbon->diffInWeeks(\Carbon\Carbon::now()) >= 1 ? $carbon->format($time_format_string) : $carbon->diffForHumans();
}
return $carbon->format($time_format_string);
}
}
if (!function_exists('parse_seo_template')) {
function parse_seo_template($type, $source)
{
$seo_template = Setting()->get($type);
$seo_template = str_replace("{wzmc}", Setting()->get('website_name'), $seo_template);
$seo_template = str_replace("{wzkh}", Setting()->get('website_slogan'), $seo_template);
if (in_array($type, ['question', 'article'])) {
if ($source->tags) {
$tagList = array_pluck($source->tags->toArray(), 'name');
$seo_template = str_replace("{htlb}", implode(",", $tagList), $seo_template);
}
}
if (str_contains($type, 'question')) {
$seo_template = str_replace("{wtbt}", strip_tags($source->title), $seo_template);
$seo_template = str_replace("{wtms}", str_limit(strip_tags($source->description), 200), $seo_template);
} else {
if (str_contains($type, 'article')) {
$seo_template = str_replace("{wzbt}", strip_tags($source->title), $seo_template);
$seo_template = str_replace("{wzzy}", str_limit($source->summary, 200), $seo_template);
} else {
if (str_contains($type, 'topic')) {
$seo_template = str_replace("{htmc}", $source->name, $seo_template);
$seo_template = str_replace("{htjj}", str_limit($source->summary, 200), $seo_template);
}
}
}
return $seo_template;
}
}
/*生成头像图片地址*/
if (!function_exists('get_user_avatar')) {
function get_user_avatar($user_id, $size = 'middle', $extension = 'jpg', $random = '')
{
$avatarName = $user_id . '_' . $size . '.' . $extension;
if ($random) {
$avatarName .= '?' . str_random(8);
}
return route('website.image.avatar', ['avatar_name' => $avatarName]);
}
}
/*常见的正则判断*/
/*邮箱判断*/
if (!function_exists('is_email')) {
function is_email($email)
{
$reg = "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
if (preg_match($reg, $email)) {
return true;
}
return false;
}
}
/*手机号码判断*/
if (!function_exists('is_mobile')) {
function is_mobile($mobile)
{
$reg = "/^1[3456789]\d{9}$/";
if (!preg_match($reg, $mobile)) {
return false;
}
return true;
}
}
/*创建唯一订单号*/
if (!function_exists('build_order_no')) {
function build_order_no($user_id = 0)
{
$order_no = date('Ymd') . substr(implode(null, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
$salt = md5($user_id);
$star = strtoupper(substr($salt, 1, 5));
return $order_no . $star;
}
}
/*创建唯一订单号*/
if (!function_exists('random_number')) {
function random_number($length = 6)
{
$pool = '0123456789';
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
}
/*金币转换元*/
if (!function_exists('coins_to_cent')) {
function coins_to_cent($coins)
{
/*获取1元能够吗多少个金币*/
$charge_rage = config('pay.charge_rate');
if ($charge_rage > 0 && $coins > 0) {
$rate = ceil(100 / $charge_rage); //计算单个金币的价格
$result = $coins * $rate;
return $result;
}
return 0;
}
}
if (!function_exists('yuan_to_coins')) {
function yuan_to_coins($yuan)
{
$charge_rage = config('pay.charge_rate');
if ($charge_rage > 0 && $yuan > 0) {
$result = $yuan * $charge_rage;
return $result;
}
return false;
}
}
/*分转元*/
if (!function_exists('cent_to_yuan')) {
function cent_to_yuan($cent)
{
return '¥' . number_format($cent / 100, 2);
}
}
if (!function_exists('format_money')) {
function format_money($money)
{
return number_format($money / 100, 2);
}
}
/*提取html内容中的img标签图片地址*/
if (!function_exists('get_editor_images')) {
function get_editor_images($content)
{
preg_match_all('/<img[^>]+>/i', $content, $imgTags);
$imageUrls = [];
for ($i = 0; $i < count($imgTags[0]); $i++) {
preg_match('/src="([^"]+)/i', $imgTags[0][$i], $imgage);
$imageUrls[] = str_ireplace('src="', '', $imgage[0]);
}
return $imageUrls;
}
}
if (!function_exists('env_cert')) {
function env_cert($env_param)
{
$cert_string = '';
if (file_exists(env($env_param, ''))) {
$cert_string = file_get_contents(env($env_param));
}
return $cert_string;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/mirrors/tipask.git
git@gitee.com:mirrors/tipask.git
mirrors
tipask
tipask
master

搜索帮助