This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 判断是否微信内访问. | |
Request::macro('isWechat', function (): bool { | |
if (app()->environment(['local', 'testing'])) { | |
return true; | |
} | |
/** @var Request $request */ | |
$request = $this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// abcde -> a*e | |
Str::macro('mask', function ($subject, $maxlength = 5, $mask_symbol = '*'): string { | |
$subject = mb_substr($subject, 0, $maxlength); | |
$length = mb_strlen($subject, 'utf-8'); | |
if ($length < 2) { | |
return $subject; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function bootSupportMacros(): self | |
{ | |
\Illuminate\Database\Query\Builder::macro('toRawSql', function (): string { | |
/** @var \Illuminate\Database\Query\Builder $builder */ | |
$builder = $this; | |
return array_reduce($builder->getBindings(), static function ($sql, $binding) { | |
return preg_replace('/\?/', is_numeric($binding) ? $binding : "'".$binding."'", $sql, 1); | |
}, $builder->toSql()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 男人袜十周年活动. | |
* 抽奖规则说明:11.25 收盘时的上证指数 × 深证成指 × 10000 = 12 位数(指数以活动页面公布链接数字为准); | |
* 将此 12 位数的数字倒序排列后,再除以本次活动结束时的参与人次(每个抽奖号为一个人次),得到的余数加 1 即为获奖号码。 | |
* | |
* @param float $sh 上证指盘收盘价 | |
* @param float $sz 深证成指收盘价 | |
* @param int $totalCount 参与人次(每个抽奖号为一个人次) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Zalas\Tests; | |
use PHPUnit\Framework\TestCase; | |
class ExampleTest extends TestCase | |
{ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
use Illuminate\Database\Eloquent\Model; | |
trait HasPivotTrait | |
{ | |
/** | |
* 检查多对多关系是否存在. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
use Illuminate\Support\Str; | |
trait HasUuid | |
{ | |
/** | |
* Get the route key for the model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function is_weixin() { | |
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) { | |
return true; | |
} | |
return false; | |
} |