zory 3 dní pred
rodič
commit
1d636870bb

+ 1 - 1
app/controller/admin/Combo.php

@@ -14,7 +14,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/combo"),Middleware(AuthMiddleware::class)]

+ 1 - 1
app/controller/admin/Config.php

@@ -10,7 +10,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/config"),Middleware(AuthMiddleware::class)]

+ 1 - 1
app/controller/admin/Dashboard.php

@@ -7,7 +7,7 @@ use app\middleware\AuthMiddleware;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 #[Controller(prefix: "/api/dashboard"),Middleware(AuthMiddleware::class)]
 class Dashboard extends Base

+ 1 - 1
app/controller/admin/Shop.php

@@ -17,7 +17,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/shop"),Middleware(AuthMiddleware::class)]

+ 1 - 1
app/controller/admin/User.php

@@ -13,7 +13,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/user"),Middleware(AuthMiddleware::class)]

+ 1 - 1
app/controller/api/Cart.php

@@ -5,9 +5,9 @@ namespace app\controller\api;
 use app\extra\basic\Base;
 use app\middleware\WxMiddleware;
 use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Middleware;
 use LinFly\Annotation\Route\Route;
 use support\Response;
-use Webman\Annotation\Middleware;
 
 
 #[Controller(prefix: "/wx_api/cart"),Middleware(WxMiddleware::class)]

+ 1 - 1
app/controller/api/Home.php

@@ -13,7 +13,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 use Shopwwi\WebmanAuth\Facade\Auth as AuthMode;
 
 

+ 1 - 1
app/controller/api/Uploads.php

@@ -10,7 +10,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/wx_api/upload"),Middleware(WxMiddleware::class)]

+ 17 - 3
app/controller/api/User.php

@@ -4,9 +4,12 @@ namespace app\controller\api;
 
 use app\extra\basic\Base;
 use app\middleware\WxMiddleware;
+use app\model\saas\SaasUserOpen;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
+use support\Request;
+use support\Response;
 
 
 #[Controller(prefix: "/wx_api/user"),Middleware(WxMiddleware::class)]
@@ -15,10 +18,21 @@ class User extends Base
 
 
     #[Route(path: "data",methods: "get")]
