| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\shopapi\logic;
- use app\common\enum\FootprintEnum;
- use app\common\enum\UserTerminalEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\IndexVisit;
- use app\common\model\Visitor;
- class IndexLogic extends BaseLogic
- {
- /**
- * @notes 首页访客记录
- * @return bool
- * @author Tab
- * @date 2021/9/11 9:29
- */
- public static function visit($userId)
- {
- try {
- if ($userId) {
- // 汽泡足迹
- event('Footprint', ['type' => FootprintEnum::VISIT_MALL, 'user_id' => $userId]);
- }
- $params = request()->post();
- if (!isset($params['terminal']) || !in_array($params['terminal'], UserTerminalEnum::ALL_TERMINAL)) {
- throw new \Exception('终端参数缺失或有误');
- }
- $ip = request()->ip();
- // 一个ip一个终端一天只生成一条记录
- $record = IndexVisit::where([
- 'ip' => $ip,
- 'terminal' => $params['terminal']
- ])->whereDay('create_time')->findOrEmpty();
- if (!$record->isEmpty()) {
- // 增加访客在终端的浏览量
- $record->visit += 1;
- $record->save();
- return true;
- }
- // 生成访客记录
- IndexVisit::create([
- 'ip' => $ip,
- 'terminal' => $params['terminal'],
- 'visit' => 1
- ]);
- return true;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- }
|