|
|
@@ -0,0 +1,208 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\controller\merchant;
|
|
|
+
|
|
|
+use app\extra\basic\Base;
|
|
|
+use app\extra\service\saas\PrintService;
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
+use app\model\saas\SaasPrint;
|
|
|
+use app\validate\saas\PrintValidate;
|
|
|
+use DI\Attribute\Inject;
|
|
|
+use LinFly\Annotation\Route\Controller;
|
|
|
+use LinFly\Annotation\Route\Route;
|
|
|
+use support\Request;
|
|
|
+use support\Response;
|
|
|
+use Webman\Annotation\Middleware;
|
|
|
+use Webman\RedisQueue\Redis;
|
|
|
+
|
|
|
+
|
|
|
+#[Controller(prefix: "/api/merchant/print"),Middleware(AuthMiddleware::class)]
|
|
|
+class PrintCloud extends Base
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected PrintService $service;
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected PrintValidate $validate;
|
|
|
+
|
|
|
+ #[Inject]
|
|
|
+ protected SaasPrint $model;
|
|
|
+
|
|
|
+ #[Route(path: "list",methods: "get")]
|
|
|
+ public function getStoreList(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $request->get();
|
|
|
+ $param['agent'] = $request->user['agent_id'];
|
|
|
+ $list = $this->service->getDataList($param);
|
|
|
+ return successTrans("success.data",pageFormat($list),200);
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询打印机状态
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "refresh",methods: "post")]
|
|
|
+ public function refreshState(): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ Redis::send("print-state",[]);
|
|
|
+ return successTrans("success.print-state");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打印测试
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "test",methods: "post")]
|
|
|
+ public function testPrint(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "sn.require" => trans("empty.require")
|
|
|
+ ],"post");
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ $print = $this->model->where("sn",$param["sn"])->findOrEmpty();
|
|
|
+ if ($print->isEmpty()) return errorTrans("empty.data");
|
|
|
+ $resp = (new \app\extra\tools\PrintService())->config(['appid' => sConf('dy.ex_appid'),'secret' => sConf('dy.ex_secret')])->printTemplate(sConf('dy.ex_print'),$param['sn'],[
|
|
|
+ [
|
|
|
+ "express" => [
|
|
|
+ [
|
|
|
+ "j_mobile" => "180****9980",
|
|
|
+ "j_address" =>"安徽省阜阳市颍州区xxx镇xxx村xxx",
|
|
|
+ "express_num" => "SF3270714680386",
|
|
|
+ "name" => "测试的商品标题名称测试的商品标题名称测试的商品标题名称测试的商品标题名称测试的商品标题名称",
|
|
|
+ "time" => getDateFull(),
|
|
|
+ "type" => "特快",
|
|
|
+ "s_name" => "王*二",
|
|
|
+ "s_address" => "安徽省阜阳市颍州区xxx镇xxx村xxx",
|
|
|
+ "s_mobile" => "******00982",
|
|
|
+ "j_name" => "王麻子",
|
|
|
+ "express_type" => "饰品",
|
|
|
+ "order" => "1033999288123123"
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ if (!$resp['status']) return error($resp['message']);
|
|
|
+ return successTrans("success.print");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增/编辑代理
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "save",methods: "post")]
|
|
|
+ public function save(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $request->post();
|
|
|
+ if (!$this->validate->check($param)) return error($this->validate->getError());
|
|
|
+ if (!isset($param['id'])) {
|
|
|
+ $resp = (new \app\extra\tools\PrintService())->config(['appid' => sConf('dy.ex_appid'),'secret' => sConf('dy.ex_secret')])->bindDevice($param['sn'],$param['name']);
|
|
|
+ if (!$resp['status']) return error($resp['message']);
|
|
|
+ }
|
|
|
+ $state = $this->model->setAutoData($param);
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
+ echo $throwable->getFile()."\n";
|
|
|
+ echo $throwable->getLine()."\n";
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增/编辑代理
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "edit",methods: "post")]
|
|
|
+ public function edit(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $request->post();
|
|
|
+ if (!$this->validate->scene('edit')->check($request->post())) return error($this->validate->getError());
|
|
|
+ $state = $this->model->setAutoData($param);
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
+ echo $throwable->getFile()."\n";
|
|
|
+ echo $throwable->getLine()."\n";
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "batch",methods: "post")]
|
|
|
+ public function setBatchData(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
+ "value.require" => trans("empty.require"),
|
|
|
+ "field.require" => trans("empty.require"),
|
|
|
+ "type.require" => trans("empty.require"),
|
|
|
+ ],"post");
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ if ($param['type'] == "batch") {
|
|
|
+ $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]);
|
|
|
+ } else {
|
|
|
+ $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]);
|
|
|
+ }
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "del",methods: "post")]
|
|
|
+ public function delUser(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
+ "type.default" => "one",
|
|
|
+ ],"post");
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ if ($param['type'] == "batch") {
|
|
|
+ $state = $this->model->where("id","in",$param['id'])->delete();
|
|
|
+ } else {
|
|
|
+ $data = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
+ if ($data->isEmpty()) return errorTrans("empty.data");
|
|
|
+ // 删除其他相关数据
|
|
|
+ $state = $data->delete();
|
|
|
+ }
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|