| xqd
@@ -12,6 +12,7 @@ use App\Models\AlbumAgentModel;
|
|
|
use App\Models\AlbumManufacturerModel;
|
|
|
use App\Models\AlbumPosterModel;
|
|
|
use App\Services\Base\ErrorCode;
|
|
|
+use EasyWeChat\Factory;
|
|
|
use Grafika\Color;
|
|
|
use Grafika\Grafika;
|
|
|
use Validator, Response,Auth;
|
| xqd
@@ -126,6 +127,43 @@ class AlbumPosterController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取小程序码 EasyWeChat
|
|
|
+ * @param $appId string
|
|
|
+ * @param $appSecret string
|
|
|
+ * @param $agent_id int
|
|
|
+ * @param $store_id int
|
|
|
+ * @param $user_id int
|
|
|
+ * @return bool|string
|
|
|
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
+ */
|
|
|
+ private function getQrCodeEasy($appId, $appSecret, $agent_id, $store_id, $user_id)
|
|
|
+ {
|
|
|
+ $config = [
|
|
|
+ 'app_id' => $appId,
|
|
|
+ 'secret' => $appSecret,
|
|
|
+ 'response_type' => 'array',
|
|
|
+ ];
|
|
|
+ $app = Factory::miniProgram($config);
|
|
|
+ $response = $app->app_code->get('pages/index/loading?agentid=' . $agent_id, [
|
|
|
+ 'width' => 140,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
|
|
+ if (file_exists(public_path() . '/base/poster/QrCode/' . $store_id)) {
|
|
|
+ mkdir(public_path() . '/base/poster/QrCode/' . $store_id, 0755, true);
|
|
|
+ }
|
|
|
+ $filename = $response->saveAs(public_path() . '/base/poster/QrCode/' . $store_id . "/", "$user_id.png");
|
|
|
+ if ($filename) {
|
|
|
+ return "/base/poster/QrCode/" . $store_id . "/$user_id.png";
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @api {post} /api/album_post/create 生成海报(create)
|
|
|
* @apiDescription 生成海报(create)
|
| xqd
@@ -171,6 +209,12 @@ class AlbumPosterController extends Controller
|
|
|
if ($validator->fails()) {
|
|
|
return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
|
|
|
}
|
|
|
+ if ($userAuth->is_dealer == 1) {
|
|
|
+ $user_agent = AlbumAgentModel::where([['user_id',$userAuth->id],['status',1]])->first();
|
|
|
+ $agent_id = $user_agent['id'];
|
|
|
+ } else {
|
|
|
+ $agent_id = $userAuth->up_agent_id == 0 ? 0 : $userAuth->up_agent_id;
|
|
|
+ }
|
|
|
$data = $request->input();
|
|
|
$info = AlbumPosterModel::where('store_id', $data['store_id'])->first()->toArray();
|
|
|
$editor = Grafika::createEditor();
|
| xqd
@@ -221,9 +265,18 @@ class AlbumPosterController extends Controller
|
|
|
}
|
|
|
$editor->text($image_poster, $phone, 20, 55, 577, new Color("#eb7a48"), $font, 0);
|
|
|
$editor->text($image_poster, '长按识别二维码 展示家具画册', 16, 10, 650, new Color("#666666"), $font, 0);
|
|
|
- $editor->open($image_qrcode, str_replace(env('CDN_URL'), public_path(), $info['qrcode']));
|
|
|
- $editor->resizeExactWidth($image_qrcode, 140);
|
|
|
- $editor->resizeExactHeight($image_qrcode, 140);
|
|
|
+ if ($agent_id == 0) {
|
|
|
+ $editor->open($image_qrcode, str_replace(env('CDN_URL'), public_path(), $info['qrcode']));
|
|
|
+ $editor->resizeExactWidth($image_qrcode, 140);
|
|
|
+ $editor->resizeExactHeight($image_qrcode, 140);
|
|
|
+ } else {
|
|
|
+ $file = $this->getQrCodeEasy($WeChatApp->xyx_id, $WeChatApp->xyx_secret, $agent_id, $data['store_id'], $userAuth->id);
|
|
|
+ if (!$file) {
|
|
|
+ return $this->error(0, '参数错误,请检查配置', []);
|
|
|
+ }
|
|
|
+ $editor->open($image_qrcode, $file);
|
|
|
+ }
|
|
|
+
|
|
|
$editor->blend($image_poster, $image_qrcode, 'normal', 1, 'top-left', 310, 500);
|
|
|
$editor->open($image_avatar, public_path() . '/base/poster/avatar/' . $data['store_id'] . "/$userAuth->id.jpg");
|
|
|
$editor->resizeExactWidth($image_avatar, 64);
|