params['type'] ?? '') { // 转入 case 'in': $this->searchWhere[] = [ 'ut.transfer_in', '=', $this->userId ]; break; // 转出 case 'out': $this->searchWhere[] = [ 'ut.transfer_out', '=', $this->userId ]; break; // 转入 + 转出 default: $this->searchWhere[] = [ 'ut.transfer_out|ut.transfer_in', '=', $this->userId ]; break; } $this->searchWhere[] = [ 'u.user_delete', '=', 0 ]; } /** * @notes 转账列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Tab * @date 2021/8/12 14:14 */ public function lists(): array { // 设置搜索 $this->setSearch(); $lists = User::alias('u') ->field('ut.id,ut.transfer_in,ut.transfer_out,ut.money,ut.money as money_desc,ut.create_time,u.nickname,u.avatar,u.sn') ->where($this->searchWhere) ->join('user_transfer ut', 'u.id=ut.transfer_out or u.id=ut.transfer_in') ->group('ut.id') ->limit($this->limitOffset, $this->limitLength) ->order('ut.id', 'desc') ->select() ->toArray(); foreach($lists as &$item) { $this->format($item); } return $lists; } /** * @notes 转账记录数量 * @return int * @author Tab * @date 2021/8/12 14:14 */ public function count(): int { // 设置搜索 $this->setSearch(); $count = User::alias('u') ->join('user_transfer ut', 'u.id=ut.transfer_out or u.id=ut.transfer_in') ->group('ut.id') ->where($this->searchWhere) ->count(); return $count; } /** * @notes notes * @param $item * @return void * @author lbzy * @datetime 2023-12-15 11:14:12 */ public function format(&$item) { // 转入 if($item['transfer_in'] == $this->userId) { $item['money_desc'] = '+' . $item['money']; } // 转出 if($item['transfer_out'] == $this->userId) { $item['money_desc'] = '-' . $item['money']; } $item['nickname'] = '转账-' . $item['nickname']; } }