<?php

namespace Modules\Mall;

use Illuminate\Support\Facades\Artisan;

class Mall
{

    protected static string $mainTitle = '商城管理';

    /**
     * Notes   : 模块初始化要做的一些操作
     *
     * @Date   : 2021/3/12 11:34 上午
     * @Author : < Jason.C >
     */
    public static function install()
    {
        Artisan::call('migrate', [
            '--path' => 'modules/Mall/Database/Migrations',
        ]);

        self::createAdminMenu();
    }

    /**
     * Notes   : 卸载模块的一些操作
     *
     * @Date   : 2021/3/12 11:35 上午
     * @Author : < Jason.C >
     */
    public static function uninstall()
    {
        $menu = config('admin.database.menu_model');

        $mains = $menu::where('title', self::$mainTitle)->get();

        foreach ($mains as $main) {
            $main->delete();
        }
    }

    protected static function createAdminMenu()
    {
        $menu = config('admin.database.menu_model');

        $main = $menu::create([
            'parent_id' => 0,
            'order'     => 20,
            'title'     => self::$mainTitle,
            'icon'      => 'fa-institution',
        ]);

        $main->children()->createMany([
                [
                    'order' => 0,
                    'title' => '商城看板',
                    'icon'  => 'fa-bar-chart',
                    'uri'   => 'mall/dashboard',
                ], [
                    'order' => 0,
                    'title' => '活动管理',
                    'icon'  => 'fa-bar-chart',
                    'uri'   => 'mall/activities',
                ],
                //                [
                //                    'order' => 1,
                //                    'title' => '店铺管理',
                //                    'icon'  => 'fa-puzzle-piece',
                //                    'uri'   => 'mall/shops',
                //                ],
                //                [
                //                    'order' => 1,
                //                    'title' => '职位管理',
                //                    'icon'  => 'fa-joomla',
                //                    'uri'   => 'mall/jobs',
                //                ],
                [
                    'order' => 2,
                    'title' => '商品列表',
                    'icon'  => 'fa-archive',
                    'uri'   => 'mall/goods',
                ], [
                    'order' => 3,
                    'title' => '商品分类',
                    'icon'  => 'fa-bars',
                    'uri'   => 'mall/categories',
                ],
                //                [
                //                    'order' => 4,
                //                    'title' => '商品标签',
                //                    'icon'  => 'fa-tags',
                //                    'uri'   => 'mall/tags',
                //                ],
                [
                    'order' => 5,
                    'title' => '品牌管理',
                    'icon'  => 'fa-copyright',
                    'uri'   => 'mall/brands',
                ], [
                    'order' => 6,
                    'title' => '订单管理',
                    'icon'  => 'fa-bars',
                    'uri'   => 'mall/orders',
                ], [
                    'order' => 6,
                    'title' => '提货订单',
                    'icon'  => 'fa-bars',
                    'uri'   => 'mall/stock_orders',
                ], [
                    'order' => 7,
                    'title' => '退款订单',
                    'icon'  => 'fa-bars',
                    'uri'   => 'mall/refunds',
                ], [
                    'order' => 8,
                    'title' => '物流公司',
                    'icon'  => 'fa-cab',
                    'uri'   => 'mall/expresses',
                ], [
                    'order' => 9,
                    'title' => '运费模板',
                    'icon'  => 'fa-send',
                    'uri'   => 'mall/deliveries',
                ], [
                    'order' => 10,
                    'title' => '轮播图管理',
                    'icon'  => 'fa-th-large',
                    'uri'   => 'mall/banners',
                ], [
                    'order' => 11,
                    'title' => '退货理由',
                    'icon'  => 'fa-th-large',
                    'uri'   => 'mall/reasons',
                ], [
                    'order' => 12,
                    'title' => '收货地址',
                    'icon'  => 'fa-th-large',
                    'uri'   => 'mall/addresses',
                ], [
                    'order' => 13,
                    'title' => '视频管理',
                    'icon'  => 'fa-th-large',
                    'uri'   => 'mall/videos',
                ],
            ]
        );
    }

}
