belongsTo(User::class)->withDefault(); } public function belong() { return $this->belongsTo(User::class, 'belong_uid')->withDefault(); } public function getStatusTextAttribute() { if ($this->used_at == '') { return '未使用'; } elseif ($this->used_at) { return '已使用'; } return ''; } public function getIsPrintTextAttribute() { switch ($this->is_print) { case 0: return ''; break; case 1: return ''; break; } } public function generateCard($number) { } /** * 支付完成之后,直接生产虚拟卡 * @Author: * @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: * @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; } }