<?php
declare (strict_types = 1);
namespace app\system\controller\v1;

use app\BaseController;
use app\model\system\AdverPage;
use app\model\system\Advert;
use app\model\system\WeixinPushUser;
use app\Request;
use library\services\UtilService;
use Qiniu\Config;

// +----------------------------------------------------------------------
// | [ WE CAN DO IT MORE SIMPLE  ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2020 rights reserved.
// +----------------------------------------------------------------------
// | Author: TABLE ME
// +----------------------------------------------------------------------
// | Date: 2020-09-06 21:53
// +----------------------------------------------------------------------

class Bind extends  BaseController{

    /**
     * 绑定后台管理
     * @param Request $request
     */
    public function qrocde(Request $request) {
        $token= base64_encode(crypto_encrypt($request->adminInfo['id']."|" . time(),'md5_token'));
        $url =  \config('app')['API_URL'] .'/systemv1/login/system_bind?token='.$token;
        return app('json')->success($url);
    }


    /**
     * 绑定数据
     * @param Request $request
     */
    public function index(Request $request) {
        $pageSize = 50;
        $post =  UtilService::getMore(
            [
                ['page',1],
                ['keyword','']
            ],$request
        );
        $where = [];
        $where['type'] = 'system';
        $where['sassid'] = 0;
        if(!empty($post['keyword'])) {
            $where['nickname'] = ['%' . $post['keyword'] .'%','whereLike'];
        }
        list($pageCount,$data) = (new WeixinPushUser)
            ->getList($post['page'],$where,$pageSize,'id desc');
       $result = UtilService::getParam(
            ['avatar','nickname','openid',['time','time','date("Y-m-d H:i:s",$1)'],'id'],$data
        );

        return app('json')->success([
            'list'      => $result,
            'pageCount' => $pageCount,
            'pageSize'  => $pageSize,
            'page'      => $post['page']
        ]);
    }


    /**
     * 删除数据
     * @param Request $request
     */
    public function del(Request $request) {
        $post =  UtilService::getMore(
            [
                ['id','','empty','参数错误'],
            ],$request
        );
        (new WeixinPushUser)->where('id',$post['id'])->where('sassid',0)->delete();
        return app('json')->success('删除成功');
    }




}