1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace graychen\yii2\jd\deposit\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\base\Model; |
7
|
|
|
use yii\behaviors\TimestampBehavior; |
8
|
|
|
use yii\web\ConflictHttpException; |
9
|
|
|
|
10
|
|
|
/**京东充值 |
11
|
|
|
* Class OrderDeposit |
12
|
|
|
*/ |
13
|
|
|
class OrderDeposit extends Model |
14
|
|
|
{ |
15
|
|
|
public $orderId;//京东订单号 |
16
|
|
|
public $buyNum;//购买数量 |
17
|
|
|
public $skuId; //对应京东的商品 skuId |
18
|
|
|
public $brandId; //对应京东游戏品牌 ID |
19
|
|
|
public $userIp; //用户 ip 地址 |
20
|
|
|
public $totalPrice; //订单总价 |
21
|
|
|
public $gameAccount; //游戏账号 |
22
|
|
|
public $permit; //通行证 |
23
|
|
|
public $raw; |
24
|
|
|
public $equipment; |
25
|
|
|
public $serverinfo; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
|
|
public static function tableName() |
31
|
|
|
{ |
32
|
|
|
return '{{%order}}'; |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
1 |
|
[['orderId', 'buyNum', 'skuId', 'brandId', 'userIp', 'totalPrice', 'gameAccount'], 'required'], |
39
|
|
|
[['orderId', 'brandId', 'skuId'], 'integer'], |
40
|
|
|
[['orderId', 'skuId'], 'match', 'pattern' => '/^\d{11,}$/'], |
41
|
|
|
['buyNum', 'integer', 'min' => 1, 'max' => 200], |
42
|
|
|
['userIp', 'ip'], |
43
|
|
|
['totalPrice', 'double'], |
44
|
|
|
[['gameAccount', 'equipment', 'serverinfo', 'permit'], 'string'], |
45
|
|
|
['raw', 'safe'], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
1 |
|
public function behaviors() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
'timestamp' => [ |
56
|
1 |
|
'class' => TimestampBehavior::className(), |
|
|
|
|
57
|
|
|
], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function save() |
62
|
|
|
{ |
63
|
1 |
|
if (Order::find()->where(['sn' => Order::SOURCE_JD . $this->orderId])->exists()) { |
64
|
|
|
throw new ConflictHttpException('订单号已存在'); |
65
|
|
|
} |
66
|
|
|
/* @var $order Order */ |
67
|
1 |
|
$order = new Order(); |
68
|
1 |
|
$order->sn = Order::SOURCE_JD . $this->orderId; |
|
|
|
|
69
|
1 |
|
$order->name = Order::skuidList()[$this->skuId]['name'] ?? '京东订单'; |
|
|
|
|
70
|
1 |
|
$order->count = $this->buyNum; |
|
|
|
|
71
|
1 |
|
$order->final_price = $this->totalPrice; |
|
|
|
|
72
|
1 |
|
$order->account = $this->gameAccount; |
|
|
|
|
73
|
1 |
|
$order->remark = $this->raw; |
|
|
|
|
74
|
1 |
|
$order->game_id = Order::skuidList()[$this->skuId]['game_id'] ?? 1; |
|
|
|
|
75
|
1 |
|
$order->hours = 1; |
|
|
|
|
76
|
1 |
|
$order->type = Order::skuidList()[$this->skuId]['type'] ?? Order::TYPE_PEIWAN_PUTONG; |
|
|
|
|
77
|
1 |
|
$order->start_time = date('Y-m-d H:i'); |
|
|
|
|
78
|
1 |
|
$order->end_time = date('Y-m-d H:i', strtotime($order->start_time) + 3600); |
|
|
|
|
79
|
1 |
|
$order->equipment = $this->equipment; |
|
|
|
|
80
|
1 |
|
$order->serverinfo = $this->serverinfo; |
|
|
|
|
81
|
1 |
|
$order->user_id = 1; |
|
|
|
|
82
|
1 |
|
$order->status = Order::STATUS_PAID; |
|
|
|
|
83
|
1 |
|
$order->source = $order::SOURCE_JD; |
84
|
1 |
|
$order->payment_method = Order::PAYMENT_METHOD_JD; |
|
|
|
|
85
|
1 |
|
return $order->save(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.