UserHistoryDao.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\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. public function joinSpu($where)
  53. {
  54. $query = UserHistory::hasWhere('spu',function($query) use($where){
  55. $query->when(isset($where['keyword']) && $where['keyword'] !== '', function($query) use ($where){
  56. $query->whereLike('store_name',"%{$where['keyword']}%");
  57. });
  58. $query->where(true);
  59. });
  60. $query->where('uid', $where['uid']);
  61. $query->where('res_type', $where['type']);
  62. return $query;
  63. }
  64. }