|
@@ -15,6 +15,8 @@ use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
|
+use Intervention\Image\Facades\Image;
|
|
|
+use Intervention\Image\Gd\Font;
|
|
|
|
|
|
/**
|
|
|
* 订单管理
|
|
@@ -126,12 +128,19 @@ class Orders extends Auth{
|
|
|
$value['image'] = path_compat($value['image']);
|
|
|
$orderReceipt[$key] = $value;
|
|
|
}
|
|
|
+ // 积分
|
|
|
+ $score = max(array_column($orderReceipt,'give_score'));
|
|
|
+ // 恭喜
|
|
|
+ $shopName = $orderAddr['contact_shop'] ? $orderAddr['contact_shop'] : $order['custom_name'];
|
|
|
+ // 结果
|
|
|
+ $shareImage = $this->getShareImage($shopName,$order['custom_uid'],$order['id'],$score);
|
|
|
// 分配数据
|
|
|
$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
|
|
|
$this->assign('order', $order);
|
|
|
$this->assign('orderAddr', $orderAddr);
|
|
|
$this->assign('orderItems', $orderItems);
|
|
|
$this->assign('orderReceipt', $orderReceipt);
|
|
|
+ $this->assign('shareImage', $shareImage);
|
|
|
// 加载模板
|
|
|
return $this->fetch();
|
|
|
}
|
|
@@ -523,4 +532,67 @@ class Orders extends Auth{
|
|
|
return $sheet;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分享图片
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private function getShareImage($shopName,$uid,$orderId,$score=0){
|
|
|
+ // 尝试执行
|
|
|
+ try {
|
|
|
+ // 加载图片
|
|
|
+ $image = Image::make(public_path('uploads/images/default/').'order_receipt_share.jpg');
|
|
|
+ // 加载图片
|
|
|
+ $qrcode = Image::make(public_path('uploads/images/default/').'mp_qrcode.jpg')->resize(100,100);
|
|
|
+ // 设置文字样式(字体、大小、颜色等)
|
|
|
+ $fontPath = public_path().'/fonts/msyh14.ttf';// 指定字体文件路径
|
|
|
+ // 文本
|
|
|
+ $score = $score ? '即将获得'.$score.'积分' : '';
|
|
|
+
|
|
|
+ // 给图片写入文字
|
|
|
+ $image->text('恭喜 '.$shopName, 240,60,function (Font $font) use ($fontPath) {
|
|
|
+ $font->file($fontPath); // 字体文件地址
|
|
|
+ $font->size(24); // 字体大小
|
|
|
+ $font->color('#FFFFFF');
|
|
|
+ $font->align('center');
|
|
|
+ });
|
|
|
+
|
|
|
+ // 给图片写入文字
|
|
|
+ $image->text('完成了一笔订单', 240,100,function (Font $font) use ($fontPath) {
|
|
|
+ $font->file($fontPath); // 字体文件地址
|
|
|
+ $font->size(24); // 字体大小
|
|
|
+ $font->color('#FFFFFF');
|
|
|
+ $font->align('center');
|
|
|
+ });
|
|
|
+ // 是否有积分
|
|
|
+ if( $score ){
|
|
|
+ // 给图片写入文字
|
|
|
+ $image->text($score, 240,140,function (Font $font) use ($fontPath) {
|
|
|
+ $font->file($fontPath); // 字体文件地址
|
|
|
+ $font->size(24); // 字体大小
|
|
|
+ $font->color('#FFFFFF');
|
|
|
+ $font->align('center');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 给图片写入文字
|
|
|
+ $image->text('你也来试试吧', 240,$score?180:140,function (Font $font) use ($fontPath) {
|
|
|
+ $font->file($fontPath); // 字体文件地址
|
|
|
+ $font->size(24); // 字体大小
|
|
|
+ $font->color('#FFFFFF');
|
|
|
+ $font->align('center');
|
|
|
+ });
|
|
|
+ // 插入图片
|
|
|
+ $image->insert($qrcode,'bottom-right',10,10);
|
|
|
+ // 转码成字符串
|
|
|
+ $image = $image->encode('jpg', 90)->__toString();
|
|
|
+ // 转base64
|
|
|
+ $base64 = 'data:image/jpg;base64,' . base64_encode($image);
|
|
|
+
|
|
|
+ return $base64;
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ dd($th);
|
|
|
+ // 返回路径
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|