diff --git a/app/api/controller/user/UserVisitController.php b/app/api/controller/user/UserVisitController.php new file mode 100644 index 000000000..26fac0cff --- /dev/null +++ b/app/api/controller/user/UserVisitController.php @@ -0,0 +1,35 @@ +post()->goCheck('add'); + + $result = UserVisitLogic::add($params,$this->userId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(UserVisitLogic::getError()); + + } + +} \ No newline at end of file diff --git a/app/api/logic/user/UserVisitLogic.php b/app/api/logic/user/UserVisitLogic.php new file mode 100644 index 000000000..5a95ef88c --- /dev/null +++ b/app/api/logic/user/UserVisitLogic.php @@ -0,0 +1,47 @@ +$params['product_id'], + 'uid'=>$uid + ]) + ->whereDay('create_time') + ->find(); + if($check){ + StoreVisit::where('id',$check['id'])->inc('count')->update(); + }else{ + StoreVisit::create([ + 'uid' => $uid, + 'product_id' => $params['product_id'], + 'cate_id' => $params['cate_id'], + 'count' => 1, + 'create_time' => time(), + ]); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + } \ No newline at end of file diff --git a/app/api/validate/VisitValidate.php b/app/api/validate/VisitValidate.php new file mode 100644 index 000000000..daf39519a --- /dev/null +++ b/app/api/validate/VisitValidate.php @@ -0,0 +1,50 @@ + 'require|number', + 'cate_id' => 'require|number', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'product_id' => '商品id', + 'cate_id' => '分类', + ]; + + + /** + * @notes 添加场景 + * @return VisitValidate + * @author likeadmin + * @date 2024/04/24 10:37 + */ + public function sceneAdd() + { + return $this->only(['product_id','cate_id']); + } + + + +} \ No newline at end of file diff --git a/app/common/model/store_visit/StoreVisit.php b/app/common/model/store_visit/StoreVisit.php new file mode 100644 index 000000000..0f506070a --- /dev/null +++ b/app/common/model/store_visit/StoreVisit.php @@ -0,0 +1,22 @@ +