Panda hai 1 mes
pai
achega
54936c4482
Modificáronse 1 ficheiros con 31 adicións e 0 borrados
  1. 31 0
      application/api/controller/OfflineShop.php

+ 31 - 0
application/api/controller/OfflineShop.php

@@ -89,4 +89,35 @@ class OfflineShop extends Api
         }
         return $this->success('success',$info);
     }
+
+    // 评价
+    public function comment()
+    {
+        $params = $this->request->param();
+        if (empty($params['shop_id'])) {
+            return $this->error('请选择评价门店');
+        }
+        if (empty($params['star'])){
+            return $this->error('请选择评分');
+        }
+        if (empty($params['remark'])){
+            return $this->error('请填写评价');
+        }
+
+        $data = [
+            'shop_id' => $params['shop_id'],
+            'user_id' => $this->auth->id,
+            'star' => $params['star'],
+            'remark' => $params['remark'],
+            'images' => $params['images'] ?? '',
+            'status' => 1,
+            'create_time' => time(),
+        ];
+        Db::name('offline_shop_comment')->insert($data);
+
+        $comment = Db::name('offline_shop_comment')->where('shop_id',$params['shop_id'])->field([Db::raw('sum(star) as star'),Db::raw('count(*) as num')])->find();
+        $star = bcdiv($comment['star'] ?? 0,$comment['num'] ?? 0,2);
+        Db::name('offline_shop')->where('id',$params['shop_id'])->update(['star'=>$star]);
+        return $this->success('评价成功');
+    }
 }