RechargeOrder.php
2.0 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace app\mobile\model;
use think\Model;
use think\Db;
class RechargeOrder extends Model
{
// 表名
protected $name = 'mobile_recharge_order';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 错误提示
public $error = '';
// 状态码
public $code = 0;
/**
* 下单预览
*/
public function payView($data)
{
if(empty($data['recharge_id'])){
$this->setError('缺少必要参数');
return false;
}
$info = Recharge::get($data['recharge_id']);
if(empty($info)){
$this->setError('充值产品信息不存在');
return false;
}
return [
'recharge_id' => $data['recharge_id'],
'pay_price' => $info['price'],
'money' => $info['price']
];
}
/**
* 新增订单
*/
public function add($user, $order, $pay_type)
{
$this->save([
'user_id' => $user['id'],
'recharge_id' => $order['recharge_id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'money' => $order['money']
]);
return true;
}
/**
* 设置错误信息
* @param $error
*/
private function setError($error,$code=0)
{
empty($this->error) && $this->error = $error;
$this->code = $code;
}
/**
* 是否存在错误
* @return bool
*/
private function hasError()
{
return !empty($this->error);
}
/**
* 获取错误信息
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* 获取状态码
* @return string
*/
public function getCode()
{
return $this->code;
}
}