-    public function getUserData()
+    public function getUserData(Request $request): Response
     {
         try {
-
+            $param = $this->_valid([
+                "shop.require"  => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $user = $request->user;
+            if (empty($user)) return errorTrans("empty.data");
+            $member = (new SaasUserOpen)->where("openid",$user['openid'])->with(['vip' => function($query) use($param){
+                $query->where("shop_id",$param['shop'])->field("openid,shop_id,ROUND(balance/100,2) as f_balance,ROUND(total_balance/100,2) as f_total_balance,ROUND(total_consume/100,2) as f_total_consume,card_no");
+            }])->field("openid,headimg,nickname")->append(["coupon"])->withAttr(['coupon' => function(){
+                return 0;
+            }])->findOrEmpty();
+            return success("ok",$member->toArray());
         } catch (\Throwable $th) {
             return error($th->getMessage());
         }

+ 4 - 4
app/controller/common/Login.php

@@ -5,7 +5,7 @@ namespace app\controller\common;
 use app\extra\basic\Base;
 use app\extra\service\basic\SmsService;
 use app\middleware\AuthMiddleware;
-use app\model\saas\SaasAgent;
+use app\model\saas\SaasShop;
 use app\model\system\SystemUser;
 use Hzdad\Codecheck\Codecheck;
 use LinFly\Annotation\Route\Controller;
@@ -15,7 +15,7 @@ use support\Request;
 use support\Response;
 use think\facade\Db;
 use Tinywan\Captcha\Captcha;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/login")]
@@ -111,7 +111,7 @@ class Login extends Base
      */
     protected function getTypeUser(int $agentId = 0): array
     {
-        return (new SaasAgent)->where("agent_id",$agentId)->findOrEmpty()->toArray();
+        return (new SaasShop)->where("shop_id",$agentId)->findOrEmpty()->toArray();
     }
 
     /**
@@ -123,7 +123,7 @@ class Login extends Base
         try {
             $userData = (new Auth)->guard("admin")->user()->toArray();
             if (isset($userData['password'])) unset($userData['password']);
-            $agent = (new SaasAgent)->where("agent_id",$userData['agent_id'])->findOrEmpty();
+            $agent = (new SaasShop)->where("shop_id",$userData['agent_id'])->findOrEmpty();
             if (empty($agent['vip_end']))
             {
                 $userData['vip_end'] = 0;

+ 1 - 1
app/controller/common/Menu.php

@@ -12,7 +12,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/api/menu"),Middleware(AuthMiddleware::class)]

+ 4 - 4
app/controller/exe/Login.php

@@ -4,7 +4,7 @@ namespace app\controller\exe;
 
 use app\extra\basic\Base;
 use app\middleware\ExeMiddleware;
-use app\model\saas\SaasAgent;
+use app\model\saas\SaasShop;
 use app\model\system\SystemUser;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
@@ -13,7 +13,7 @@ use support\Request;
 use support\Response;
 use think\facade\Db;
 use Tinywan\Captcha\Captcha;
-use Webman\Annotation\Middleware;
+use LinFly\Annotation\Route\Middleware;
 
 
 #[Controller(prefix: "/exe/login")]
@@ -80,7 +80,7 @@ class Login extends Base
      */
     protected function getTypeUser(int $agentId = 0): array
     {
-        return (new SaasAgent)->where("agent_id",$agentId)->findOrEmpty()->toArray();
+        return (new SaasShop)->where("shop_id",$agentId)->findOrEmpty()->toArray();
     }
 
 
@@ -91,7 +91,7 @@ class Login extends Base
     public function getLoginUser(Request $request): Response
     {
         try {
-            $agent = (new SaasAgent)->where("agent_id",$request->uuid)->findOrEmpty();
+            $agent = (new SaasShop)->where("shop_id",$request->uuid)->findOrEmpty();
             return successTrans("success.data",[
                 "vip_at"    => empty($agent['vip_end'])?'无限期':date('Y-m-d',strtotime($agent['vip_end'])),
                 "agent_id"  => $agent['agent_id'],

+ 56 - 0
app/controller/exe/Prints.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace app\controller\exe;
+
+use app\extra\basic\Base;
+use app\middleware\ExeMiddleware;
+use app\model\saas\SaasPrintClient;
+use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Middleware;
+use LinFly\Annotation\Route\Route;
+use support\Request;
+use support\Response;
+
+
+#[Controller(prefix: "/exe/prints"),Middleware(ExeMiddleware::class)]
+class Prints extends Base
+{
+
+    /**
+     * 回传打印机信息
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "set",methods: "post")]
+    public function getPrintList(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            if (empty($param)) return errorTrans("empty.data");
+            $shopId = $request->uuid;
+            $mode = (new SaasPrintClient);
+            $printIn = [];
+            foreach ($param as $key=>$val)
+            {
+                $printId = strToUniqueNumberV4(trim($val['name']));
+                $printData = $mode->where("code",$printId)->where("shop_id",$shopId)->findOrEmpty();
+                if ($printData->isEmpty()) {
+                    $printIn[$key] = [
+                        "shop_id"       => $shopId,
+                        "code"          => $printId,
+                        "name"          => $val['name'],
+                        "ipaddress"     => $val['ipAddress'],
+                        "print_status"  => $val['status'],
+                    ];
+                }
+            }
+            if (!empty($printIn)) {
+                $mode->insertAll(array_values($printIn));
+            }
+            return success("ok");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 144 - 0
app/controller/merchant/Prints.php

@@ -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());
+        }
+    }
+
+}

+ 34 - 0
app/extra/service/saas/PrintService.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\extra\service\saas;
+
+use app\extra\basic\Service;
+use app\model\saas\SaasPrintClient;
+
+class PrintService extends Service
+{
+
+    /**
+     * 列表
+     * @param array $param
+     */
+    public function getList(array $param = [])
+    {
+        $this->mode = new SaasPrintClient();
+        return $this->searchVal($param,$this->searchFilter($param))->paginate([
+            "list_rows" => $param['pageSize'],
+            "page"      => $param['page']
+        ]);
+    }
+
+
+
+    protected function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
+        !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

+ 1 - 0
app/extra/weMini/Link.php

@@ -128,6 +128,7 @@ class Link extends BasicWeChat
                 "env_version"   => $version
             ],
         ];
+        print_r($param);
         return Http::asJson()->post($url,$param)->array();
     }
 

+ 32 - 0
app/functions.php

@@ -460,4 +460,36 @@ if(!function_exists('getHourlyTimeSlots')){
 
         return $slots;
     }
+}
+
+if (!function_exists("strToUniqueNumberV4"))
+{
+    /**
+     * 名称加密
+     * @param string $str
+     * @param string $salt
+     * @return string
+     */
+    function strToUniqueNumberV4(string $str = "", string $salt = ''): string
+    {
+        // 添加盐值增加唯一性
+        $str = $str . $salt;
+        // 使用多种哈希组合
+        $crc = abs(crc32($str));
+        $md5 = hexdec(substr(md5($str), 0, 8));
+        $sha1 = hexdec(substr(sha1($str), 0, 8));
+        // 组合并取模
+        $number = ($crc + $md5 + $sha1) % 1000000000000;
+        // 使用时间戳微调确保唯一性(针对同一字符串)
+        static $lastStr = '';
+        static $counter = 0;
+        if ($str === $lastStr) {
+            $counter++;
+            $number = ($number + $counter) % 1000000000000;
+        } else {
+            $lastStr = $str;
+            $counter = 0;
+        }
+        return str_pad($number, 12, '0', STR_PAD_LEFT);
+    }
 }

+ 10 - 1
app/middleware/WxMiddleware.php

@@ -2,6 +2,8 @@
 
 namespace app\middleware;
 
+use Shopwwi\WebmanAuth\Auth;
+use Shopwwi\WebmanAuth\JWT;
 use Webman\Http\Request;
 use Webman\Http\Response;
 use Webman\MiddlewareInterface;
@@ -14,7 +16,14 @@ class WxMiddleware implements MiddlewareInterface
             $controller = new \ReflectionClass($request->controller);
             $noNeedLogin = $controller->getDefaultProperties()['noNeedLogin']??[];
             if (empty($noNeedLogin) || !in_array($request->action, $noNeedLogin)) {
-
+                $type = $request->header('platform','');
+                if (empty($type)) return json(['code'=> 0,'msg'=> trans("error.param")]);
+                $token =  $request->header("Authorization","");
+                if (empty($token)) return json(['code'=> 0,'msg'=> trans("error.request")]);
+                (new JWT)->guard("member")->verify();
+                $user = (new Auth)->guard("member")->user();
+                if (empty($user)) return json(['code'=>401,'msg'=> trans("error.login")]);
+                $request->user = $user->toArray();
             }
         } catch (\ReflectionException $exception) {
             return json(['code'=> 500,'msg'=> $exception->getMessage()]);

+ 50 - 0
app/model/saas/SaasPrice.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property integer $shop_id 
+ * @property integer $source 1文档2复印
+ * @property integer $type 1普通纸张
+ * @property string $paper_size 纸张类型
+ * @property integer $duplex 1单面2双面
+ * @property integer $color 1彩色2黑白
+ * @property integer $price 价格
+ * @property mixed $create_at
+ */
+class SaasPrice extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_price";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+
+}

+ 11 - 4
app/model/saas/SaasUserOpen.php

@@ -3,13 +3,14 @@
 namespace app\model\saas;
 
 use app\extra\basic\Model;
+use think\model\relation\HasOne;
 
 
 /**
- * @property integer $id (主键)
- * @property string $nickname 
- * @property mixed $openid 
- * @property string $headimg 
+ * @property integer $id (主键)
+ * @property string $nickname 
+ * @property mixed $openid 
+ * @property string $headimg 
  * @property mixed $create_at
  */
 class SaasUserOpen extends Model
@@ -43,4 +44,10 @@ class SaasUserOpen extends Model
     public bool $timestamps = false;
 
 
+    public function vip(): HasOne
+    {
+        return $this->hasOne("app\model\saas\SaasUser","openid","openid");
+    }
+
+
 }

BIN
public/uploads/card/1220637573959186-print-004356708646.jpg


BIN
public/uploads/card/1220637573959186-print-008723553191.jpg


BIN
public/uploads/card/1220637573959186-print-009769536260.jpg


BIN
public/uploads/qrcode/1220637573959186-008723553191.jpg


BIN
public/uploads/qrcode/1220637573959186-009769536260.jpg


BIN
resource/font/msyh.ttc


BIN
resource/img/store-qrcode.jpg