zory преди 1 месец
родител
ревизия
34853ad2ef

+ 28 - 0
app/controller/api/Goods.php

@@ -3,12 +3,16 @@
 namespace app\controller\api;
 
 use app\extra\basic\Base;
+use app\extra\tools\CodeExtend;
 use app\middleware\AuthMiddleware;
 use app\model\saas\SaasGoods;
+use app\model\saas\SaasGoodsSku;
+use app\model\saas\SaasOrder;
 use DI\Attribute\Inject;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\GetMapping;
 use LinFly\Annotation\Attributes\Route\Middleware;
+use LinFly\Annotation\Attributes\Route\PostMapping;
 use support\Request;
 use support\Response;
 
@@ -40,4 +44,28 @@ class Goods extends Base
         }
     }
 
+
+    #[PostMapping("add_order")]
+    public function addOrder(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            if (!empty($param['spm'])) $param['goods_id'] = $param['spm'];
+            $goods = (new SaasGoods)->where([ "product_id" => $param['product_id'], "id" => $param['goods_id'] ])->findOrEmpty();
+            $sku = (new SaasGoodsSku)->where([ "product_id" => $param['product_id'], "sku_id" => $param['sku_id'] ])->findOrEmpty();
+            $priceData = empty($sku['price']) ? $goods['price'] * 100 : $sku['price'] * 100;
+            $param['line_price'] = empty($sku['line_price']) ? $goods['price'] * 100 : $sku['line_price'] * 100;
+            $param['price'] = $priceData * $param['number'];
+            $param['order_sn'] = CodeExtend::uniqidDate(18);
+            $param['openid'] = $request->user['openid'];
+            $param['sku_name'] = $param['name'];
+            $param['poi_id'] = $goods['poi_id'];
+            $state = (new SaasOrder)->setAutoData($param);
+            if (!$state) return error("提交订单失败");
+            return success("提交成功",['order' => $param['order_sn']]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 57 - 0
app/controller/api/Order.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasOrder;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use LinFly\Annotation\Attributes\Route\PostMapping;
+use support\Request;
+
+
+#[Controller("/dy/order"),Middleware(AuthMiddleware::class)]
+class Order extends Base
+{
+
+    #[Inject]
+    protected SaasOrder $model;
+
+
+    #[GetMapping("confirm")]
+    public function confirmOrder(Request $request)
+    {
+        try {
+            $param = $this->_valid([
+                "order.require"     => trans("empty.require")
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty();
+            if ($order->isEmpty()) return errorTrans("empty.data");
+            if ($order['status'] <> 0) return errorTrans("empty.data");
+            return $this->encode("ok",$order->toArray());
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+
+    #[PostMapping("data")]
+    public function confirmOrderSubmit(Request $request)
+    {
+        try {
+            $param = $this->_valid([
+                "order.require"     => trans("empty.require")
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 7 - 0
app/controller/api/Service.php

@@ -4,6 +4,8 @@ namespace app\controller\api;
 
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasStore;
+use app\model\system\SystemUser;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\Middleware;
 use LinFly\Annotation\Attributes\Route\PostMapping;
@@ -26,6 +28,11 @@ class Service extends Base
     {
         try {
             $param = $request->all();
+            $store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
+            if ($store->isEmpty()) return error("店铺不存在");
+            // 获取在线客服
+            $service = (new SystemUser)->where("store_id",$param['poi'])->where("type",3)->where("is_line",1)->findOrEmpty();
+            if ($service->isEmpty()) return $this->encode("ok",['store' => $store,'code' => 3]); // 无客服在线
 
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());

+ 37 - 0
app/controller/service/Heart.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\controller\service;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\system\SystemUser;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Request;
+use support\Response;
+
+
+#[Controller("/api/service/heart"),Middleware(AuthMiddleware::class)]
+class Heart extends Base
+{
+
+
+    #[GetMapping("beat")]
+    public function setHeartBeat(Request $request): Response
+    {
+        try {
+            $user = (new SystemUser)->where("id",$request->user['id'])->findOrEmpty();
+            if ($user->isEmpty()) return errorTrans("empty.data");
+            if ($user['is_line'] == 0) {
+                $user->is_line = 1;
+            }
+            $user->last_active_at = getDateFull();
+            $user->save();
+            return success("ok");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 1 - 1
app/middleware/AuthMiddleware.php

@@ -31,7 +31,7 @@ class AuthMiddleware implements MiddlewareInterface
                 $request->user = $user->toArray();
             }
         } catch (\Throwable $throwable) {
-            return json(['code'=> 500,'msg'=> $throwable->getMessage()]);
+            return json(['code'=> 401,'msg'=> $throwable->getMessage()]);
         }
         $response = $request->method() == 'OPTIONS' ? response('',204) : $handler($request);
         return $response;

+ 48 - 0
app/model/saas/SaasChatMsg.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $openid 
+ * @property integer $service_id 
+ * @property string $content 
+ * @property string $type 
+ * @property integer $status 1已读
+ * @property mixed $create_at
+ */
+class SaasChatMsg 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_chat_msg";
+    
+    /**
+     * 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;
+
+
+}

+ 63 - 0
app/model/saas/SaasOrder.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+use think\model\relation\HasOne;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $order_sn 
+ * @property mixed $openid 
+ * @property mixed $product_id 
+ * @property mixed $sku_id 
+ * @property integer $number 
+ * @property string $img 
+ * @property integer $price 
+ * @property integer $line_price 
+ * @property string $sku_name 
+ * @property mixed $poi_id 
+ * @property mixed $mobile
+ */
+class SaasOrder 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_order";
+    
+    /**
+     * 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;
+
+    public function product(): HasOne
+    {
+        return $this->hasOne(SaasGoods::class,"product_id","product_id");
+    }
+
+    public function poi(): HasOne
+    {
+        return $this->hasOne(SaasStore::class,"poi_id","poi_id");
+    }
+
+}