Ver código fonte

feat():订单页面

geek 4 anos atrás
pai
commit
1c9e5e0d9b

+ 127 - 0
application/api/controller/Discuss.php

@@ -0,0 +1,127 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/12/16 23:06
+ */
+
+namespace app\api\controller;
+
+
+use app\api\BaseController;
+use app\api\model\DiscussModel;
+use app\api\model\GroupModel;
+use app\common\until\Until;
+
+class Discuss extends BaseController {
+
+    /**
+     * @OA\Post(path="/api/Discuss/index",
+     *   tags={"评论管理"},
+     *   summary="评论列表",
+     *   @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
+     *   @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
+     *   @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
+     *   @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="integer",default="1")),
+     *   @OA\Parameter(name="productId", in="query", description="产品id", @OA\Schema(type="integer",default="1")),
+     *   @OA\Parameter(name="myDiscuss", in="query", description="用户的评论 1获取我的评论", @OA\Schema(type="integer",default="1")),
+     *   @OA\RequestBody(
+     *     ),
+     *   @OA\Response(response="200", description="请求成功")
+     * )
+     */
+    public function index() {
+        $input = request()->get();
+        $model = new DiscussModel();
+        $model->setPage($input['page'] ?? 1);
+        $model->setPageSize($input['pageSize'] ?? 10);
+        $where = [];
+
+        if (!empty($input['storeId'])) {
+            $where[] = ['do.store_id', '=', (int)$input['storeId']];
+        }
+        if (!empty($input['productId'])) {
+            $where[] = ['do.product_id', '=', (int)$input['productId']];
+        }
+        if (!empty($input['myDiscuss'])) {
+            $where[] = ['do.user_id', '=', $this->userId];
+        }
+
+        $model->setWhere($where);
+        $data = $model->getDiscussList();
+        Until::output($data);
+    }
+
+
+    /**
+     * @OA\Post(path="/api/Discuss/save",
+     *   tags={"评论管理"},
+     *   summary="保存评论信息",
+     *   @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
+     *   @OA\RequestBody(
+     *     @OA\MediaType(
+     *       mediaType="multipart/form-data",
+     *         @OA\Schema(
+     *           @OA\Property(description="产品id", property="productId", type="integer", default="1"),
+     *           @OA\Property(description="订单id", property="orderId", type="integer", default="1"),
+     *           @OA\Property(description="门店id", property="storeId", type="integer", default="1"),
+     *           @OA\Property(description="产品得分", property="productScore", type="integer", default="5"),
+     *           @OA\Property(description="门店得分", property="storeScore", type="integer", default="5"),
+     *           @OA\Property(description="评论详情", property="content", type="string", default="妹子真好看"),
+     *           @OA\Property(description="评论图片(多个用逗号分隔)", property="imgUrls", type="integer",
+     *     default="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg,https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg"),
+     *           required={"productId","orderId","storeId","productScore","storeScore","content","imgUrls"})
+     *       )
+     *     ),
+     *   @OA\Response(response="200", description="请求成功")
+     * )
+     */
+    public function save() {
+        $input = Until::getInput();
+        $rule = [
+            'productId|产品id'    => 'require',
+            'orderId|订单id'    => 'require',
+            'storeId|门店id'      => 'require',
+            'productScore|产品得分' => 'require',
+            'storeScore|门店得分'   => 'require',
+            'content|评论详情'      => 'require',
+            'imgUrls|评论图片'      => 'require',
+        ];
+        Until::check($rule, $input);
+        $model = new DiscussModel();
+        if (!empty($input['id'])) {
+            $id = (int)$input['id'];
+            $model::where(['id' => $id])->update([
+                'product_id'    => $input['productId'],
+                'store_id'      => $input['storeId'],
+                'product_score' => $input['productScore'],
+                'store_score'   => $input['storeScore'],
+                'content'       => $input['content'],
+                'img_urls'      => $input['imgUrls'],
+            ]);
+        } else {
+            $id = $model->insertGetId([
+                'product_id'    => $input['productId'],
+                'store_id'      => $input['storeId'],
+                'order_id'      => $input['orderId'],
+                'user_id'       => $this->userId,
+                'product_score' => $input['productScore'],
+                'store_score'   => $input['storeScore'],
+                'content'       => $input['content'],
+                'img_urls'      => $input['imgUrls'],
+            ]);
+        }
+        $where[] = ['do.id', '=', (int)$id];
+        $model->setWhere($where);
+        $info = $model->getDiscussInfo();
+        Until::output(['info' => $info]);
+    }
+
+
+    public function delete($id, $status) {
+        $model = new GroupModel();
+        $where[] = ['id', '=', (int)$id];
+        $data = ['status' => (int)$status];
+        $isSuccess = $model::where($where)->update($data);
+        Until::output(['isSuccess' => $isSuccess]);
+    }
+}

