瀏覽代碼

【Add】分享图片

liuxiangxin 6 月之前
父節點
當前提交
7a7f603509

+ 72 - 0
app/Http/Controllers/Admin/Orders.php

@@ -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 			'';
+		}
+	}
+
 }

+ 2 - 2
app/Http/Controllers/Admin/OrdersReceipt.php

@@ -73,7 +73,7 @@ class OrdersReceipt extends Auth{
 			// 判断结果
 			try {
 				// 查询数据
-				$result					= $Model->edit($id,['status'=>$status,'give_score'=>$giveScore,'remark'=>$remark]);
+				$result					= $Model->edit($id,['status'=>$status,'give_score'=>$giveScore,'remark'=>$remark,'admin_uid'=>admin('uid')]);
 				// 提示新增失败
 				if( !$result )			return json_send(['code'=>'error','msg'=>'操作失败']);
 				// 发放积分
@@ -127,7 +127,7 @@ class OrdersReceipt extends Auth{
 			// 判断结果
 			try {
 				// 查询数据
-				$result				= $Model->edit($id,['status'=>$status,'remark'=>$remark]);
+				$result				= $Model->edit($id,['status'=>$status,'remark'=>$remark,'admin_uid'=>admin('uid')]);
 				// 提示新增失败
 				if( !$result )		return json_send(['code'=>'error','msg'=>'操作失败']);
 				// 恢复订单进行中

二進制
public/uploads/images/default/mp_qrcode.jpg


+ 10 - 0
resources/views/admin/orders/detail.blade.php

@@ -114,6 +114,16 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 		</div>
 	</div>
 </div>
+<div class="row">
+	<div class="col-xs-12">
+		<div class="table-responsive">
+			<label for="">分享图片</label>
+			<div class="table-responsive">
+				<img src="{{$shareImage}}" alt="">
+			</div>
+		</div>
+	</div>
+</div>
 <!-- Modal -->
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
 	<div class="modal-dialog" role="document">