<?php

namespace Modules\Payment;

use Illuminate\Support\Facades\Artisan;

class Payment
{

    protected static string $mainTitle = '支付管理';

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

        self::createAdminMenu();
    }

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

        $settingMenu = $menu::where('title', '支付设置')->get();

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

        $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'     => 30,
            'title'     => self::$mainTitle,
            'icon'      => 'fa-wordpress',
        ]);

        $main->children()->createMany([
            [
                'order' => 1,
                'title' => '支付订单',
                'icon'  => 'fa-bars',
                'uri'   => 'payments',
            ],
            [
                'order' => 2,
                'title' => '退款订单',
                'icon'  => 'fa-bars',
                'uri'   => 'payments/refunds',
            ],
            [
                'order' => 3,
                'title' => '转账订单',
                'icon'  => 'fa-edit',
                'uri'   => 'payments/transfers',
            ],
            [
                'order' => 4,
                'title' => '现金红包',
                'icon'  => 'fa-folder',
                'uri'   => 'payments/redpacks',
            ],
            [
                'order' => 5,
                'title' => '日账单',
                'icon'  => 'fa-bars',
                'uri'   => 'payments/bills',
            ],
        ]);

        $settingMenu = $main->children()->create([
            'order' => 99,
            'title' => '支付设置',
            'icon'  => 'fa-cogs',
            'uri'   => '',
        ]);

        $settingMenu->children()->createMany([
            [
                'order' => 13,
                'title' => '支付配置',
                'icon'  => 'fa-cogs',
                'uri'   => 'payments/settings',
            ],
            [
                'order' => 14,
                'title' => '微信支付',
                'icon'  => 'fa-wechat',
                'uri'   => 'payments/wechats',
            ],
            [
                'order' => 15,
                'title' => '支付宝',
                'icon'  => 'fa-adn',
                'uri'   => 'payments/alipays',
            ],
        ]);
    }

}
