<?php

namespace app\mobile\controller;

use app\common\model\BrokerIncome as BrokerIncomeModel;
use app\common\model\OutRecruitReport;
use app\mobile\MobileBaseController;
use think\App;
use think\facade\View;

class My extends MobileBaseController
{
    private $_broker = null;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->_broker = get_broker();
        View::assign('broker', $this->_broker);
    }

    /**
     * 个人中心
     */
    public function index()
    {
        return view('my/index');
    }

    /**
     * 收益明细
     */
    public function income()
    {
        $data = [];

        //上月收益
        $month_time           = date('Ym', strtotime('-1 month'));
        $month_income         = BrokerIncomeModel::where(['monthtime' => $month_time, 'brokerid' => $this->_broker['id']])->sum('value');
        $data['month_income'] = $month_income;

        return view('my/income', $data);
    }

    /**
     * 收益明细列表
     */
    public function listIncome()
    {
        $map = $this->dealEqualInput(['cate_id']);

        $map[] = ['brokerid', '=', $this->_broker['id']];
        $list  = BrokerIncomeModel::where($map)
            ->order(['id' => 'desc'])
            ->limit(input('limit', 10))
            ->page(input('page', 1))
            ->append(['status_text'])
            ->select();

        ajax_success($list);
    }

    /**
     * 推广码
     */
    public function qrcode()
    {
        error_reporting(E_ERROR);
        $url = request()->domain(true) . '/mobile/candidate/info?broker_id=' . $this->_broker['id'];
        header('Content-Type: image/png');
        ob_clean();
        $errorCorrectionLevel = "L"; // 纠错级别：L、M、Q、H
        $matrixPointSize      = "4"; //生成图片大小 ：1到10
        \phpqrcode\QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize);
        exit();
    }

    /**
     * 我的报备
     */
    public function report()
    {
        return view('my/report');
    }

    public function listReport()
    {
        $map = $this->dealEqualInput(['status'],$this->dealLikeInput(['keyword'=>'realname|mobile']));

        $map[] = ['brokerid', '=', $this->_broker['id']];
        $list  = OutRecruitReport::with(['recruit'])
            ->where($map)
            ->order(['id' => 'desc'])
            ->limit(input('limit', 10))
            ->page(input('page', 1))
            ->append(['status_text'])
            ->select();

        ajax_success($list);
    }
}
