SpecialWatch.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. use think\Db;
  15. /**专题观看记录
  16. * Class SpecialWatch
  17. * @package app\wap\model\special
  18. */
  19. class SpecialWatch extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**
  23. * 素材观看时间
  24. */
  25. public static function materialViewing($uid, $data)
  26. {
  27. $viewing = self::where(['uid' => $uid, 'special_id' => $data['special_id'], 'task_id' => $data['task_id']])->find();
  28. if ($viewing) {
  29. $dat['viewing_time'] = $data['viewing_time'];
  30. $dat['percentage'] = $data['percentage'];
  31. $dat['total'] = $data['total'];
  32. if ($data['percentage'] > $viewing['percentage']) {
  33. return self::edit($dat, $viewing['id']);
  34. } else {
  35. return true;
  36. }
  37. } else {
  38. $data['uid'] = $uid;
  39. $data['add_time'] = time();
  40. return self::set($data);
  41. }
  42. }
  43. /**
  44. * 查看素材是否观看
  45. */
  46. public static function whetherWatch($uid, $special_id = 0, $task_id = 0)
  47. {
  48. return self::where(['uid' => $uid, 'special_id' => $special_id, 'task_id' => $task_id])->find();
  49. }
  50. }