Showing
57 changed files
with
4766 additions
and
0 deletions
Too many changes to show.
To preserve performance only 57 of 2142 files are displayed.
README.md
0 → 100644
1 | +#Suishengwan admin project | |
2 | + | |
3 | +#### Init steps | |
4 | +1. clone project | |
5 | +``` | |
6 | +git clone git@139.224.35.235:binqi.yuan/suishenwan_admin.git | |
7 | +``` | |
8 | + | |
9 | +2. Go to project directory, rename .env.example to .env | |
10 | +``` | |
11 | +mv .env.example .env | |
12 | +``` | |
13 | + | |
14 | +3. run `composer update` | |
15 | + | |
16 | +4. modify .env file to change db connections | |
17 | +``` | |
18 | +DB_CONNECTION=mysql | |
19 | +DB_HOST=127.0.0.1 | |
20 | +DB_PORT=3306 | |
21 | +DB_DATABASE=suishenwan | |
22 | +DB_USERNAME=root | |
23 | +DB_PASSWORD=123123 | |
24 | +``` | |
25 | + | |
26 | +5. run migration to create the database tables | |
27 | +``` | |
28 | +php artisan migrate --seed | |
29 | +``` | |
30 | + | |
31 | +6. use git subtree to use shared components | |
32 | +``` | |
33 | +//init remote | |
34 | +git remote add modules git@139.224.35.235:binqi.yuan/suishenwan_module.git | |
35 | +git remote add common git@139.224.35.235:binqi.yuan/suishenwan_common.git | |
36 | +git remote add db git@139.224.35.235:binqi.yuan/suishenwan_database.git | |
37 | +//subtree add modules | |
38 | +git subtree add --prefix=app/Modules modules master --squash | |
39 | +git subtree add --prefix=app/Common common master --squash | |
40 | +git subtree add --prefix=database db master --squash | |
41 | +``` | |
42 | + | |
43 | +7. use your own branch to start develop | |
\ No newline at end of file | ... | ... |
app/Access/Model/Permission/Permission.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Permission; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | +use App\Access\Model\Permission\Traits\Relationship\PermissionRelationship; | |
7 | + | |
8 | +/** | |
9 | + * Class Permission. | |
10 | + */ | |
11 | +class Permission extends Model | |
12 | +{ | |
13 | + use PermissionRelationship; | |
14 | + | |
15 | + /** | |
16 | + * The database table used by the model. | |
17 | + * | |
18 | + * @var string | |
19 | + */ | |
20 | + protected $table; | |
21 | + | |
22 | + /** | |
23 | + * The attributes that are mass assignable. | |
24 | + * | |
25 | + * @var array | |
26 | + */ | |
27 | + protected $fillable = ['name', 'display_name', 'sort']; | |
28 | + | |
29 | + /** | |
30 | + * @param array $attributes | |
31 | + */ | |
32 | + public function __construct(array $attributes = []) | |
33 | + { | |
34 | + parent::__construct($attributes); | |
35 | + $this->table = config('access.permissions_table'); | |
36 | + } | |
37 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Permission\Traits\Relationship; | |
4 | + | |
5 | +/** | |
6 | + * Class PermissionRelationship. | |
7 | + */ | |
8 | +trait PermissionRelationship | |
9 | +{ | |
10 | + /** | |
11 | + * @return mixed | |
12 | + */ | |
13 | + public function roles() | |
14 | + { | |
15 | + return $this->belongsToMany(config('access.role'), config('access.permission_role_table'), 'permission_id', 'role_id'); | |
16 | + } | |
17 | +} | ... | ... |
app/Access/Model/Role/Role.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Role; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | +use App\Access\Model\Role\Traits\RoleAccess; | |
7 | +use App\Access\Model\Role\Traits\Scope\RoleScope; | |
8 | +use App\Access\Model\Role\Traits\Attribute\RoleAttribute; | |
9 | +use App\Access\Model\Role\Traits\Relationship\RoleRelationship; | |
10 | + | |
11 | +/** | |
12 | + * Class Role. | |
13 | + */ | |
14 | +class Role extends Model | |
15 | +{ | |
16 | + use RoleScope, | |
17 | + RoleAccess, | |
18 | + RoleAttribute, | |
19 | + RoleRelationship; | |
20 | + | |
21 | + /** | |
22 | + * The database table used by the model. | |
23 | + * | |
24 | + * @var string | |
25 | + */ | |
26 | + protected $table; | |
27 | + | |
28 | + /** | |
29 | + * The attributes that are mass assignable. | |
30 | + * | |
31 | + * @var array | |
32 | + */ | |
33 | + protected $fillable = ['name', 'all', 'sort']; | |
34 | + | |
35 | + /** | |
36 | + * @param array $attributes | |
37 | + */ | |
38 | + public function __construct(array $attributes = []) | |
39 | + { | |
40 | + parent::__construct($attributes); | |
41 | + $this->table = config('access.roles_table'); | |
42 | + } | |
43 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Role\Traits\Attribute; | |
4 | + | |
5 | +/** | |
6 | + * Class RoleAttribute. | |
7 | + */ | |
8 | +trait RoleAttribute | |
9 | +{ | |
10 | + /** | |
11 | + * @return string | |
12 | + */ | |
13 | + public function getEditButtonAttribute() | |
14 | + { | |
15 | + return '<a href="'.route('admin.access.role.edit', $this, false).'" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'"></i></a> '; | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * @return string | |
20 | + */ | |
21 | + public function getDeleteButtonAttribute() | |
22 | + { | |
23 | + //Can't delete master admin role | |
24 | + if ($this->id != 1) { | |
25 | + return '<a href="'.route('admin.access.role.destroy', $this, false).'" | |
26 | + data-method="delete" | |
27 | + data-trans-button-cancel="'.trans('buttons.general.cancel').'" | |
28 | + data-trans-button-confirm="'.trans('buttons.general.crud.delete').'" | |
29 | + data-trans-title="'.trans('strings.backend.general.are_you_sure').'" | |
30 | + class="btn btn-xs btn-danger"><i class="fa fa-times" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.delete').'"></i></a>'; | |
31 | + } | |
32 | + | |
33 | + return ''; | |
34 | + } | |
35 | + | |
36 | + /** | |
37 | + * @return string | |
38 | + */ | |
39 | + public function getActionButtonsAttribute() | |
40 | + { | |
41 | + return $this->edit_button.$this->delete_button; | |
42 | + } | |
43 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Role\Traits\Relationship; | |
4 | + | |
5 | +/** | |
6 | + * Class RoleRelationship. | |
7 | + */ | |
8 | +trait RoleRelationship | |
9 | +{ | |
10 | + /** | |
11 | + * @return mixed | |
12 | + */ | |
13 | + public function users() | |
14 | + { | |
15 | + return $this->belongsToMany(config('auth.providers.users.model'), config('access.role_user_table'), 'role_id', 'user_id'); | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * @return mixed | |
20 | + */ | |
21 | + public function permissions() | |
22 | + { | |
23 | + return $this->belongsToMany(config('access.permission'), config('access.permission_role_table'), 'role_id', 'permission_id') | |
24 | + ->orderBy('display_name', 'asc'); | |
25 | + } | |
26 | +} | ... | ... |
app/Access/Model/Role/Traits/RoleAccess.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Role\Traits; | |
4 | + | |
5 | +/** | |
6 | + * Class RoleAccess. | |
7 | + */ | |
8 | +trait RoleAccess | |
9 | +{ | |
10 | + /** | |
11 | + * Save the inputted permissions. | |
12 | + * | |
13 | + * @param mixed $inputPermissions | |
14 | + * | |
15 | + * @return void | |
16 | + */ | |
17 | + public function savePermissions($inputPermissions) | |
18 | + { | |
19 | + if (! empty($inputPermissions)) { | |
20 | + $this->permissions()->sync($inputPermissions); | |
21 | + } else { | |
22 | + $this->permissions()->detach(); | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * Attach permission to current role. | |
28 | + * | |
29 | + * @param object|array $permission | |
30 | + * | |
31 | + * @return void | |
32 | + */ | |
33 | + public function attachPermission($permission) | |
34 | + { | |
35 | + if (is_object($permission)) { | |
36 | + $permission = $permission->getKey(); | |
37 | + } | |
38 | + | |
39 | + if (is_array($permission)) { | |
40 | + $permission = $permission['id']; | |
41 | + } | |
42 | + | |
43 | + $this->permissions()->attach($permission); | |
44 | + } | |
45 | + | |
46 | + /** | |
47 | + * Detach permission form current role. | |
48 | + * | |
49 | + * @param object|array $permission | |
50 | + * | |
51 | + * @return void | |
52 | + */ | |
53 | + public function detachPermission($permission) | |
54 | + { | |
55 | + if (is_object($permission)) { | |
56 | + $permission = $permission->getKey(); | |
57 | + } | |
58 | + | |
59 | + if (is_array($permission)) { | |
60 | + $permission = $permission['id']; | |
61 | + } | |
62 | + | |
63 | + $this->permissions()->detach($permission); | |
64 | + } | |
65 | + | |
66 | + /** | |
67 | + * Attach multiple permissions to current role. | |
68 | + * | |
69 | + * @param mixed $permissions | |
70 | + * | |
71 | + * @return void | |
72 | + */ | |
73 | + public function attachPermissions($permissions) | |
74 | + { | |
75 | + foreach ($permissions as $permission) { | |
76 | + $this->attachPermission($permission); | |
77 | + } | |
78 | + } | |
79 | + | |
80 | + /** | |
81 | + * Detach multiple permissions from current role. | |
82 | + * | |
83 | + * @param mixed $permissions | |
84 | + * | |
85 | + * @return void | |
86 | + */ | |
87 | + public function detachPermissions($permissions) | |
88 | + { | |
89 | + foreach ($permissions as $permission) { | |
90 | + $this->detachPermission($permission); | |
91 | + } | |
92 | + } | |
93 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\Role\Traits\Scope; | |
4 | + | |
5 | +/** | |
6 | + * Class RoleScope. | |
7 | + */ | |
8 | +trait RoleScope | |
9 | +{ | |
10 | + /** | |
11 | + * @param $query | |
12 | + * @param string $direction | |
13 | + * | |
14 | + * @return mixed | |
15 | + */ | |
16 | + public function scopeSort($query, $direction = 'asc') | |
17 | + { | |
18 | + return $query->orderBy('sort', $direction); | |
19 | + } | |
20 | +} | ... | ... |
app/Access/Model/User/SocialLogin.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | + | |
7 | +/** | |
8 | + * Class SocialLogin. | |
9 | + */ | |
10 | +class SocialLogin extends Model | |
11 | +{ | |
12 | + /** | |
13 | + * The database table used by the model. | |
14 | + * | |
15 | + * @var string | |
16 | + */ | |
17 | + protected $table = 'social_logins'; | |
18 | + | |
19 | + /** | |
20 | + * The attributes that are mass assignable. | |
21 | + * | |
22 | + * @var array | |
23 | + */ | |
24 | + protected $fillable = ['user_id', 'provider', 'provider_id', 'token', 'avatar']; | |
25 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User\Traits\Attribute; | |
4 | + | |
5 | +/** | |
6 | + * Class UserAttribute. | |
7 | + */ | |
8 | +trait UserAttribute | |
9 | +{ | |
10 | + /** | |
11 | + * @return mixed | |
12 | + */ | |
13 | + public function canChangeEmail() | |
14 | + { | |
15 | + return config('access.users.change_email'); | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * @return bool | |
20 | + */ | |
21 | + public function canChangePassword() | |
22 | + { | |
23 | + return ! app('session')->has(config('access.socialite_session_name')); | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @return string | |
28 | + */ | |
29 | + public function getStatusLabelAttribute() | |
30 | + { | |
31 | + if ($this->isActive()) { | |
32 | + return "<label class='label label-success'>".trans('labels.general.active').'</label>'; | |
33 | + } | |
34 | + | |
35 | + return "<label class='label label-danger'>".trans('labels.general.inactive').'</label>'; | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * @return string | |
40 | + */ | |
41 | + public function getConfirmedLabelAttribute() | |
42 | + { | |
43 | + if ($this->isConfirmed()) { | |
44 | + if ($this->id != 1 && $this->id != access()->id()) { | |
45 | + return '<a href="'.route('admin.access.user.unconfirm', | |
46 | + $this).'" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.unconfirm').'" name="confirm_item"><label class="label label-success" style="cursor:pointer">'.trans('labels.general.yes').'</label></a>'; | |
47 | + } else { | |
48 | + return '<label class="label label-success">'.trans('labels.general.yes').'</label>'; | |
49 | + } | |
50 | + } | |
51 | + | |
52 | + return '<a href="'.route('admin.access.user.confirm', $this).'" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.confirm').'" name="confirm_item"><label class="label label-danger" style="cursor:pointer">'.trans('labels.general.no').'</label></a>'; | |
53 | + } | |
54 | + | |
55 | + /** | |
56 | + * @return mixed | |
57 | + */ | |
58 | + public function getPictureAttribute() | |
59 | + { | |
60 | + return $this->getPicture(); | |
61 | + } | |
62 | + | |
63 | + /** | |
64 | + * @param bool $size | |
65 | + * | |
66 | + * @return mixed | |
67 | + */ | |
68 | + public function getPicture($size = false) | |
69 | + { | |
70 | + if (! $size) { | |
71 | + $size = config('gravatar.default.size'); | |
72 | + } | |
73 | + | |
74 | + return gravatar()->get($this->username."@suishenwan.com", ['size' => $size]); | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * @param $provider | |
79 | + * | |
80 | + * @return bool | |
81 | + */ | |
82 | + public function hasProvider($provider) | |
83 | + { | |
84 | + foreach ($this->providers as $p) { | |
85 | + if ($p->provider == $provider) { | |
86 | + return true; | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + return false; | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * @return bool | |
95 | + */ | |
96 | + public function isActive() | |
97 | + { | |
98 | + return $this->status == 1; | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * @return bool | |
103 | + */ | |
104 | + public function isConfirmed() | |
105 | + { | |
106 | + return $this->confirmed == 1; | |
107 | + } | |
108 | + | |
109 | + /** | |
110 | + * @return bool | |
111 | + */ | |
112 | + public function isPending() | |
113 | + { | |
114 | + return config('access.users.requires_approval') && $this->confirmed == 0; | |
115 | + } | |
116 | + | |
117 | + /** | |
118 | + * @return string | |
119 | + */ | |
120 | + public function getFullNameAttribute() | |
121 | + { | |
122 | + return $this->last_name | |
123 | + ? $this->first_name.' '.$this->last_name | |
124 | + : $this->first_name; | |
125 | + } | |
126 | + | |
127 | + /** | |
128 | + * @return string | |
129 | + */ | |
130 | + public function getNameAttribute() | |
131 | + { | |
132 | + return $this->full_name; | |
133 | + } | |
134 | + | |
135 | + /** | |
136 | + * @return string | |
137 | + */ | |
138 | + public function getShowButtonAttribute() | |
139 | + { | |
140 | + return '<a href="'.route('admin.access.user.show', $this, false).'" class="btn btn-xs btn-info"><i class="fa fa-search" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.view').'"></i></a> '; | |
141 | + } | |
142 | + | |
143 | + /** | |
144 | + * @return string | |
145 | + */ | |
146 | + public function getEditButtonAttribute() | |
147 | + { | |
148 | + return '<a href="'.route('admin.access.user.edit', $this, false).'" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.edit').'"></i></a> '; | |
149 | + } | |
150 | + | |
151 | + /** | |
152 | + * @return string | |
153 | + */ | |
154 | + public function getChangePasswordButtonAttribute() | |
155 | + { | |
156 | + return '<a href="'.route('admin.access.user.change-password', $this, false).'" class="btn btn-xs btn-info"><i class="fa fa-refresh" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.change_password').'"></i></a> '; | |
157 | + } | |
158 | + | |
159 | + /** | |
160 | + * @return string | |
161 | + */ | |
162 | + public function getStatusButtonAttribute() | |
163 | + { | |
164 | + if ($this->id != access()->id()) { | |
165 | + switch ($this->status) { | |
166 | + case 0: | |
167 | + return '<a href="'.route('admin.access.user.mark', [ | |
168 | + $this, | |
169 | + 1, | |
170 | + ], false).'" class="btn btn-xs btn-success"><i class="fa fa-play" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.activate').'"></i></a> '; | |
171 | + // No break | |
172 | + | |
173 | + case 1: | |
174 | + return '<a href="'.route('admin.access.user.mark', [ | |
175 | + $this, | |
176 | + 0, | |
177 | + ]).'" class="btn btn-xs btn-warning"><i class="fa fa-pause" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.deactivate').'"></i></a> '; | |
178 | + // No break | |
179 | + | |
180 | + default: | |
181 | + return ''; | |
182 | + // No break | |
183 | + } | |
184 | + } | |
185 | + | |
186 | + return ''; | |
187 | + } | |
188 | + | |
189 | + /** | |
190 | + * @return string | |
191 | + */ | |
192 | + public function getDeleteButtonAttribute() | |
193 | + { | |
194 | + if ($this->id != access()->id() && $this->id != 1) { | |
195 | + return '<a href="'.route('admin.access.user.destroy', $this, false).'" | |
196 | + data-method="delete" | |
197 | + data-trans-button-cancel="'.trans('buttons.general.cancel').'" | |
198 | + data-trans-button-confirm="'.trans('buttons.general.crud.delete').'" | |
199 | + data-trans-title="'.trans('strings.backend.general.are_you_sure').'" | |
200 | + class="btn btn-xs btn-danger"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.general.crud.delete').'"></i></a> '; | |
201 | + } | |
202 | + | |
203 | + return ''; | |
204 | + } | |
205 | + | |
206 | + /** | |
207 | + * @return string | |
208 | + */ | |
209 | + public function getRestoreButtonAttribute() | |
210 | + { | |
211 | + return '<a href="'.route('admin.access.user.restore', $this, false).'" name="restore_user" class="btn btn-xs btn-info"><i class="fa fa-refresh" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.restore_user').'"></i></a> '; | |
212 | + } | |
213 | + | |
214 | + /** | |
215 | + * @return string | |
216 | + */ | |
217 | + public function getDeletePermanentlyButtonAttribute() | |
218 | + { | |
219 | + return '<a href="'.route('admin.access.user.delete-permanently', $this, false).'" name="delete_user_perm" class="btn btn-xs btn-danger"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.delete_permanently').'"></i></a> '; | |
220 | + } | |
221 | + | |
222 | + /** | |
223 | + * @return string | |
224 | + */ | |
225 | + public function getLoginAsButtonAttribute() | |
226 | + { | |
227 | + /* | |
228 | + * If the admin is currently NOT spoofing a user | |
229 | + */ | |
230 | + if (! session()->has('admin_user_id') || ! session()->has('temp_user_id')) { | |
231 | + //Won't break, but don't let them "Login As" themselves | |
232 | + if ($this->id != access()->id()) { | |
233 | + return '<a href="'.route('admin.access.user.login-as', | |
234 | + $this, false).'" class="btn btn-xs btn-success"><i class="fa fa-lock" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.login_as', | |
235 | + ['user' => $this->full_name]).'"></i></a> '; | |
236 | + } | |
237 | + } | |
238 | + | |
239 | + return ''; | |
240 | + } | |
241 | + | |
242 | + /** | |
243 | + * @return string | |
244 | + */ | |
245 | + public function getClearSessionButtonAttribute() | |
246 | + { | |
247 | + if ($this->id != access()->id() && config('session.driver') == 'database') { | |
248 | + return '<a href="'.route('admin.access.user.clear-session', $this, false).'" | |
249 | + data-trans-button-cancel="'.trans('buttons.general.cancel').'" | |
250 | + data-trans-button-confirm="'.trans('buttons.general.continue').'" | |
251 | + data-trans-title="'.trans('strings.backend.general.are_you_sure').'" | |
252 | + class="btn btn-xs btn-warning" name="confirm_item"><i class="fa fa-times" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.clear_session').'"></i></a> '; | |
253 | + } | |
254 | + | |
255 | + return ''; | |
256 | + } | |
257 | + | |
258 | + /** | |
259 | + * @return string | |
260 | + */ | |
261 | + public function getActionButtonsAttribute() | |
262 | + { | |
263 | + if ($this->trashed()) { | |
264 | + return $this->restore_button.$this->delete_permanently_button; | |
265 | + } | |
266 | + | |
267 | + return | |
268 | + $this->clear_session_button. | |
269 | + $this->login_as_button. | |
270 | + //$this->show_button. | |
271 | + $this->edit_button. | |
272 | + $this->change_password_button. | |
273 | + $this->status_button. | |
274 | + $this->delete_button; | |
275 | + } | |
276 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User\Traits\Relationship; | |
4 | + | |
5 | +use App\Modules\Models\System\Session; | |
6 | +use App\Access\Model\User\SocialLogin; | |
7 | + | |
8 | +/** | |
9 | + * Class UserRelationship. | |
10 | + */ | |
11 | +trait UserRelationship | |
12 | +{ | |
13 | + /** | |
14 | + * Many-to-Many relations with Role. | |
15 | + * | |
16 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |
17 | + */ | |
18 | + public function roles() | |
19 | + { | |
20 | + return $this->belongsToMany(config('access.role'), config('access.role_user_table'), 'user_id', 'role_id'); | |
21 | + } | |
22 | + | |
23 | + /** | |
24 | + * @return mixed | |
25 | + */ | |
26 | + public function providers() | |
27 | + { | |
28 | + return $this->hasMany(SocialLogin::class); | |
29 | + } | |
30 | + | |
31 | + /** | |
32 | + * @return mixed | |
33 | + */ | |
34 | + public function sessions() | |
35 | + { | |
36 | + return $this->hasMany(Session::class); | |
37 | + } | |
38 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User\Traits\Scope; | |
4 | + | |
5 | +/** | |
6 | + * Class UserScope. | |
7 | + */ | |
8 | +trait UserScope | |
9 | +{ | |
10 | + /** | |
11 | + * @param $query | |
12 | + * @param bool $confirmed | |
13 | + * | |
14 | + * @return mixed | |
15 | + */ | |
16 | + public function scopeConfirmed($query, $confirmed = true) | |
17 | + { | |
18 | + return $query->where('confirmed', $confirmed); | |
19 | + } | |
20 | + | |
21 | + /** | |
22 | + * @param $query | |
23 | + * @param bool $status | |
24 | + * | |
25 | + * @return mixed | |
26 | + */ | |
27 | + public function scopeActive($query, $status = true) | |
28 | + { | |
29 | + return $query->where('status', $status); | |
30 | + } | |
31 | +} | ... | ... |
app/Access/Model/User/Traits/UserAccess.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User\Traits; | |
4 | + | |
5 | +/** | |
6 | + * Class UserAccess. | |
7 | + */ | |
8 | +trait UserAccess | |
9 | +{ | |
10 | + /** | |
11 | + * Checks if the user has a Role by its name or id. | |
12 | + * | |
13 | + * @param string $nameOrId Role name or id. | |
14 | + * | |
15 | + * @return bool | |
16 | + */ | |
17 | + public function hasRole($nameOrId) | |
18 | + { | |
19 | + foreach ($this->roles as $role) { | |
20 | + //See if role has all permissions | |
21 | + if ($role->all) { | |
22 | + return true; | |
23 | + } | |
24 | + | |
25 | + //First check to see if it's an ID | |
26 | + if (is_numeric($nameOrId)) { | |
27 | + if ($role->id == $nameOrId) { | |
28 | + return true; | |
29 | + } | |
30 | + } | |
31 | + | |
32 | + //Otherwise check by name | |
33 | + if ($role->name == $nameOrId) { | |
34 | + return true; | |
35 | + } | |
36 | + } | |
37 | + | |
38 | + return false; | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * Checks to see if user has array of roles. | |
43 | + * | |
44 | + * All must return true | |
45 | + * | |
46 | + * @param $roles | |
47 | + * @param $needsAll | |
48 | + * | |
49 | + * @return bool | |
50 | + */ | |
51 | + public function hasRoles($roles, $needsAll = false) | |
52 | + { | |
53 | + //If not an array, make a one item array | |
54 | + if (! is_array($roles)) { | |
55 | + $roles = [$roles]; | |
56 | + } | |
57 | + | |
58 | + //User has to possess all of the roles specified | |
59 | + if ($needsAll) { | |
60 | + $hasRoles = 0; | |
61 | + $numRoles = count($roles); | |
62 | + | |
63 | + foreach ($roles as $role) { | |
64 | + if ($this->hasRole($role)) { | |
65 | + $hasRoles++; | |
66 | + } | |
67 | + } | |
68 | + | |
69 | + return $numRoles == $hasRoles; | |
70 | + } | |
71 | + | |
72 | + //User has to possess one of the roles specified | |
73 | + foreach ($roles as $role) { | |
74 | + if ($this->hasRole($role)) { | |
75 | + return true; | |
76 | + } | |
77 | + } | |
78 | + | |
79 | + return false; | |
80 | + } | |
81 | + | |
82 | + /** | |
83 | + * Check if user has a permission by its name or id. | |
84 | + * | |
85 | + * @param string $nameOrId Permission name or id. | |
86 | + * | |
87 | + * @return bool | |
88 | + */ | |
89 | + public function allow($nameOrId) | |
90 | + { | |
91 | + foreach ($this->roles as $role) { | |
92 | + // See if role has all permissions | |
93 | + if ($role->all) { | |
94 | + return true; | |
95 | + } | |
96 | + | |
97 | + // Validate against the Permission table | |
98 | + foreach ($role->permissions as $perm) { | |
99 | + | |
100 | + // First check to see if it's an ID | |
101 | + if (is_numeric($nameOrId)) { | |
102 | + if ($perm->id == $nameOrId) { | |
103 | + return true; | |
104 | + } | |
105 | + } | |
106 | + | |
107 | + // Otherwise check by name | |
108 | + if ($perm->name == $nameOrId) { | |
109 | + return true; | |
110 | + } | |
111 | + } | |
112 | + } | |
113 | + | |
114 | + return false; | |
115 | + } | |
116 | + | |
117 | + /** | |
118 | + * Check an array of permissions and whether or not all are required to continue. | |
119 | + * | |
120 | + * @param $permissions | |
121 | + * @param $needsAll | |
122 | + * | |
123 | + * @return bool | |
124 | + */ | |
125 | + public function allowMultiple($permissions, $needsAll = false) | |
126 | + { | |
127 | + //If not an array, make a one item array | |
128 | + if (! is_array($permissions)) { | |
129 | + $permissions = [$permissions]; | |
130 | + } | |
131 | + | |
132 | + //User has to possess all of the permissions specified | |
133 | + if ($needsAll) { | |
134 | + $hasPermissions = 0; | |
135 | + $numPermissions = count($permissions); | |
136 | + | |
137 | + foreach ($permissions as $perm) { | |
138 | + if ($this->allow($perm)) { | |
139 | + $hasPermissions++; | |
140 | + } | |
141 | + } | |
142 | + | |
143 | + return $numPermissions == $hasPermissions; | |
144 | + } | |
145 | + | |
146 | + //User has to possess one of the permissions specified | |
147 | + foreach ($permissions as $perm) { | |
148 | + if ($this->allow($perm)) { | |
149 | + return true; | |
150 | + } | |
151 | + } | |
152 | + | |
153 | + return false; | |
154 | + } | |
155 | + | |
156 | + /** | |
157 | + * @param $nameOrId | |
158 | + * | |
159 | + * @return bool | |
160 | + */ | |
161 | + public function hasPermission($nameOrId) | |
162 | + { | |
163 | + return $this->allow($nameOrId); | |
164 | + } | |
165 | + | |
166 | + /** | |
167 | + * @param $permissions | |
168 | + * @param bool $needsAll | |
169 | + * | |
170 | + * @return bool | |
171 | + */ | |
172 | + public function hasPermissions($permissions, $needsAll = false) | |
173 | + { | |
174 | + return $this->allowMultiple($permissions, $needsAll); | |
175 | + } | |
176 | + | |
177 | + /** | |
178 | + * Alias to eloquent many-to-many relation's attach() method. | |
179 | + * | |
180 | + * @param mixed $role | |
181 | + * | |
182 | + * @return void | |
183 | + */ | |
184 | + public function attachRole($role) | |
185 | + { | |
186 | + if (is_object($role)) { | |
187 | + $role = $role->getKey(); | |
188 | + } | |
189 | + | |
190 | + if (is_array($role)) { | |
191 | + $role = $role['id']; | |
192 | + } | |
193 | + | |
194 | + $this->roles()->attach($role); | |
195 | + } | |
196 | + | |
197 | + /** | |
198 | + * Alias to eloquent many-to-many relation's detach() method. | |
199 | + * | |
200 | + * @param mixed $role | |
201 | + * | |
202 | + * @return void | |
203 | + */ | |
204 | + public function detachRole($role) | |
205 | + { | |
206 | + if (is_object($role)) { | |
207 | + $role = $role->getKey(); | |
208 | + } | |
209 | + | |
210 | + if (is_array($role)) { | |
211 | + $role = $role['id']; | |
212 | + } | |
213 | + | |
214 | + $this->roles()->detach($role); | |
215 | + } | |
216 | + | |
217 | + /** | |
218 | + * Attach multiple roles to a user. | |
219 | + * | |
220 | + * @param mixed $roles | |
221 | + * | |
222 | + * @return void | |
223 | + */ | |
224 | + public function attachRoles($roles) | |
225 | + { | |
226 | + foreach ($roles as $role) { | |
227 | + $this->attachRole($role); | |
228 | + } | |
229 | + } | |
230 | + | |
231 | + /** | |
232 | + * Detach multiple roles from a user. | |
233 | + * | |
234 | + * @param mixed $roles | |
235 | + * | |
236 | + * @return void | |
237 | + */ | |
238 | + public function detachRoles($roles) | |
239 | + { | |
240 | + foreach ($roles as $role) { | |
241 | + $this->detachRole($role); | |
242 | + } | |
243 | + } | |
244 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User\Traits; | |
4 | + | |
5 | +use App\Notifications\Frontend\Auth\UserNeedsPasswordReset; | |
6 | + | |
7 | +/** | |
8 | + * Class UserSendPasswordReset. | |
9 | + */ | |
10 | +trait UserSendPasswordReset | |
11 | +{ | |
12 | + /** | |
13 | + * Send the password reset notification. | |
14 | + * | |
15 | + * @param string $token | |
16 | + * | |
17 | + * @return void | |
18 | + */ | |
19 | + public function sendPasswordResetNotification($token) | |
20 | + { | |
21 | + $this->notify(new UserNeedsPasswordReset($token)); | |
22 | + } | |
23 | +} | ... | ... |
app/Access/Model/User/User.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Model\User; | |
4 | + | |
5 | +use Illuminate\Notifications\Notifiable; | |
6 | +use App\Access\Model\User\Traits\UserAccess; | |
7 | +use Illuminate\Database\Eloquent\SoftDeletes; | |
8 | +use App\Access\Model\User\Traits\Scope\UserScope; | |
9 | +use Illuminate\Foundation\Auth\User as Authenticatable; | |
10 | +use App\Access\Model\User\Traits\UserSendPasswordReset; | |
11 | +use App\Access\Model\User\Traits\Attribute\UserAttribute; | |
12 | +use App\Access\Model\User\Traits\Relationship\UserRelationship; | |
13 | + | |
14 | +/** | |
15 | + * Class User. | |
16 | + */ | |
17 | +class User extends Authenticatable | |
18 | +{ | |
19 | + use UserScope, | |
20 | + UserAccess, | |
21 | + Notifiable, | |
22 | + SoftDeletes, | |
23 | + UserAttribute, | |
24 | + UserRelationship, | |
25 | + UserSendPasswordReset; | |
26 | + | |
27 | + /** | |
28 | + * The database table used by the model. | |
29 | + * | |
30 | + * @var string | |
31 | + */ | |
32 | + protected $table; | |
33 | + | |
34 | + /** | |
35 | + * The attributes that are mass assignable. | |
36 | + * | |
37 | + * @var array | |
38 | + */ | |
39 | + protected $fillable = ['id','first_name', 'last_name', 'password', 'status','business_id','confirmation_code', 'confirmed','science_id']; | |
40 | + | |
41 | + /** | |
42 | + * The attributes that should be hidden for arrays. | |
43 | + * | |
44 | + * @var array | |
45 | + */ | |
46 | + protected $hidden = ['password', 'remember_token']; | |
47 | + | |
48 | + /** | |
49 | + * @var array | |
50 | + */ | |
51 | + protected $dates = ['deleted_at']; | |
52 | + | |
53 | + /** | |
54 | + * The dynamic attributes from mutators that should be returned with the user object. | |
55 | + * @var array | |
56 | + */ | |
57 | + protected $appends = ['full_name', 'name']; | |
58 | + | |
59 | + /** | |
60 | + * @param array $attributes | |
61 | + */ | |
62 | + public function __construct(array $attributes = []) | |
63 | + { | |
64 | + parent::__construct($attributes); | |
65 | + $this->table = config('access.users_table'); | |
66 | + } | |
67 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Provider; | |
4 | + | |
5 | +use App\Access\Service\Access; | |
6 | +use Illuminate\Support\Facades\Blade; | |
7 | +use Illuminate\Support\ServiceProvider; | |
8 | + | |
9 | +/** | |
10 | + * Class AccessServiceProvider. | |
11 | + */ | |
12 | +class AccessServiceProvider extends ServiceProvider | |
13 | +{ | |
14 | + /** | |
15 | + * Indicates if loading of the provider is deferred. | |
16 | + * | |
17 | + * @var bool | |
18 | + */ | |
19 | + protected $defer = false; | |
20 | + | |
21 | + /** | |
22 | + * Package boot method. | |
23 | + */ | |
24 | + public function boot() | |
25 | + { | |
26 | + $this->registerBladeExtensions(); | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * Register the service provider. | |
31 | + * | |
32 | + * @return void | |
33 | + */ | |
34 | + public function register() | |
35 | + { | |
36 | + $this->registerAccess(); | |
37 | + $this->registerFacade(); | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * Register the application bindings. | |
42 | + * | |
43 | + * @return void | |
44 | + */ | |
45 | + private function registerAccess() | |
46 | + { | |
47 | + $this->app->bind('access', function ($app) { | |
48 | + return new Access($app); | |
49 | + }); | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * Register the vault facade without the user having to add it to the app.php file. | |
54 | + * | |
55 | + * @return void | |
56 | + */ | |
57 | + public function registerFacade() | |
58 | + { | |
59 | + $this->app->booting(function () { | |
60 | + $loader = \Illuminate\Foundation\AliasLoader::getInstance(); | |
61 | + $loader->alias('Access', \App\Access\Service\Facades\Access::class); | |
62 | + }); | |
63 | + } | |
64 | + | |
65 | + /** | |
66 | + * Register the blade extender to use new blade sections. | |
67 | + */ | |
68 | + protected function registerBladeExtensions() | |
69 | + { | |
70 | + /* | |
71 | + * Role based blade extensions | |
72 | + * Accepts either string of Role Name or Role ID | |
73 | + */ | |
74 | + Blade::directive('role', function ($role) { | |
75 | + return "<?php if (access()->hasRole({$role})): ?>"; | |
76 | + }); | |
77 | + | |
78 | + /* | |
79 | + * Accepts array of names or id's | |
80 | + */ | |
81 | + Blade::directive('roles', function ($roles) { | |
82 | + return "<?php if (access()->hasRoles({$roles})): ?>"; | |
83 | + }); | |
84 | + | |
85 | + Blade::directive('needsroles', function ($roles) { | |
86 | + return '<?php if (access()->hasRoles('.$roles.', true)): ?>'; | |
87 | + }); | |
88 | + | |
89 | + /* | |
90 | + * Permission based blade extensions | |
91 | + * Accepts wither string of Permission Name or Permission ID | |
92 | + */ | |
93 | + Blade::directive('permission', function ($permission) { | |
94 | + return "<?php if (access()->allow({$permission})): ?>"; | |
95 | + }); | |
96 | + | |
97 | + /* | |
98 | + * Accepts array of names or id's | |
99 | + */ | |
100 | + Blade::directive('permissions', function ($permissions) { | |
101 | + return "<?php if (access()->allowMultiple({$permissions})): ?>"; | |
102 | + }); | |
103 | + | |
104 | + Blade::directive('needspermissions', function ($permissions) { | |
105 | + return '<?php if (access()->allowMultiple('.$permissions.', true)): ?>'; | |
106 | + }); | |
107 | + | |
108 | + /* | |
109 | + * Generic if closer to not interfere with built in blade | |
110 | + */ | |
111 | + Blade::directive('endauth', function () { | |
112 | + return '<?php endif; ?>'; | |
113 | + }); | |
114 | + } | |
115 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Repository\Permission; | |
4 | + | |
5 | +use App\Repositories\BaseRepository; | |
6 | +use App\Access\Model\Permission\Permission; | |
7 | + | |
8 | +/** | |
9 | + * Class PermissionRepository. | |
10 | + */ | |
11 | +class PermissionRepository extends BaseRepository | |
12 | +{ | |
13 | + /** | |
14 | + * Associated Repository Model. | |
15 | + */ | |
16 | + const MODEL = Permission::class; | |
17 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Repository\Role; | |
4 | + | |
5 | +use App\Access\Model\Role\Role; | |
6 | +use Illuminate\Support\Facades\DB; | |
7 | +use App\Exceptions\GeneralException; | |
8 | +use App\Repositories\BaseRepository; | |
9 | +use Illuminate\Database\Eloquent\Model; | |
10 | +use App\Events\Backend\Access\Role\RoleCreated; | |
11 | +use App\Events\Backend\Access\Role\RoleDeleted; | |
12 | +use App\Events\Backend\Access\Role\RoleUpdated; | |
13 | + | |
14 | +/** | |
15 | + * Class RoleRepository. | |
16 | + */ | |
17 | +class RoleRepository extends BaseRepository | |
18 | +{ | |
19 | + /** | |
20 | + * Associated Repository Model. | |
21 | + */ | |
22 | + const MODEL = Role::class; | |
23 | + | |
24 | + /** | |
25 | + * @param string $order_by | |
26 | + * @param string $sort | |
27 | + * | |
28 | + * @return mixed | |
29 | + */ | |
30 | + public function getAll($order_by = 'sort', $sort = 'asc') | |
31 | + { | |
32 | + return $this->query() | |
33 | + ->with('users', 'permissions') | |
34 | + ->orderBy($order_by, $sort) | |
35 | + ->get(); | |
36 | + } | |
37 | + | |
38 | + | |
39 | + public function getscience($order_by = 'sort', $sort = 'asc') | |
40 | + { | |
41 | + //迁移文件李要加个 3 表示景区创建 | |
42 | + return $this->query()->where(['id'=>3]) | |
43 | + ->with('users', 'permissions') | |
44 | + ->orderBy($order_by, $sort) | |
45 | + ->first() | |
46 | + ; | |
47 | + } | |
48 | + | |
49 | + /** | |
50 | + * @return mixed | |
51 | + */ | |
52 | + public function getForDataTable() | |
53 | + { | |
54 | + return $this->query() | |
55 | + ->with('users', 'permissions') | |
56 | + ->select([ | |
57 | + config('access.roles_table').'.id', | |
58 | + config('access.roles_table').'.name', | |
59 | + config('access.roles_table').'.all', | |
60 | + config('access.roles_table').'.sort', | |
61 | + ]); | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * @param array $input | |
66 | + * | |
67 | + * @throws GeneralException | |
68 | + * | |
69 | + * @return bool | |
70 | + */ | |
71 | + public function create(array $input) | |
72 | + { | |
73 | + if ($this->query()->where('name', $input['name'])->first()) { | |
74 | + throw new GeneralException(trans('exceptions.backend.access.roles.already_exists')); | |
75 | + } | |
76 | + | |
77 | + //See if the role has all access | |
78 | + $all = $input['associated-permissions'] == 'all' ? true : false; | |
79 | + | |
80 | + if (! isset($input['permissions'])) { | |
81 | + $input['permissions'] = []; | |
82 | + } | |
83 | + | |
84 | + //This config is only required if all is false | |
85 | + if (! $all) { | |
86 | + //See if the role must contain a permission as per config | |
87 | + if (config('access.roles.role_must_contain_permission') && count($input['permissions']) == 0) { | |
88 | + throw new GeneralException(trans('exceptions.backend.access.roles.needs_permission')); | |
89 | + } | |
90 | + } | |
91 | + | |
92 | + DB::transaction(function () use ($input, $all) { | |
93 | + $role = self::MODEL; | |
94 | + $role = new $role(); | |
95 | + $role->name = $input['name']; | |
96 | + $role->sort = isset($input['sort']) && strlen($input['sort']) > 0 && is_numeric($input['sort']) ? (int) $input['sort'] : 0; | |
97 | + | |
98 | + //See if this role has all permissions and set the flag on the role | |
99 | + $role->all = $all; | |
100 | + | |
101 | + if ($role->save()) { | |
102 | + if (! $all) { | |
103 | + $permissions = []; | |
104 | + | |
105 | + if (is_array($input['permissions']) && count($input['permissions'])) { | |
106 | + foreach ($input['permissions'] as $perm) { | |
107 | + if (is_numeric($perm)) { | |
108 | + array_push($permissions, $perm); | |
109 | + } | |
110 | + } | |
111 | + } | |
112 | + | |
113 | + $role->attachPermissions($permissions); | |
114 | + } | |
115 | + | |
116 | + event(new RoleCreated($role)); | |
117 | + | |
118 | + return true; | |
119 | + } | |
120 | + | |
121 | + throw new GeneralException(trans('exceptions.backend.access.roles.create_error')); | |
122 | + }); | |
123 | + } | |
124 | + | |
125 | + /** | |
126 | + * @param Model $role | |
127 | + * @param $input | |
128 | + * | |
129 | + * @throws GeneralException | |
130 | + * | |
131 | + * @return bool | |
132 | + */ | |
133 | + public function update(Model $role, array $input) | |
134 | + { | |
135 | + //See if the role has all access, administrator always has all access | |
136 | + if ($role->id == 1) { | |
137 | + $all = true; | |
138 | + } else { | |
139 | + $all = $input['associated-permissions'] == 'all' ? true : false; | |
140 | + } | |
141 | + | |
142 | + if (! isset($input['permissions'])) { | |
143 | + $input['permissions'] = []; | |
144 | + } | |
145 | + | |
146 | + //This config is only required if all is false | |
147 | + if (! $all) { | |
148 | + //See if the role must contain a permission as per config | |
149 | + if (config('access.roles.role_must_contain_permission') && count($input['permissions']) == 0) { | |
150 | + throw new GeneralException(trans('exceptions.backend.access.roles.needs_permission')); | |
151 | + } | |
152 | + } | |
153 | + | |
154 | + $role->name = $input['name']; | |
155 | + $role->sort = isset($input['sort']) && strlen($input['sort']) > 0 && is_numeric($input['sort']) ? (int) $input['sort'] : 0; | |
156 | + | |
157 | + //See if this role has all permissions and set the flag on the role | |
158 | + $role->all = $all; | |
159 | + | |
160 | + DB::transaction(function () use ($role, $input, $all) { | |
161 | + if ($role->save()) { | |
162 | + //If role has all access detach all permissions because they're not needed | |
163 | + if ($all) { | |
164 | + $role->permissions()->sync([]); | |
165 | + } else { | |
166 | + //Remove all roles first | |
167 | + $role->permissions()->sync([]); | |
168 | + | |
169 | + //Attach permissions if the role does not have all access | |
170 | + $permissions = []; | |
171 | + | |
172 | + if (is_array($input['permissions']) && count($input['permissions'])) { | |
173 | + foreach ($input['permissions'] as $perm) { | |
174 | + if (is_numeric($perm)) { | |
175 | + array_push($permissions, $perm); | |
176 | + } | |
177 | + } | |
178 | + } | |
179 | + | |
180 | + $role->attachPermissions($permissions); | |
181 | + } | |
182 | + | |
183 | + event(new RoleUpdated($role)); | |
184 | + | |
185 | + return true; | |
186 | + } | |
187 | + | |
188 | + throw new GeneralException(trans('exceptions.backend.access.roles.update_error')); | |
189 | + }); | |
190 | + } | |
191 | + | |
192 | + /** | |
193 | + * @param Model $role | |
194 | + * | |
195 | + * @throws GeneralException | |
196 | + * | |
197 | + * @return bool | |
198 | + */ | |
199 | + public function delete(Model $role) | |
200 | + { | |
201 | + //Would be stupid to delete the administrator role | |
202 | + if ($role->id == 1) { //id is 1 because of the seeder | |
203 | + throw new GeneralException(trans('exceptions.backend.access.roles.cant_delete_admin')); | |
204 | + } | |
205 | + | |
206 | + //Don't delete the role is there are users associated | |
207 | + if ($role->users()->count() > 0) { | |
208 | + throw new GeneralException(trans('exceptions.backend.access.roles.has_users')); | |
209 | + } | |
210 | + | |
211 | + DB::transaction(function () use ($role) { | |
212 | + //Detach all associated roles | |
213 | + $role->permissions()->sync([]); | |
214 | + | |
215 | + if ($role->delete()) { | |
216 | + event(new RoleDeleted($role)); | |
217 | + | |
218 | + return true; | |
219 | + } | |
220 | + | |
221 | + throw new GeneralException(trans('exceptions.backend.access.roles.delete_error')); | |
222 | + }); | |
223 | + } | |
224 | + | |
225 | + /** | |
226 | + * @return mixed | |
227 | + */ | |
228 | + public function getDefaultUserRole() | |
229 | + { | |
230 | + if (is_numeric(config('access.users.default_role'))) { | |
231 | + return $this->query()->where('id', (int) config('access.users.default_role'))->first(); | |
232 | + } | |
233 | + | |
234 | + return $this->query()->where('name', config('access.users.default_role'))->first(); | |
235 | + } | |
236 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Repository\User; | |
4 | + | |
5 | +use App\Access\Model\User\User; | |
6 | +use Illuminate\Support\Facades\DB; | |
7 | +use App\Exceptions\GeneralException; | |
8 | +use App\Repositories\BaseRepository; | |
9 | +use Illuminate\Database\Eloquent\Model; | |
10 | +use App\Events\Backend\Access\User\UserCreated; | |
11 | +use App\Events\Backend\Access\User\UserDeleted; | |
12 | +use App\Events\Backend\Access\User\UserUpdated; | |
13 | +use App\Events\Backend\Access\User\UserRestored; | |
14 | +use App\Events\Backend\Access\User\UserConfirmed; | |
15 | +use App\Events\Backend\Access\User\UserDeactivated; | |
16 | +use App\Events\Backend\Access\User\UserReactivated; | |
17 | +use App\Events\Backend\Access\User\UserUnconfirmed; | |
18 | +use App\Events\Backend\Access\User\UserPasswordChanged; | |
19 | +use App\Notifications\Backend\Access\UserAccountActive; | |
20 | +use App\Access\Repository\Role\RoleRepository; | |
21 | +use App\Events\Backend\Access\User\UserPermanentlyDeleted; | |
22 | +use App\Notifications\Frontend\Auth\UserNeedsConfirmation; | |
23 | + | |
24 | +/** | |
25 | + * Class UserRepository. | |
26 | + */ | |
27 | +class UserRepository extends BaseRepository | |
28 | +{ | |
29 | + /** | |
30 | + * Associated Repository Model. | |
31 | + */ | |
32 | + const MODEL = User::class; | |
33 | + | |
34 | + /** | |
35 | + * @var RoleRepository | |
36 | + */ | |
37 | + protected $role; | |
38 | + | |
39 | + /** | |
40 | + * @param RoleRepository $role | |
41 | + */ | |
42 | + public function __construct(RoleRepository $role) | |
43 | + { | |
44 | + $this->role = $role; | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * @param $permissions | |
49 | + * @param string $by | |
50 | + * | |
51 | + * @return mixed | |
52 | + */ | |
53 | + public function getByPermission($permissions, $by = 'name') | |
54 | + { | |
55 | + if (! is_array($permissions)) { | |
56 | + $permissions = [$permissions]; | |
57 | + } | |
58 | + | |
59 | + return $this->query()->whereHas('roles.permissions', function ($query) use ($permissions, $by) { | |
60 | + $query->whereIn('permissions.'.$by, $permissions); | |
61 | + })->get(); | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * @param $roles | |
66 | + * @param string $by | |
67 | + * | |
68 | + * @return mixed | |
69 | + */ | |
70 | + public function getByRole($roles, $by = 'name') | |
71 | + { | |
72 | + if (! is_array($roles)) { | |
73 | + $roles = [$roles]; | |
74 | + } | |
75 | + | |
76 | + return $this->query()->whereHas('roles', function ($query) use ($roles, $by) { | |
77 | + $query->whereIn('roles.'.$by, $roles); | |
78 | + })->get(); | |
79 | + } | |
80 | + | |
81 | + /** | |
82 | + * @param int $status | |
83 | + * @param bool $trashed | |
84 | + * | |
85 | + * @return mixed | |
86 | + */ | |
87 | + public function getForDataTable($status = 1, $trashed = false) | |
88 | + { | |
89 | + /** | |
90 | + * Note: You must return deleted_at or the User getActionButtonsAttribute won't | |
91 | + * be able to differentiate what buttons to show for each row. | |
92 | + */ | |
93 | + $dataTableQuery = $this->query() | |
94 | + ->with('roles') | |
95 | + ->select([ | |
96 | + config('access.users_table').'.id', | |
97 | + config('access.users_table').'.username', | |
98 | + config('access.users_table').'.first_name', | |
99 | + config('access.users_table').'.last_name', | |
100 | + config('access.users_table').'.status', | |
101 | + config('access.users_table').'.business_id', | |
102 | + config('access.users_table').'.science_id', | |
103 | + config('access.users_table').'.created_at', | |
104 | + config('access.users_table').'.updated_at', | |
105 | + config('access.users_table').'.deleted_at', | |
106 | + ]); | |
107 | + | |
108 | + if ($trashed == 'true') { | |
109 | + return $dataTableQuery->onlyTrashed(); | |
110 | + } | |
111 | + else{ | |
112 | + return $dataTableQuery->withTrashed(); | |
113 | + } | |
114 | + | |
115 | + // active() is a scope on the UserScope trait | |
116 | + return $dataTableQuery->active($status); | |
117 | + } | |
118 | + | |
119 | + /** | |
120 | + * @return mixed | |
121 | + */ | |
122 | + public function getUnconfirmedCount() | |
123 | + { | |
124 | + return $this->query()->where('confirmed', 0)->count(); | |
125 | + } | |
126 | + | |
127 | + /** | |
128 | + * @param array $input | |
129 | + */ | |
130 | + public function create($input) | |
131 | + { | |
132 | + $data = $input['data']; | |
133 | + $roles = $input['roles']; | |
134 | + | |
135 | + $user = $this->createUserStub($data); | |
136 | + | |
137 | + DB::transaction(function () use ($user, $data, $roles) { | |
138 | + if ($user->save()) { | |
139 | + //User Created, Validate Roles | |
140 | + if (! count($roles['assignees_roles'])) { | |
141 | + throw new GeneralException(trans('exceptions.backend.access.users.role_needed_create')); | |
142 | + } | |
143 | + | |
144 | + //Attach new roles | |
145 | + $user->attachRoles($roles['assignees_roles']); | |
146 | + | |
147 | + | |
148 | + event(new UserCreated($user)); | |
149 | + | |
150 | + return true; | |
151 | + } | |
152 | + | |
153 | + throw new GeneralException(trans('exceptions.backend.access.users.create_error')); | |
154 | + }); | |
155 | + } | |
156 | + | |
157 | + | |
158 | + | |
159 | + public function scienceCreate($input) | |
160 | + { | |
161 | + $data = $input['data']; | |
162 | + $roles = $input['roles']; | |
163 | + | |
164 | + $user = $this->createUserStub($data); | |
165 | + | |
166 | + DB::transaction(function () use ($user, $data, $roles) { | |
167 | + if ($user->save()) { | |
168 | + //User Created, Validate Roles | |
169 | + | |
170 | + $science = $user->id; | |
171 | + $user->science_id =$science; | |
172 | + $user->update(); | |
173 | + | |
174 | + | |
175 | + if (! count($roles['assignees_roles'])) { | |
176 | + throw new GeneralException(trans('exceptions.backend.access.users.role_needed_create')); | |
177 | + } | |
178 | + | |
179 | + //Attach new roles | |
180 | + $user->attachRoles($roles['assignees_roles']); | |
181 | + | |
182 | + | |
183 | + | |
184 | + return true; | |
185 | + } | |
186 | + | |
187 | + throw new GeneralException(trans('exceptions.backend.access.users.create_error')); | |
188 | + }); | |
189 | + } | |
190 | + /** | |
191 | + * @param Model $user | |
192 | + * @param array $input | |
193 | + * | |
194 | + * @return bool | |
195 | + * @throws GeneralException | |
196 | + */ | |
197 | + public function update(Model $user, array $input) | |
198 | + { | |
199 | + $data = $input['data']; | |
200 | + $roles = $input['roles']; | |
201 | + | |
202 | + $this->checkUserByUsername($data, $user); | |
203 | + | |
204 | + $user->first_name = $data['first_name']; | |
205 | + $user->last_name = $data['last_name']; | |
206 | + $user->username = $data['username']; | |
207 | + $user->status = isset($data['status']) ? 1 : 0; | |
208 | + | |
209 | + DB::transaction(function () use ($user, $data, $roles) { | |
210 | + if ($user->save()) { | |
211 | +// $this->checkUserRolesCount($roles); | |
212 | +// $this->flushRoles($roles, $user); | |
213 | + | |
214 | + event(new UserUpdated($user)); | |
215 | + | |
216 | + return true; | |
217 | + } | |
218 | + | |
219 | + throw new GeneralException(trans('exceptions.backend.access.users.update_error')); | |
220 | + }); | |
221 | + } | |
222 | + | |
223 | + /** | |
224 | + * @param Model $user | |
225 | + * @param $input | |
226 | + * | |
227 | + * @throws GeneralException | |
228 | + * | |
229 | + * @return bool | |
230 | + */ | |
231 | + public function updatePassword(Model $user, $input) | |
232 | + { | |
233 | + $user->password = bcrypt($input['password']); | |
234 | + | |
235 | + if ($user->save()) { | |
236 | + event(new UserPasswordChanged($user)); | |
237 | + | |
238 | + return true; | |
239 | + } | |
240 | + | |
241 | + throw new GeneralException(trans('exceptions.backend.access.users.update_password_error')); | |
242 | + } | |
243 | + | |
244 | + /** | |
245 | + * @param Model $user | |
246 | + * | |
247 | + * @throws GeneralException | |
248 | + * | |
249 | + * @return bool | |
250 | + */ | |
251 | + public function delete(Model $user) | |
252 | + { | |
253 | + | |
254 | + if (access()->id() == $user->id) { | |
255 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_delete_self')); | |
256 | + } | |
257 | + | |
258 | + if ($user->id == 1) { | |
259 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_delete_admin')); | |
260 | + } | |
261 | + | |
262 | + if ($user->delete()) { | |
263 | + event(new UserDeleted($user)); | |
264 | + | |
265 | + return true; | |
266 | + } | |
267 | + | |
268 | + throw new GeneralException(trans('exceptions.backend.access.users.delete_error')); | |
269 | + } | |
270 | + | |
271 | + /** | |
272 | + * @param Model $user | |
273 | + * | |
274 | + * @throws GeneralException | |
275 | + */ | |
276 | + public function forceDelete(Model $user) | |
277 | + { | |
278 | + if (is_null($user->deleted_at)) { | |
279 | + throw new GeneralException(trans('exceptions.backend.access.users.delete_first')); | |
280 | + } | |
281 | + | |
282 | + DB::transaction(function () use ($user) { | |
283 | + if ($user->forceDelete()) { | |
284 | + event(new UserPermanentlyDeleted($user)); | |
285 | + | |
286 | + return true; | |
287 | + } | |
288 | + | |
289 | + throw new GeneralException(trans('exceptions.backend.access.users.delete_error')); | |
290 | + }); | |
291 | + } | |
292 | + | |
293 | + /** | |
294 | + * @param Model $user | |
295 | + * | |
296 | + * @throws GeneralException | |
297 | + * | |
298 | + * @return bool | |
299 | + */ | |
300 | + public function restore(Model $user) | |
301 | + { | |
302 | + if (is_null($user->deleted_at)) { | |
303 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_restore')); | |
304 | + } | |
305 | + | |
306 | + if ($user->restore()) { | |
307 | + event(new UserRestored($user)); | |
308 | + | |
309 | + return true; | |
310 | + } | |
311 | + | |
312 | + throw new GeneralException(trans('exceptions.backend.access.users.restore_error')); | |
313 | + } | |
314 | + | |
315 | + /** | |
316 | + * @param Model $user | |
317 | + * @param $status | |
318 | + * | |
319 | + * @throws GeneralException | |
320 | + * | |
321 | + * @return bool | |
322 | + */ | |
323 | + public function mark(Model $user, $status) | |
324 | + { | |
325 | + if (access()->id() == $user->id && $status == 0) { | |
326 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_deactivate_self')); | |
327 | + } | |
328 | + | |
329 | + $user->status = $status; | |
330 | + | |
331 | + switch ($status) { | |
332 | + case 0: | |
333 | + event(new UserDeactivated($user)); | |
334 | + break; | |
335 | + | |
336 | + case 1: | |
337 | + event(new UserReactivated($user)); | |
338 | + break; | |
339 | + } | |
340 | + | |
341 | + if ($user->save()) { | |
342 | + return true; | |
343 | + } | |
344 | + | |
345 | + throw new GeneralException(trans('exceptions.backend.access.users.mark_error')); | |
346 | + } | |
347 | + | |
348 | + /** | |
349 | + * @param Model $user | |
350 | + * | |
351 | + * @return bool | |
352 | + * @throws GeneralException | |
353 | + */ | |
354 | + public function confirm(Model $user) | |
355 | + { | |
356 | + if ($user->confirmed == 1) { | |
357 | + throw new GeneralException(trans('exceptions.backend.access.users.already_confirmed')); | |
358 | + } | |
359 | + | |
360 | + $user->confirmed = 1; | |
361 | + $confirmed = $user->save(); | |
362 | + | |
363 | + if ($confirmed) { | |
364 | + event(new UserConfirmed($user)); | |
365 | + | |
366 | + // Let user know their account was approved | |
367 | + if (config('access.users.requires_approval')) { | |
368 | + $user->notify(new UserAccountActive()); | |
369 | + } | |
370 | + | |
371 | + return true; | |
372 | + } | |
373 | + | |
374 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_confirm')); | |
375 | + } | |
376 | + | |
377 | + /** | |
378 | + * @param Model $user | |
379 | + * | |
380 | + * @return bool | |
381 | + * @throws GeneralException | |
382 | + */ | |
383 | + public function unconfirm(Model $user) | |
384 | + { | |
385 | + if ($user->confirmed == 0) { | |
386 | + throw new GeneralException(trans('exceptions.backend.access.users.not_confirmed')); | |
387 | + } | |
388 | + | |
389 | + if ($user->id == 1) { | |
390 | + // Cant un-confirm admin | |
391 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_unconfirm_admin')); | |
392 | + } | |
393 | + | |
394 | + if ($user->id == access()->id()) { | |
395 | + // Cant un-confirm self | |
396 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_unconfirm_self')); | |
397 | + } | |
398 | + | |
399 | + $user->confirmed = 0; | |
400 | + $unconfirmed = $user->save(); | |
401 | + | |
402 | + if ($unconfirmed) { | |
403 | + event(new UserUnconfirmed($user)); | |
404 | + | |
405 | + return true; | |
406 | + } | |
407 | + | |
408 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_unconfirm')); // TODO | |
409 | + } | |
410 | + | |
411 | + /** | |
412 | + * @param $input | |
413 | + * @param $user | |
414 | + * | |
415 | + * @throws GeneralException | |
416 | + */ | |
417 | + protected function checkUserByUsername($input, $user) | |
418 | + { | |
419 | + //Figure out if username is not the same | |
420 | + if ($user->username != $input['username']) { | |
421 | + //Check to see if username exists | |
422 | + if ($this->query()->where('username', '=', $input['username'])->first()) { | |
423 | + throw new GeneralException(trans('exceptions.backend.access.users.username_error')); | |
424 | + } | |
425 | + } | |
426 | + } | |
427 | + | |
428 | + /** | |
429 | + * @param $roles | |
430 | + * @param $user | |
431 | + */ | |
432 | + protected function flushRoles($roles, $user) | |
433 | + { | |
434 | + //Flush roles out, then add array of new ones | |
435 | + $user->detachRoles($user->roles); | |
436 | + $user->attachRoles($roles['assignees_roles']); | |
437 | + } | |
438 | + | |
439 | + /** | |
440 | + * @param $roles | |
441 | + * | |
442 | + * @throws GeneralException | |
443 | + */ | |
444 | + protected function checkUserRolesCount($roles) | |
445 | + { | |
446 | + //User Updated, Update Roles | |
447 | + //Validate that there's at least one role chosen | |
448 | + if (count($roles['assignees_roles']) == 0) { | |
449 | + throw new GeneralException(trans('exceptions.backend.access.users.role_needed')); | |
450 | + } | |
451 | + } | |
452 | + | |
453 | + /** | |
454 | + * @param $input | |
455 | + * | |
456 | + * @return mixed | |
457 | + */ | |
458 | + protected function createUserStub($input) | |
459 | + { | |
460 | + $user = self::MODEL; | |
461 | + $user = new $user; | |
462 | + $user->first_name = $input['first_name']; | |
463 | + $user->last_name = $input['last_name']; | |
464 | + $user->username = $input['username']; | |
465 | + $user->business_id = $input['business_id']; | |
466 | + $user->password = bcrypt($input['password']); | |
467 | + $user->status = isset($input['status']) ? 1 : 0; | |
468 | + return $user; | |
469 | + } | |
470 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Repository\User; | |
4 | + | |
5 | +use App\Access\Model\User\User; | |
6 | +use App\Exceptions\GeneralException; | |
7 | + | |
8 | +/** | |
9 | + * Class UserSessionRepository. | |
10 | + */ | |
11 | +class UserSessionRepository | |
12 | +{ | |
13 | + /** | |
14 | + * @param User $user | |
15 | + * | |
16 | + * @return mixed | |
17 | + * @throws GeneralException | |
18 | + */ | |
19 | + public function clearSession(User $user) | |
20 | + { | |
21 | + if ($user->id === access()->id()) { | |
22 | + throw new GeneralException(trans('exceptions.backend.access.users.cant_delete_own_session')); | |
23 | + } | |
24 | + | |
25 | + if (config('session.driver') != 'database') { | |
26 | + throw new GeneralException(trans('exceptions.backend.access.users.session_wrong_driver')); | |
27 | + } | |
28 | + | |
29 | + return $user->sessions()->delete(); | |
30 | + } | |
31 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Repository\User; | |
4 | + | |
5 | +use App\Access\Model\User\User; | |
6 | +use App\Exceptions\GeneralException; | |
7 | +use App\Access\Model\User\SocialLogin; | |
8 | +use App\Events\Backend\Access\User\UserSocialDeleted; | |
9 | + | |
10 | +/** | |
11 | + * Class UserSocialRepository. | |
12 | + */ | |
13 | +class UserSocialRepository | |
14 | +{ | |
15 | + /** | |
16 | + * @param User $user | |
17 | + * @param SocialLogin $social | |
18 | + * | |
19 | + * @return bool | |
20 | + * @throws GeneralException | |
21 | + */ | |
22 | + public function delete(User $user, SocialLogin $social) | |
23 | + { | |
24 | + if ($user->providers()->whereId($social->id)->delete()) { | |
25 | + event(new UserSocialDeleted($user, $social)); | |
26 | + | |
27 | + return true; | |
28 | + } | |
29 | + | |
30 | + throw new GeneralException(trans('exceptions.backend.access.users.social_delete_error')); | |
31 | + } | |
32 | +} | ... | ... |
app/Access/Service/Access.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Service; | |
4 | + | |
5 | +use App\Events\Frontend\Auth\UserLoggedIn; | |
6 | +use App\Events\Frontend\Auth\UserLoggedOut; | |
7 | +use Illuminate\Contracts\Auth\Authenticatable; | |
8 | + | |
9 | +/** | |
10 | + * Class Access. | |
11 | + */ | |
12 | +class Access | |
13 | +{ | |
14 | + /** | |
15 | + * Get the currently authenticated user or null. | |
16 | + */ | |
17 | + public function user() | |
18 | + { | |
19 | + return auth('web')->user(); | |
20 | + } | |
21 | + | |
22 | + /** | |
23 | + * Return if the current session user is a guest or not. | |
24 | + * | |
25 | + * @return mixed | |
26 | + */ | |
27 | + public function guest() | |
28 | + { | |
29 | + return auth('web')->guest(); | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * @return mixed | |
34 | + */ | |
35 | + public function logout() | |
36 | + { | |
37 | + event(new UserLoggedOut($this->user())); | |
38 | + | |
39 | + return auth('web')->logout(); | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * Get the currently authenticated user's id. | |
44 | + * | |
45 | + * @return mixed | |
46 | + */ | |
47 | + public function id() | |
48 | + { | |
49 | + return auth('web')->id(); | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * @param Authenticatable $user | |
54 | + * @param bool $remember | |
55 | + */ | |
56 | + public function login(Authenticatable $user, $remember = false) | |
57 | + { | |
58 | + $logged_in = auth('web')->login($user, $remember); | |
59 | + event(new UserLoggedIn($this->user())); | |
60 | + | |
61 | + return $logged_in; | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * @param $id | |
66 | + * | |
67 | + * @return mixed | |
68 | + */ | |
69 | + public function loginUsingId($id) | |
70 | + { | |
71 | + $logged_in = auth('web')->loginUsingId($id); | |
72 | + event(new UserLoggedIn($this->user())); | |
73 | + | |
74 | + return $logged_in; | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * Checks if the current user has a Role by its name or id. | |
79 | + * | |
80 | + * @param string $role Role name. | |
81 | + * | |
82 | + * @return bool | |
83 | + */ | |
84 | + public function hasRole($role) | |
85 | + { | |
86 | + if ($user = $this->user()) { | |
87 | + return $user->hasRole($role); | |
88 | + } | |
89 | + | |
90 | + return false; | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * Checks if the user has either one or more, or all of an array of roles. | |
95 | + * | |
96 | + * @param $roles | |
97 | + * @param bool $needsAll | |
98 | + * | |
99 | + * @return bool | |
100 | + */ | |
101 | + public function hasRoles($roles, $needsAll = false) | |
102 | + { | |
103 | + if ($user = $this->user()) { | |
104 | + return $user->hasRoles($roles, $needsAll); | |
105 | + } | |
106 | + | |
107 | + return false; | |
108 | + } | |
109 | + | |
110 | + /** | |
111 | + * Check if the current user has a permission by its name or id. | |
112 | + * | |
113 | + * @param string $permission Permission name or id. | |
114 | + * | |
115 | + * @return bool | |
116 | + */ | |
117 | + public function allow($permission) | |
118 | + { | |
119 | + if ($user = $this->user()) { | |
120 | + return $user->allow($permission); | |
121 | + } | |
122 | + | |
123 | + return false; | |
124 | + } | |
125 | + | |
126 | + /** | |
127 | + * Check an array of permissions and whether or not all are required to continue. | |
128 | + * | |
129 | + * @param $permissions | |
130 | + * @param $needsAll | |
131 | + * | |
132 | + * @return bool | |
133 | + */ | |
134 | + public function allowMultiple($permissions, $needsAll = false) | |
135 | + { | |
136 | + if ($user = $this->user()) { | |
137 | + return $user->allowMultiple($permissions, $needsAll); | |
138 | + } | |
139 | + | |
140 | + return false; | |
141 | + } | |
142 | + | |
143 | + /** | |
144 | + * @param $permission | |
145 | + * | |
146 | + * @return bool | |
147 | + */ | |
148 | + public function hasPermission($permission) | |
149 | + { | |
150 | + return $this->allow($permission); | |
151 | + } | |
152 | + | |
153 | + /** | |
154 | + * @param $permissions | |
155 | + * @param $needsAll | |
156 | + * | |
157 | + * @return bool | |
158 | + */ | |
159 | + public function hasPermissions($permissions, $needsAll = false) | |
160 | + { | |
161 | + return $this->allowMultiple($permissions, $needsAll); | |
162 | + } | |
163 | +} | ... | ... |
app/Access/Service/Facades/Access.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Access\Service\Facades; | |
4 | + | |
5 | +use Illuminate\Support\Facades\Facade; | |
6 | + | |
7 | +/** | |
8 | + * Class Access. | |
9 | + */ | |
10 | +class Access extends Facade | |
11 | +{ | |
12 | + /** | |
13 | + * Get the registered name of the component. | |
14 | + * | |
15 | + * @return string | |
16 | + */ | |
17 | + protected static function getFacadeAccessor() | |
18 | + { | |
19 | + return 'access'; | |
20 | + } | |
21 | +} | ... | ... |
app/Certs/Alipay/alipay_mch_private_key.pem
0 → 100644
1 | +-----BEGIN RSA PRIVATE KEY----- | |
2 | +MIIEpAIBAAKCAQEA4G2FytLndzQPksUkOlAtv1WbQYsg4M5YUcWOcFn/fJlGUNZrHWV3V+7zHP/tdm30ecaQbIodjhnzsQZ/TumF55x+4AeTeqLFuS0DELYkJn3rX/r3xNviaP+1Dkuqon/RgmAIzh0XAU2DJIZ6otooqhA2ZtonFl+T5xKH9bPBATOyupZQ1YGsS+dpGtt9Pk1zla5xTU70s7r6z5GnWKQTekGAgxYt2NT7zjEf/I8nfAmEXpvMwDOhZnNgav47lkDmogn+CXNdwMiOLGhl/G/ZdumgE9gk4QIBO/oQtrYtbNyZbCBg5eqZiN6cOXOmyfey3zYaI0TcQPte15oIHS35hQIDAQABAoIBABUqnzS64XO/qDxadYk+aKIkC8mJuqcZLwE/VajJBCyXNCeJoX6bRD853Rn+FUJXKniVvqdN+22civxGNZmWsrdebiTo8gLd+TH2ydQ4qX4r4BgkTlv1tQvcGhJoFobO8U6PiiUOX04TJmw6drSHSNCJSOg4aPlWOFfRyprkwi4/qbWloxuUSPQ0+zmdaGxaqbe79UKzigzqsVXVgSFopOZlB/OcDMWvvAd1zawW5CDteDhFomOB0zLgqsO+fTCgIVOvOpKP7TYu+uTL2eu9weRDrQhzsW3grhhPke2nTbNp78XW2mUdNld8fHib24frYsfW9718uddLyFoy5E2YjKECgYEA+/JE86Q+M7WjxwGeW6hQk2qAI526FRP0SeYajIBambLF7IniEMQaSwSSPZEqpeG2RZiG/bCyqzkb75g+vJ/APeF/ytJK+8FJcgQGUxaY4lOSPmgqa8y0XfOHbCqGvZ4IjC9B/fMBCGT1YFeTVDXa6NuFtK/xEHtoo80iUdwo4g0CgYEA5AnojBFbI757pyB16aQbhX1oVEkKbQuN8GH+/w639tD4WpWDHzREqceuU92jsy/REJAUSNJHvDSNwOg7qubgAO/l7bnZkz0Tdp9NdbHf2AhliK4sy8a5aBkfLVbpwh2eczdgLbAKL1NCE19Qw71eEzsTBzUZbOzkyvIlRVSTL1kCgYA99Y2ZcVnOs6vMRAyis9jk9/r9R0u85URdbBY5WVNumvVrv1j2EJP6wOwJ8gpP8xs1MFZ6SxsVWp0RJhq/nnXTggJAackA8r7SKEU558O/XRgI+ur7ycLNnBdAtZCfTx8BApozDrDBVLq3b7IOspPcUigmkGIzUHYiWk9HXGI9fQKBgQCkw2P6kC/By8ecIaAQiDo6YToYbA3UbBzKKoQL1Z6l/qbzDEQJL8LMyTHz9phox4vO48tEMmsSWQZy81jpSpdfFfaTpUzHTcHaW4+kEjkh5i82amKDebpMtJoKMFoFn1D0/nXHjQJO32FGjf/U7eYjDvPYqU0NnrxQxlSXm1wdQQKBgQC90UO5iFrrZK3I+dxygV+7k0Bjre5lBWG7IMKhAJgZj2NygpRJ/O3FVfbuhL4iCYBNTlb+pggp0y00g07n915j3aQ/aYk+HEoqE0pQ8zIGpIoTHM343GOH43yyeVe5/ID4K1bxCZ2H3jiNTM7UdO0YZjM3P4MYYQXU18IOlDExAQ== | |
3 | +-----END RSA PRIVATE KEY----- | |
\ No newline at end of file | ... | ... |
app/Certs/Alipay/alipay_mch_public_key.pem
0 → 100644
1 | +-----BEGIN PUBLIC KEY----- | |
2 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4G2FytLndzQPksUkOlAtv1WbQYsg4M5YUcWOcFn/fJlGUNZrHWV3V+7zHP/tdm30ecaQbIodjhnzsQZ/TumF55x+4AeTeqLFuS0DELYkJn3rX/r3xNviaP+1Dkuqon/RgmAIzh0XAU2DJIZ6otooqhA2ZtonFl+T5xKH9bPBATOyupZQ1YGsS+dpGtt9Pk1zla5xTU70s7r6z5GnWKQTekGAgxYt2NT7zjEf/I8nfAmEXpvMwDOhZnNgav47lkDmogn+CXNdwMiOLGhl/G/ZdumgE9gk4QIBO/oQtrYtbNyZbCBg5eqZiN6cOXOmyfey3zYaI0TcQPte15oIHS35hQIDAQAB | |
3 | +-----END RSA PUBLIC KEY----- | |
\ No newline at end of file | ... | ... |
app/Certs/Alipay/alipay_public_key.pem
0 → 100644
1 | +-----BEGIN PUBLIC KEY----- | |
2 | +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2J8XSVliMFk51D6BTB2otLINtmIJYWjgDzOhSJbENz8zevWbMFndLfbkBdutmHrlsZM1wSn7tR3wugs0px1EaX9c9hBuET+7fIlya8sc7iUaJiI+S5sL60vK2A5yM8Rlx2yJNg4MYgMjty0wFogQd2V9aCThriW796rYLuqIHrgt5DWSaBYYuvZDQjYdvnd1p4agJOEux1LfVjtkcgu9UBfwg5oWL5RZpWiI5tR7MG0JOzZbrAY+EPOtOnh5tWoEjOZiQD6E0XcmOO4jOxI7x5DJ2om+AHHU3cpVUqRt/F6tKbnxuv8R406ZQZyJ5omK3/8G+ibb8keYuv+qMzHANwIDAQAB | |
3 | +-----END PUBLIC KEY----- | |
\ No newline at end of file | ... | ... |
app/Certs/Wechat/apiclient_cert.pem
0 → 100644
1 | +-----BEGIN CERTIFICATE----- | |
2 | +MIIEaTCCA9KgAwIBAgIEAV8JPjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC | |
3 | +Q04xEjAQBgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNV | |
4 | +BAoTB1RlbmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEf | |
5 | +MB0GCSqGSIb3DQEJARYQbW1wYXltY2hAdGVuY2VudDAeFw0xNzA3MDUwODEwMjVa | |
6 | +Fw0yNzA3MDMwODEwMjVaMIGYMQswCQYDVQQGEwJDTjESMBAGA1UECBMJR3Vhbmdk | |
7 | +b25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UEChMHVGVuY2VudDEOMAwGA1UE | |
8 | +CxMFTU1QYXkxLTArBgNVBAMUJOaxn+iLj+S8mOWNoeWFheeJqeiBlOe9keaciemZ | |
9 | +kOWFrOWPuDERMA8GA1UEBBMIMzQ4MzI1NjEwggEiMA0GCSqGSIb3DQEBAQUAA4IB | |
10 | +DwAwggEKAoIBAQDraDvMFsfhbtsS01fYAHO1OWyFHSxbaZDqQT7tIPilbh2OMlqA | |
11 | +Tucat4aScMrpuQunNf/4FBndIJIAVMKDkmkpVPMth5ibQx3xPwdSLYi/FYA0G8N2 | |
12 | +urGwypwpBXfpRdvziS4ZbnpSyHLxU2TovMqRF4SwPgZYUXeayrzj0foMou0Sb2md | |
13 | +dnLnaChgKFsbktT6F+2mB1j9hei3YtACqneyiN49lCoeqHzShBG8CLjNZUQa8YwQ | |
14 | +zS/l49EE4szgI1FvKRPyMXxhjVqrrfDitXiB9bSUvwwUuD2xjYSbtUvC8yB5xBrw | |
15 | +AXeYZl8sq2pSIDp4Z5pZpheoYtm94K1QyMMJAgMBAAGjggFGMIIBQjAJBgNVHRME | |
16 | +AjAAMCwGCWCGSAGG+EIBDQQfFh0iQ0VTLUNBIEdlbmVyYXRlIENlcnRpZmljYXRl | |
17 | +IjAdBgNVHQ4EFgQUEcZOEiba6FQC/bjYVthBS+MSN4kwgb8GA1UdIwSBtzCBtIAU | |
18 | +PgUm9iJitBVbiM1kfrDUYqflhnShgZCkgY0wgYoxCzAJBgNVBAYTAkNOMRIwEAYD | |
19 | +VQQIEwlHdWFuZ2RvbmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdUZW5j | |
20 | +ZW50MQwwCgYDVQQLEwNXWEcxEzARBgNVBAMTCk1tcGF5bWNoQ0ExHzAdBgkqhkiG | |
21 | +9w0BCQEWEG1tcGF5bWNoQHRlbmNlbnSCCQC7VJcrvADoVzAOBgNVHQ8BAf8EBAMC | |
22 | +BsAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEAwr6V | |
23 | +4nnw4A/b41CvWyqbeAoOutTFjeEBoT+zPctv1T0WeUc1BDkC8vAPOullnnyiWiDv | |
24 | +HUlm05PMvcA0Msrp4WpsAOi59zQI9opAnGxX1T44ynTnF0IJe5hFcpBO7m4oIyOg | |
25 | +GZ5dhje09XbRzDqNvtfv/Qu3mTaXInLDzFUMFug= | |
26 | +-----END CERTIFICATE----- | ... | ... |
app/Certs/Wechat/apiclient_cert_new.pem
0 → 100644
1 | +-----BEGIN CERTIFICATE----- | |
2 | +MIIEbDCCA9WgAwIBAgIEAWJK2zANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC | |
3 | +Q04xEjAQBgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNV | |
4 | +BAoTB1RlbmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEf | |
5 | +MB0GCSqGSIb3DQEJARYQbW1wYXltY2hAdGVuY2VudDAeFw0xNzA4MDcwOTAwNDZa | |
6 | +Fw0yNzA4MDUwOTAwNDZaMIGbMQswCQYDVQQGEwJDTjESMBAGA1UECBMJR3Vhbmdk | |
7 | +b25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UEChMHVGVuY2VudDEOMAwGA1UE | |
8 | +CxMFTU1QYXkxMDAuBgNVBAMUJ+iLj+W3numaj+i6q+eOqeS/oeaBr+aKgOacr+ac | |
9 | +iemZkOWFrOWPuDERMA8GA1UEBBMINDEyOTEyMTcwggEiMA0GCSqGSIb3DQEBAQUA | |
10 | +A4IBDwAwggEKAoIBAQDeUEFC0H3NiPALgWZQGtAEFoyiAMEcGKWKxDAXA+7RTzkH | |
11 | +Y6rRqWa4UtmLn+y2Dq3Bqj0JV9/hpxH4XDGmyVEPoeX1vrvjY+hZa5vsHo5iAowC | |
12 | ++/5tfbSK0MCIqLVu32RUL/2XNKzu1uI9qJCyG5S5xviwY+LUsIiQVSYS68xxPmQi | |
13 | +UvB/Si7nPVu8flQp/CErGj67+UnfRstzdlXmIedVZI2B/zDY36GWz99OcC1vKAoH | |
14 | +1Qyr0djSPKUjBW728SgKgt7koS1DV4tQdd+Z3d0JUMaf1xC3HQgYxrIsOAo/mRki | |
15 | +fCvRG19WB6UgQn57pAPQ1aRmc8uHoc4K0t5PG3z3AgMBAAGjggFGMIIBQjAJBgNV | |
16 | +HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh0iQ0VTLUNBIEdlbmVyYXRlIENlcnRpZmlj | |
17 | +YXRlIjAdBgNVHQ4EFgQUkwjPtBG/QHSUDjRnzQs7jkYgkHwwgb8GA1UdIwSBtzCB | |
18 | +tIAUPgUm9iJitBVbiM1kfrDUYqflhnShgZCkgY0wgYoxCzAJBgNVBAYTAkNOMRIw | |
19 | +EAYDVQQIEwlHdWFuZ2RvbmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdU | |
20 | +ZW5jZW50MQwwCgYDVQQLEwNXWEcxEzARBgNVBAMTCk1tcGF5bWNoQ0ExHzAdBgkq | |
21 | +hkiG9w0BCQEWEG1tcGF5bWNoQHRlbmNlbnSCCQC7VJcrvADoVzAOBgNVHQ8BAf8E | |
22 | +BAMCBsAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEA | |
23 | +NkWBjd8qNtg5LT8u+lns5kmoqMgJmPqWsLkeAdDzGQgk0umVIivnbvjBK9gyQDo8 | |
24 | +M3uQjHDOeoL9kpYQoZCzcC/0NqMluXjmvfXiarc1lv2RYu4nNoUVp4ix/15dFhML | |
25 | +pS65pTZ3LXXDigY76nFOu6XztJNvylnDZ/c7nejsC3g= | |
26 | +-----END CERTIFICATE----- | ... | ... |
app/Certs/Wechat/apiclient_key.pem
0 → 100644
1 | +-----BEGIN PRIVATE KEY----- | |
2 | +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDraDvMFsfhbtsS | |
3 | +01fYAHO1OWyFHSxbaZDqQT7tIPilbh2OMlqATucat4aScMrpuQunNf/4FBndIJIA | |
4 | +VMKDkmkpVPMth5ibQx3xPwdSLYi/FYA0G8N2urGwypwpBXfpRdvziS4ZbnpSyHLx | |
5 | +U2TovMqRF4SwPgZYUXeayrzj0foMou0Sb2mddnLnaChgKFsbktT6F+2mB1j9hei3 | |
6 | +YtACqneyiN49lCoeqHzShBG8CLjNZUQa8YwQzS/l49EE4szgI1FvKRPyMXxhjVqr | |
7 | +rfDitXiB9bSUvwwUuD2xjYSbtUvC8yB5xBrwAXeYZl8sq2pSIDp4Z5pZpheoYtm9 | |
8 | +4K1QyMMJAgMBAAECggEBAMO6BI3qGwLKwwdiBVWo+ouhVSNQYEMZAM5ktUc/9LzH | |
9 | +U3eZUjoAYJKMKS207mFp49CBS3Qecmqy2/G+h4QRxbIB2bbvWOku4sRk3VdsWJhX | |
10 | +7iJlOx2KmJcfvrs0usCPvxM76cJnYvlVhIw2BF6mKd59KWvIBkqEYeenzWm2eirp | |
11 | +6+4f87Re72162zBNRpJ9T4og9sPbOGWEgw07tGJ+1rCFWoJAgWvMOBdjFTUXGlS0 | |
12 | +gTcQBDH/2EHtbeWqTfHOTV4IdY5m78fxPfyThzyFcn/y4x0jYxyK8LrLuPXWVRYV | |
13 | +FB5z2T325c44tHefVs2UGbIOJaMkN/VeFDoSc/d2WQECgYEA9fhH3y4lHuqprPRD | |
14 | +Bi30964xMUyTuBeShL+XuB+OHEDxppDBbUY5Ze9jsYt77OuaAUghkmihIzUSi+gX | |
15 | +bKNBDRg0qctUUvrSii3dFyOjBddjugJO2FQfR9wPHNbpkNmXhoCDUQBl7pyL++g/ | |
16 | +VY5o6pwyeXSzQmhQWmpBmDpiLvECgYEA9QGv7+TJRZJPz2/grTAfp38SHSeiC23a | |
17 | +eBO5iJgHe425B5ZLsl4DJWpl+ILNk6Cz08WHnlDyX9bCyCWipSiYpF4RiRSCwoSY | |
18 | +c+lPlAkcbmmixjTvJNdCzOVX01uGHlv0Dd5q6dsV5zQuVvm5IMv4ma0Yexn0DKIv | |
19 | ++afC6PQwBZkCgYA++k8Mqbf/bn37Np9imam7MPKPeNfprr9pFdU2431zZn149F9S | |
20 | +J0TTALQ55UjZpIlOArX10qxPY2tYPxigTDx/qc7yGomApY/6qTuOjSVUfY2fNrAR | |
21 | +W5iWwZVtAOnUmKHfYlA9ESkIKzT8Tr7InSnnyA50YpjzS9onDEW3QFubQQKBgBpq | |
22 | +dietSS4hGk3JSDYkDCWpA7D1BvmofHeZ2NUrXxMpMpvoznyKulgcYqYqpDOYjgr1 | |
23 | +LywYmilPJG0j8adQ+zQtmEJpXbfPSAinTRcu7EvTQ+OO7YHRW7hvucpmAc3gKC4e | |
24 | +nvRb1L6614w1HIq2szUOfqc3IyMBkZ6fQdqQCWVxAoGABNpxtkmltmW/ITwKqbrJ | |
25 | +Y/z6YKT4a0pt8dGGBgA7UhqzUUIB1go7zQsliuPuKwYZLM6MyVLNMcFEA4oCUv1r | |
26 | +Ddl/H6DXPshPaA2MhDbMM3GFy1JITTJ4LlUg1qppUMnh6DKTZNF/wzkitGQhHAb8 | |
27 | +5Cnk44Gw1/YdRTjqDnRUQNs= | |
28 | +-----END PRIVATE KEY----- | ... | ... |
app/Certs/Wechat/apiclient_key_new.pem
0 → 100644
1 | +-----BEGIN PRIVATE KEY----- | |
2 | +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDeUEFC0H3NiPAL | |
3 | +gWZQGtAEFoyiAMEcGKWKxDAXA+7RTzkHY6rRqWa4UtmLn+y2Dq3Bqj0JV9/hpxH4 | |
4 | +XDGmyVEPoeX1vrvjY+hZa5vsHo5iAowC+/5tfbSK0MCIqLVu32RUL/2XNKzu1uI9 | |
5 | +qJCyG5S5xviwY+LUsIiQVSYS68xxPmQiUvB/Si7nPVu8flQp/CErGj67+UnfRstz | |
6 | +dlXmIedVZI2B/zDY36GWz99OcC1vKAoH1Qyr0djSPKUjBW728SgKgt7koS1DV4tQ | |
7 | +dd+Z3d0JUMaf1xC3HQgYxrIsOAo/mRkifCvRG19WB6UgQn57pAPQ1aRmc8uHoc4K | |
8 | +0t5PG3z3AgMBAAECggEAIepAan8AEjEH3dl50FKm1VjTT4up6i1gY9EWPQyejFP3 | |
9 | +sUblMmMThp8tDP3y0LtgiqD7+sbrIrOoLCl0catYsHfUay8T3tbJBYtDGDx5ID6f | |
10 | +OX1UDUQWHO9H0BFczHNMDQPdPgoNL8qcbSegG2vVvpm6Kr6yRhxAWTSEQHK0l7nS | |
11 | +F30WM0uTtu4iaJi71MCvZZSHiRkr1hJettfeECJYZoCxxKpI/+DXV2bi1xVbyBTl | |
12 | +k4/n6sBV7lSS5ELsm4RGkV9YIMuHmjeV0qGn4pnvt79tCK72KAP5a06OorrVHUqH | |
13 | +IKymJqi8MTPceI4h2D2Q3XN0YUUjAsko2bg54kQBgQKBgQD4dck0IizWQdu2fb3W | |
14 | +n/42I7XEA9YtgXuiQRAnSgzTi6Yk98vcVyDDUi4xfw8JzxvPSpIlItJVEEiQSJOt | |
15 | +9nK6VXW5ZAGiG6C2RKrtZ4bWEYmp57C0mu3Q3X7NBez/mRkvkc2p64ZN4o9p4pBL | |
16 | +NKow0EFH+0LaTVHkgef39Qh91wKBgQDlD1f3p8jtClIYMYKrLjW7wUmd2+o+VpFT | |
17 | +Dkfx39Kx9GzS0UdpwUAXdrWX8a9q33raMj0hih5GSc0hYOA+TVZ7feZxwDwvfsra | |
18 | +uY/9Z7ShoYKs35Tz0i6quqQtbOz47bDo63uvivf8C/juXR+tdJFt8Dw7he9v7IT5 | |
19 | +sduzVXfV4QKBgQCGJFmf+v+IIgB0k4jF8pV2N2twS737zZepb0VAYRtxr0jhVqPK | |
20 | +74Nx0NG9yWKeIiJalWE4CYfTgzoaJAUPfCpO7crkb9jt48qt/X7nM+i5dLiFceCW | |
21 | +cbsJ9Dv8h0GAcfEGHMsT/WQCctqJCVhsMh/cwOMt8LsUT4ByRayu061k+wKBgQC0 | |
22 | +Pz22uUZoGS3+sb8kWwmXhIMcgHg0s8RJujws/jb7J98Wie6LLrHzhMtjFKE4FUHE | |
23 | +P7JRGTG3l82ejXAINq1uIeVb76yspzaTpV/ERX4jjkeZJ5s7vlJQsOwOft9/BvOm | |
24 | +Zd9/hHid0wIA+DC8OrVR8LBFGqEOzuzY2/eJiCDzoQKBgQDmPl4D02GIeORgO46R | |
25 | +/SVVMdK4/wz9OhwaWX2NNkHi6d5YZjR+e0w7XmmmT1n8C+Dcf0i3EdSCH2ci9kYU | |
26 | +dQ5A0wHPVYX1tw6yeqQYXYyfVHwcLCZO4sTJXUwD2OZ4AncjhI3PG1YnhJUov0Y8 | |
27 | +dVXi8bkgyP/Wo47YevasN7t2qQ== | |
28 | +-----END PRIVATE KEY----- | ... | ... |
app/Common/Alipay.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 13/03/2017 | |
6 | + * Time: 1:40 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +/** | |
13 | + * Class Alipay | |
14 | + * @package App\Common | |
15 | + */ | |
16 | +/** | |
17 | + * Class Alipay | |
18 | + * @package App\Common | |
19 | + */ | |
20 | + | |
21 | +use App\Common\Enums\AlipayLoginType; | |
22 | +use App\Common\Util\OrderUtil; | |
23 | +use Illuminate\Support\Facades\Log; | |
24 | + | |
25 | +/** | |
26 | + * Class Alipay | |
27 | + * @package App\Common | |
28 | + */ | |
29 | +class Alipay | |
30 | +{ | |
31 | + /** | |
32 | + * order Id | |
33 | + * @var | |
34 | + */ | |
35 | + private $order_id; | |
36 | + | |
37 | + /** | |
38 | + * Order price | |
39 | + * @var | |
40 | + */ | |
41 | + private $price; | |
42 | + | |
43 | + /** | |
44 | + * pay description | |
45 | + * @var | |
46 | + */ | |
47 | + private $body; | |
48 | + | |
49 | + /** | |
50 | + * @var | |
51 | + */ | |
52 | + private $subject; | |
53 | + | |
54 | + /** | |
55 | + * Callback Url | |
56 | + * @var | |
57 | + */ | |
58 | + private $call_back_url; | |
59 | + | |
60 | + /** | |
61 | + * @var | |
62 | + */ | |
63 | + private $refund_fee; | |
64 | + | |
65 | + /** | |
66 | + * @var | |
67 | + */ | |
68 | + private $refund_id; | |
69 | + | |
70 | + /** | |
71 | + * @var | |
72 | + */ | |
73 | + private $op_user_id; | |
74 | + | |
75 | + /** | |
76 | + * @var | |
77 | + */ | |
78 | + private $pay_no; | |
79 | + | |
80 | + /** | |
81 | + * WechatPay constructor. | |
82 | + * @param $order_id | |
83 | + * @param $price | |
84 | + * @param $body | |
85 | + * @param $call_back_url | |
86 | + */ | |
87 | + public function __construct($order_id="", $price=0, $body="", $call_back_url="", $subject="") | |
88 | + { | |
89 | + $this->order_id = $order_id; | |
90 | + $this->price = $price; | |
91 | + $this->body = $body; | |
92 | + $this->call_back_url = $call_back_url; | |
93 | + $this->subject = $subject; | |
94 | + } | |
95 | + | |
96 | + /** | |
97 | + * @param mixed $refund_fee | |
98 | + */ | |
99 | + public function setRefundFee($refund_fee) | |
100 | + { | |
101 | + $this->refund_fee = $refund_fee; | |
102 | + } | |
103 | + | |
104 | + /** | |
105 | + * @param mixed $op_user_id | |
106 | + */ | |
107 | + public function setOpUserId($op_user_id) | |
108 | + { | |
109 | + $this->op_user_id = $op_user_id; | |
110 | + } | |
111 | + | |
112 | + /** | |
113 | + * @param mixed $refund_id | |
114 | + */ | |
115 | + public function setRefundId($refund_id) | |
116 | + { | |
117 | + $this->refund_id = $refund_id; | |
118 | + } | |
119 | + | |
120 | + /** | |
121 | + * @param mixed $pay_no | |
122 | + */ | |
123 | + public function setPayNo($pay_no) | |
124 | + { | |
125 | + $this->pay_no = $pay_no; | |
126 | + } | |
127 | + | |
128 | + /** | |
129 | + * @param $success | |
130 | + * @param $error_messge | |
131 | + * @param string $payInfo | |
132 | + * @return array | |
133 | + */ | |
134 | + private function response($success, $error_messge, $payInfo="") | |
135 | + { | |
136 | + $result = array('success'=>$success, 'error_message'=>$error_messge, 'payInfo'=>$payInfo); | |
137 | + | |
138 | + return $result; | |
139 | + } | |
140 | + | |
141 | + /** | |
142 | + * @param $type | |
143 | + * @return \AopClient | |
144 | + */ | |
145 | + private function getAopClient($type = AlipayLoginType::APP) | |
146 | + { | |
147 | + $aop = new \AopClient(); | |
148 | + $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; | |
149 | + $aop->appId = $type == AlipayLoginType::APP ? config('constants.alipay.app_id') : config('constants.alipay.app_miniprogram_id'); | |
150 | + $aop->rsaPrivateKeyFilePath = $type == AlipayLoginType::APP ? config('constants.alipay.alipay_mch_private_key') : config('constants.alipay.alipay_miniprogram_private_key'); | |
151 | + $aop->format = "json"; | |
152 | + $aop->charset = "UTF-8"; | |
153 | + $aop->signType = "RSA2"; | |
154 | + $aop->alipayPublicKey=config('constants.alipay.alipay_pub_key'); | |
155 | + | |
156 | + return $aop; | |
157 | + } | |
158 | + | |
159 | + /** | |
160 | + * 获取第三方登录字串 | |
161 | + * | |
162 | + * @return string | |
163 | + */ | |
164 | + public function getAppAuthCode() | |
165 | + { | |
166 | + $params = array( | |
167 | + "apiname" => 'com.alipay.account.auth', | |
168 | + "method" => 'alipay.open.auth.sdk.code.get', | |
169 | + "app_id"=> config('constants.alipay.app_id'), | |
170 | + "app_name"=>'mc', | |
171 | + "biz_type" => 'openservice', | |
172 | + 'pid' => '2088721389489661', | |
173 | + 'product_id' => 'APP_FAST_LOGIN', | |
174 | + 'scope' => 'kuaijie', | |
175 | + 'target_id' => OrderUtil::generateCosumeOrderId(), | |
176 | + "auth_type" => 'AUTHACCOUNT', | |
177 | + "sign_type" => 'RSA2' | |
178 | + ); | |
179 | + | |
180 | + $aop = $this->getAopClient(); | |
181 | + $sign = $aop->generateSign($params, 'RSA2'); | |
182 | + $params['sign'] = $sign; | |
183 | + | |
184 | + return http_build_query($params); | |
185 | + } | |
186 | + | |
187 | + /** | |
188 | + * 无线账户授权 | |
189 | + * | |
190 | + * @param $code | |
191 | + * @param $type | |
192 | + * @return bool|mixed|\SimpleXMLElement | |
193 | + */ | |
194 | + public function alipaySystemAccountAuth($code, $type = AlipayLoginType::APP) | |
195 | + { | |
196 | + $aop = $this->getAopClient($type); | |
197 | + | |
198 | + $request = new \AlipaySystemOauthTokenRequest(); | |
199 | + $request->setCode($code); | |
200 | + $request->setGrantType('authorization_code'); | |
201 | + | |
202 | + $response = $aop->execute($request); | |
203 | + | |
204 | + Log::info('response is $response!'); | |
205 | + | |
206 | + if (isset($response->alipay_system_oauth_token_response)) | |
207 | + { | |
208 | + return ['access_token' => $response->alipay_system_oauth_token_response->access_token, 'user_id'=> $response->alipay_system_oauth_token_response->user_id]; | |
209 | + } | |
210 | + | |
211 | + return false; | |
212 | + } | |
213 | + | |
214 | + /** | |
215 | + * 用户信息共享 | |
216 | + * | |
217 | + * @param $access_token | |
218 | + * @param $type | |
219 | + * @return bool|mixed|\SimpleXMLElement | |
220 | + */ | |
221 | + public function alipayUserInfoShare($access_token, $type = AlipayLoginType::APP) | |
222 | + { | |
223 | + $aop = $this->getAopClient($type); | |
224 | + $request = new \AlipayUserInfoShareRequest(); | |
225 | + | |
226 | + $response = $aop->execute($request, $access_token); | |
227 | + | |
228 | + Log::info('response is $response!'); | |
229 | + | |
230 | + if (isset($response->alipay_user_info_share_response)) | |
231 | + { | |
232 | + return (array)$response->alipay_user_info_share_response; | |
233 | + } | |
234 | + | |
235 | + return false; | |
236 | + } | |
237 | + | |
238 | + /** | |
239 | + * @param $property_id | |
240 | + * @return array|bool | |
241 | + */ | |
242 | + public function alipayTradePrecreate($property_id) | |
243 | + { | |
244 | + $aop = $this->getAopClient(); | |
245 | + | |
246 | + $bizContent = $this->getPrecreateAppBizContent($property_id); | |
247 | + $request = new \AlipayTradePrecreateRequest(); | |
248 | + $request->setNotifyUrl($this->call_back_url); | |
249 | + $request->setBizContent($bizContent); | |
250 | + | |
251 | + $response = $aop->execute($request); | |
252 | + if (isset($response->alipay_trade_precreate_response)) | |
253 | + { | |
254 | + return (array)$response->alipay_trade_precreate_response; | |
255 | + } | |
256 | + | |
257 | + return false; | |
258 | + } | |
259 | + | |
260 | + /** | |
261 | + * @param $property_id | |
262 | + * | |
263 | + * @return string | |
264 | + */ | |
265 | + private function getPrecreateAppBizContent($property_id) | |
266 | + { | |
267 | + $param = array( | |
268 | + "out_trade_no"=>$this->order_id, | |
269 | + "subject" => "优卡充充值", | |
270 | + 'store_id' => $property_id, | |
271 | + "total_amount" => $this->price, | |
272 | + "timeout_express" => "10m", | |
273 | + ); | |
274 | + | |
275 | + return json_encode($param); | |
276 | + } | |
277 | + | |
278 | + /** | |
279 | + * @return mixed | |
280 | + */ | |
281 | + public function getUnifiedOrderInfo() | |
282 | + { | |
283 | + $aop = $this->getAopClient(); | |
284 | + $request = new \AlipayTradeAppPayRequest(); | |
285 | + | |
286 | + $bizContent = $this->getAppBizContent(); | |
287 | + $request->setNotifyUrl($this->call_back_url); | |
288 | + $request->setBizContent($bizContent); | |
289 | + | |
290 | + $response = $aop->sdkExecute($request); | |
291 | + return $this->response("success", "", $response); | |
292 | + } | |
293 | + | |
294 | + /** | |
295 | + * @return string | |
296 | + */ | |
297 | + private function getAppBizContent() | |
298 | + { | |
299 | + $param = array( | |
300 | + "body" => $this->body, | |
301 | + "subject" => $this->body, | |
302 | + "out_trade_no"=>$this->order_id, | |
303 | + "timeout_express" => "40m", | |
304 | + "total_amount" => $this->price, | |
305 | + "product_code" => "QUICK_MSECURITY_PAY" | |
306 | + ); | |
307 | + | |
308 | + return json_encode($param); | |
309 | + } | |
310 | + | |
311 | + | |
312 | + /** | |
313 | + * @param $input | |
314 | + * @return bool | |
315 | + */ | |
316 | + public function checkSign($input) | |
317 | + { | |
318 | + $aop = new \AopClient(); | |
319 | + $aop->alipayPublicKey=config('constants.alipay.alipay_pub_key'); | |
320 | + $flag = $aop->rsaCheckV1($input, config('constants.alipay.alipay_pub_key'), "RSA2"); | |
321 | + | |
322 | + return $flag; | |
323 | + } | |
324 | + | |
325 | + /** | |
326 | + * | |
327 | + */ | |
328 | + public function refund() | |
329 | + { | |
330 | + $aop = new \AopClient(); | |
331 | + $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; | |
332 | + $aop->appId = config('constants.alipay.app_id'); | |
333 | + $aop->rsaPrivateKeyFilePath = config('constants.alipay.alipay_mch_private_key'); | |
334 | + $aop->alipayPublicKey= config('constants.alipay.alipay_pub_key'); | |
335 | + $aop->postCharset='UTF-8'; | |
336 | + $aop->format='json'; | |
337 | + $request = new \AlipayTradeRefundRequest(); | |
338 | + | |
339 | + $bizContent = $this->getRefundBizContent(); | |
340 | + $request->setBizContent($bizContent); | |
341 | + $response = $aop->execute ( $request); | |
342 | + | |
343 | + $this->response(true, "", htmlspecialchars($response)); | |
344 | + } | |
345 | + | |
346 | + /** | |
347 | + * @return string | |
348 | + */ | |
349 | + private function getRefundBizContent() | |
350 | + { | |
351 | + $param = array( | |
352 | + "out_trade_no" => $this->order_id, | |
353 | + "trade_no" => $this->pay_no, | |
354 | + "refund_amount"=>$this->refund_fee, | |
355 | + "refund_reason" => "refund", | |
356 | + "out_request_no" => $this->refund_id, | |
357 | + "operator_id" => "OP001", | |
358 | + "store_id" => "NJ_S_001", | |
359 | + "terminal_id" => "NJ_T_001" | |
360 | + ); | |
361 | + | |
362 | + return json_encode($param); | |
363 | + } | |
364 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Amap.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 11:47 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +class Amap | |
13 | +{ | |
14 | + public static function getAdCodeUsingLatAndLng($lat, $lng) | |
15 | + { | |
16 | + $url = config('constants.amap.url').'?key='.config('constants.amap.key').'&location='.$lng.','.$lat; | |
17 | + $result = Http::Get($url); | |
18 | + | |
19 | + $result = json_decode($result, true); | |
20 | + | |
21 | + return $result['regeocode']['addressComponent']['adcode']; | |
22 | + } | |
23 | +} | |
24 | + | ... | ... |
app/Common/Byte.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 20/03/2017 | |
6 | + * Time: 2:17 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +class Byte | |
13 | +{ | |
14 | + /** | |
15 | + * 转换一个String字符串为byte数组(10进制) | |
16 | + * @param $str | |
17 | + * @return array | |
18 | + */ | |
19 | + public static function getBytes_10($str) { | |
20 | + $len = strlen($str); | |
21 | + $bytes = array(); | |
22 | + for($i=0;$i<$len;$i++) { | |
23 | + if(ord($str[$i]) >= 128){ | |
24 | + $byte = ord($str[$i]) - 256; | |
25 | + }else{ | |
26 | + $byte = ord($str[$i]); | |
27 | + } | |
28 | + $bytes[] = $byte ; | |
29 | + } | |
30 | + return $bytes; | |
31 | + } | |
32 | + | |
33 | + | |
34 | + /** | |
35 | + * 转换一个String字符串为byte数组(16进制) | |
36 | + * @param $str | |
37 | + * @return array | |
38 | + */ | |
39 | + public static function getBytes_16($str) { | |
40 | + | |
41 | + | |
42 | + $len = strlen($str); | |
43 | + $bytes = array(); | |
44 | + for($i=0;$i<$len;$i++) { | |
45 | + if(ord($str[$i]) >= 128){ | |
46 | + $byte = ord($str[$i]) - 256; | |
47 | + }else{ | |
48 | + $byte = ord($str[$i]); | |
49 | + } | |
50 | + $bytes[] = "0x".dechex($byte) ; | |
51 | + } | |
52 | + return $bytes; | |
53 | + } | |
54 | + | |
55 | + | |
56 | + /** | |
57 | + * 转换一个String字符串为byte数组(2进制) | |
58 | + * @param $str | |
59 | + * @return array | |
60 | + */ | |
61 | + public static function StrToBin($str){ | |
62 | + //1.列出每个字符 | |
63 | + $arr = preg_split('/(?<!^)(?!$)/u', $str); | |
64 | + //2.unpack字符 | |
65 | + foreach($arr as &$v){ | |
66 | + $temp = unpack('H*', $v); | |
67 | + $v = base_convert($temp[1], 16, 2); | |
68 | + unset($temp); | |
69 | + } | |
70 | + | |
71 | + return $arr; | |
72 | + } | |
73 | + | |
74 | + | |
75 | + /** | |
76 | + * 转换一个byte数组为String(2进制) | |
77 | + * @param $str 需要转换的字符串 | |
78 | + * @return string | |
79 | + */ | |
80 | + function BinToStr($str){ | |
81 | + $arr = explode(' ', $str); | |
82 | + foreach($arr as &$v){ | |
83 | + $v = pack("H".strlen(base_convert($v, 2, 16)), base_convert($v, 2, 16)); | |
84 | + } | |
85 | + | |
86 | + return $v; | |
87 | + } | |
88 | + | |
89 | + /** | |
90 | + * 将字节数组转化为String类型的数据 | |
91 | + * @param $bytes | |
92 | + * @return string | |
93 | + */ | |
94 | + public static function toStr($bytes) { | |
95 | + $str = ''; | |
96 | + foreach($bytes as $ch) { | |
97 | + $str .= chr($ch); | |
98 | + } | |
99 | + | |
100 | + | |
101 | + return $str; | |
102 | + } | |
103 | + | |
104 | + /** | |
105 | + * 转换一个int为byte数组 | |
106 | + * @param $val | |
107 | + * @return array | |
108 | + */ | |
109 | + | |
110 | + public static function integerToBytes($val) { | |
111 | + $byt = array(); | |
112 | + $byt[0] = ($val & 0xff); | |
113 | + $byt[1] = ($val >> 8 & 0xff); | |
114 | + $byt[2] = ($val >> 16 & 0xff); | |
115 | + $byt[3] = ($val >> 24 & 0xff); | |
116 | + return $byt; | |
117 | + } | |
118 | + | |
119 | + /** | |
120 | + * 从字节数组中指定的位置读取一个Integer类型的数据 | |
121 | + * @param $bytes 字节数组 | |
122 | + * @param $position 指定的开始位置 | |
123 | + * @return 一个Integer类型的数据 | |
124 | + */ | |
125 | + | |
126 | + public static function bytesToInteger($bytes, $position) { | |
127 | + $val = 0; | |
128 | + $val = $bytes[$position + 3] & 0xff; | |
129 | + $val <<= 8; | |
130 | + $val |= $bytes[$position + 2] & 0xff; | |
131 | + $val <<= 8; | |
132 | + $val |= $bytes[$position + 1] & 0xff; | |
133 | + $val <<= 8; | |
134 | + $val |= $bytes[$position] & 0xff; | |
135 | + return $val; | |
136 | + } | |
137 | + | |
138 | + | |
139 | + /** | |
140 | + * 转换一个short字符串为byte数组 | |
141 | + * @param $val | |
142 | + * @return array | |
143 | + */ | |
144 | + | |
145 | + public static function shortToBytes($val) { | |
146 | + $byt = array(); | |
147 | + $byt[0] = ($val & 0xff); | |
148 | + $byt[1] = ($val >> 8 & 0xff); | |
149 | + return $byt; | |
150 | + } | |
151 | + | |
152 | + /** | |
153 | + * 从字节数组中指定的位置读取一个Short类型的数据。 | |
154 | + * @param $bytes | |
155 | + * @param $position | |
156 | + * @return short | |
157 | + */ | |
158 | + public static function bytesToShort($bytes, $position) { | |
159 | + $val = 0; | |
160 | + $val = $bytes[$position + 1] & 0xFF; | |
161 | + $val = $val << 8; | |
162 | + $val |= $bytes[$position] & 0xFF; | |
163 | + return $val; | |
164 | + } | |
165 | + | |
166 | +} | |
\ No newline at end of file | ... | ... |
app/Common/CropAvatar.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 24/02/2017 | |
6 | + * Time: 5:11 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +class CropAvatar { | |
13 | + private $src; | |
14 | + private $data; | |
15 | + private $file; | |
16 | + private $dst; | |
17 | + private $type; | |
18 | + private $extension; | |
19 | + private $msg; | |
20 | + private $imgWidth; | |
21 | + private $imgHeight; | |
22 | + | |
23 | + function __construct($src, $data, $file, $imgWidth, $imgHeight) { | |
24 | + $this ->imgWidth = $imgWidth; | |
25 | + $this ->imgHeight = $imgHeight; | |
26 | + $this -> setSrc($src); | |
27 | + $this -> setData($data); | |
28 | + $this -> setFile($file); | |
29 | + $this -> crop($this -> src, $this -> dst, $this -> data); | |
30 | + } | |
31 | + | |
32 | + private function setSrc($src) { | |
33 | + if (!empty($src)) { | |
34 | + $type = exif_imagetype($src); | |
35 | + | |
36 | + if ($type) { | |
37 | + $this -> src = $src; | |
38 | + $this -> type = $type; | |
39 | + $this -> extension = image_type_to_extension($type); | |
40 | + $this -> setDst(); | |
41 | + } | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + private function setData($data) { | |
46 | + if (!empty($data)) { | |
47 | + $this -> data = json_decode(stripslashes($data)); | |
48 | + } | |
49 | + } | |
50 | + | |
51 | + private function setFile($file) { | |
52 | + $errorCode = $file['error']; | |
53 | + | |
54 | + if ($errorCode === UPLOAD_ERR_OK) { | |
55 | + $type = exif_imagetype($file['tmp_name']); | |
56 | + | |
57 | + if ($type) { | |
58 | + $extension = image_type_to_extension($type); | |
59 | + $src = config("constants.common.temp_file_location") . date('YmdHis') . '.original' . $extension; | |
60 | + | |
61 | + if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) { | |
62 | + | |
63 | + if (file_exists($src)) { | |
64 | + unlink($src); | |
65 | + } | |
66 | + | |
67 | + $result = move_uploaded_file($file['tmp_name'], $src); | |
68 | + | |
69 | + if ($result) { | |
70 | + $this -> src = $src; | |
71 | + $this -> type = $type; | |
72 | + $this -> extension = $extension; | |
73 | + $this -> setDst(); | |
74 | + } else { | |
75 | + $this -> msg = 'Failed to save file'; | |
76 | + } | |
77 | + } else { | |
78 | + $this -> msg = 'Please upload image with the following types: JPG, PNG, GIF'; | |
79 | + } | |
80 | + } else { | |
81 | + $this -> msg = 'Please upload image file'; | |
82 | + } | |
83 | + } else { | |
84 | + $this -> msg = $this -> codeToMessage($errorCode); | |
85 | + } | |
86 | + } | |
87 | + | |
88 | + private function setDst() { | |
89 | + $this -> dst = config("constants.common.temp_file_location") . date('YmdHis') . '.png'; | |
90 | + } | |
91 | + | |
92 | + private function crop($src, $dst, $data) { | |
93 | + if (!empty($src) && !empty($dst) && !empty($data)) { | |
94 | + switch ($this -> type) { | |
95 | + case IMAGETYPE_GIF: | |
96 | + $src_img = imagecreatefromgif($src); | |
97 | + break; | |
98 | + | |
99 | + case IMAGETYPE_JPEG: | |
100 | + $src_img = imagecreatefromjpeg($src); | |
101 | + break; | |
102 | + | |
103 | + case IMAGETYPE_PNG: | |
104 | + $src_img = imagecreatefrompng($src); | |
105 | + break; | |
106 | + } | |
107 | + | |
108 | + if (!$src_img) { | |
109 | + $this -> msg = "Failed to read the image file"; | |
110 | + return; | |
111 | + } | |
112 | + | |
113 | + $size = getimagesize($src); | |
114 | + $size_w = $size[0]; // natural width | |
115 | + $size_h = $size[1]; // natural height | |
116 | + | |
117 | + $src_img_w = $size_w; | |
118 | + $src_img_h = $size_h; | |
119 | + | |
120 | + $degrees = $data -> rotate; | |
121 | + | |
122 | + // Rotate the source image | |
123 | + if (is_numeric($degrees) && $degrees != 0) { | |
124 | + // PHP's degrees is opposite to CSS's degrees | |
125 | + $new_img = imagerotate( $src_img, -$degrees, imagecolorallocatealpha($src_img, 0, 0, 0, 127) ); | |
126 | + | |
127 | + imagedestroy($src_img); | |
128 | + $src_img = $new_img; | |
129 | + | |
130 | + $deg = abs($degrees) % 180; | |
131 | + $arc = ($deg > 90 ? (180 - $deg) : $deg) * M_PI / 180; | |
132 | + | |
133 | + $src_img_w = $size_w * cos($arc) + $size_h * sin($arc); | |
134 | + $src_img_h = $size_w * sin($arc) + $size_h * cos($arc); | |
135 | + | |
136 | + // Fix rotated image miss 1px issue when degrees < 0 | |
137 | + $src_img_w -= 1; | |
138 | + $src_img_h -= 1; | |
139 | + } | |
140 | + | |
141 | + $tmp_img_w = $data -> width; | |
142 | + $tmp_img_h = $data -> height; | |
143 | + $dst_img_w = $this ->imgWidth; | |
144 | + $dst_img_h = $this ->imgHeight; | |
145 | + | |
146 | + $src_x = $data -> x; | |
147 | + $src_y = $data -> y; | |
148 | + | |
149 | + if ($src_x <= -$tmp_img_w || $src_x > $src_img_w) { | |
150 | + $src_x = $src_w = $dst_x = $dst_w = 0; | |
151 | + } else if ($src_x <= 0) { | |
152 | + $dst_x = -$src_x; | |
153 | + $src_x = 0; | |
154 | + $src_w = $dst_w = min($src_img_w, $tmp_img_w + $src_x); | |
155 | + } else if ($src_x <= $src_img_w) { | |
156 | + $dst_x = 0; | |
157 | + $src_w = $dst_w = min($tmp_img_w, $src_img_w - $src_x); | |
158 | + } | |
159 | + | |
160 | + if ($src_w <= 0 || $src_y <= -$tmp_img_h || $src_y > $src_img_h) { | |
161 | + $src_y = $src_h = $dst_y = $dst_h = 0; | |
162 | + } else if ($src_y <= 0) { | |
163 | + $dst_y = -$src_y; | |
164 | + $src_y = 0; | |
165 | + $src_h = $dst_h = min($src_img_h, $tmp_img_h + $src_y); | |
166 | + } else if ($src_y <= $src_img_h) { | |
167 | + $dst_y = 0; | |
168 | + $src_h = $dst_h = min($tmp_img_h, $src_img_h - $src_y); | |
169 | + } | |
170 | + | |
171 | + // Scale to destination position and size | |
172 | + $ratio = $tmp_img_w / $dst_img_w; | |
173 | + $dst_x /= $ratio; | |
174 | + $dst_y /= $ratio; | |
175 | + $dst_w /= $ratio; | |
176 | + $dst_h /= $ratio; | |
177 | + | |
178 | + $dst_img = imagecreatetruecolor($dst_img_w, $dst_img_h); | |
179 | + | |
180 | + // Add transparent background to destination image | |
181 | + imagefill($dst_img, 0, 0, imagecolorallocatealpha($dst_img, 0, 0, 0, 127)); | |
182 | + imagesavealpha($dst_img, true); | |
183 | + | |
184 | + $result = imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); | |
185 | + | |
186 | + if ($result) { | |
187 | + if (!imagepng($dst_img, $dst)) { | |
188 | + $this -> msg = "Failed to save the cropped image file"; | |
189 | + } | |
190 | + } else { | |
191 | + $this -> msg = "Failed to crop the image file"; | |
192 | + } | |
193 | + | |
194 | + imagedestroy($src_img); | |
195 | + imagedestroy($dst_img); | |
196 | + } | |
197 | + } | |
198 | + | |
199 | + private function codeToMessage($code) { | |
200 | + switch ($code) { | |
201 | + case UPLOAD_ERR_INI_SIZE: | |
202 | + $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; | |
203 | + break; | |
204 | + | |
205 | + case UPLOAD_ERR_FORM_SIZE: | |
206 | + $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; | |
207 | + break; | |
208 | + | |
209 | + case UPLOAD_ERR_PARTIAL: | |
210 | + $message = 'The uploaded file was only partially uploaded'; | |
211 | + break; | |
212 | + | |
213 | + case UPLOAD_ERR_NO_FILE: | |
214 | + $message = 'No file was uploaded'; | |
215 | + break; | |
216 | + | |
217 | + case UPLOAD_ERR_NO_TMP_DIR: | |
218 | + $message = 'Missing a temporary folder'; | |
219 | + break; | |
220 | + | |
221 | + case UPLOAD_ERR_CANT_WRITE: | |
222 | + $message = 'Failed to write file to disk'; | |
223 | + break; | |
224 | + | |
225 | + case UPLOAD_ERR_EXTENSION: | |
226 | + $message = 'File upload stopped by extension'; | |
227 | + break; | |
228 | + | |
229 | + default: | |
230 | + $message = 'Unknown upload error'; | |
231 | + } | |
232 | + | |
233 | + return $message; | |
234 | + } | |
235 | + | |
236 | + public function getResult() { | |
237 | + return !empty($this -> data) ? $this -> dst : $this -> src; | |
238 | + } | |
239 | + | |
240 | + public function getMsg() { | |
241 | + return $this -> msg; | |
242 | + } | |
243 | + | |
244 | + public function getSrc() { | |
245 | + return $this -> src; | |
246 | + } | |
247 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Enums/AlipayLoginType.php
0 → 100644
app/Common/Enums/LoginType.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 11/02/2017 | |
6 | + * Time: 9:47 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\Enums; | |
10 | + | |
11 | + | |
12 | +class LoginType | |
13 | +{ | |
14 | + const PASSWORD = 1; | |
15 | + const SMS = 2; | |
16 | + const QQ = 3; | |
17 | + const WECHAT = 4; | |
18 | + const ALIPAY = 5; | |
19 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Enums/PayMethod.php
0 → 100644
app/Common/Enums/PaySource.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 11/03/2017 | |
6 | + * Time: 1:19 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\Enums; | |
10 | + | |
11 | + | |
12 | +class PaySource | |
13 | +{ | |
14 | + const APP = 1; | |
15 | + const JS = 2; | |
16 | + const MINI_PROGRAM = 3; | |
17 | + const NATIVE = 4; | |
18 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Enums/SmsType.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 11/02/2017 | |
6 | + * Time: 9:47 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\Enums; | |
10 | + | |
11 | + | |
12 | +class SmsType | |
13 | +{ | |
14 | + const REGISTER = 1; | |
15 | + const RESET_PASSWORD = 2; | |
16 | + const SMS_LOGIN = 3; | |
17 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Http.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 10/02/2017 | |
6 | + * Time: 5:47 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | +class Http | |
12 | +{ | |
13 | + public static function Post($curlPost, $url) | |
14 | + { | |
15 | + $curl = curl_init(); | |
16 | + curl_setopt($curl, CURLOPT_URL, $url); | |
17 | + curl_setopt($curl, CURLOPT_HEADER, false); | |
18 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
19 | + curl_setopt($curl, CURLOPT_NOBODY, true); | |
20 | + curl_setopt($curl, CURLOPT_POST, true); | |
21 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | |
22 | + $return_str = curl_exec($curl); | |
23 | + curl_close($curl); | |
24 | + return $return_str; | |
25 | + } | |
26 | + | |
27 | + public static function Get($url) | |
28 | + { | |
29 | + $curl = curl_init(); | |
30 | + curl_setopt($curl, CURLOPT_URL, $url); | |
31 | + curl_setopt($curl, CURLOPT_HEADER, false); | |
32 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
33 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
34 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
35 | + $return_str = curl_exec($curl); | |
36 | + curl_close($curl); | |
37 | + return $return_str; | |
38 | + } | |
39 | + | |
40 | + public static function PostWithHeader($curlPost, $curlHeader, $url) | |
41 | + { | |
42 | + $curl = curl_init(); | |
43 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
44 | + curl_setopt($curl, CURLOPT_URL, $url); | |
45 | + curl_setopt($curl, CURLOPT_POST, true); | |
46 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeader); | |
47 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
48 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | |
49 | + $return_str = curl_exec($curl); | |
50 | + curl_close($curl); | |
51 | + return $return_str; | |
52 | + } | |
53 | + | |
54 | + public static function GetWithHeader($curlHeader, $url) | |
55 | + { | |
56 | + $curl = curl_init(); | |
57 | + curl_setopt($curl, CURLOPT_URL, $url); | |
58 | + curl_setopt($curl, CURLOPT_HEADER, $curlHeader); | |
59 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
60 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
61 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
62 | + $return_str = curl_exec($curl); | |
63 | + curl_close($curl); | |
64 | + return $return_str; | |
65 | + } | |
66 | + | |
67 | + public static function WechatPostWithSecurity($curlPost, $url, $useCert=false) | |
68 | + { | |
69 | + $curl = curl_init(); | |
70 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
71 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); | |
72 | + curl_setopt($curl, CURLOPT_URL, $url); | |
73 | + curl_setopt($curl, CURLOPT_POST, true); | |
74 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
75 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); | |
76 | + | |
77 | + if($useCert == true){ | |
78 | + //设置证书 | |
79 | + //使用证书:cert 与 key 分别属于两个.pem文件 | |
80 | + curl_setopt($curl,CURLOPT_SSLCERTTYPE,'PEM'); | |
81 | + curl_setopt($curl,CURLOPT_SSLCERT, config('constants.wechat.ssl_cert_path')); | |
82 | + curl_setopt($curl,CURLOPT_SSLKEYTYPE,'PEM'); | |
83 | + curl_setopt($curl,CURLOPT_SSLKEY, config('constants.wechat.ssl_key_path')); | |
84 | + } | |
85 | + | |
86 | + $return_str = curl_exec($curl); | |
87 | + curl_close($curl); | |
88 | + return $return_str; | |
89 | + } | |
90 | + | |
91 | + public static function DeleteWithHeader($curlHeader, $url) | |
92 | + { | |
93 | + $curl = curl_init(); | |
94 | + curl_setopt($curl,CURLOPT_HTTPHEADER,$curlHeader); | |
95 | + curl_setopt($curl,CURLOPT_URL,$url); | |
96 | + curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'DELETE'); | |
97 | + | |
98 | + ob_start(); | |
99 | + curl_exec($curl); | |
100 | + $result = ob_get_contents(); | |
101 | + ob_end_clean(); | |
102 | + curl_close($curl); | |
103 | + | |
104 | + return $result; | |
105 | + } | |
106 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Jpush.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 12/02/2017 | |
6 | + * Time: 10:58 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | +use Exception; | |
12 | + | |
13 | +class Jpush | |
14 | +{ | |
15 | + public static function pushNotification($userIds, $title, $msg, $params) | |
16 | + { | |
17 | + $client = new \JPush(config('constants.jpush.access_key'), config('constants.jpush.secret')); | |
18 | + | |
19 | + try | |
20 | + { | |
21 | + $res = $client->push() | |
22 | + ->setPlatform('all') | |
23 | + ->addAlias($userIds) | |
24 | + ->addIosNotification($msg, 'iOS sound', "+1", true, 'iOS category', $params) | |
25 | + ->setMessage($msg, $title, null, $params) | |
26 | + ->setOptions(null, 864000, null, (bool)config('constants.jpush.production')) | |
27 | + ->send(); | |
28 | + } | |
29 | + catch(Exception $e) | |
30 | + { | |
31 | + $res = 'false'; | |
32 | + } | |
33 | + | |
34 | + return $res; | |
35 | + } | |
36 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/CheckoutMessageHandler.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 8:49 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\MQ; | |
10 | + | |
11 | + | |
12 | +class CheckoutMessageHandler extends HttpConsumer | |
13 | +{ | |
14 | + | |
15 | + /** | |
16 | + * UnlockMessageHandler constructor. | |
17 | + */ | |
18 | + public function __construct() | |
19 | + { | |
20 | + parent::__construct(config('constants.mq.url'), | |
21 | + config('constants.mq.ak'), | |
22 | + config('constants.mq.sk'), | |
23 | + config('constants.mq.checkout.consumer'), | |
24 | + config('constants.mq.checkout.topic')); | |
25 | + } | |
26 | + | |
27 | + protected function handleMessage() | |
28 | + { | |
29 | + return true; | |
30 | + } | |
31 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/CmdStatusMessageHandler.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 8:49 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\MQ; | |
10 | + | |
11 | + | |
12 | +class CmdStatusMessageHandler extends HttpConsumer | |
13 | +{ | |
14 | + | |
15 | + /** | |
16 | + * UnlockMessageHandler constructor. | |
17 | + */ | |
18 | + public function __construct() | |
19 | + { | |
20 | + parent::__construct(config('constants.mq.url'), | |
21 | + config('constants.mq.ak'), | |
22 | + config('constants.mq.sk'), | |
23 | + config('constants.mq.cmd_status.consumer'), | |
24 | + config('constants.mq.cmd_status.topic')); | |
25 | + } | |
26 | + | |
27 | + protected function handleMessage() | |
28 | + { | |
29 | + return true; | |
30 | + } | |
31 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/HttpConsumer.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 8:17 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\MQ; | |
10 | + | |
11 | + | |
12 | +use App\Common\Http; | |
13 | + | |
14 | +class HttpConsumer | |
15 | +{ | |
16 | + //签名 | |
17 | + private static $signature = "Signature"; | |
18 | + //Consumer ID | |
19 | + private static $consumerid = "ConsumerID"; | |
20 | + //访问码 | |
21 | + private static $aks = "AccessKey"; | |
22 | + | |
23 | + /** | |
24 | + * @var | |
25 | + */ | |
26 | + private $url; | |
27 | + | |
28 | + /** | |
29 | + * @var | |
30 | + */ | |
31 | + private $ak; | |
32 | + | |
33 | + /** | |
34 | + * @var | |
35 | + */ | |
36 | + private $sk; | |
37 | + | |
38 | + /** | |
39 | + * @var | |
40 | + */ | |
41 | + private $cid; | |
42 | + | |
43 | + /** | |
44 | + * @var | |
45 | + */ | |
46 | + private $topic; | |
47 | + | |
48 | + /** | |
49 | + * HttpConsumer constructor. | |
50 | + * @param $url | |
51 | + * @param $ak | |
52 | + * @param $sk | |
53 | + * @param $cid | |
54 | + * @param $topic | |
55 | + */ | |
56 | + public function __construct($url, $ak, $sk, $cid, $topic) | |
57 | + { | |
58 | + $this->url = $url; | |
59 | + $this->ak = $ak; | |
60 | + $this->sk = $sk; | |
61 | + $this->cid = $cid; | |
62 | + $this->topic = $topic; | |
63 | + } | |
64 | + | |
65 | + protected function handleMessage() | |
66 | + { | |
67 | + return true; | |
68 | + } | |
69 | + | |
70 | + public function consume() | |
71 | + { | |
72 | + $newline = "\n"; | |
73 | + | |
74 | + while (true) | |
75 | + { | |
76 | + try | |
77 | + { | |
78 | + //构造时间戳 | |
79 | + $date = time()*1000; | |
80 | + //签名字符串 | |
81 | + $signString = $this->topic.$newline.$this->cid.$newline.$date; | |
82 | + //计算签名 | |
83 | + $sign = Util::calSignature($signString,$this->sk); | |
84 | + //构造签名标记 | |
85 | + $signFlag = $this::$signature.":".$sign; | |
86 | + //构造密钥标记 | |
87 | + $akFlag = $this::$aks.":".$this->ak; | |
88 | + //标记 | |
89 | + $consumerFlag = $this::$consumerid.":".$this->cid; | |
90 | + //构造HTTP请求发送内容类型标记 | |
91 | + $contentFlag = "Content-Type:text/html;charset=UTF-8"; | |
92 | + //构造HTTP头部信息 | |
93 | + $headers = array( | |
94 | + $signFlag, | |
95 | + $akFlag, | |
96 | + $consumerFlag, | |
97 | + $contentFlag, | |
98 | + ); | |
99 | + //构造HTTP请求URL | |
100 | + $getUrl = $this->url."/message/?topic=".$this->topic."&time=".$date."&num=32"; | |
101 | + | |
102 | + $result = Http::GetWithHeader($headers, $getUrl); | |
103 | + //解析HTTP应答信息 | |
104 | + $messages = json_decode($result,true); | |
105 | + //如果应答信息中的没有包含任何的Topic信息,则直接跳过 | |
106 | + if (count($messages) ==0) | |
107 | + { | |
108 | + continue; | |
109 | + } | |
110 | + //依次遍历每个Topic消息 | |
111 | + foreach ((array)$messages as $message) | |
112 | + { | |
113 | + var_dump($message); | |
114 | + | |
115 | + if ($this->handleMessage()) | |
116 | + { | |
117 | + //构造删除Topic消息URL | |
118 | + $delUrl = $this->url."/message/?msgHandle=".$message['msgHandle']."&topic=".$this->topic."&time=".$date; | |
119 | + //签名字符串 | |
120 | + $signString = $this->topic.$newline.$this->cid.$newline.$message['msgHandle'].$newline.$date; | |
121 | + //计算签名 | |
122 | + $sign = Util::calSignature($signString,$this->sk); | |
123 | + //构造签名标记 | |
124 | + $signFlag = $this::$signature.":".$sign; | |
125 | + //构造密钥标记 | |
126 | + $akFlag = $this::$aks.":".$this->ak; | |
127 | + //构造消费者组标记 | |
128 | + $consumerFlag = $this::$consumerid.":".$this->cid; | |
129 | + //构造HTTP请求头部信息 | |
130 | + $delHeaders = array( | |
131 | + $signFlag, | |
132 | + $akFlag, | |
133 | + $consumerFlag, | |
134 | + $contentFlag, | |
135 | + ); | |
136 | + | |
137 | + $result = Http::DeleteWithHeader($delHeaders, $delUrl); | |
138 | + } | |
139 | + } | |
140 | + } | |
141 | + catch (\Exception $e) | |
142 | + { | |
143 | + //打印异常信息 | |
144 | + echo $e->getMessage(); | |
145 | + } | |
146 | + } | |
147 | + } | |
148 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/HttpProducer.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 7:58 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\MQ; | |
10 | + | |
11 | +use App\Common\Http; | |
12 | + | |
13 | +/** | |
14 | + * Class HttpProducer | |
15 | + * @package App\Common\MQ | |
16 | + */ | |
17 | +class HttpProducer | |
18 | +{ | |
19 | + //签名 | |
20 | + private static $signature = "Signature"; | |
21 | + | |
22 | + //在MQ控制台创建的Producer ID | |
23 | + private static $producerId = "ProducerID"; | |
24 | + | |
25 | + //阿里云身份验证码 | |
26 | + private static $aks = "AccessKey"; | |
27 | + | |
28 | + /** | |
29 | + * @var | |
30 | + */ | |
31 | + private $url; | |
32 | + | |
33 | + /** | |
34 | + * @var | |
35 | + */ | |
36 | + private $ak; | |
37 | + | |
38 | + /** | |
39 | + * @var | |
40 | + */ | |
41 | + private $sk; | |
42 | + | |
43 | + /** | |
44 | + * @var | |
45 | + */ | |
46 | + private $pid; | |
47 | + | |
48 | + /** | |
49 | + * @var | |
50 | + */ | |
51 | + private $topic; | |
52 | + | |
53 | + /** | |
54 | + * @var | |
55 | + */ | |
56 | + private $content; | |
57 | + | |
58 | + /** | |
59 | + * @var | |
60 | + */ | |
61 | + private $tag; | |
62 | + | |
63 | + /** | |
64 | + * @var | |
65 | + */ | |
66 | + private $key; | |
67 | + | |
68 | + | |
69 | + /** | |
70 | + * HttpProducer constructor. | |
71 | + * @param $url | |
72 | + * @param $ak | |
73 | + * @param $sk | |
74 | + * @param $pid | |
75 | + * @param $topic | |
76 | + * @param $content | |
77 | + * @param $tag | |
78 | + * @param $key | |
79 | + */ | |
80 | + public function __construct($url, $ak, $sk, $pid, $topic, $content, $tag, $key) | |
81 | + { | |
82 | + $this->url = $url; | |
83 | + $this->ak = $ak; | |
84 | + $this->sk = $sk; | |
85 | + $this->pid = $pid; | |
86 | + $this->topic = $topic; | |
87 | + $this->content = $content; | |
88 | + $this->tag = $tag; | |
89 | + $this->key = $key; | |
90 | + } | |
91 | + | |
92 | + | |
93 | + /** | |
94 | + * @param array $headerParam | |
95 | + * @param array $urlParam | |
96 | + * @return mixed | |
97 | + */ | |
98 | + public function produce($headerParam=array(), $urlParam=array()) | |
99 | + { | |
100 | + $date = time()*1000; | |
101 | + $newline = "\n"; | |
102 | + //POST请求url | |
103 | + $postUrl = $this->url."/message/?topic=".$this->topic."&time=".$date."&tag=".$this->tag."&key=".$this->key; | |
104 | + | |
105 | + foreach ($urlParam as $key=>$value) | |
106 | + { | |
107 | + $postUrl.='&'.$key.'='.$value; | |
108 | + } | |
109 | + | |
110 | + //签名字符串 | |
111 | + $signString = $this->topic.$newline.$this->pid.$newline.md5($this->content).$newline.$date; | |
112 | + //计算签名 | |
113 | + $sign = Util::calSignature($signString,$this->sk); | |
114 | + | |
115 | + //构造签名标记 | |
116 | + $signFlag = $this::$signature.":".$sign; | |
117 | + //构造密钥标记 | |
118 | + $akFlag = $this::$aks.":".$this->ak; | |
119 | + //标记 | |
120 | + $producerFlag = $this::$producerId.":".$this->pid; | |
121 | + //构造HTTP请求头部内容类型标记 | |
122 | + $contentFlag = "Content-Type:text/html;charset=UTF-8"; | |
123 | + //构造HTTP请求头部 | |
124 | + $headers = array( | |
125 | + $signFlag, | |
126 | + $akFlag, | |
127 | + $producerFlag, | |
128 | + $contentFlag, | |
129 | + ); | |
130 | + | |
131 | + foreach ($headerParam as $key=>$value) | |
132 | + { | |
133 | + array_push($headers, $key.':'.$value); | |
134 | + } | |
135 | + | |
136 | + $result = Http::PostWithHeader($this->content, $headers, $postUrl); | |
137 | + | |
138 | + $result = json_decode($result, true); | |
139 | + | |
140 | + return $result; | |
141 | + } | |
142 | + | |
143 | + | |
144 | + /** | |
145 | + * @param $delayTime | |
146 | + * @return mixed | |
147 | + */ | |
148 | + public function produceDelayMessage($delayTime) | |
149 | + { | |
150 | + $deliveryTime = time()*1000 + $delayTime * 1000; | |
151 | + $param['startdelivertime'] = $deliveryTime; | |
152 | + | |
153 | + return $this->produce(array(), $param); | |
154 | + } | |
155 | + | |
156 | + | |
157 | + /** | |
158 | + * @param $shardingKey | |
159 | + * @return mixed | |
160 | + */ | |
161 | + public function produceOrderMessage($shardingKey) | |
162 | + { | |
163 | + $param = array(); | |
164 | + $param['isOrder'] = true; | |
165 | + $param['shardingKey'] = $shardingKey; | |
166 | + | |
167 | + return $this->produce($param); | |
168 | + } | |
169 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/UnlockMessageHandler.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 25/04/2017 | |
6 | + * Time: 8:49 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\MQ; | |
10 | + | |
11 | + | |
12 | +class UnlockMessageHandler extends HttpConsumer | |
13 | +{ | |
14 | + | |
15 | + /** | |
16 | + * UnlockMessageHandler constructor. | |
17 | + */ | |
18 | + public function __construct() | |
19 | + { | |
20 | + parent::__construct(config('constants.mq.url'), | |
21 | + config('constants.mq.ak'), | |
22 | + config('constants.mq.sk'), | |
23 | + config('constants.mq.box_unlock.consumer'), | |
24 | + config('constants.mq.box_unlock.topic')); | |
25 | + } | |
26 | + | |
27 | + protected function handleMessage() | |
28 | + { | |
29 | + return true; | |
30 | + } | |
31 | +} | |
\ No newline at end of file | ... | ... |
app/Common/MQ/Util.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Common\MQ; | |
4 | + | |
5 | +/** | |
6 | + * Created by PhpStorm. | |
7 | + * User: billy | |
8 | + * Date: 25/04/2017 | |
9 | + * Time: 7:57 PM | |
10 | + */ | |
11 | +class Util | |
12 | +{ | |
13 | + //计算签名 | |
14 | + public static function calSignature($str,$key) | |
15 | + { | |
16 | + $sign = ""; | |
17 | + if(function_exists("hash_hmac")) | |
18 | + { | |
19 | + $sign = base64_encode(hash_hmac("sha1",$str,$key,true)); | |
20 | + } | |
21 | + else | |
22 | + { | |
23 | + $blockSize = 64; | |
24 | + $hashfunc = "sha1"; | |
25 | + if(strlen($key) > $blockSize) | |
26 | + { | |
27 | + $key = pack('H*',$hashfunc($key)); | |
28 | + } | |
29 | + $key = str_pad($key,$blockSize,chr(0x00)); | |
30 | + $ipad = str_repeat(chr(0x36),$blockSize); | |
31 | + $opad = str_repeat(chr(0x5c),$blockSize); | |
32 | + $hmac = pack( | |
33 | + 'H*',$hashfunc( | |
34 | + ($key^$opad).pack( | |
35 | + 'H*',$hashfunc($key^$ipad).$str | |
36 | + ) | |
37 | + ) | |
38 | + ); | |
39 | + $sign = base64_encode($hmac); | |
40 | + } | |
41 | + return $sign; | |
42 | + } | |
43 | + //计算时间戳 | |
44 | + public static function microtime_float() | |
45 | + { | |
46 | + list($usec,$sec) = explode(" ",microtime()); | |
47 | + return ((float)$usec+(float)$sec); | |
48 | + } | |
49 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Qiniu.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 12/02/2017 | |
6 | + * Time: 11:03 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | +use Qiniu\Auth; | |
12 | +use Qiniu\Storage\UploadManager; | |
13 | + | |
14 | +class Qiniu | |
15 | +{ | |
16 | + public static function getUpToken($bucket, $postfix, $policy, $fileName='') | |
17 | + { | |
18 | + if ($fileName == '') | |
19 | + { | |
20 | + $fileName = Utils::guid().'.'.$postfix; | |
21 | + } | |
22 | + else | |
23 | + { | |
24 | + $fileName = $fileName.'.'.$postfix; | |
25 | + } | |
26 | + | |
27 | + $policy['saveKey'] = $fileName; | |
28 | + | |
29 | + $auth = new Auth(config('constants.qiniu.access_key'), config('constants.qiniu.secret')); | |
30 | + $token = $auth->uploadToken($bucket, null, 3600, $policy); | |
31 | + | |
32 | + return $token; | |
33 | + } | |
34 | + | |
35 | + public static function uploadFile($bucket, $filePath, $postfix="png", $fileName='') | |
36 | + { | |
37 | + $token = Qiniu::getUpToken($bucket, $postfix, array(), $fileName); | |
38 | + $uploadMgr = new UploadManager(); | |
39 | + $ret = $uploadMgr->putFile($token, null, $filePath); | |
40 | + | |
41 | + $result = array(); | |
42 | + if(!empty($ret[0])) | |
43 | + { | |
44 | + $result = $ret[0]['key']; | |
45 | + } | |
46 | + else | |
47 | + { | |
48 | + $result = ""; | |
49 | + } | |
50 | + return $result; | |
51 | + } | |
52 | + | |
53 | + public static function fileUploadWithCorp($avatar_src, $avatar_data, $avatar_file, $width, $height, $bucket, $domain) | |
54 | + { | |
55 | + if($width == 0 && $height == 0) | |
56 | + { | |
57 | + $data_Array = json_decode($avatar_data, true); | |
58 | + | |
59 | + $width = $data_Array['width']; | |
60 | + $height = $data_Array['height']; | |
61 | + } | |
62 | + | |
63 | + $crop = new CropAvatar($avatar_src, $avatar_data, $avatar_file, $width, $height); | |
64 | + | |
65 | + $origin = $crop->getSrc(); | |
66 | + $result = $crop->getResult(); | |
67 | + | |
68 | + $response = Qiniu::uploadFile($bucket, $result); | |
69 | + | |
70 | + if(!empty($response)) | |
71 | + { | |
72 | + $response = $domain.$response; | |
73 | + @unlink($origin); | |
74 | + @unlink($result); | |
75 | + } | |
76 | + | |
77 | + $response = array( | |
78 | + 'state' => 200, | |
79 | + 'message' => $crop -> getMsg(), | |
80 | + 'result' => $response, | |
81 | + 'filename' => substr($response, strrpos($response, '/') + 1) | |
82 | + ); | |
83 | + | |
84 | + return json_encode($response); | |
85 | + } | |
86 | +} | |
\ No newline at end of file | ... | ... |
app/Common/README.md
0 → 100644
1 | +suishengwan common project | |
\ No newline at end of file | ... | ... |
app/Common/RegExpPattern.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 11/02/2017 | |
6 | + * Time: 5:20 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +class RegExpPattern | |
13 | +{ | |
14 | + /** | |
15 | + * 验证手机号 | |
16 | + */ | |
17 | + const REGEX_MOBILE = '/^1[34578]\d{9}$/'; | |
18 | + | |
19 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Sms.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 10/02/2017 | |
6 | + * Time: 6:23 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | +use Illuminate\Support\Facades\Log; | |
11 | + | |
12 | +/** | |
13 | + * Class Sms | |
14 | + * @package App\Common | |
15 | + */ | |
16 | +class Sms | |
17 | +{ | |
18 | + /** | |
19 | + * @return array | |
20 | + */ | |
21 | + private static function getHeadArray() | |
22 | + { | |
23 | + $AppKey = config('constants.sms.app_key'); | |
24 | + $AppSecret = config('constants.sms.app_Secret'); | |
25 | + $Nonce = rand(100000, 999999); | |
26 | + $CurTime = time(); | |
27 | + $CheckSum = strtolower(sha1($AppSecret . $Nonce . $CurTime)); | |
28 | + $head_arr = array(); | |
29 | + $head_arr[] = 'Content-Type: application/x-www-form-urlencoded'; | |
30 | + $head_arr[] = 'charset: utf-8'; | |
31 | + $head_arr[] = 'AppKey:' . $AppKey; | |
32 | + $head_arr[] = 'Nonce:' . $Nonce; | |
33 | + $head_arr[] = 'CurTime:' . $CurTime; | |
34 | + $head_arr[] = 'CheckSum:' . $CheckSum; | |
35 | + | |
36 | + return $head_arr; | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * @param $mobile | |
41 | + * @return bool | |
42 | + */ | |
43 | + public static function sendCode($mobile) | |
44 | + { | |
45 | + $target = config('constants.sms.base_url').config('constants.sms.code_url'); | |
46 | + | |
47 | + $head_arr = self::getHeadArray(); | |
48 | + | |
49 | + $post_data = "mobile=".$mobile."&codeLen=".config('constants.sms.code_len'); | |
50 | + | |
51 | + if (config('constants.sms.template_id')) | |
52 | + { | |
53 | + $post_data .= "&templateid=".config('constants.sms.template_id'); | |
54 | + } | |
55 | + | |
56 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | |
57 | + | |
58 | + Log::info('send code result: '.$result); | |
59 | + | |
60 | + if (strstr($result,"\"code\":200")) | |
61 | + return true; | |
62 | + else | |
63 | + return false; | |
64 | + } | |
65 | + | |
66 | + /** | |
67 | + * @param $mobile | |
68 | + * @param $code | |
69 | + * @return bool | |
70 | + */ | |
71 | + public static function verifyCode($mobile, $code) | |
72 | + { | |
73 | + $target = config('constants.sms.base_url').config('constants.sms.verify_url'); | |
74 | + | |
75 | + $head_arr = self::getHeadArray(); | |
76 | + | |
77 | + $post_data = "mobile=".$mobile."&code=".$code; | |
78 | + | |
79 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | |
80 | + | |
81 | + if (strstr($result,"\"code\":200")) | |
82 | + return true; | |
83 | + else | |
84 | + return false; | |
85 | + } | |
86 | + | |
87 | + /** | |
88 | + * @param $mobiles | |
89 | + * @param $template_id | |
90 | + * @param $params | |
91 | + * @return bool | |
92 | + */ | |
93 | + public static function sendTemplateMessage($mobiles, $template_id, $params) | |
94 | + { | |
95 | + $target = config('constants.sms.base_url').config('constants.sms.template_url'); | |
96 | + | |
97 | + $head_arr = self::getHeadArray(); | |
98 | + | |
99 | + $post_data = "templateid=".$template_id."&mobiles=".json_encode($mobiles)."¶ms=".json_encode($params); | |
100 | + | |
101 | + $result = Http::PostWithHeader($post_data, $head_arr, $target); | |
102 | + | |
103 | + if (strstr($result,"\"code\":200")) | |
104 | + return true; | |
105 | + else | |
106 | + return false; | |
107 | + } | |
108 | +} | |
\ No newline at end of file | ... | ... |
app/Common/ThirdPartyLogin.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 10/02/2017 | |
6 | + * Time: 6:23 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | +use App\Common\Enums\LoginType; | |
12 | + | |
13 | +/** | |
14 | + * Class ThirdPartyLogin | |
15 | + * @package App\Common | |
16 | + */ | |
17 | +class ThirdPartyLogin | |
18 | +{ | |
19 | + public static function verify($openId, $accessToken, $type) | |
20 | + { | |
21 | + if ($type == LoginType::QQ) | |
22 | + { | |
23 | + return self::qq_verify($openId, $accessToken); | |
24 | + } | |
25 | + else if($type == LoginType::WECHAT) | |
26 | + { | |
27 | + return self::wechat_verify($openId, $accessToken); | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + | |
32 | + private static function qq_verify($openId, $accessToken) | |
33 | + { | |
34 | + $target = "https://graph.qq.com/oauth2.0/me?access_token=".$accessToken; | |
35 | + $result = Http::Get($target); | |
36 | + | |
37 | + if($result != null) | |
38 | + { | |
39 | + if (preg_match('/openid":"'.$openId.'"/', $result)) | |
40 | + { | |
41 | + return true; | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + return false; | |
46 | + } | |
47 | + | |
48 | + private static function wechat_verify($openId, $accessToken) | |
49 | + { | |
50 | + $target = "https://api.weixin.qq.com/sns/auth?access_token=".$accessToken."&openid=".$openId; | |
51 | + $result = Http::Get($target); | |
52 | + | |
53 | + if($result != null) | |
54 | + { | |
55 | + if (preg_match('/"errcode":0,/', $result)) | |
56 | + { | |
57 | + return true; | |
58 | + } | |
59 | + } | |
60 | + | |
61 | + return false; | |
62 | + } | |
63 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Util/OrderUtil.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 11/03/2017 | |
6 | + * Time: 11:12 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common\Util; | |
10 | + | |
11 | + | |
12 | +class OrderUtil | |
13 | +{ | |
14 | + private static function generateOrderId() | |
15 | + { | |
16 | + $time_ms_array = explode(" ", microtime()); | |
17 | + $ms_part = sprintf("%06d", $time_ms_array[0] * 1000 * 1000); | |
18 | + $s_part = $time_ms_array[1]; | |
19 | + | |
20 | + return date('YmdHis', $s_part) . $ms_part . rand(10000000,99999999); | |
21 | + } | |
22 | + | |
23 | + public static function generateRechargeOrderId() | |
24 | + { | |
25 | + return 'ykr'.self::generateOrderId(); | |
26 | + } | |
27 | + | |
28 | + public static function generateCosumeOrderId() | |
29 | + { | |
30 | + return 'ykc'.self::generateOrderId(); | |
31 | + } | |
32 | +} | |
\ No newline at end of file | ... | ... |
app/Common/Utils.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 12/02/2017 | |
6 | + * Time: 11:06 AM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | + | |
12 | +class Utils | |
13 | +{ | |
14 | + /** | |
15 | + * @return string | |
16 | + */ | |
17 | + public static function guid() | |
18 | + { | |
19 | + $timestamp = time(); | |
20 | + $ranstr = rand(9999, 9999999999); | |
21 | + return md5($timestamp . $ranstr) . substr(md5($ranstr), 0, 8); | |
22 | + } | |
23 | + | |
24 | + /** | |
25 | + * xml转为数组 | |
26 | + */ | |
27 | + public static function xmlToArray($xmlStr) | |
28 | + { | |
29 | + $msg = array(); | |
30 | + $postStr = $xmlStr; | |
31 | + | |
32 | + $msg = json_decode(json_encode(simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA)), true); | |
33 | + | |
34 | + return $msg; | |
35 | + } | |
36 | + | |
37 | + | |
38 | + /** | |
39 | + * @param $number | |
40 | + * @param int $precision | |
41 | + * @return float|int | |
42 | + */ | |
43 | + public static function round_up($number, $precision = 3) | |
44 | + { | |
45 | + $fig = (int) str_pad('1', $precision, '0'); | |
46 | + return (ceil($number * $fig) / $fig); | |
47 | + } | |
48 | + | |
49 | + /** | |
50 | + * @param $number | |
51 | + * @param int $precision | |
52 | + * @return float|int | |
53 | + */ | |
54 | + public static function round_down($number, $precision = 3) | |
55 | + { | |
56 | + $fig = (int) str_pad('1', $precision, '0'); | |
57 | + return (floor($number * $fig) / $fig); | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * @param $data | |
62 | + * @param $key | |
63 | + * @return mixed | |
64 | + */ | |
65 | + public static function array_remove($data, $key) | |
66 | + { | |
67 | + if(!array_key_exists($key, $data)){ | |
68 | + return $data; | |
69 | + } | |
70 | + $keys = array_keys($data); | |
71 | + $index = array_search($key, $keys); | |
72 | + if($index !== FALSE){ | |
73 | + array_splice($data, $index, 1); | |
74 | + } | |
75 | + return $data; | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * @param $day1 | |
80 | + * @param $day2 | |
81 | + * @return float|int | |
82 | + */ | |
83 | + public static function diffBetweenTwoDays ($day1, $day2) | |
84 | + { | |
85 | + $second1 = strtotime($day1); | |
86 | + $second2 = strtotime($day2); | |
87 | + | |
88 | + if ($second1 < $second2) { | |
89 | + $tmp = $second2; | |
90 | + $second2 = $second1; | |
91 | + $second1 = $tmp; | |
92 | + } | |
93 | + return ($second1 - $second2) / 86400; | |
94 | + } | |
95 | +} | |
\ No newline at end of file | ... | ... |
app/Common/WechatPay.php
0 → 100644
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: billy | |
5 | + * Date: 09/03/2017 | |
6 | + * Time: 8:33 PM | |
7 | + */ | |
8 | + | |
9 | +namespace App\Common; | |
10 | + | |
11 | +/** | |
12 | + * Class WechatPay | |
13 | + * @package App\Common | |
14 | + */ | |
15 | +use App\Common\Enums\PaySource; | |
16 | + | |
17 | +/** | |
18 | + * Class WechatPay | |
19 | + * @package App\Common | |
20 | + */ | |
21 | +class WechatPay | |
22 | +{ | |
23 | + /** | |
24 | + * order Id | |
25 | + * @var | |
26 | + */ | |
27 | + private $order_id; | |
28 | + | |
29 | + /** | |
30 | + * Order price | |
31 | + * @var | |
32 | + */ | |
33 | + private $price; | |
34 | + | |
35 | + /** | |
36 | + * pay description | |
37 | + * @var | |
38 | + */ | |
39 | + private $body; | |
40 | + | |
41 | + /** | |
42 | + * @var | |
43 | + */ | |
44 | + private $pay_type; | |
45 | + | |
46 | + /** | |
47 | + * Callback Url | |
48 | + * @var | |
49 | + */ | |
50 | + private $call_back_url; | |
51 | + | |
52 | + /** | |
53 | + * Used for js and mini program | |
54 | + * @var | |
55 | + */ | |
56 | + private $open_id; | |
57 | + | |
58 | + /** | |
59 | + * @var | |
60 | + */ | |
61 | + private $refund_fee; | |
62 | + | |
63 | + /** | |
64 | + * @var | |
65 | + */ | |
66 | + private $refund_id; | |
67 | + | |
68 | + /** | |
69 | + * @var | |
70 | + */ | |
71 | + private $op_user_id; | |
72 | + | |
73 | + /** | |
74 | + * WechatPay constructor. | |
75 | + * @param $order_id | |
76 | + * @param $price | |
77 | + * @param $body | |
78 | + * @param $pay_type | |
79 | + * @param $call_back_url | |
80 | + */ | |
81 | + public function __construct($order_id="", $price=0, $body="", $call_back_url="", $pay_type=PaySource::APP) | |
82 | + { | |
83 | + $this->order_id = $order_id; | |
84 | + $this->price = $price; | |
85 | + $this->body = $body; | |
86 | + $this->call_back_url = $call_back_url; | |
87 | + $this->pay_type = $pay_type; | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * @param mixed $pay_type | |
92 | + */ | |
93 | + public function setPayType($pay_type) | |
94 | + { | |
95 | + $this->pay_type = $pay_type; | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * @param mixed $open_id | |
100 | + */ | |
101 | + public function setOpenId($open_id) | |
102 | + { | |
103 | + $this->open_id = $open_id; | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * @param mixed $refund_fee | |
108 | + */ | |
109 | + public function setRefundFee($refund_fee) | |
110 | + { | |
111 | + $this->refund_fee = $refund_fee; | |
112 | + } | |
113 | + | |
114 | + /** | |
115 | + * @param mixed $op_user_id | |
116 | + */ | |
117 | + public function setOpUserId($op_user_id) | |
118 | + { | |
119 | + $this->op_user_id = $op_user_id; | |
120 | + } | |
121 | + | |
122 | + /** | |
123 | + * @param mixed $refund_id | |
124 | + */ | |
125 | + public function setRefundId($refund_id) | |
126 | + { | |
127 | + $this->refund_id = $refund_id; | |
128 | + } | |
129 | + | |
130 | + /** | |
131 | + * @param $success | |
132 | + * @param $error_messge | |
133 | + * @param string $payInfo | |
134 | + * @return array | |
135 | + */ | |
136 | + private function response($success, $error_messge, $payInfo="") | |
137 | + { | |
138 | + $result = array('success'=>$success, 'error_message'=>$error_messge, 'payInfo'=>$payInfo); | |
139 | + | |
140 | + return $result; | |
141 | + } | |
142 | + | |
143 | + | |
144 | + /** | |
145 | + * 请求微信API进行微信统一下单 | |
146 | + * URL地址:https://api.mch.weixin.qq.com/pay/unifiedorder | |
147 | + */ | |
148 | + public function getUnifiedOrderInfo() | |
149 | + { | |
150 | + $check_result = $this->checkConfigParam(); | |
151 | + if (!empty($check_result)) | |
152 | + { | |
153 | + return $this->response(false, $check_result); | |
154 | + } | |
155 | + | |
156 | + $param = $this->getUnifiedOrderParam(); | |
157 | + | |
158 | + //wechat unified order request | |
159 | + $resultXmlStr = Http::WechatPostWithSecurity($param, config('constants.wechat.unified_order_url')); | |
160 | + $result = Utils::xmlToArray($resultXmlStr); | |
161 | + | |
162 | + if (!$this->checkRespSign($result)) | |
163 | + { | |
164 | + return $this->response(false, "统一下单失败"); | |
165 | + } | |
166 | + | |
167 | + switch ($this->pay_type) | |
168 | + { | |
169 | + case PaySource::APP: | |
170 | + $unifiedOrderInfo = $this->getAppUnifiedOrderInfo($result['prepay_id']); | |
171 | + break; | |
172 | + case PaySource::JS: | |
173 | + case PaySource::MINI_PROGRAM: | |
174 | + $unifiedOrderInfo = $this->getJSUnifiedOrderInfo($result['prepay_id']); | |
175 | + break; | |
176 | + case PaySource::NATIVE: | |
177 | + $unifiedOrderInfo = ['code_url' => $result['code_url']]; | |
178 | + break; | |
179 | + | |
180 | + default: | |
181 | + $unifiedOrderInfo = $this->getAppUnifiedOrderInfo($result['prepay_id']); | |
182 | + break; | |
183 | + } | |
184 | + | |
185 | + | |
186 | + $unifiedOrderInfo["sign"] = $this->sign($unifiedOrderInfo);//生成签名 | |
187 | + | |
188 | + return $this->response(true, "", $unifiedOrderInfo); | |
189 | + } | |
190 | + | |
191 | + /** | |
192 | + * @return mixed|string | |
193 | + */ | |
194 | + private function getAppId() | |
195 | + { | |
196 | + switch ($this->pay_type) | |
197 | + { | |
198 | + case PaySource::APP: | |
199 | + case PaySource::NATIVE: | |
200 | + return config('constants.wechat.app_id'); | |
201 | + break; | |
202 | + case PaySource::JS: | |
203 | + return config('constants.wechat.js_id'); | |
204 | + break; | |
205 | + case PaySource::MINI_PROGRAM: | |
206 | + return config('constants.wechat.mini_program_id'); | |
207 | + break; | |
208 | + } | |
209 | + | |
210 | + return ""; | |
211 | + } | |
212 | + | |
213 | + /** | |
214 | + * @return string | |
215 | + */ | |
216 | + private function getTradeType() | |
217 | + { | |
218 | + switch ($this->pay_type) | |
219 | + { | |
220 | + case PaySource::APP: | |
221 | + return "APP"; | |
222 | + break; | |
223 | + case PaySource::JS: | |
224 | + case PaySource::MINI_PROGRAM: | |
225 | + return "JSAPI"; | |
226 | + break; | |
227 | + case PaySource::NATIVE: | |
228 | + return "NATIVE"; | |
229 | + break; | |
230 | + default: | |
231 | + return "APP"; | |
232 | + break; | |
233 | + } | |
234 | + } | |
235 | + | |
236 | + | |
237 | + /** | |
238 | + * 获取同意下单参数 | |
239 | + * @return string | |
240 | + */ | |
241 | + private function getUnifiedOrderParam() | |
242 | + { | |
243 | + $price=sprintf("%.2f",$this->price); | |
244 | + $param = array( | |
245 | + "appid" => $this->getAppId(), | |
246 | + "body" => $this->body, | |
247 | + "mch_id" => config('constants.wechat.mch_id'), | |
248 | + "nonce_str" => $this->getNonceStr(), | |
249 | + "notify_url" => $this->call_back_url, | |
250 | + "out_trade_no" => $this->order_id, | |
251 | + "total_fee" => $price * 100, | |
252 | + "trade_type" => $this->getTradeType(), | |
253 | + ); | |
254 | + | |
255 | + if ($this->pay_type == PaySource::JS || $this->pay_type == PaySource::MINI_PROGRAM) | |
256 | + { | |
257 | + $param['openid'] = $this->open_id; | |
258 | + } | |
259 | + | |
260 | + $sign = $this->sign($param);//生成签名 | |
261 | + $param['sign'] = $sign; | |
262 | + $paramXml = "<xml>"; | |
263 | + foreach ($param as $k => $v) { | |
264 | + $paramXml .= "<" . $k . ">" . $v . "</" . $k . ">"; | |
265 | + | |
266 | + } | |
267 | + $paramXml .= "</xml>"; | |
268 | + | |
269 | + return $paramXml; | |
270 | + } | |
271 | + | |
272 | + /** | |
273 | + * @param $prepay_id | |
274 | + * @return array | |
275 | + */ | |
276 | + private function getAppUnifiedOrderInfo($prepay_id) | |
277 | + { | |
278 | + $unifiedOrderInfo = [ | |
279 | + "appid" => $this->getAppId(), | |
280 | + "noncestr" => $this->getNonceStr(), | |
281 | + "package" => "Sign=WXPay", | |
282 | + "partnerid" => config('constants.wechat.mch_id'), | |
283 | + "prepayid" => $prepay_id, | |
284 | + "timestamp" => substr(time().'',0,10) | |
285 | + ]; | |
286 | + | |
287 | + return $unifiedOrderInfo; | |
288 | + } | |
289 | + | |
290 | + /** | |
291 | + * @param $prepay_id | |
292 | + * @return array | |
293 | + */ | |
294 | + private function getJSUnifiedOrderInfo($prepay_id) | |
295 | + { | |
296 | + $unifiedOrderInfo = [ | |
297 | + "appId" => $this->getAppId(), | |
298 | + "nonceStr" => $this->getNonceStr(), | |
299 | + "package" => "prepay_id=".$prepay_id, | |
300 | + "signType" => "MD5", | |
301 | + "timeStamp" => substr(time().'',0,10) | |
302 | + ]; | |
303 | + | |
304 | + return $unifiedOrderInfo; | |
305 | + } | |
306 | + | |
307 | + | |
308 | + /** | |
309 | + * 获取随机字符串 | |
310 | + * @return string | |
311 | + */ | |
312 | + private function getNonceStr() | |
313 | + { | |
314 | + $nonceStr = md5(rand(100, 1000) . time()); | |
315 | + return $nonceStr; | |
316 | + } | |
317 | + | |
318 | + /** | |
319 | + * 检测配置信息是否完整 | |
320 | + */ | |
321 | + public function checkConfigParam() | |
322 | + { | |
323 | + | |
324 | + if ($this->getAppId() == "") { | |
325 | + return "微信APPID未配置"; | |
326 | + } elseif (config('constants.wechat.mch_id') == "") { | |
327 | + return "微信商户号MCHID未配置"; | |
328 | + } elseif (config('constants.wechat.api_key') == "") { | |
329 | + return "微信API密钥KEY未配置"; | |
330 | + } | |
331 | + | |
332 | + return ""; | |
333 | + } | |
334 | + | |
335 | + public function refund() | |
336 | + { | |
337 | + $check_result = $this->checkConfigParam(); | |
338 | + if (!empty($check_result)) | |
339 | + { | |
340 | + return $this->response(false, $check_result); | |
341 | + } | |
342 | + | |
343 | + $param = $this->getRefundInfo(); | |
344 | + | |
345 | + //wechat unified order request | |
346 | + $resultXmlStr = Http::WechatPostWithSecurity($param, config('constants.wechat.refund_url'), true); | |
347 | + $result = Utils::xmlToArray($resultXmlStr); | |
348 | + | |
349 | + if (!$this->checkRespSign($result)) | |
350 | + { | |
351 | + return $this->response(false, "退款失败"); | |
352 | + } | |
353 | + | |
354 | + return $this->response(true, "", $result); | |
355 | + } | |
356 | + | |
357 | + private function getRefundInfo() | |
358 | + { | |
359 | + $price=sprintf("%.2f",$this->price); | |
360 | + $refund_fee = sprintf("%.2f", $this->refund_fee); | |
361 | + $param = array( | |
362 | + "appid" => $this->getAppId(), | |
363 | + "mch_id" => config('constants.wechat.mch_id'), | |
364 | + "nonce_str" => $this->getNonceStr(), | |
365 | + "out_trade_no" => $this->order_id, | |
366 | + "out_refund_no" => $this->refund_id, | |
367 | + "total_fee" => $price * 100, | |
368 | + "refund_fee" => $refund_fee * 100, | |
369 | + "op_user_id" => config('constants.wechat.mch_id'), | |
370 | + ); | |
371 | + | |
372 | + $sign = $this->sign($param);//生成签名 | |
373 | + $param['sign'] = $sign; | |
374 | + $paramXml = "<xml>"; | |
375 | + foreach ($param as $k => $v) { | |
376 | + $paramXml .= "<" . $k . ">" . $v . "</" . $k . ">"; | |
377 | + | |
378 | + } | |
379 | + $paramXml .= "</xml>"; | |
380 | + | |
381 | + return $paramXml; | |
382 | + } | |
383 | + | |
384 | + | |
385 | + /** | |
386 | + * sign拼装获取 | |
387 | + * @param Array $param | |
388 | + * @return String | |
389 | + */ | |
390 | + private function sign($param) | |
391 | + { | |
392 | + ksort($param); | |
393 | + $sign = ""; | |
394 | + foreach ($param as $k => $v) { | |
395 | + if ($v != "" && !is_array($v)) | |
396 | + { | |
397 | + $sign .= $k . "=" . $v . "&"; | |
398 | + } | |
399 | + } | |
400 | + | |
401 | + $sign .= "key=" . config('constants.wechat.api_key'); | |
402 | + $sign = strtoupper(md5($sign)); | |
403 | + return $sign; | |
404 | + | |
405 | + } | |
406 | + | |
407 | + /** | |
408 | + * 检查微信回调签名 | |
409 | + * @param $param | |
410 | + * @return bool | |
411 | + */ | |
412 | + public function checkRespSign($param) | |
413 | + { | |
414 | + if ($param['return_code'] == "SUCCESS") { | |
415 | + $wxSign = $param['sign']; | |
416 | + unset($param['sign']); | |
417 | + | |
418 | + $sign = $this->sign($param);//生成签名 | |
419 | + | |
420 | + if ($this->checkSign($wxSign, $sign)) { | |
421 | + return true; | |
422 | + } else { | |
423 | + return false; | |
424 | + } | |
425 | + } else { | |
426 | + return false; | |
427 | + } | |
428 | + } | |
429 | + | |
430 | + /** | |
431 | + * @param $type | |
432 | + * @param $msg | |
433 | + * @return string | |
434 | + */ | |
435 | + public static function returnInfo($type, $msg) | |
436 | + { | |
437 | + if ($type == "SUCCESS") { | |
438 | + return $returnXml = "<xml><return_code><![CDATA[{$type}]]></return_code></xml>"; | |
439 | + } else { | |
440 | + return $returnXml = "<xml><return_code><![CDATA[{$type}]]></return_code><return_msg><![CDATA[{$msg}]]></return_msg></xml>"; | |
441 | + } | |
442 | + } | |
443 | + | |
444 | + /** | |
445 | + * 签名验证 | |
446 | + * @param $sign1 | |
447 | + * @param $sign2 | |
448 | + * @return bool | |
449 | + */ | |
450 | + private function checkSign($sign1, $sign2) | |
451 | + { | |
452 | + return trim($sign1) == trim($sign2); | |
453 | + } | |
454 | +} | |
\ No newline at end of file | ... | ... |
app/Console/Commands/MonthTotal.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Console\Commands; | |
4 | + | |
5 | +use App\Modules\Models\GuideRecord\GuideRecord; | |
6 | +use App\Modules\Models\Production\Production; | |
7 | +use App\Modules\Models\Settlement\Finance; | |
8 | +//use App\Modules\Models\Settlement\Settlement; | |
9 | +use App\Modules\Models\Spot\Spot; | |
10 | +use Illuminate\Console\Command; | |
11 | + | |
12 | +class MonthTotal extends Command | |
13 | +{ | |
14 | + /** | |
15 | + * The name and signature of the console command. | |
16 | + * | |
17 | + * @var string | |
18 | + */ | |
19 | + protected $signature = 'MonthTotal {--day=}'; | |
20 | + | |
21 | + /** | |
22 | + * The console command description. | |
23 | + * | |
24 | + * @var string | |
25 | + */ | |
26 | + protected $description = '每月景区的价格'; | |
27 | + | |
28 | + /** | |
29 | + * Create a new command instance. | |
30 | + * | |
31 | + * @return void | |
32 | + */ | |
33 | + public function __construct() | |
34 | + { | |
35 | + parent::__construct(); | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * Execute the console command. | |
40 | + * | |
41 | + * @return mixed | |
42 | + */ | |
43 | + public function handle() | |
44 | + { | |
45 | + | |
46 | + | |
47 | +// $time = $this->option('day'); | |
48 | + | |
49 | +// if( empty($time) ){ | |
50 | + $time = date('Y-m'); | |
51 | +// } | |
52 | + | |
53 | + | |
54 | + $deal_time = date("Ym", strtotime("$time -1 month")); | |
55 | + | |
56 | + | |
57 | + $start_time = date("Y-m-01 00:00:00", strtotime("$time -1 month")); | |
58 | + $end_time = date("Y-m-01 00:00:00", strtotime("$time")); | |
59 | + $orders = Production::select('rent.spot_id','rent.business_id','rent.real_total','production.return_time') | |
60 | + ->leftJoin('rent', 'production.rent_id', '=', 'rent.id') | |
61 | + ->where('production.return_time', '>=', $start_time) | |
62 | + ->where('production.return_time','<=',$end_time) | |
63 | + ->where('production.is_return',1) | |
64 | + ->get() | |
65 | + ->toArray(); | |
66 | + | |
67 | + | |
68 | + $res=GuideRecord::select('guide_record.spot_id','guide_record.business_id','guide_record.real_total') | |
69 | + ->where('guide_record.pay_time', '>=', $start_time) | |
70 | + ->where('guide_record.pay_time','<=',$end_time) | |
71 | + ->where('guide_record.is_pay',1) | |
72 | + ->get() | |
73 | + ->toArray(); | |
74 | + | |
75 | + | |
76 | + | |
77 | + $income_data = []; | |
78 | + $date = [ ]; | |
79 | + | |
80 | + | |
81 | + if (!empty($orders)) { | |
82 | + for ($i = 0; $i < count($orders); $i++) { | |
83 | + if (!isset($income_data[$orders[$i]['spot_id']]['real_total'])) { | |
84 | + $income_data[$orders[$i]['spot_id']]['real_total'] = 0; | |
85 | + } | |
86 | + $income_data[$orders[$i]['spot_id']]['real_total'] += $orders[$i]['real_total']; | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + if(!empty($res)){ | |
91 | + for($i=0;$i<count($res);$i++){ | |
92 | + if(!isset($date[$res[$i]['spot_id']]['real_total'])){ | |
93 | + $date[$res[$i]['spot_id']]['real_total'] = 0; | |
94 | + } | |
95 | + $date[$res[$i]['spot_id']]['real_total'] += $res[$i]['real_total']; | |
96 | + } | |
97 | + | |
98 | + } | |
99 | + | |
100 | + $insert_data = []; | |
101 | + $spots = Spot::select('*')->get()->toArray(); | |
102 | + foreach ($spots as $k => $v) { | |
103 | + $insert_data[$k]['business_id'] = (int)$v['business_id']; | |
104 | + $insert_data[$k]['spot_id'] = (int)$v['id']; | |
105 | + $insert_data[$k]['month'] = (int)$deal_time; | |
106 | + $insert_data[$k]['total'] = empty($income_data[$v['id']]['real_total']) ? 0 : $income_data[$v['id']]['real_total']; | |
107 | + $insert_data[$k]['guide_total'] = empty($date[$v['id']]['real_total']) ? 0 : $date[$v['id']]['real_total']; | |
108 | + $insert_data[$k]['created_at'] =date("Y-m-d H:i:s"); | |
109 | + $insert_data[$k]['updated_at'] =date("Y-m-d H:i:s"); | |
110 | + } | |
111 | + | |
112 | + | |
113 | + $res = Finance::insert($insert_data); | |
114 | + | |
115 | + } | |
116 | + } | ... | ... |
app/Console/Commands/NoReturnOrder.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +namespace App\Console\Commands; | |
4 | + | |
5 | +use App\Common\Http; | |
6 | +use App\Modules\Models\Production\Production; | |
7 | +use Illuminate\Console\Command; | |
8 | +use Illuminate\Support\Facades\Log; | |
9 | + | |
10 | +class NoReturnOrder extends Command | |
11 | +{ | |
12 | + /** | |
13 | + * The name and signature of the console command. | |
14 | + * | |
15 | + * @var string | |
16 | + */ | |
17 | + protected $signature = 'NoReturnOrder {--day=}'; | |
18 | + | |
19 | + /** | |
20 | + * The console command description. | |
21 | + * | |
22 | + * @var string | |
23 | + */ | |
24 | + protected $description = '未归还的订单费用'; | |
25 | + | |
26 | + /** | |
27 | + * Create a new command instance. | |
28 | + * | |
29 | + * @return void | |
30 | + */ | |
31 | + public function __construct() | |
32 | + { | |
33 | + parent::__construct(); | |
34 | + } | |
35 | + | |
36 | + /** | |
37 | + * Execute the console command. | |
38 | + * | |
39 | + * @return mixed | |
40 | + */ | |
41 | + public function handle() | |
42 | + { | |
43 | + // | |
44 | + $datas = Production::select('machine.mac_no', 'production.power_no', 'production.rent_hatch_no','production.is_return', 'power.machine_id', 'rent.deposit', 'rent.one_day_price', 'rent.pay_time') | |
45 | + ->leftjoin('power', 'production.power_no', '=', 'power.power_no') | |
46 | + ->leftjoin('rent', 'rent.id', '=', 'production.rent_id') | |
47 | + ->leftjoin('machine', 'machine.id', '=', 'production.rent_machine_id') | |
48 | + ->where('production.is_return', '=', 0) | |
49 | + ->where('rent.is_over', '=', 0) | |
50 | + ->whereNull('power.machine_id') | |
51 | + ->get() | |
52 | + ->toArray(); | |
53 | + | |
54 | + foreach ($datas as $key => $data){ | |
55 | + $days = ceil($data['deposit'] / $data['one_day_price']); | |
56 | + if(time() > (strtotime($data['pay_time']) + $days * 60 * 60 * 24)){ | |
57 | + //todo 请求归还接口 | |
58 | + | |
59 | + $datas = "machine=".$data["mac_no"]. | |
60 | + "&hatch_no=".$data["rent_hatch_no"]. | |
61 | + "&power_no=".$data["power_no"]. | |
62 | + "&has_power=80". | |
63 | + "&backTime=".date('Y-m-d H:i:s'). | |
64 | + "&isTrue=0"; | |
65 | + | |
66 | + $url = "http://api.ssw-htzn.com/api/v1/customers/manualReturn"; | |
67 | + | |
68 | + json_decode( Http::post($datas, $url ), true) ; | |
69 | + | |
70 | + Log::info('未归还设备请求手动归还: '. $data['power_no']); | |
71 | + } | |
72 | + | |
73 | + } | |
74 | + Log::info('未归还设备请求手动归还---------------------end---------------------------'); | |
75 | + } | |
76 | +} | ... | ... |
Please
register
or
login
to post a comment