1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TopFee.php |
4
|
|
|
* |
5
|
|
|
* Part of Overtrue\Wechat. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author a939638621 <[email protected]> |
11
|
|
|
* @copyright 2015 a939638621 <[email protected]> |
12
|
|
|
* @link https://github.com/a939638621 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Overtrue\Wechat\Shop\Data; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use Overtrue\Wechat\Utils\MagicAttributes; |
19
|
|
|
use Overtrue\Wechat\Shop\Foundation\ShopsException; |
20
|
|
|
use Overtrue\Wechat\Shop\Postage; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class TopFee |
24
|
|
|
* @package Shop\Data |
25
|
|
|
* @property $custom |
26
|
|
|
* @property $normal |
27
|
|
|
* @property $topFee |
28
|
|
|
*/ |
29
|
|
|
class TopFee extends MagicAttributes |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* 设置TopFee |
34
|
|
|
* |
35
|
|
|
* @param string $type |
36
|
|
|
* @return $this |
37
|
|
|
* @throws ShopsException |
38
|
|
|
*/ |
39
|
|
|
public function setTopFee($type = Postage::KUAI_DI) |
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
if (!isset($this->normal) && !isset($this->custom)) throw new ShopsException('normal 和 custom 必须设置'); |
43
|
|
|
if (!isset($this->normal) || !isset($this->custom)) throw new ShopsException('normal 和 custom 必须全部设置'); |
44
|
|
|
$keys = array_keys($this->custom); |
|
|
|
|
45
|
|
|
|
46
|
|
|
foreach ($keys as $v) { |
47
|
|
|
if (!is_numeric($v)) throw new ShopsException('数据不合法'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->attributes['topFee'][] = array( |
51
|
|
|
'Type' => $type, |
52
|
|
|
'Normal' => $this->normal, |
|
|
|
|
53
|
|
|
'Custom' => $this->custom |
|
|
|
|
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* 设置 Normal |
61
|
|
|
* |
62
|
|
|
* @param $startStandards |
63
|
|
|
* @param $startFees |
64
|
|
|
* @param $addStandards |
65
|
|
|
* @param $addFees |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function setNormal($startStandards, $startFees, $addStandards, $addFees) |
69
|
|
|
{ |
70
|
|
|
$this->normal = array( |
|
|
|
|
71
|
|
|
'StartStandards' => $startStandards, |
72
|
|
|
'StartFees' => $startFees, |
73
|
|
|
'AddStandards' => $addStandards, |
74
|
|
|
'AddFees' => $addFees |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* 设置Custom |
82
|
|
|
* |
83
|
|
|
* @param $startStandards |
84
|
|
|
* @param $startFees |
85
|
|
|
* @param $addStandards |
86
|
|
|
* @param $addFees |
87
|
|
|
* @param $destProvince |
88
|
|
|
* @param null $destCity |
89
|
|
|
* @param string $destCountry |
90
|
|
|
* @return $this |
91
|
|
|
* @throws ShopsException |
92
|
|
|
*/ |
93
|
|
|
public function setCustom( |
94
|
|
|
$startStandards, $startFees, $addStandards, $addFees, |
95
|
|
|
$destProvince, $destCity = null,$destCountry = '中国' |
96
|
|
|
) |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
if (empty($destProvince)) throw new ShopsException('$destProvince不允许为空'); |
100
|
|
|
|
101
|
|
|
$this->custom = array(); |
|
|
|
|
102
|
|
|
|
103
|
|
|
//todo 未做反选,排除一个城市,选择其他 |
104
|
|
|
|
105
|
|
|
if (empty($destCity)) { |
106
|
|
|
|
107
|
|
|
//todo $destProvince的判断 |
108
|
|
|
//todo 加入 全国省直辖市的 简称等 |
109
|
|
|
//todo 加入 某些不平等条约的存在 例如 江浙沪 ,你们懂得!! |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
$destProvince = is_string($destProvince) ? array($destProvince) : $destProvince; |
114
|
|
|
|
115
|
|
|
$regional = new Regional(); |
116
|
|
|
|
117
|
|
|
foreach ($destProvince as $province) { |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
$citys = $regional->getCity($province); |
121
|
|
|
|
122
|
|
|
if (empty($citys)) throw new ShopsException('请传入合法的省份名!!!'); |
123
|
|
|
|
124
|
|
View Code Duplication |
foreach ($citys[0] as $city) { |
|
|
|
|
125
|
|
|
$this->attributes['custom'][] = array( |
126
|
|
|
'StartStandards' => $startStandards, |
127
|
|
|
'StartFees' => $startFees, |
128
|
|
|
'AddStandards' => $addStandards, |
129
|
|
|
'AddFees' => $addFees, |
130
|
|
|
'DestCountry' => $destCountry, |
131
|
|
|
'DestProvince' => $province, |
132
|
|
|
'DestCity' => $city |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return $this; |
139
|
|
|
|
140
|
|
|
} else { |
141
|
|
|
|
142
|
|
|
//todo 未做省份的检测 |
143
|
|
|
//todo 未做市检测 |
144
|
|
|
|
145
|
|
|
$destCity = is_string($destCity) ? array($destCity) : $destCity; |
146
|
|
|
|
147
|
|
|
if (is_array($destCity)) { |
148
|
|
View Code Duplication |
foreach ($destCity as $city) { |
|
|
|
|
149
|
|
|
|
150
|
|
|
$this->attributes['custom'][] = array( |
151
|
|
|
'StartStandards' => $startStandards, |
152
|
|
|
'StartFees' => $startFees, |
153
|
|
|
'AddStandards' => $addStandards, |
154
|
|
|
'AddFees' => $addFees, |
155
|
|
|
'DestCountry' => $destCountry, |
156
|
|
|
'DestProvince' => $destProvince, |
157
|
|
|
'DestCity' => $city |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function __get($property) |
170
|
|
|
{ |
171
|
|
|
return parent::__get($property); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function __isset($property) |
175
|
|
|
{ |
176
|
|
|
return isset($this->attributes[$this->snake($property)]); |
177
|
|
|
} |
178
|
|
|
} |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.