+ 13 - 3
application/api/controller/Order.php

@@ -29,6 +29,7 @@ class Order extends BaseController {
      *   @OA\Parameter(name="writeOffStatus", in="query", description="核销状态 1未核销 2已核销 ", @OA\Schema(type="integer")),
      *   @OA\Parameter(name="orderSn", in="query", description="订单号", @OA\Schema(type="string")),
      *   @OA\Parameter(name="mobile", in="query", description="手机号", @OA\Schema(type="string")),
+     *   @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="integer")),
      *   @OA\RequestBody(
      *     ),
      *   @OA\Response(response="200", description="请求成功")
@@ -39,7 +40,7 @@ class Order extends BaseController {
         $model = new OrderModel();
         $model->setPage($input['page'] ?? 1);
         $model->setPageSize($input['pageSize'] ?? 10);
-        $where  = [];
+        $where = [];
         if (!empty($input['orderSn'])) {
             $where[] = ['o.order_sn', 'like', "%{$input['orderSn']}%"];
         }
@@ -56,7 +57,9 @@ class Order extends BaseController {
             $where[] = ['o.status', '=', $input['orderStatus']];
         }
 
-
+        if (!empty($input['storeId'])) {
+            $where[] = ['store.store_id', '=', $input['storeId']];
+        }
         $model->setWhere($where);
         $data = $model->getOrderList();
         Until::output($data);
@@ -145,6 +148,12 @@ class Order extends BaseController {
         $productInfo = (new ProductModel())::where(['id' => $input['productId']])->find();
         $model = new OrderModel();
         try {
+            $userId = $this->userId;
+            $orderType = 1;
+            if ($this->isAdmin()) {
+                $userId = 0;
+                $orderType = 2;
+            }
             $model->startTrans();
             $orderId = $model->insertGetId([
                 'order_sn'         => $orderSn,
@@ -154,7 +163,8 @@ class Order extends BaseController {
                 'appointment_time' => $input['appointmentTime'],
                 'mobile'           => $input['mobile'],
                 'status'           => 1,
-                'user_id'          => $this->userId,
+                'order_type'       => $orderType,
+                'user_id'          => $userId,
             ]);
             (new WriteOffModel())->insertGetId([
                 'write_off_code'   => '',

+ 1 - 1
application/api/controller/Store.php

@@ -202,7 +202,7 @@ class Store extends BaseController {
     }
 
     /**
-     * @OA\Post(path="/api/Product/save",
+     * @OA\Post(path="/api/Store/getStore",
      *   tags={"门店管理"},
      *   summary="距离最近的一家门店",
      *   @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),

+ 27 - 0
application/api/model/DiscussModel.php

@@ -12,4 +12,31 @@ use think\Db;
 class DiscussModel  extends BaseModel {
 
     protected $table = 'discuss_order';
+
+    public function getDiscussList() {
+        $count = $this->alias('do')
+            ->join('store store','store.id = do.store_id')
+            ->join('user u','u.id = do.user_id')
+            ->join('product p','p.id = do.product_id');
+
+        $select = $this->alias('do')
+            ->field('do.*,u.name,u.avatar,p.product_name')
+            ->join('store store','store.id = do.store_id')
+            ->join('user u','u.id = do.user_id')
+            ->join('product p','p.id = do.product_id')
+            ->order('do.id desc');
+        return $this->joinModelPageList($count, $select);
+    }
+
+    public function getDiscussInfo() {
+        $select = $this->alias('do')
+            ->field('do.*,u.name,u.avatar,p.product_name')
+            ->join('store store', 'store.id = do.store_id')
+            ->join('user u', 'u.id = do.user_id')
+            ->join('product p', 'p.id = do.product_id')
+            ->order('do.id desc')
+            ->where($this->getWhere())
+            ->find();
+        return Until::modelToArray($select);
+    }
 }

+ 149 - 0
public/api.yaml

@@ -496,6 +496,116 @@ paths:
       responses:
         '200':
           description: 请求成功
+  /api/Discuss/index:
+    post:
+      tags:
+        - 评论管理
+      summary: 评论列表
+      operationId: 'app\api\controller\Discuss::index'
+      parameters:
+        -
+          name: token
+          in: header
+          description: token
+          schema:
+            type: string
+        -
+          name: page
+          in: query
+          description: 页码
+          schema:
+            type: ineger
+            default: '1'
+        -
+          name: pageSize
+          in: query
+          description: 页尺寸
+          schema:
+            type: integer
+            default: '10'
+        -
+          name: storeId
+          in: query
+          description: 门店id
+          schema:
+            type: integer
+            default: '1'
+        -
+          name: productId
+          in: query
+          description: 产品id
+          schema:
+            type: integer
+            default: '1'
+        -
+          name: myDiscuss
+          in: query
+          description: '用户的评论 1获取我的评论'
+          schema:
+            type: integer
+            default: '1'
+      requestBody: {  }
+      responses:
+        '200':
+          description: 请求成功
+  /api/Discuss/save:
+    post:
+      tags:
+        - 评论管理
+      summary: 保存评论信息
+      operationId: 'app\api\controller\Discuss::save'
+      parameters:
+        -
+          name: token
+          in: header
+          description: token
+          schema:
+            type: string
+      requestBody:
+        content:
+          multipart/form-data:
+            schema:
+              required:
+                - productId
+                - orderId
+                - storeId
+                - productScore
+                - storeScore
+                - content
+                - imgUrls
+              properties:
+                productId:
+                  description: 产品id
+                  type: integer
+                  default: '1'
+                orderId:
+                  description: 订单id
+                  type: integer
+                  default: '1'
+                storeId:
+                  description: 门店id
+                  type: integer
+                  default: '1'
+                productScore:
+                  description: 产品得分
+                  type: integer
+                  default: '5'
+                storeScore:
+                  description: 门店得分
+                  type: integer
+                  default: '5'
+                content:
+                  description: 评论详情
+                  type: string
+                  default: 妹子真好看
+                imgUrls:
+                  description: 评论图片(多个用逗号分隔)
+                  type: integer
+                  default: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg,https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg'
+              type: object
+      responses:
+        '200':
+          description: 请求成功
   /api/Group/index:
     post:
       tags:
@@ -606,6 +716,12 @@ paths:
           description: 手机号
           schema:
             type: string
+        -
+          name: storeId
+          in: query
+          description: 门店id
+          schema:
+            type: integer
       requestBody: {  }
       responses:
         '200':
@@ -1458,6 +1574,39 @@ paths:
       responses:
         '200':
           description: 请求成功
+  /api/Store/getStore:
+    post:
+      tags:
+        - 门店管理
+      summary: 距离最近的一家门店
+      operationId: 'app\api\controller\Store::getStore'
+      parameters:
+        -
+          name: token
+          in: header
+          description: token
+          schema:
+            type: string
+      requestBody:
+        content:
+          multipart/form-data:
+            schema:
+              required:
+                - lat
+                - lon
+              properties:
+                lat:
+                  description: 纬度
+                  type: string
+                  default: ''
+                lon:
+                  description: 经度
+                  type: string
+                  default: ''
+              type: object
+      responses:
+        '200':
+          description: 请求成功
   /api/User:
     post:
       tags: