12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\common\dao\user;
- use app\common\dao\BaseDao;
- use app\common\model\user\UserHistory;
- class UserHistoryDao extends BaseDao
- {
- protected function getModel(): string
- {
- return UserHistory::class;
- }
- public function createOrUpdate(array $data)
- {
- $ret = $this->getModel()::getDB()->where($data)->find();
- if($ret){
- $ret->update_time = time();
- $ret->save();
- }else{
- $data['update_time'] = time();
- $this->create($data);
- }
- }
- public function search(?int $uid, int $type)
- {
- $query = ($this->getModel()::getDB())->when($uid, function ($query) use ($uid) {
- $query->where('uid', $uid);
- })->when($type, function ($query) use ($type) {
- $query->where('res_type', $type);
- });
- return $query->order('update_time DESC');
- }
- public function deleteBatch($uid,$data)
- {
- if(is_array($data)){
- $this->getModel()::getDB()->where($this->getPk(),'in',$data)->delete();
- }else if($data == 1){
- $this->getModel()::getDB()->where('uid',$uid)->delete();
- }
- }
- public function userTotalHistory($uid)
- {
- return $this->getModel()::getDB()->where('uid',$uid)->count();
- }
- }
|