RecordDao.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\system\Record;
  14. class RecordDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return Record::class;
  19. }
  20. /**
  21. * 根据类型自增
  22. * @param string $type
  23. * @param int $linkId
  24. * @param $num
  25. */
  26. public function incType(string $type, int $linkId, $num = 1, $data = [])
  27. {
  28. $data = [
  29. 'uid' => $data['uid'] ?? 0,
  30. 'title' => $data['title'] ?? $type,
  31. 'type' => $type,
  32. 'link_id' => $linkId
  33. ];
  34. $res = $this->findOrCreate($data);
  35. $res->num = $res['num'] + $num;
  36. $res->save();
  37. }
  38. /**
  39. * 根据类型自减
  40. * @param string $type
  41. * @param int $linkId
  42. * @param $num
  43. */
  44. public function decType(string $type, int $linkId, $num = 1)
  45. {
  46. $this->getSearch(['type' => $type])->where('link_id', $linkId)->where('num','>=',1)->dec('num', $num)->update();
  47. }
  48. }