88 lines
2.1 KiB
PHP
88 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
|
|
class Cdkey extends Model
|
|
{
|
|
|
|
protected $dates = [
|
|
'effective_at',
|
|
'used_at',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class)->withDefault();
|
|
}
|
|
|
|
public function belong()
|
|
{
|
|
return $this->belongsTo(User::class, 'belong_uid')->withDefault();
|
|
}
|
|
|
|
public function getStatusTextAttribute()
|
|
{
|
|
if ($this->used_at == '') {
|
|
return '<span style="color:blue">未使用</span>';
|
|
} elseif ($this->used_at) {
|
|
return '<span style="color:green">已使用</span>';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
public function getIsPrintTextAttribute()
|
|
{
|
|
switch ($this->is_print) {
|
|
case 0:
|
|
return '<span style="color:blue">否</span>';
|
|
break;
|
|
case 1:
|
|
return '<span style="color:green">是</span>';
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function generateCard($number)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 支付完成之后,直接生产虚拟卡
|
|
* @Author:<C.Jason>
|
|
* @Date:2018-12-23T17:47:51+0800
|
|
* @return function [description]
|
|
*/
|
|
public function callback()
|
|
{
|
|
$codes = [];
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$codes[$i]['belong_uid'] = Auth::id();
|
|
$codes[$i]['code'] = $this->random();
|
|
$codes[$i]['is_print'] = 0;
|
|
$codes[$i]['effective_at'] = now();
|
|
$codes[$i]['created_at'] = now();
|
|
$codes[$i]['updated_at'] = now();
|
|
}
|
|
Cdkey::insert($codes);
|
|
}
|
|
|
|
/**
|
|
* 产生随机字串,可用来自动生成密码 17010
|
|
* @Author:<C.Jason>
|
|
* @Date:2018-09-14T17:00:34+0800
|
|
* @param integer $len [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function random($len = 10): string
|
|
{
|
|
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
|
|
$chars = str_repeat($chars, 4);
|
|
$chars = str_shuffle($chars);
|
|
$str = substr($chars, 0, $len);
|
|
return $str;
|
|
}
|
|
}
|