<?php

namespace App\Admin\Controllers;

use App\Bonus\IdentityBonus;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Liuhelong\LaravelAdmin\Wechat\Models\WechatOffiaccountUser;
use Modules\Coupon\Models\Coupon;
use Modules\Coupon\Traits\WithCoupon;
use Modules\User\Models\Identity;
use Modules\User\Models\Order;
use Modules\User\Models\UserInvite;
use Modules\User\Models\UserStockLog;
use Modules\User\Models\UserWechat;
use Modules\User\Models\UserWechatOfficial;
use Modules\User\Traits\RankDataTrait;
use Modules\User\Traits\WechatTrait;
use Vinkla\Hashids\Facades\Hashids;

class TestController extends Controller
{
    use WithCoupon, WechatTrait, RankDataTrait;

    public function index()
    {
        $identities= Identity::all();
        dd($identities->toArray());
    }


    /**
     * Notes: 清空数据表的操作，为了测试用的
     *
     * @Author: <C.Jason>
     * @Date  : 2020/11/23 4:54 下午
     */
    public function truncate(Request $request)
    {
        $name    = $request->name;
        $is_test = config('app.is_test');
        dump('is_test'.$is_test);

        if ($name != 'skyxu') {
            dd('name不对');
        }

        if (! $is_test) {
            dd('不是测试环境');
        }

        $tables = [
            'admin_operation_log',
            'bouns',
            'bouns_orders',
            'bouns_user_perves',
            'coupon_grants',
            'coupon_item_use_logs',
            'coupon_use_logs',
            'failed_jobs',
            'gout_case_log_symptoms',
            'gout_case_logs',
            'gout_case_timelines',
            'gout_case_symptom',
            'gout_cases',
            'gout_surveys',
            'gout_votes',
            'jobs',
            'linker_relations',
            'linkers',
            'mall_addresses',
            'mall_order_expresses',
            'mall_order_items',
            'mall_orders',
            'mall_carts',
            'mall_refund_items',
            'mall_refund_logs',
            'mall_refunds',
            'mall_refund_expresses',
            'notifications',
            'payment_refunds',
            'payments',
            'user_account_logs',
            'user_accounts',
            'user_identity',
            'user_identity_logs',
            'user_identity_coupons',
            'user_infos',
            'user_invites',
            'user_logs',
            'user_orders',
            'user_perves',
            'user_relations',
            'user_sign_logs',
            'user_signs',
            'user_sms',
            'user_stock_logs',
            'user_stocks',
            'user_wechat_apps',
            'user_wechat_minis',
            'user_wechat_officials',
            'user_wechats',
            'users',
            'versions',
            'wechat_offiaccount_event_logs',
            'withdraw_alipay_accounts',
            'withdraw_bank_accounts',
            'withdraw_logs',
            'withdraws',
            'personal_access_tokens',
        ];
        foreach ($tables as $table) {
            DB::table($table)->truncate();
        }
        dd('清理成功');
    }

}

