Order.php
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
use HasDateTimeFormatter;
protected $table = 'order';
/** 未支付*/
const UNPAID = 100;
/** 用户取消*/
const USER_CANCEL = 101;
/** 超时取消*/
const TIMEOUT_CANCEL = 102;
/** 商户取消*/
const MERCHANT_CANCEL = 103;
/** 已支付*/ // 回调
const PAID = 201;
/** 已完成*/ // 回调并且业务逻辑(加天数、加销量)执行完毕
const DONE = 204;
/** 订单超时时间 30分钟 */
const TIMEOUT = 1800;
public function order_goods()
{
return $this->hasOne('App\Models\OrderGood','order_sn','order_sn');
}
/**
* 获取SN唯一编号
* @param string $prefix
* @return string
*/
static public function get_sn($prefix = '')
{
$chars = md5(uniqid(mt_rand(), true));
$len = strlen($prefix);
if ($len > 5) $prefix = substr($prefix, 0, 5);
$uuid = $prefix . dechex(date('m')) . date('d') . substr(time(), -5 + $len) . '-'
. substr(microtime(), 2, 4) . '-'
. substr($chars, 12, 4) . '-'
. substr($chars, 16, 4) . '-'
. substr($chars, 20, 12);
return strtoupper($uuid);
}
}