|
@@ -1,12 +1,14 @@
|
|
|
<?php namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
use App\Http\Requests\Admin\Orders as Request;
|
|
|
+use App\Models\AdminUser;
|
|
|
use App\Models\Custom;
|
|
|
use App\Models\CustomAddr;
|
|
|
use App\Models\CustomScore;
|
|
|
use App\Models\FilesManager;
|
|
|
use App\Models\Product;
|
|
|
use App\Models\Orders as Model;
|
|
|
+use App\Models\Orders\Receipt;
|
|
|
use App\Models\OrdersAddr;
|
|
|
use App\Models\OrdersProduct;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -14,6 +16,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;
|
|
|
|
|
|
/**
|
|
|
* 订单管理
|
|
@@ -81,7 +85,7 @@ class Orders extends Auth{
|
|
|
$value['order_code'] = $Model->idToCode($value['order_id']);
|
|
|
$value['custom_code'] = $Custom->idToCode($value['custom_uid']);
|
|
|
$value['state'] = $Model->getState($value['status'],'state');
|
|
|
- $value['product_code'] = $Product->idToCode($value['product_id']);
|
|
|
+ $value['product_code'] = $value['product_id'] ? $Product->idToCode($value['product_id']) : '— —';
|
|
|
// 重组
|
|
|
$list[$key] = $value;
|
|
|
}
|
|
@@ -93,6 +97,58 @@ class Orders extends Auth{
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 首页列表
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function detail(Model $Model,AdminUser $AdminUser,OrdersProduct $OrdersProduct,Product $Product,Custom $Custom,OrdersAddr $OrdersAddr,Receipt $Receipt){
|
|
|
+ // 接受参数
|
|
|
+ $id = request('order_id','');
|
|
|
+ // 查询数据
|
|
|
+ $order = $Model->query()->find($id);
|
|
|
+ // 查询不到订单
|
|
|
+ if( !$order ) return $this->error('订单数据不存在');
|
|
|
+ // id转编号
|
|
|
+ $order['order_code'] = $Model->idToCode($order['id']);
|
|
|
+ $order['custom_code'] = $Custom->idToCode($order['custom_uid']);
|
|
|
+ $order['custom_name'] = $Custom->getValue($order['custom_uid'],'username');
|
|
|
+ $order['state'] = $Model->getState($order['status'],'state');
|
|
|
+ // 查询子订单数据
|
|
|
+ $orderItems = $OrdersProduct->query()->where([['order_id','=',$id]])->select(['id as item_id','order_id','product_id','buy_num','pay_total','is_rebate','sku_attr_names as product_spec','product_name','product_thumb'])->get()->toArray();
|
|
|
+ // 地址
|
|
|
+ $orderAddr = $OrdersAddr->query()->where([['order_id','=',$id]])->first(['contact_name','contact_phone','contact_province','contact_city','contact_area','contact_addr','contact_shop']);
|
|
|
+ // 审核记录
|
|
|
+ $orderReceipt = $Receipt->query()->where([['order_id','=',$id]])->orderByDesc('id')->get()->toArray();
|
|
|
+ // 循环数据
|
|
|
+ foreach ($orderItems as $key => $value) {
|
|
|
+ $value['product_code'] = $Product->idToCode($value['product_id']);
|
|
|
+ $orderItems[$key] = $value;
|
|
|
+ }
|
|
|
+ // 循环数据
|
|
|
+ foreach ($orderReceipt as $key => $value) {
|
|
|
+ // 操作人员
|
|
|
+ $value['admin_name']= $AdminUser->getOne($value['admin_uid'],'username');
|
|
|
+ $value['image'] = path_compat($value['image']);
|
|
|
+ $orderReceipt[$key] = $value;
|
|
|
+ }
|
|
|
+ // 积分
|
|
|
+ $score = $orderReceipt ? max(array_column($orderReceipt,'give_score')) : 0;
|
|
|
+ // 恭喜
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 状态
|
|
|
*
|
|
@@ -174,7 +230,7 @@ class Orders extends Auth{
|
|
|
// 当前时间
|
|
|
$time = time();
|
|
|
// 循环表格数据
|
|
|
- foreach ($sheetList as $value) {
|
|
|
+ foreach ($sheetList as $value) {
|
|
|
// 状态更改
|
|
|
$value['status'] = $Model->getWeibanStatus($value['status']);
|
|
|
// 客户手机号
|
|
@@ -479,4 +535,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 '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|