<?php
namespace app\workerapi\logic;

use app\common\logic\BaseLogic;
use app\common\service\wechat\WeChatConfigService;
use app\common\service\wechat\WeChatMnpService;
use EasyWeChat\MiniApp\Application;
use think\facade\Db;
use think\facade\Log;

/**
 * 服务商品逻辑处理
 * Class GoodsCategoryLogic
 * @package app\workerapi\logic
 */
class GoodsCategoryLogic extends BaseLogic
{
    /**
     * @return string|void
     */
    public static function getQRCode($params)
    {
        try {
            $response = (new WeChatMnpService())->getUnlimitedQRCode(
                '&type=2&id='.$params['id'].'&worker='.$params['user_info']['worker_number'],
                "pages/good/good",
                'release',//trial、release、develop
                false
            );
            $qrcode = $response->getContent();
            if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
                mkdir('./uploads/wx_qrcode/'.date('Ymd'));
            }
            $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
            file_put_contents($file_name, $qrcode);
            return $file_name;
        } catch (\Throwable $e) {
            // 失败
            echo $e->getMessage();
        }
    }

}