SpecialRecord.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\special;
  12. use basic\ModelBasic;
  13. use traits\ModelTrait;
  14. /**
  15. * Class SpecialRecord
  16. * @package app\wap\model\special
  17. */
  18. class SpecialRecord extends ModelBasic
  19. {
  20. use ModelTrait;
  21. /**
  22. * 记录用户浏览记录
  23. * @param $specialId
  24. * @param $uid
  25. * @return false|int|object
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. */
  30. public static function record($specialId, $uid)
  31. {
  32. $info = self::where(['special_id' => $specialId, 'uid' => $uid])->find();
  33. if ($info) {
  34. $info->number = $info->number + 1;
  35. $info->update_time = time();
  36. $res = $info->save();
  37. } else {
  38. $res = self::set([
  39. 'number' => 1,
  40. 'add_time' => time(),
  41. 'update_time' => time(),
  42. 'uid' => $uid,
  43. 'special_id' => $specialId
  44. ]);
  45. }
  46. return $res;
  47. }
  48. }