UserHistoryDao.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\common\dao\user;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\user\UserHistory;
  14. class UserHistoryDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return UserHistory::class;
  19. }
  20. public function createOrUpdate(array $data)
  21. {
  22. $ret = $this->getModel()::getDB()->where($data)->find();
  23. if($ret){
  24. $ret->update_time = time();
  25. $ret->save();
  26. }else{
  27. $data['update_time'] = time();
  28. $this->create($data);
  29. }
  30. }
  31. public function search(?int $uid, int $type)
  32. {
  33. $query = ($this->getModel()::getDB())->when($uid, function ($query) use ($uid) {
  34. $query->where('uid', $uid);
  35. })->when($type, function ($query) use ($type) {
  36. $query->where('res_type', $type);
  37. });
  38. return $query->order('update_time DESC');
  39. }
  40. public function deleteBatch($uid,$data)
  41. {
  42. if(is_array($data)){
  43. $this->getModel()::getDB()->where($this->getPk(),'in',$data)->delete();
  44. }else if($data == 1){
  45. $this->getModel()::getDB()->where('uid',$uid)->delete();
  46. }
  47. }
  48. public function userTotalHistory($uid)
  49. {
  50. return $this->getModel()::getDB()->where('uid',$uid)->count();
  51. }
  52. }