getQrcode($app_type, $page, $qrcode_param, $site_id); if ($qrcode_info['code'] < 0) return $qrcode_info; $member_info = $this->getMemberInfo($qrcode_param['source_member']); if (empty($member_info)) return $this->error('未获取到会员信息'); $poster = new PosterExtend(740, 1250); if (empty($template_info)) { $option = [ [ 'action' => 'imageCopy', // 背景图 'data' => [ 'upload/poster/bg/fenxiao_1.png', 0, 0, 740, 1250, 'square', 0, 1 ] ], [ 'action' => 'imageCopy', // 写入二维码 'data' => [ $qrcode_info['data']['path'], 505, 980, 205, 205, 'square', 0, 1 ] ], [ 'action' => 'imageCircularCopy', // 写入用户头像 'data' => [ !empty($member_info['headimg']) ? $member_info['headimg'] : 'public/static/img/default_img/head.png', 82, 852, 112, 112 ] ], [ 'action' => 'imageText', // 写入分享人昵称 'data' => [ $member_info['nickname'], 22, [255, 129, 61], 40, 1030, 440, 1, true, 1 ] ], [ 'action' => 'imageText', // 写入分享语 'data' => [ '邀您一起分享赚佣金', 18, [141, 141, 141], 40, 1070, 440, 1 ] ] ]; } else { $params = $template_info; $poster = new PosterExtend(740, 1250); $fontRate = 0.725; $nickname_color = is_array($params['template_json']['nickname_color']) ? $params['template_json']['nickname_color'] : hex2rgb($params['template_json']['nickname_color']); $option = [ [ 'action' => 'imageCopy', // 写入背景图 'data' => [ img($params['background']), 0, 0, 740, 1250, 'square', 0, 1 ] ], [ 'action' => 'imageCopy', // 写入二维码 'data' => [ $qrcode_info['data']['path'], (int)$params['qrcode_left'] * 2, (int)$params['qrcode_top'] * 2, (int)$params['qrcode_width'] * 2, (int)$params['qrcode_height'] * 2, 'square', 0, 1 ] ], [ 'action' => 'imageText', // 写入分享语 'data' => [ $params['template_json']['share_content'], $params['template_json']['share_content_font_size'] * $fontRate * 2, is_array($params['template_json']['share_content_color']) ? $params['template_json']['share_content_color'] : hex2rgb($params['template_json']['share_content_color']), $params['template_json']['share_content_left'] * 2, ($params['template_json']['share_content_top'] + $params['template_json']['share_content_font_size']) * 2, $params['template_json']['share_content_width'] * 2, 1 ] ], [ 'action' => 'imageCopy', // 写入用户头像 'data' => [ !empty($member_info['headimg']) ? img($member_info['headimg']) : img('public/static/img/default_img/head.png'), $params['template_json']['headimg_left'] * 2, $params['template_json']['headimg_top'] * 2, $params['template_json']['headimg_width'] * 2, $params['template_json']['headimg_height'] * 2, !empty($params['template_json']['headimg_shape']) ? $params['template_json']['headimg_shape'] : 'square', 0, $params['template_json']['headimg_is_show'] ] ], [ 'action' => 'imageText', // 写入分享人昵称 'data' => [ $member_info['nickname'], $params['template_json']['nickname_font_size'] * $fontRate * 2, $nickname_color, $params['template_json']['nickname_left'] * 2, ($params['template_json']['nickname_top'] + $params['template_json']['nickname_font_size']) * 2, $params['template_json']['nickname_width'] * 2, 1, true, $params['template_json']['nickname_is_show'] ] ], ]; } $option_res = $poster->create($option); if (is_array($option_res)) return $option_res; $pic_name = ""; if (!empty($params)) { $pic_name = md5(json_encode([ 'id' => $params['template_id'], 'poster_name' => $params['poster_name'] ])); $pic_name = "_" . $pic_name; } $res = $option_res->jpeg('upload/poster/distribution', 'distribution_' . $qrcode_param['source_member'] . $pic_name . '_' . $app_type); if ($res['code'] == 0) { $upload = new Upload($site_id); if (strpos($res['data']['path'], 'http://') !== false || strpos($res['data']['path'], 'https://') !== false) { return $this->success(["path" => $res['data']['path']]); } else { $cloud_res = $upload->fileCloud($res['data']['path']); if (isset($cloud_res['code']) && $cloud_res['code'] >= 0) { return $this->success(["path" => $cloud_res['data']]); } else if($res['data']['path']){ return $this->success(["path" => $res['data']['path']]); } else { return $this->error(); } } } return $res; } catch (\Exception $e) { return $this->error($e->getMessage() . $e->getFile() . $e->getLine()); } } /** * 获取用户信息 * @param unknown $member_id */ private function getMemberInfo($member_id) { $info = model('member')->getInfo(['member_id' => $member_id], 'nickname,headimg'); return $info; } /** * 获取二维码 * @param unknown $app_type 请求类型 * @param unknown $page uniapp页面路径 * @param unknown $qrcode_param 二维码携带参数 * @param string $promotion_type 活动类型 null为无活动 */ private function getQrcode($app_type, $page, $qrcode_param, $site_id) { $res = event('Qrcode', [ 'site_id' => $site_id, 'app_type' => $app_type, 'type' => 'get', 'data' => $qrcode_param, 'page' => $page, 'qrcode_path' => 'upload/qrcode/distribution', 'qrcode_name' => 'distribution' . '_' . $qrcode_param['source_member'] . '_' . $site_id, ], true); return $res; } /** * 获取分销海报 * @param $param * @return array|\extend\multitype|PosterExtend|mixed|string|void */ public function getFenxiaoPoster($param) { $app_type = $param['app_type'] ?? 'h5'; $qrcode_param = $param['qrcode_param'] ?? []; $site_id = $param['site_id'] ?? 0; $page = $param['page'] ?? ''; $template_id = $param['template_id'] ?? 'default'; if ($template_id == 'default') { //默认海报 $template_info = model('poster_template')->getInfo([ ['site_id', '=', $site_id], ['template_type', '=', 'fenxiao'], ['template_status', '=', 1], ]); if (!empty($template_info)) { $template_info['template_json'] = json_decode($template_info['template_json'], true); } } else { //设置的海报 $template_info = model('poster_template')->getInfo([ ['site_id', '=', $site_id], ['template_type', '=', 'fenxiao'], ['template_status', '=', 1], ['template_id', '=', $template_id], ]); if (empty($template_info)) return $this->error(null, '模板信息有误'); $template_info['template_json'] = json_decode($template_info['template_json'], true); } $res = $this->distribution($app_type, $page, $qrcode_param, $site_id, $template_info); return $res; } }