0
0

更新代码

This commit is contained in:
2020-08-04 10:09:42 +08:00
parent 6118b5b63b
commit c2ac5d964e
478 changed files with 34410 additions and 0 deletions

75
app/Models/WechatMenu.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace App\Models;
class WechatMenu extends Model
{
public function children()
{
return $this->hasMany(WechatMenu::class, 'parent_id')->orderBy('sort', 'asc');
}
public function parent()
{
return $this->belongsTo(WechatMenu::class)->withDefault();
}
public static function getPublishArray()
{
$buttons = [];
$menus = self::where('parent_id', 0)->orderBy('sort', 'asc')->get();
foreach ($menus as $key => $menu) {
$button['name'] = $menu->name;
if ($menu->children->isEmpty()) {
$button = array_merge($button, $menu->type_value);
} else {
foreach ($menu->children as $k => $child) {
$subButton['name'] = $child->name;
$subButton = array_merge($subButton, $child->type_value);
$button['sub_button'][$k] = $subButton;
$subButton = [];
}
}
$buttons[] = $button;
$button = [];
}
return $buttons;
}
public function getTypeValueAttribute()
{
switch ($this->type) {
case 'click':
return [
'type' => $this->type,
'key' => $this->value,
];
break;
case 'view':
return [
'type' => $this->type,
'url' => $this->value,
];
break;
case 'miniprogram':
return [
'type' => $this->type,
'url' => explode($this->value)[0],
'appid' => explode($this->value)[1],
'pagepath' => explode($this->value)[2],
];
break;
default:
return [
'type' => 'view',
'url' => $this->value,
];
break;
}
}
}