|
|
|
@ -17,12 +17,15 @@ use App\Models\Guide; |
|
|
|
use App\Models\Product; |
|
|
|
use App\Models\ProductSpec; |
|
|
|
use App\Models\Supplier; |
|
|
|
use App\Service\OpenPlatform; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Form\NestedForm; |
|
|
|
use Dcat\Admin\Grid; |
|
|
|
use Dcat\Admin\Show; |
|
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
use EasyWeChat\Kernel\Http\StreamResponse; |
|
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
|
|
|
|
class AgentProductController extends AdminController |
|
|
|
{ |
|
|
|
@ -67,27 +70,8 @@ class AgentProductController extends AdminController |
|
|
|
}); |
|
|
|
$grid->column('sale'); |
|
|
|
$grid->column('stock'); |
|
|
|
|
|
|
|
$grid->column('category.name', '分类'); |
|
|
|
/*$grid->column('product_ids', '产品详情') |
|
|
|
->display('查看') |
|
|
|
->modal(function ($modal) { |
|
|
|
$titles = ['供应商', '产品标题', '产品图片', '市场价', '现价', '销量', '库存']; |
|
|
|
$pic = isset($this->product->picture) |
|
|
|
? "<img data-action=\"preview-img\" src=\"{$this->product->picture}\" style=\"max-width:80px;max-height:200px;cursor:pointer\" class=\"img img-thumbnail\">" |
|
|
|
: ''; |
|
|
|
$data = [[ |
|
|
|
$this->product->supplier->company_name ?? '', |
|
|
|
$this->product->title ?? '', |
|
|
|
$pic, |
|
|
|
$this->product->original_price ?? '', |
|
|
|
$this->product->price ?? '', |
|
|
|
$this->product->sale ?? '', |
|
|
|
$this->product->stock ?? '', |
|
|
|
]]; |
|
|
|
return Table::make($titles, $data); |
|
|
|
});*/ |
|
|
|
// $grid->column('single_deposit');
|
|
|
|
|
|
|
|
$grid->column('status')->help('切换开关可改变上下架状态') |
|
|
|
->if(fn() => in_array($this->status, [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE])) |
|
|
|
->using([ProductStatus::SOLD_OUT => 0, ProductStatus::ON_SALE => 1]) |
|
|
|
@ -103,7 +87,12 @@ class AgentProductController extends AdminController |
|
|
|
if (Admin::user()->type != AgentType::OPERATOR) { |
|
|
|
$grid->column('is_rec')->switch()->help('推荐后将在“我的”页面下方显示'); |
|
|
|
} |
|
|
|
$grid->column('updated_at'); |
|
|
|
$grid->column('小程序码') |
|
|
|
->display('查看') |
|
|
|
->modal(function ($modal) { |
|
|
|
return '<img data-action="preview-img" src="'.(new AgentProductController)->mpQrcode($this->id).'" style="max-width:60px;max-height:60px;cursor:pointer" class="img img-thumbnail">'; |
|
|
|
}); |
|
|
|
$grid->column('updated_at')->width(100); |
|
|
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
|
$filter->panel(); |
|
|
|
@ -125,6 +114,24 @@ class AgentProductController extends AdminController |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
# 小程序码
|
|
|
|
public function mpQrcode(int $agent_product_id) |
|
|
|
{ |
|
|
|
$save_path = 'agent/qrcode/' . Admin::user()->id; |
|
|
|
$filename = $save_path . '/' . $agent_product_id . '.jpg'; |
|
|
|
if (Storage::exists($filename)) { |
|
|
|
return redirect(Storage::disk('public')->url($filename)); |
|
|
|
} |
|
|
|
|
|
|
|
$mp = (new OpenPlatform)->miniProgram(Admin::user()->appid); |
|
|
|
$response = $mp->app_code->getQrCode('/pages/goodsDetail/index?goods_id=' . $agent_product_id); |
|
|
|
if ($response instanceof StreamResponse) { |
|
|
|
$response->saveAs(Storage::disk('public')->path($save_path), $filename); //保存二维码
|
|
|
|
header("Content-Type: " . $response->getHeaderLine('Content-Type')); |
|
|
|
return $response; //输出图片
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make a show builder. |
|
|
|
* |
|
|
|
|