72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Activity;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\View;
|
|
use Image;
|
|
use QrCode;
|
|
use RuLong\Order\Models\Order;
|
|
|
|
class ActivityController extends Controller
|
|
{
|
|
|
|
public function __construct(Request $request)
|
|
{
|
|
$this->middleware('auth');
|
|
View::share('nav', 1);
|
|
}
|
|
|
|
public function index(Category $category)
|
|
{
|
|
if (in_array($category->id, [13, 14])) {
|
|
$categorys = Category::with('storage')->where('parent_id', $category->id)->orderby('sort', 'asc')->get();
|
|
$category_ids = Category::where('parent_id', $category->id)->pluck('id');
|
|
} else {
|
|
$categorys = Category::with('storage')->where('parent_id', $category->parent_id)->orderby('sort', 'asc')->get();
|
|
$category_ids = Category::where('id', $category->id)->pluck('id');
|
|
}
|
|
$activitys = Activity::inRandomOrder()->whereIn('category_id', $category_ids)->get();
|
|
|
|
return view('activity.index', compact('activitys', 'categorys', 'category'));
|
|
}
|
|
|
|
public function show(Activity $activity)
|
|
{
|
|
return view('activity.show', compact('activity'));
|
|
}
|
|
|
|
public function create(Request $request, Activity $activity)
|
|
{
|
|
return view('activity.create', compact('activity'));
|
|
}
|
|
|
|
//生成核销二维码
|
|
public function qrcode(Request $request)
|
|
{
|
|
$orderid = $request->orderid;
|
|
$order = Order::find($orderid);
|
|
|
|
if (!$order) {
|
|
return Image::canvas(200, 200)->text('没有这个订单', 50, 100, function ($font) {
|
|
$font->file('fonts/yahei.ttf')->color('#1f1f1f')->size(21);
|
|
})->response('jpg');
|
|
} elseif ($order->item_type != 'ACTIVITY') {
|
|
return Image::canvas(200, 200)->text('订单类型不对', 50, 100, function ($font) {
|
|
$font->file('fonts/yahei.ttf')->color('#1f1f1f')->size(21);
|
|
})->response('jpg');
|
|
}
|
|
|
|
if (!$order->canActivityAudit()) {
|
|
return $this->error('订单状态不对');
|
|
}
|
|
|
|
$activity = $order->detail->item_id;
|
|
$qrCode = Image::make(QrCode::size(3000)->format('png')->margin(1)->generate(route('sellers.verification', ['orderid' => $orderid])))->resize(230, 230);
|
|
return $qrCode->response('jpg');
|
|
}
|
|
|
|
}
|