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