|
@@ -0,0 +1,144 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace app\controller\merchant;
|
|
|
|
|
+
|
|
|
|
|
+use app\extra\basic\Base;
|
|
|
|
|
+use app\extra\service\saas\PrintService;
|
|
|
|
|
+use app\extra\weMini\Link;
|
|
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
|
|
+use app\model\saas\SaasPrintClient;
|
|
|
|
|
+use DI\Attribute\Inject;
|
|
|
|
|
+use Kkokk\Poster\Facades\Poster;
|
|
|
|
|
+use LinFly\Annotation\Route\Controller;
|
|
|
|
|
+use LinFly\Annotation\Route\Middleware;
|
|
|
|
|
+use LinFly\Annotation\Route\Route;
|
|
|
|
|
+use support\Request;
|
|
|
|
|
+use support\Response;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#[Controller(prefix: "/api/mer/prints"),Middleware(AuthMiddleware::class)]
|
|
|
|
|
+class Prints extends Base
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected PrintService $service;
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected SaasPrintClient $model;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #[Route(path: "list",methods: "get")]
|
|
|
|
|
+ public function getPrintList(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->get();
|
|
|
|
|
+ $list = $this->service->getList($param);
|
|
|
|
|
+ return successTrans("success.data",pageFormat($list),200);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存配置
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "save",methods: "post")]
|
|
|
|
|
+ public function savePrint(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "id.require" => trans(20010),
|
|
|
|
|
+ "is_price.require" => trans(20010),
|
|
|
|
|
+ "paper_size.require" => trans(20010),
|
|
|
|
|
+ "color.require" => trans(20010),
|
|
|
|
|
+ "direction.require" => trans(20010),
|
|
|
|
|
+ "duplex.require" => trans(20010),
|
|
|
|
|
+ "package.require" => trans(20010),
|
|
|
|
|
+ "type.require" => trans(20010)
|
|
|
|
|
+ ],"post");
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $printId = $param['id'];
|
|
|
|
|
+ $is_price = $param['is_price'];
|
|
|
|
|
+ unset($param['id'],$param['is_price']);
|
|
|
|
|
+ $print = (new SaasPrintClient)->where("id",$printId)->findOrEmpty();
|
|
|
|
|
+ if ($print->isEmpty()) return errorTrans("empty.data");
|
|
|
|
|
+ $print->is_price = $is_price;
|
|
|
|
|
+ $print->rule = json_encode($param);
|
|
|
|
|
+ $state = $print->save();
|
|
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
|
|
+ return successTrans("success.data");
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存配置
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "single",methods: "post")]
|
|
|
|
|
+ public function savePrintSingle(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->post();
|
|
|
|
|
+ if (empty($param['id'])) return errorTrans("empty.require");
|
|
|
|
|
+ $print = (new SaasPrintClient)->where("id",$param['id'])->findOrEmpty();
|
|
|
|
|
+ if ($print->isEmpty()) return errorTrans("empty.data");
|
|
|
|
|
+ if (isset($param['status'])) {
|
|
|
|
|
+ $param['status'] = $print['status'] == 1 ? 2 : 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ $state = $print->save($param);
|
|
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
|
|
+ return successTrans("success.data");
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 二维码
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[Route(path: "qrcode",methods: "post")]
|
|
|
|
|
+ public function printQrcode(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->post();
|
|
|
|
|
+ if (empty($param['id'])) return errorTrans("empty.require");
|
|
|
|
|
+ $print = (new SaasPrintClient)->where("id",$param['id'])->findOrEmpty();
|
|
|
|
|
+ if ($print->isEmpty()) return errorTrans("empty.data");
|
|
|
|
|
+ $qrcodePath = public_path()."/uploads/card/{$print['shop_id']}-print-{$print['code']}.jpg";
|
|
|
|
|
+ if (!is_file($qrcodePath)) {
|
|
|
|
|
+ $pathBase = "/uploads/qrcode/".$print['shop_id']."-".$print['code'].".jpg";
|
|
|
|
|
+ $path = (new Link([
|
|
|
|
|
+ "appid" => sConf("wechat.mini_appid"),
|
|
|
|
|
+ "appsecret" => sConf("wechat.mini_secret")
|
|
|
|
|
+ ]))->createQrcodeWx("/pages/index/index","shop={$print['shop_id']}&code={$print['code']}",$pathBase);
|
|
|
|
|
+ $bg = base_path()."/resource/img/store-qrcode.jpg";
|
|
|
|
|
+ $fontPath = base_path()."/resource/font/msyh.ttc";
|
|
|
|
|
+ if (!is_file($qrcodePath)) {
|
|
|
|
|
+ Poster::config([
|
|
|
|
|
+ "path" => $qrcodePath
|
|
|
|
|
+ ])->buildImDst($bg,425,578)
|
|
|
|
|
+ // ->buildText(isset($print['shop']['shop_name'])?$print['shop']['shop_name']:'印美自助打印','center',390,18,[0,0,0,1],180,$fontPath)
|
|
|
|
|
+// ->buildQr($link,105,160,0,0,217,217)
|
|
|
|
|
+ // ->buildImage($qrcodeminiPath,105,180,0,0,217,217)
|
|
|
|
|
+ ->buildImage($path,105,170,0,0,217,247)
|
|
|
|
|
+ ->getPoster();;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return successTrans("success.data",['img' => 'data:image/png;base64,'.base64_encode(file_get_contents($qrcodePath))]);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|