qrcode 生成二維碼的代碼

<?php
/**
 * 關於員工的信息處理
 * @author anyuan
 */
namespace app\recruitcard\service;

use app\common\base\service\BaseService;
use app\library\ErrorCode;
use app\model\ShopStaffInfo;
use doushen\frame\ResponseBath;
use phpDocumentor\Reflection\Types\Integer;
use Yii;
use doushen\request\Http;

class RecruitStaffService extends BaseService
{
    const STAFF_STATUS = 2;//員工狀態-正常
    const STAFF_SOURCE_SCHOOL = 1;//正常分校老師
    const STAFF_SOURCE_ORGAN = 2;//機構
    const STAFF_SOURCE_JOIN = 4;//加盟校
    const STAFF_TITLE_COMMON = 3;//普通員工
    ####圖片風格####
    const STAFF_CODE_STYLE_1 = 1;//大語文培優班
    const STAFF_CODE_STYLE_2 = 2;//大語文拔尖班
    const STAFF_CODE_STYLE_3 = 3;//寫作拔尖班
    const STAFF_CODE_STYLE_4 = 4;//閱讀拔尖班
    const STAFF_CODE_STYLE_5 = 5;//大語文王者班
    const STAFF_CODE_STYLE_6 = 6;//諸葛學堂
    ####圖片風格####
    ####2020暑秋課程代理商分銷圖片風格####
    const STAFF_CODE_STYLE_SA_1 = 1;//暑期線上培優班
    const STAFF_CODE_STYLE_SA_2 = 2;//其他
    ####2020暑秋課程代理商分銷圖片風格####
    ####特殊機構####
    const ORGAN_CODE_STYLE_1 = 1;//大語文培優班
    const ORGAN_CODE_STYLE_2 = 2;//大語文拔尖班
    const ORGAN_CODE_STYLE_3 = 3;//寫作拔尖班
    const ORGAN_CODE_STYLE_4 = 4;//閱讀拔尖班
    const ORGAN_CODE_STYLE_5 = 5;//大語文王者班
    const ORGAN_CODE_STYLE_6 = 6;//諸葛學堂會員/大英語
    const ORGAN_CODE_STYLE_7 = 7;//理科前線
    const ORGAN_CODE_STYLE_8 = 8;//納約數學
    const ORGAN_CODE_STYLE_9 = 9;//拼音識字
    const ORGAN_CODE_STYLE_10 = 10;//諸葛學堂課程分銷
    ####特殊機構####
    const ORGAN_FLAG_KAISA = 10001;//凱撒旅遊
    const ORGAN_FLAG_CCT_BJ = 10002;//北京康輝
    const ORGAN_FLAG_CCT_JS = 10003;//集善康輝
    const ORGAN_FLAG_CCT_QD = 10004;//青島康輝
    const ORGAN_FLAG_CCT_HB = 10005;//湖北康輝
    const ORGAN_FLAG_CCT_JSU = 10006;//江蘇康輝
    const ORGAN_FLAG_CCT_GL = 10007;//桂林康輝
    const ORGAN_FLAG_CCT_GX = 10008;//廣西康輝
    const ORGAN_FLAG_CCT_SC = 10009;//四川康輝
    const ORGAN_FLAG_CCT_HN = 10010;//海南康輝
    const ORGAN_FLAG_CCT_GZ = 10011;//貴州康輝
    const ORGAN_FLAG_CCT_ZJ = 10012;//浙江康輝
    const ORGAN_FLAG_CCT_XA = 10013;//西安康輝
    const ORGAN_FLAG_CCT_GM = 10014;//昆明康輝
    const ORGAN_FLAG_CCT_SH = 10015;//上海康輝
    const ORGAN_FLAG_CCT_GS = 10016;//甘肅康輝
    const ORGAN_FLAG_CCT_AH = 10017;//安徽康輝
    const ORGAN_FLAG_CCT_HNA = 10018;//河南康輝
    const ORGAN_FLAG_CCT_DL = 10019;//大連康輝
    const ORGAN_FLAG_CCT_HLJ = 10020;//黑龍江康輝
    const ORGAN_FLAG_CCT_JX = 10021;//江西康輝
    const ORGAN_FLAG_CCT_NX = 10022;//寧夏康輝
    const ORGAN_FLAG_CCT_SD = 10023;//山東康輝
    const ORGAN_FLAG_CCT_HUN = 10024;//湖南康輝
    const ORGAN_FLAG_CCT_SZ = 10025;//深圳康輝
    const ORGAN_FLAG_CCT_QH = 10026;//青海康輝
    const ORGAN_FLAG_CCT_HUNX = 10027;//湖南新康輝國旅
    const ORGAN_FLAG_CCT_ST = 10028;//汕頭康輝
    const ORGAN_FLAG_CCT_DG = 10029;//東莞康輝
    const ORGAN_FLAG_CCT_TJ = 10038;//天津康輝
    const ORGAN_FLAG_CCT_XJ = 10054;//新疆康輝
    const ORGAN_FLAG_LUYIZAITU = 10030;//旅途路易 安旅
    const ORGAN_FLAG_HELI = 10031;//禾力旅行
    const ORGAN_FLAG_XISHU = 10032;//義學書院
    const ORGAN_FLAG_DIERKETANG = 10033;//第二課堂
    const ORGAN_FLAG_JIUFANG = 10034;//九方書院
    const ORGAN_FLAG_RULIN = 10035;//儒林學院
    const ORGAN_FLAG_KANG = 10036;//康爸爸
    const ORGAN_FLAG_DOUSHENSHUANGSHI = 10037;//豆神雙師
    const ORGAN_FLAG_KANGWEIXUETANG = 10039; //康微學堂
    const ORGAN_FLAG_HOUDEIJY = 10040; //厚德教育
    const ORGAN_FLAG_SUIXINKT = 10041; //隨心課堂
    const ORGAN_FLAG_LISICHENLIUXUE = 10042; //立思辰留學
    const ORGAN_FLAG_LISICHENMEITEJY = 10043; //立思辰敏特教育
    const ORGAN_FLAG_LISICHENRTW_YXH = 10044; //立思辰瑞特威-新疆烏魯木齊優學匯
    const ORGAN_FLAG_LISICHENRTW_XEZ = 10045; //立思辰瑞特威-新疆烏魯木齊學而知
    const ORGAN_FLAG_LISICHENRTW_TXH = 10046; //立思辰瑞特威-新疆石河子市童學匯
    const ORGAN_FLAG_LISICHENRTW_WLWYJY = 10047; //立思辰瑞特威-新疆烏市聯衆文化藝術教育
    const ORGAN_FLAG_LISICHENRTW_XJBNYC = 10048; //立思辰瑞特威-新疆百年英才
    const ORGAN_FLAG_LISICHENQUYUFZ = 10049; //立思辰區域發展
    const ORGAN_FLAG_LISICHENJITUANZB = 10050; //立思辰集團總部
    const ORGAN_FLAG_LISICHENBAINIANYC = 10051; //立思辰百年英才
    const ORGAN_FLAG_LISICHENZONGBUKANGB = 10052; //立思辰總部康邦
    const ORGAN_FLAG_LISICHENZONGBUNX = 10053; //立思辰總部寧夏
    const ORGAN_FLAG_LISICHENKUAXUEWANG = 10055; //立思辰跨學網
    const ORGAN_FLAG_LISICHENJTSHICHANGBU = 10056; //立思辰集團市場部
    const ORGAN_FLAG_YIQI= 10057; //易啓
    const ORGAN_FLAG_ZHONGQIAOGUOLV= 10058; //中僑國旅
    const ORGAN_FLAG_LISICHENHUIRONGEXUE= 10059; //立思辰集團 匯融e學
    const ORGAN_FLAG_GAINIANXING= 10060; //概念行
    const ORGAN_FLAG_LAOJIN = 10061;//老金
    const ORGAN_FLAG_CAICAI = 10062;//蔡蔡
    const ORGAN_FLAG_ZJXT = 10063;//諸葛學堂課程分銷
    const ORGAN_ARRAY = array(10001,10002,10003,10004,10005,10006,10007,10008,10009,10010,10011,10012,10013,10014,10015,
                                10016,10017,10018,10019,10020,10021,10022,10023,10024,10025,10026,10027,10028,10029,10030,
                                10031,10032,10033,10034,10035,10036,10037,10038,10039,10040,10041,10042,10043,10044,10045,
                                10046,10047,10048,10049,10050,10051,10052,10053,10054,10055,10056,10057,10058,10059,10060,
                                10061,10062,10063);
    const ORGAN_NO_DEPARTMENT_INITIAL_ARRAY = array(10001,10002,10003,10004,10005,10006,10007,10008,10009,10010,10011,10012,10013,10014,10015,
        10016,10017,10018,10019,10020,10021,10022,10023,10024,10025,10026,10027,10028,10029,10030,
        10031,10032,10033,10034,10035,10036,10037,10038,10039,10040,10041,10054,10057,10058,10060,10061,10062,10063);  //非立思辰集團子公司機構
    const ORGAN_NO_DEPARTMENT_LATER_ARRAY = array(
        10042,10043,10044,10045,10046,10047,10048,10053,10055,10056,10059
    );//後加的沒有部門的機構
    const ORGAN_DEPARTMENT_LATER_ARRAY = array(
        10049,10050,10051,10052
    );//後來的有部門的機構
    const ORGAN_CHANNEL_ARRAY = array(
        10047,10049,10050,10051,10052,10055,10056
    );//後加的有二級渠道的
    const ORGAN_LONG_MAP_TIME = array(10062);
    const ORGAN_DEPARTMENT_INFO = array(
        self::ORGAN_FLAG_LISICHENQUYUFZ => array(
            "總經辦",
            "綜合管理部",
            "項目實施部",
            "外企與國際教育事業部",
            "售前諮詢部",
            "區域教育事業部-魯西南",
            "區域教育事業部-華中",
            "區域教育事業部-華南",
            "區域教育事業部-華北",
            "軍校與集成事業部",
        ),
        self::ORGAN_FLAG_LISICHENJITUANZB => array(
            "總裁辦",
            "人力資源管理中心",
            "財務管理中心",
            "行政管理中心",
            "物業管理中心",
            "投資管理與金融合作部",
            "戰略與創新發展部",
            "證券事務部",
            "市場部",
            "互聯網運營部",
            "風險管理部",
            "公共關係部",
            "信息安全集團",
        ),
        self::ORGAN_FLAG_LISICHENBAINIANYC => array(
            "市場部",
        ),
        self::ORGAN_FLAG_LISICHENZONGBUKANGB => array(
            "業務三部",
            "業務四部",
            "業務五部",
            "業務六部",
            "業務七部",
            "業務八部",
            "新渠道事業部",
            "鄭州分公司",
            "天津分公司",
            "上海分公司",
            "濟南分公司",
            "南京分公司",
            "成都分公司",
            "西南大區",
        ),
    );//有部門的機構 詳細部門信息
    const ORGAN_CCT_ARRAY = array(10002,10003,10004,10005,10006,10007,10008,10009,10010,10011,10012,10013,10014,10015,
        10016,10017,10018,10019,10020,10021,10022,10023,10024,10025,10026,10027,10028,10029,10038,10054);//其實都是康輝的,不同城市區分
    public static $name;
    public static $city;
    public static $city_id;
    public static $campus;
    public static $campus_id;
    public static $staff_source;
    public static $id;
    public static $title;
    private static $jiangsusanxiao = ['常熟分校','張家港分校','江陰分校'];//江蘇三校
    private static $special_school = ['台州分校','湘潭分校','長春分校'];//三個特殊的分校走全國
    public static $second_id;
    /**
     * 驗證員工身份正確性
     * @param int $tel
     * @param string $name
     * @return bool
     */
    public static function checkStaff(int $tel, string $name ) {
        #驗證信息
        $staff_info = ShopStaffInfo::find()->select('id,city,staff_source,city_id,campus,campus_id,title')
            ->where(['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'name'=>trim($name)])->asArray()->one();
        if (!$staff_info) {
            return false;
        }
        #賦值 爲創建二維碼省一條sql
        self::$name = $name;
        self::$city = $staff_info['city'];
        self::$city_id = $staff_info['city_id'];
        self::$campus = $staff_info['campus'];
        self::$campus_id = $staff_info['campus_id'];
        self::$staff_source = $staff_info['staff_source'];
        self::$id = $staff_info['id'];
        self::$title = $staff_info['title'];

        return true;
    }

    /**
     * 驗證員工身份正確性
     * @param int $tel
     * @param string $name
     * @return bool
     */
    public static function checkStaffWithSource(int $tel, string $name, int $staff_source ) {
        #驗證信息
        $staff_info = ShopStaffInfo::find()->select('id,city,staff_source,city_id,campus,campus_id,title')
            ->where(['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'name'=>trim($name), 'staff_source'=>$staff_source])->asArray()->one();
        if (!$staff_info) {
            return false;
        }

        #賦值 爲創建二維碼省一條sql
        self::$name = $name;
        self::$city = $staff_info['city'];
        self::$city_id = $staff_info['city_id'];
        self::$campus = $staff_info['campus'];
        self::$campus_id = $staff_info['campus_id'];
        self::$staff_source = $staff_info['staff_source'];
        self::$id = $staff_info['id'];
        self::$title = $staff_info['title'];

        return true;
    }

    public static function checkDistributestaff(int $tel, string $name ) {
        #驗證信息
        $staff_info = ShopStaffInfo::find()->select('id,city,staff_source,city_id,campus,campus_id,title')
            ->where(['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'name'=>trim($name),"staff_source"=>100001])->asArray()->one();
        if (!$staff_info) {
            return false;
        }
        #賦值 爲創建二維碼省一條sql
        self::$name = $name;
        self::$city = $staff_info['city'];
        self::$city_id = $staff_info['city_id'];
        self::$campus = $staff_info['campus'];
        self::$campus_id = $staff_info['campus_id'];
        self::$staff_source = $staff_info['staff_source'];
        self::$id = $staff_info['id'];
        self::$title = $staff_info['title'];

        return true;
    }

    /**
     * 以手機號驗證機構 沒有則添加,有則修改名字
     * @param int $tel
     * @param string $name
     * @return bool
     */
    public static function CheckOrgan (int $tel, string $name,int $organ,int $second,string $second_name, string $department)
    {
        $where = ['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'staff_source'=>$organ];
        if ($department) {
            $data['org_department'] = trim($department);
//            $where['org_department'] = trim($department);
        }
        $staff_info = ShopStaffInfo::find()->select('id,staff_source')
            ->where($where)->asArray()->one();
        if ($staff_info) {
            #修改
            $data['name'] = $name;
            ShopStaffInfo::getDb()->createCommand()->update(ShopStaffInfo::tableName(), $data,
                'id = ' . $staff_info['id'] )->execute();
        } else {
            #添加
            $data['name'] = $name;
            $data['staff_source'] = $organ;
            $data['tel'] = trim($tel);
            ShopStaffInfo::getDb()->createCommand()->insert(ShopStaffInfo::tableName(),
                $data)->execute();//未生成
            $staff_info = ShopStaffInfo::find()->select('id,staff_source')
                ->where($where)->asArray()->one();
        }
        if ($second) {
            #查看二級渠道是否存在
            $second_info = ShopStaffInfo::find()->select('id,staff_source')
                ->where(['name'=>$second_name,'from_staff_id'=>$staff_info['id']])->asArray()->one();
            if (!$second_info) {
                ShopStaffInfo::getDb()->createCommand()->insert(ShopStaffInfo::tableName(),
                    ['name'=>$second_name,'from_staff_id'=>$staff_info['id'],'staff_source'=>$organ])->execute();//未生成
                #這塊需要改進下,省掉這條sql
                $second_info = ShopStaffInfo::find()->select('id,staff_source')
                    ->where(['name'=>$second_name,'from_staff_id'=>$staff_info['id']])->asArray()->one();
            }
            self::$second_id = $second_info['id'];
        }
    }

    /**
     * 判斷二級渠道是否存在
     */
    public static function chekSecond (int $tel, string $name,int $organ,int $second,string $second_name, string $department)
    {
        $where = ['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'staff_source'=>$organ];
        if ($department) {
            $data['org_department'] = trim($department);
        }
        $staff_info = ShopStaffInfo::find()->select('id,staff_source')
            ->where($where)->asArray()->one();
        if (!$staff_info) {
            return false;
        }
        if ($second) {
            #查看二級渠道是否存在
            $second_info = ShopStaffInfo::find()->select('id,staff_source')
                ->where(['name'=>$second_name,'from_staff_id'=>$staff_info['id']])->asArray()->one();
            if (!$second_info) {
                #當二級渠道不存在時生成對應的二級渠道
                ShopStaffInfo::getDb()->createCommand()->insert(ShopStaffInfo::tableName(),
                    ['name'=>$second_name,'from_staff_id'=>$staff_info['id'],'staff_source'=>$organ])->execute();//未生成
                $second_info = ShopStaffInfo::find()->select('id,staff_source')
                    ->where(['name'=>$second_name,'from_staff_id'=>$staff_info['id']])->asArray()->one();
            }
            self::$second_id = $second_info['id'];
        }
        return true;
    }

    /**
     * 生成用戶二維碼
     * @param
     */
    public static function get_qr_code($tel, int $action)
    {
        #生成二維碼底圖選擇
        if ($action == self::STAFF_CODE_STYLE_1) {
            $code_x = 586;   $code_y = 2930;
            $text1_x = 20;   $text1_y = 2950;
            $text2_x = 20;   $text2_y = 2992;
            $text3_x = 20;   $text3_y = 3032;
            $red = 255; $green = 255; $blue = 255;
            $imagePath = '/library/gentlemanImg/staff1.png';//大語文培優班
        } elseif ($action == self::STAFF_CODE_STYLE_2) {
            $code_x = 586;   $code_y = 3150;
            $text1_x = 20;   $text1_y = 3170;
            $text2_x = 20;   $text2_y = 3212;
            $text3_x = 20;   $text3_y = 3252;
            $red = 0; $green = 0; $blue = 0;
            $imagePath = '/library/gentlemanImg/staff2.png';//大語文拔尖班
        }elseif ($action == self::STAFF_CODE_STYLE_3) {
            $code_x = 586;   $code_y = 2730;
            $text1_x = 20;   $text1_y = 2750;
            $text2_x = 20;   $text2_y = 2792;
            $text3_x = 20;   $text3_y = 2832;
            $red = 0; $green = 0; $blue = 0;
            $imagePath = '/library/gentlemanImg/staff3.png';//大語文拔尖班
        }elseif ($action == self::STAFF_CODE_STYLE_4) {
            $code_x = 586;   $code_y = 2730;
            $text1_x = 25;   $text1_y = 2750;
            $text2_x = 25;   $text2_y = 2792;
            $text3_x = 25;   $text3_y = 2832;
            $red = 0; $green = 0; $blue = 0;
            $imagePath = '/library/gentlemanImg/staff4.png';//大語文拔尖班
        }elseif ($action == self::STAFF_CODE_STYLE_5) {
            $code_x = 586;   $code_y = 3230;
            $text1_x = 20;   $text1_y = 3250;
            $text2_x = 20;   $text2_y = 3292;
            $text3_x = 20;   $text3_y = 3332;
            $red = 0; $green = 0; $blue = 0;
            $imagePath = '/library/gentlemanImg/staff5.png';//大語文拔尖班
        }elseif ($action == self::STAFF_CODE_STYLE_6){
            $code_x = 586;   $code_y = 2930;
            $text1_x = 20;   $text1_y = 2950;
            $text2_x = 20;   $text2_y = 2992;
            $text3_x = 20;   $text3_y = 3032;
            $text4_x = 20;   $text4_y = 3072;
            $red = 255; $green = 255; $blue = 255;
            $imagePath = '/library/gentlemanImg/staff6.png';//諸葛學堂會員
        } else {
            return ['check' => false,'data' => '生成二維碼底圖參數錯誤'];
        }
        #特殊校區的校驗跳轉
        if (in_array(trim(self::$city),self::$jiangsusanxiao) ) {
            self::$city_id = 1003;//江蘇三校
        } elseif (in_array(trim(self::$city),self::$special_school) ) {
            self::$city_id = 1002;//全國
        } elseif (mb_substr(self::$city,-2,2) == "分校" && !self::$city_id) {
            self::$city_id = 1002;//有分校名稱,但是未找到school_id異常的
        }
        //跳轉地址
        $path = '/tmp/recruitcard';
        if (self::$staff_source != self::STAFF_SOURCE_SCHOOL) {//機構或加盟校
            if (self::$staff_source == self::STAFF_SOURCE_JOIN) {//加盟校
                $url = "https://bm.zhugexuetang.com?school_id=".self::$city_id."&fromEntrance=2&entrance=2&staff_code=";
                $text = '大語文'.str_replace('分校','',self::$city).self::$campus.'誠摯爲您推薦';
            } else {//機構
                $url = "https://bm.zhugexuetang.com?fromEntrance=1&entrance=2&staff_code=";//bm.zhugexuetang.com
                $text = self::$name.'誠摯爲您推薦豆神大語文';
            }
        } else {//分校
            if (self::$title == self::STAFF_TITLE_COMMON) {//普通員工
                if (mb_substr(self::$city,-2,2) == "分校") {//存在分校字段
                    $url = "https://bm.zhugexuetang.com?school_id=".self::$city_id."&fromEntrance=2&entrance=2&staff_code=";
                    $text = '我是'.self::$name.'老師,很榮幸爲您推薦';
                } else {
                    $url = "https://bm.zhugexuetang.com?fromEntrance=1&entrance=2&staff_code=";
                    $text = '我是'.self::$name.'老師,很榮幸爲您推薦';
                }
            } else {//績效員工
                if (mb_substr(self::$city,-2,2) == "分校") {//存在分校字段
                    $url = "https://bm.zhugexuetang.com?school_id=".self::$city_id."&fromEntrance=2&entrance=2&staff_code=";
                    $text = '我是'.self::$name.'老師,很榮幸爲您推薦';
                } else {
                    $url = "https://bm.zhugexuetang.com?fromEntrance=1&entrance=2&staff_code=";
                    $text = '我是'.self::$name.'老師,很榮幸爲您推薦';
                }
            }
        }

        // 諸葛學堂鏈接
        if($action == self::STAFF_CODE_STYLE_6){
            $url = "https://m.zhugexuetang.com/zgxt_vip?source=135&staff_code=";
        }

        $code = self::get_qr_tel($tel);
        $staff_code = self::$staff_source.'_'.self::$city_id.'_'.self::$campus_id.'_'.$code;
        #會寫員工表code
        self::updateInfoData(['code'=>$staff_code],['id'=>self::$id]);
        if (!is_dir($path)) {
            @mkdir($path);
        }
        include(ROOT_PATH . '/library/phpqrcode/qrlib.php');
        $qrcodePath = $path . '/' . $tel . '.png';
        \QRcode::png($url.$staff_code, $qrcodePath, 3, 2);

        #製作圖片
        #原始圖像
        $dst = (ROOT_PATH . $imagePath);
        #得到原始圖片信息
        $dst_im1 = imagecreatefrompng($dst);
        $dst_info1 = getimagesize($dst);
        #二維碼圖片
        $src1 = $qrcodePath;
        $src1_im = imagecreatefrompng($src1);
        $src1_info = getimagesize($src1);
        #合併水印圖片
        imagecopymerge($dst_im1,$src1_im,$code_x,$code_y,0,0,$src1_info[0],$src1_info[1],100);
        #合成圖片的路徑
        $path = '/tmp/gentlemancard';
        if (!is_dir($path)) {
            @mkdir($path);
        }
        $poster_marge_path =$path . '/' . date('Y-m-d').'-'.$tel . '.png';
        #輸出合併後水印圖片
        ob_start();
        imagepng($dst_im1,$poster_marge_path);
        imagedestroy($dst_im1);
        imagedestroy($src1_im);

        #添加圖片文字
        $dst_path = $poster_marge_path;
        $dst_new = imagecreatefromstring(file_get_contents($dst_path));
        $font = (ROOT_PATH . '/library/gentlemanImg/fzlthk.ttf');
        $im = imagecreatetruecolor(400, 30);
        $colour =imagecolorallocate($im, $red,$green,$blue);
        #判斷字數
        $size = 20;
        if (mb_strlen($text) > 16) {
            $size = 15;
        }
        imagefttext($dst_new, $size, 0,$text1_x, $text1_y, $colour, $font, $text);//城市
        if($action == self::STAFF_CODE_STYLE_6){
            imagefttext($dst_new, $size, 0,$text2_x, $text2_y, $colour, $font, '諸葛學堂會員大禮包');
            imagefttext($dst_new, $size, 0,$text3_x, $text3_y, $colour, $font, '願你暢遊文化世界');
            imagefttext($dst_new, $size, 0,$text4_x, $text4_y, $colour, $font, '掃描右方二維碼即可購買');
        }else{
            imagefttext($dst_new, $size, 0,$text2_x, $text2_y, $colour, $font, '掃描右方二維碼會看到');
            imagefttext($dst_new, $size, 0,$text3_x, $text3_y, $colour, $font, '最適合您孩子的1~4個班級');
        }
        header('Content-type: image/png');
        imagepng($dst_new);
        @unlink($dst_new);
        $sImage = ob_get_contents();
        ob_end_clean();
        $base64_img = base64_encode($sImage);
        @unlink($qrcodePath);

        return ['check' => true,'data' => $base64_img];

    }

    /**
     * 生成用戶分銷二維碼-99元分銷
     * @param $tel
     * @param int $action
     * @return array
     */
    public static function get_dr_code($tel)
    {
        #生成二維碼底圖選擇
        $code_x = 521;   $code_y = 1188;
        $imagePath = '/library/gentlemanImg/distribute99.png';//大語文培優班
        //跳轉地址
        $path = '/tmp/recruitcarddistribute';
//        $url = "https://bm.zhugexuetang.com?school_id=".self::$city_id."&fromEntrance=2&entrance=2&staff_code=";  //測試地址春季招生的無用
//        $url = "http://bmdev.zhugexuetang.com/activity/ninety-nine/classlist?school_id=".self::$city_id."&fromEntrance=3&entrance=3&staff_code=";//測試地址
        $url = "https://jm.doushen.com/activity/99list?school_id=".self::$city_id."&fromEntrance=3&entrance=3&staff_code=";

        $code = self::get_qr_tel($tel);
        $staff_code = self::$staff_source.'_'.self::$city_id.'_'.self::$campus_id.'_'.$code;
        #會寫員工表code
        self::updateInfoData(['code'=>$staff_code],['id'=>self::$id]);
        if (!is_dir($path)) {
            @mkdir($path);
        }
        include(ROOT_PATH . '/library/phpqrcode/qrlib.php');
        $qrcodePath = $path . '/' . $tel . '.png';
        \QRcode::png($url.$staff_code, $qrcodePath, 3, 2);

        #製作圖片
        #原始圖像
        $dst = (ROOT_PATH . $imagePath);
        #得到原始圖片信息
        $dst_im1 = imagecreatefrompng($dst);
        $dst_info1 = getimagesize($dst);
        #二維碼圖片
        $src1 = $qrcodePath;

        $src1_im = imagecreatefrompng($src1);
        $src1_info = getimagesize($src1);
        #合併水印圖片
        imagecopymerge($dst_im1,$src1_im,$code_x,$code_y,0,0,$src1_info[0],$src1_info[1],100);
        #合成圖片的路徑
        $path = '/tmp/distribute';
        if (!is_dir($path)) {
            @mkdir($path);
        }
        $poster_marge_path =$path . '/' . date('Y-m-d').'-'.$tel . '.png';
        #輸出合併後水印圖片
        ob_start();
        imagepng($dst_im1,$poster_marge_path);

        imagedestroy($dst_im1);
        imagedestroy($src1_im);

        #添加圖片文字
        $dst_path = $poster_marge_path;
        $dst_new = imagecreatefromstring(file_get_contents($dst_path));
        header('Content-type: image/png');
        imagepng($dst_new);
        @unlink($dst_new);
        $sImage = ob_get_contents();
        ob_end_clean();
        $base64_img = base64_encode($sImage);
        @unlink($qrcodePath);

        return ['check' => true,'data' => $base64_img];

    }

    /**
     * 生成用戶分銷二維碼-2020暑秋課程代理商分銷
     * @param $tel
     * @param int $action
     * @return array
     */
    public static function get_sa_qr_code($tel, $name = '', $organ, $action, $second)
    {
        if ($action == self::STAFF_CODE_STYLE_SA_1) {
            $code_xy = "231,450";
            $imagePath = '/library/sa_distribute_2020/sadistribute2.png';
            $url = "https://bm.zhugexuetang.com?school_id=".self::$city_id."&fromEntrance=4&entrance=4&staff_code=";  //正式地址春季招生的無用
            // $url = "http://bmdev.zhugexuetang.com/activity/ninety-nine/classlist?school_id=".self::$city_id."&fromEntrance=4&entrance=4&staff_code=";//測試地址
            $text = [$name];
            $textCoordinates = ['325,357'];
            $color = '116,87,58';
            $size = 25;
            $code_level = 5;
        } elseif ($action == self::STAFF_CODE_STYLE_SA_2) {
            $code_xy = "231,450";
            $imagePath = '/library/sa_distribute_2020/sadistribute1.png';
            $url = "https://jm.doushen.com/activity/99newlist?school_id=".self::$city_id."&fromEntrance=4&entrance=4&staff_code=";
            $text = [$name];
            $textCoordinates = ['325,357'];
            $color = '116,87,58';
            $size = 25;
            $code_level = 4;
        }

        #生成organ_code並加入二維碼的跳轉url中,然後回寫至shop_staff_info表
        $code = self::get_qr_tel($tel);
        $organ_code = $organ.'_0_0_'.$code;
        if ($second) {//二級機構
            $organ_code = $organ_code.':'.self::$second_id;
        }
        #回寫員工表code
        if ($second) {
            $staff_info = ShopStaffInfo::find()->select('id')
                ->where(['is_deleted'=>self::STAFF_STATUS,'id'=>self::$second_id])->asArray()->one();
        } else {
            $staff_info = ShopStaffInfo::find()->select('id')
                ->where(['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'staff_source'=>$organ])->asArray()->one();
        }
        self::updateInfoData(['code'=>$organ_code],['id'=>$staff_info['id']]);
        #url中增加organ_code
        $url .= $organ_code;

        $return = self::CreatCard($url,$imagePath,$code_xy,$text,$textCoordinates,$color,$size,$code_level);
        if ($return['check'] == false) {
            return false;
        }
        // echo "<img src=\"data:image/png;base64,".$return["data"]."\"/>";
        return $return;
    }

    /**
     * 生成特殊機構二維碼
     * @param $tel
     * @param int $action
     */
    public static function get_organ_card ($tel, int $action,$organ,$name,$second,$second_name) {
        #生成二維碼底圖選擇
        if ($organ == self::ORGAN_FLAG_KAISA) {
            $fileCata = "kaisa";
            $text = [
                '戰略合作伙伴凱撒旅遊'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "戰略合作伙伴凱撒旅遊".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=120';//http://m.dev.zhugexuetang.com/zgxt_vip
            }
        } elseif (in_array($organ,self::ORGAN_CCT_ARRAY)) {//康輝
            if ($organ == self::ORGAN_FLAG_CCT_BJ) {
                $organ_name = '北京';
            } elseif ($organ == self::ORGAN_FLAG_CCT_JS) {
                $organ_name = '集善';
            } elseif ($organ == self::ORGAN_FLAG_CCT_QD) {
                $organ_name = '青島';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HB) {
                $organ_name = '湖北';
            } elseif ($organ == self::ORGAN_FLAG_CCT_JSU) {
                $organ_name = '江蘇';
            } elseif ($organ == self::ORGAN_FLAG_CCT_GL) {
                $organ_name = '桂林';
            } elseif ($organ == self::ORGAN_FLAG_CCT_GX) {
                $organ_name = '廣西';
            } elseif ($organ == self::ORGAN_FLAG_CCT_SC) {
                $organ_name = '四川';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HN) {
                $organ_name = '海南';
            } elseif ($organ == self::ORGAN_FLAG_CCT_GZ) {
                $organ_name = '貴州';
            } elseif ($organ == self::ORGAN_FLAG_CCT_ZJ) {
                $organ_name = '浙江';
            } elseif ($organ == self::ORGAN_FLAG_CCT_XA) {
                $organ_name = '西安';
            } elseif ($organ == self::ORGAN_FLAG_CCT_GM) {
                $organ_name = '昆明';
            } elseif ($organ == self::ORGAN_FLAG_CCT_SH) {
                $organ_name = '上海';
            } elseif ($organ == self::ORGAN_FLAG_CCT_GS) {
                $organ_name = '甘肅';
            } elseif ($organ == self::ORGAN_FLAG_CCT_AH) {
                $organ_name = '安徽';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HNA) {
                $organ_name = '河南';
            } elseif ($organ == self::ORGAN_FLAG_CCT_DL) {
                $organ_name = '大連';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HLJ) {
                $organ_name = '黑龍江';
            } elseif ($organ == self::ORGAN_FLAG_CCT_JX) {
                $organ_name = '江西';
            } elseif ($organ == self::ORGAN_FLAG_CCT_NX) {
                $organ_name = '寧夏';
            } elseif ($organ == self::ORGAN_FLAG_CCT_SD) {
                $organ_name = '山東';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HUN) {
                $organ_name = '湖南';
            } elseif ($organ == self::ORGAN_FLAG_CCT_SZ) {
                $organ_name = '深圳';
            } elseif ($organ == self::ORGAN_FLAG_CCT_QH) {
                $organ_name = '青海';
            } elseif ($organ == self::ORGAN_FLAG_CCT_HUNX) {
                $organ_name = '湖南新康輝國旅';
            } elseif ($organ == self::ORGAN_FLAG_CCT_ST) {
                $organ_name = '汕頭';
            } elseif ($organ == self::ORGAN_FLAG_CCT_DG) {
                $organ_name = '東莞';
            } elseif ($organ == self::ORGAN_FLAG_CCT_TJ){
                $organ_name = "天津";
            } elseif ($organ == self::ORGAN_FLAG_CCT_XJ){
                $organ_name = "新疆";
            }
            $fileCata = "CCT";
            $text = [
                $organ_name.'康輝旅遊'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($organ == self::ORGAN_FLAG_CCT_HUNX) {
                $text = [
                    $organ_name.$name,
                    '願您足不出戶縱覽文學世界',
                    '停課不停學,學好大語文,做有修養的中國人',
                    '掃描右方二維碼會看到最適合您孩子的1~4個班級'
                ];
            }
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    $organ_name."康輝旅遊".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                if ($organ == self::ORGAN_FLAG_CCT_HUNX) {
                    $text = [
                        $organ_name.$name,
                        '誠摯爲您推薦諸葛學堂會員大禮包',
                        '願你暢遊文化世界',
                        '掃描右方二維碼即可購買'
                    ];
                }
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=121';
            }
        } elseif ($organ == self::ORGAN_FLAG_LUYIZAITU) {
            $fileCata = "luyizaitu";
            $text = [
                '路易在途'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "路易在途".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=122';
            }
        } elseif ($organ == self::ORGAN_FLAG_HELI) {
            $fileCata = "heli";
            $text = [
                '禾力旅行'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "禾力旅行".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=123';
            }
        } elseif ($organ == self::ORGAN_FLAG_XISHU) {
            $fileCata = "other";
            $text = [
                '義學書院'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "義學書院".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=124';
            }
        } elseif ($organ == self::ORGAN_FLAG_DIERKETANG) {
            $fileCata = "other";
            $text = [
                '第二課堂'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "第二課堂".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=125';
            }
        } elseif ($organ == self::ORGAN_FLAG_JIUFANG) {
            $fileCata = "other";
            $text = [
                '九方書院'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "九方書院".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=126';
            }
        } elseif ($organ == self::ORGAN_FLAG_RULIN) {
            $fileCata = "other";
            $text = [
                '儒林學院'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "儒林學院".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=127';
            }
        } elseif ($organ == self::ORGAN_FLAG_KANG) {
            $fileCata = "other";
            $text = [
                '康爸爸'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "康爸爸".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=128';
            }
        } elseif ($organ == self::ORGAN_FLAG_DOUSHENSHUANGSHI) {
            $fileCata = "doushenshuangshi";
            $text = [
                '豆神雙師'.$name,
                '誠摯爲您推薦豆神大語文',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級',
            ];
            if ($action == self::ORGAN_CODE_STYLE_3 || $action == self::ORGAN_CODE_STYLE_4 || $action == self::ORGAN_CODE_STYLE_5) {
                return ['check' => false,'data' => '豆神雙師只有大語文拔尖班,培優班海報哦!'];
            }
        } elseif ($organ == self::ORGAN_FLAG_KANGWEIXUETANG){
            //康微學堂
            $fileCata = "other";
            $text = [
                '康微學堂'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "康微學堂".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=129';
            }
        } elseif ($organ == self::ORGAN_FLAG_HOUDEIJY){
            //厚德教育
            $fileCata = "other";
            $text = [
                '蘭德文化教育'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "蘭德文化教育".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=130';
            }
        } elseif ($organ == self::ORGAN_FLAG_SUIXINKT){
            //隨心課堂
            $fileCata = "other";
            $text = [
                '隨心課堂'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "隨心課堂".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=131';
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENLIUXUE){
            $fileCata = "lsc_other";
            $text = [
                '立思辰留學'.$name,
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENMEITEJY){
            $fileCata = "minte";
            $text = [
                '敏特教育'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENRTW_YXH){
            $fileCata = "lsc_other";
            $text = [
                '優學匯'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENRTW_XEZ){
            $fileCata = "lsc_other";
            $text = [
                '學而知'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENRTW_TXH){
            $fileCata = "lsc_other";
            $text = [
                '童學匯'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENRTW_WLWYJY){
            $fileCata = "lianzhong";
            $text = [
                '聯衆教育培訓學校'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    '聯衆教育-'.$second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENRTW_XJBNYC){
            $fileCata = "xj_bainianyingcai";
            $text = [
                '新疆百年英才'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif ($organ == self::ORGAN_FLAG_LISICHENQUYUFZ){
            $fileCata = "lsc_other";
            $text = [
                '立思辰區域'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENJITUANZB){
            $fileCata = "lsc_other";
            $text = [
                '立思辰集團'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENBAINIANYC){
            $fileCata = "lsc_bainianyingcai";
            $text = [
                '百年英才'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENZONGBUKANGB){
            $fileCata = "lsc_other";
            $text = [
                '康邦科技'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        } elseif ($organ == self::ORGAN_FLAG_LISICHENZONGBUNX){
            $fileCata = "lsc_other";
            $text = [
                '我是竇昕老師',
                '很榮幸爲您推薦,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        } elseif($organ == self::ORGAN_FLAG_LISICHENKUAXUEWANG){
            $fileCata = "lsc_other";
            $text = [
                '跨學網'.$name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        }elseif($organ == self::ORGAN_FLAG_LISICHENJTSHICHANGBU){
            $fileCata = "lsc_other";
            $text = [
                 $name.'老師',
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
            if ($second) {//二級渠道
                $text = [
                    $second_name,
                    '誠摯爲您推薦豆神大語文,',
                    '掃描右方二維碼',
                    '會看到最適合您孩子的1~4個班級'
                ];
            }
        }elseif($organ == self::ORGAN_FLAG_YIQI){
            //易啓
            $fileCata = "other";
            $text = [
                '易啓'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "易啓".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=133';
            }
        }elseif($organ == self::ORGAN_FLAG_ZHONGQIAOGUOLV){
            $fileCata = "zhongqiaoguolv";
            $text = [
                '中僑國旅'.$name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "中僑國旅".$name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=134';
            }
        }elseif($organ == self::ORGAN_FLAG_LISICHENHUIRONGEXUE){
            $fileCata = "huirongexue";
            $text = [
                $name,
                '誠摯爲您推薦豆神大語文,',
                '掃描右方二維碼',
                '會看到最適合您孩子的1~4個班級'
            ];
        }elseif($organ == self::ORGAN_FLAG_GAINIANXING){
            $fileCata = "gainianxing";
            $text = [
                 $name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    "我是".$name,
                    '很榮幸爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=137';
            }
        } elseif($organ == self::ORGAN_FLAG_LAOJIN) {
            //老金
            $fileCata = "other";
            $text = [
                $name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    $name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=138';
            }
        } elseif($organ == self::ORGAN_FLAG_CAICAI) {
            //蔡蔡機構
            $fileCata = "other";
            $text = [
                $name,
                '願您足不出戶縱覽文學世界',
                '停課不停學,學好大語文,做有修養的中國人',
                '掃描右方二維碼會看到最適合您孩子的1~4個班級'
            ];
            if ($action == self::ORGAN_CODE_STYLE_6) {
                $text = [
                    $name,
                    '誠摯爲您推薦諸葛學堂會員大禮包',
                    '願你暢遊文化世界',
                    '掃描右方二維碼即可購買'
                ];
                $newUrl = 'https://m.zhugexuetang.com/zgxt_vip?source=139';
            }
        }elseif($organ == self::ORGAN_FLAG_ZJXT) {
            //諸葛學堂
            $fileCata = "other";
            $text = [
                '',
                '',
                '',
                ''
            ];
            // if ($action == self::ORGAN_CODE_STYLE_6) {
            //     $text = [
            //         $name,
            //         '誠摯爲您推薦諸葛學堂會員大禮包',
            //         '願你暢遊文化世界',
            //         '掃描右方二維碼即可購買'
            //     ];
                $newUrl = 'https://m.zhugexuetang.com/zhugexuetang/course?type=10004';//正式
                // $newUrl = 'http://m.dev.zhugexuetang.com/zhugexuetang/course?type=10004';//測試
            // }
        }
        #生成code
        $code = self::get_qr_tel($tel);
        $organ_code = $organ.'_0_0_'.$code;
        if ($second) {//二級機構
            $organ_code = $organ_code.':'.self::$second_id;
        }
        #二維碼調整鏈接
        $url = "https://bm.zhugexuetang.com?fromEntrance=1&entrance=2&staff_code=".$organ_code; //打開註釋

        #機構區分
        if (in_array($organ,array_diff(self::ORGAN_ARRAY,self::ORGAN_NO_DEPARTMENT_INITIAL_ARRAY))) {//立思辰下集團
            if ($action == self::ORGAN_CODE_STYLE_1) {
                $code_xy = '590,2930';
                $text1_xy = '20,2940';
                $text2_xy = '20,2975';
                $text3_xy = '20,3010';
                $text4_xy = '20,3045';
                $color = '0,0,88';
                $imagePath = '/library/'.$fileCata.'/1.png';//大語文培優班
            } elseif ($action == self::ORGAN_CODE_STYLE_2) {
                $code_xy = '590,3160';
                $text1_xy = '20,3170';
                $text2_xy = '20,3205';
                $text3_xy = '20,3240';
                $text4_xy = '20,3275';
                $color = '0,0,0';
                $imagePath = '/library/'.$fileCata.'/2.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_3) {
                $code_xy = '590,2740';
                $text1_xy = '20,2750';
                $text2_xy = '20,2785';
                $text3_xy = '20,2820';
                $text4_xy = '20,2855';
                $color = '0,0,0';
                $imagePath = '/library/'.$fileCata.'/3.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_4) {
                $code_xy = '590,2740';
                $text1_xy = '20,2750';
                $text2_xy = '20,2785';
                $text3_xy = '20,2820';
                $text4_xy = '20,2855';
                $color = '0,0,0';
                $imagePath = '/library/'.$fileCata.'/4.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_5) {
                $code_xy = '590,3220';
                $text1_xy = '20,3230';
                $text2_xy = '20,3265';
                $text3_xy = '20,3305';
                $text4_xy = '20,3345';
                $color = '0,0,0';
                $imagePath = '/library/'.$fileCata.'/5.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_6) {
                $code_xy = '850,3950';
                $text1_xy = '50,4010';
                $text2_xy = '50,4045';
                $text3_xy = '50,4080';
                $text4_xy = '50,4115';
                $color = '0,0,179';
                $imagePath = '/library/'.$fileCata.'/6.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_8) {
                $code_xy = '850,6150';
                $text1_xy = '50,6210';
                $text2_xy = '50,6245';
                $text3_xy = '50,6280';
                $text4_xy = '50,6315';
                $color = '0,0,88';
                $imagePath = '/library/'.$fileCata.'/8.png';
            }  elseif ($action == self::ORGAN_CODE_STYLE_9) {
                $code_xy = '850,3950';
                $text1_xy = '50,4010';
                $text2_xy = '50,4045';
                $text3_xy = '50,4080';
                $text4_xy = '50,4115';
                $color = '0,0,88';
                $imagePath = '/library/'.$fileCata.'/9.png';
            }else {
                return ['check' => false,'data' => '生成二維碼底圖參數錯誤'];
            }
        } elseif (in_array($organ,self::ORGAN_NO_DEPARTMENT_INITIAL_ARRAY)) {//其他外部機構
            #座標參數
            if ($organ == self::ORGAN_FLAG_ZJXT) {
                //針對諸葛學堂課程分銷單獨處理
                $code_xy = '535,1350';
                $text1_xy = '50,4010';
                $text2_xy = '50,4045';
                $text3_xy = '50,4080';
                $text4_xy = '50,4115';
                $color = '0,0,88';
                $imagePath = '/library/'.$fileCata.'/7.png';
                $url = $newUrl.'&staff_code='.$organ_code;
            } else {
                if ($action == self::ORGAN_CODE_STYLE_1) {
                    $code_xy = '586,2930';
                    $text1_xy = '20,2950';
                    $text2_xy = '20,2985';
                    $text3_xy = '20,3020';
                    $text4_xy = '20,3055';
                    $color = '0,0,88';
                    $imagePath = '/library/'.$fileCata.'/1.png';//大語文培優班
                } elseif ($action == self::ORGAN_CODE_STYLE_2) {
                    $code_xy = '586,3150';
                    $text1_xy = '20,3170';
                    $text2_xy = '20,3205';
                    $text3_xy = '20,3240';
                    $text4_xy = '20,3275';
                    $color = '0,0,0';
                    if ($organ == self::ORGAN_FLAG_DOUSHENSHUANGSHI) {
                        $color = '0,0,88';
                    }
                    $imagePath = '/library/'.$fileCata.'/2.png';
                }elseif ($action == self::ORGAN_CODE_STYLE_3) {
                    $code_xy = '586,2730';
                    $text1_xy = '20,2750';
                    $text2_xy = '20,2785';
                    $text3_xy = '20,2820';
                    $text4_xy = '20,2855';
                    $color = '0,0,0';
                    $imagePath = '/library/'.$fileCata.'/3.png';
                }elseif ($action == self::ORGAN_CODE_STYLE_4) {
                    $code_xy = '586,2730';
                    $text1_xy = '20,2750';
                    $text2_xy = '20,2785';
                    $text3_xy = '20,2820';
                    $text4_xy = '20,2855';
                    $color = '0,0,0';
                    $imagePath = '/library/'.$fileCata.'/4.png';
                }elseif ($action == self::ORGAN_CODE_STYLE_5) {
                    $code_xy = '586,3230';
                    $text1_xy = '20,3250';
                    $text2_xy = '20,3285';
                    $text3_xy = '20,3320';
                    $text4_xy = '20,3355';
                    $color = '0,0,0';
                    $imagePath = '/library/'.$fileCata.'/5.png';
                }elseif ($action == self::ORGAN_CODE_STYLE_6) {
                    $code_xy = '590,2935';
                    $text1_xy = '25,2955';
                    $text2_xy = '25,2990';
                    $text3_xy = '25,3025';
                    $text4_xy = '25,3060';
                    $color = '0,0,0';
                    $imagePath = '/library/'.$fileCata.'/6.png';
                    $url = $newUrl.'&staff_code='.$organ_code;
                }else {
                    return ['check' => false,'data' => '生成二維碼底圖參數錯誤'];
                }
            }
            
        }
        $textCoordinates = [$text1_xy,$text2_xy,$text3_xy,$text4_xy];
        $size = 18;$code_level = 2;
        if (in_array($action,[self::ORGAN_CODE_STYLE_6,self::ORGAN_CODE_STYLE_8,self::ORGAN_CODE_STYLE_9])&&
            in_array($organ,array_diff(self::ORGAN_ARRAY,self::ORGAN_NO_DEPARTMENT_INITIAL_ARRAY))) {
            $size = 20;
            $code_level = 3;
        } elseif ($action == self::ORGAN_CODE_STYLE_10) {
            $size = 20;
            $code_level = 2.2;
        }
        $return = self::CreatCard($url,$imagePath,$code_xy,$text,$textCoordinates,$color,$size,$code_level);
        if ($return['check'] == false) {
            return false;
        }
        #回寫code
        if ($second) {
            $staff_info = ShopStaffInfo::find()->select('id')
                ->where(['is_deleted'=>self::STAFF_STATUS,'id'=>self::$second_id])->asArray()->one();
        } else {
            $staff_info = ShopStaffInfo::find()->select('id')
                ->where(['is_deleted'=>self::STAFF_STATUS,'tel'=>trim($tel),'staff_source'=>$organ])->asArray()->one();
        }
        self::updateInfoData(['code'=>$organ_code],['id'=>$staff_info['id']]);

        return ['check' => true,'data' => $return['data']];

    }

    /**
     * 抽象生成二維碼接口水印文字等
     * @param $url 二維碼調整的鏈接
     * @param $backgroundImage 背景圖文件地址
     * @param string $qr_code_coordinates 二維碼座標 '100,200'
     * @param array $text 要水印上去的文字 可以是多個
     * @param array $coordinates 要水印上去的文字 對應的座標 多組文字對應多組座標
     * @param $colour  水印文字 顏色rgb值
     * @return base64 image
     */
    public static function CreatCard ($url,$backgroundImage,string $qr_code_coordinates,array $text = [],array $coordinates = [],$colour,$size,$code_level)
    {
        #參數校驗
        if (!$url || !$qr_code_coordinates) {
            return ['check' => false,'data' => '二維碼跳轉鏈接或者二維碼座標不能爲空'];
        }
        if (count($text) != count($coordinates)) {
            return ['check' => false,'data' => '水印文字的數量與提供的座標不符'];
        }
        //生成二維碼圖片
        $path = '/tmp/recruitcard';
        if (!is_dir($path)) {
            @mkdir($path);
        }
        include(ROOT_PATH . '/library/phpqrcode/qrlib.php');
        $qrcodePath = $path . '/' . date('Y-m-d').'-'.rand(10000,99999) . '.png';
        \QRcode::png($url, $qrcodePath, 3,$code_level);

        #原始圖像
        $dst = (ROOT_PATH . $backgroundImage);
        #得到原始圖片信息
        $dst_im1 = imagecreatefrompng($dst);
        $dst_info1 = getimagesize($dst);
        #二維碼圖片
        $src1 = $qrcodePath;
        $src1_im = imagecreatefrompng($src1);
        $src1_info = getimagesize($src1);
        #合併水印圖片
        $code_xy = explode(',',$qr_code_coordinates);
        imagecopymerge($dst_im1,$src1_im,$code_xy[0],$code_xy[1],0,0,$src1_info[0],$src1_info[1],100);
        #合成圖片的路徑
        $path = '/tmp/gentlemancard';
        if (!is_dir($path)) {
            @mkdir($path);
        }
        $poster_marge_path =$path . '/' . date('Y-m-d').'-'.rand(0,9999) . '.png';
        #輸出合併後水印圖片
        ob_start();
        imagepng($dst_im1,$poster_marge_path);
        imagedestroy($dst_im1);
        imagedestroy($src1_im);
        #添加圖片文字
        $dst_path = $poster_marge_path;
        $dst_new = imagecreatefromstring(file_get_contents($dst_path));
        $font = (ROOT_PATH . '/library/gentlemanImg/fzlthk.ttf');
        $im = imagecreatetruecolor(400, 30);
        $colour = explode(',',$colour);
        $colour =imagecolorallocate($im, $colour[0],$colour[1],$colour[2]);
        #文字處理
        foreach ($text as $key=>$value) {
            $text_xy = explode(',',$coordinates[$key]);
            imagefttext($dst_new, $size, 0,$text_xy[0], $text_xy[1], $colour, $font, $value);
        }

        header('Content-type: image/png');
        imagepng($dst_new);
        @unlink($dst_new);
        $sImage = ob_get_contents();
        ob_end_clean();
        $base64_img = base64_encode($sImage);
        @unlink($qrcodePath);

        return ['check' => true,'data' => $base64_img];

    }

    /**
     * 獲得uid 加密串
     * 生成規則數字0-9按從小到大順序變成RIZBHGECFO,替換完成後在第5個字符後面加AKMN
     * @param $mobile
     * @return mixed
     */
    public static function get_qr_tel($tel)
    {
        $tel = str_replace("0", "R", $tel);
        $tel = str_replace("1", "I", $tel);
        $tel = str_replace("2", "Z", $tel);
        $tel = str_replace("3", "B", $tel);
        $tel = str_replace("4", "H", $tel);
        $tel = str_replace("5", "G", $tel);
        $tel = str_replace("6", "E", $tel);
        $tel = str_replace("7", "C", $tel);
        $tel = str_replace("8", "F", $tel);
        $tel = str_replace("9", "O", $tel);
        $tel = substr_replace($tel, 'AKMN', 11, 0);
        return $tel;
        // return uniqid(crc32('qr_code_' . $mobile)) . rand(10000, 99999);
    }

    public static function updateInfoData($data,$where) {
        ShopStaffInfo::getDb()->createCommand()->
        update(ShopStaffInfo::tableName(), $data, $where )
        ->execute();
    }

    public static function getOrganDepartmentInfo($organ)
    {
        $OrganInfo  = array(
            "department" => 1,
            "department_list" => array(),
            "secondChannel" => 0,
        );
        if(in_array($organ,self::ORGAN_NO_DEPARTMENT_INITIAL_ARRAY)){

        }elseif(in_array($organ,self::ORGAN_NO_DEPARTMENT_LATER_ARRAY)){
            //沒有部門的
            $OrganInfo["department"] = 2;
            $OrganInfo["department_list"] = array();
        }elseif(in_array($organ,self::ORGAN_DEPARTMENT_LATER_ARRAY)){
            //有部門的
            $OrganInfo["department"] = 3;
            $OrganInfo["department_list"] = self::ORGAN_DEPARTMENT_INFO[$organ];
        }
        //二級渠道信息
        if(in_array($organ,self::ORGAN_CHANNEL_ARRAY)){
            $OrganInfo["secondChannel"] = 1;
        }else{
            $OrganInfo["secondChannel"] = 2;
        }
        return $OrganInfo;
    }


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章