<?php

namespace app\job\controller;

use app\common\library\wxserver\Wholesaler as Server;
use cores\BaseJob;
use cores\exception\BaseException;
use cores\traits\QueueTrait;

class Wxholesaler extends BaseJob
{
    use QueueTrait;

    /**
     * 消费队列任务:输出测试信息
     * @param array $data 参数
     * @return bool 返回结果
     * @throws BaseException
     */
    public function handle(array $data): bool
    {
        if (!empty($data['appid'])) {
            if (!empty($data['template_id'])) {
                $this->sendTestVersion($data['appid'], $data['template_id']);
            } else {
                $this->sendOfficialVersion($data['appid']);
            }
        }
        return true;
    }

    /**
     * @notes:发布正式版
     * @param $appid
     * @author: wanghousheng
     */
    private function sendOfficialVersion($appid)
    {
        $obj = new Server();
        $res = $obj->privacyInfo($appid);
        if ($res == 'ok') {
            $obj->submitAudit($appid);
        }
    }

    /**
     * @notes:发布体验版
     * @param $appid
     * @param $template_id
     * @throws BaseException
     * @author: wanghousheng
     */
    private function sendTestVersion($appid, $template_id)
    {
        $obj = new Server();
        $res = $obj->commit($appid, $template_id);
    }
}