| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\shopapi\lists;
- use app\common\enum\AccountLogEnum;
- use app\common\model\AccountLog;
- /**
- * 账户流水列表
- * Class AccountLogLists
- * @package app\shopapi\lists
- */
- class AccountLogLists extends BaseShopDataLists
- {
- /**
- * @notes 设置搜索条件
- * @author Tab
- * @date 2021/8/9 17:31
- */
- public function setWhere()
- {
- // 指定用户
- $this->searchWhere[] = ['user_id', '=', $this->userId];
- // 可提现金额类型
- if(isset($this->params['type']) && $this->params['type'] == 'bw') {
- $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBwChangeType()];
- }
- // 不可提现金额类型-支出
- if(isset($this->params['type']) && $this->params['type'] == 'bnw_dec') {
- $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::BNW_DEC];
- }
- // 不可提现金额类型-收入
- if(isset($this->params['type']) && $this->params['type'] == 'bnw_inc') {
- $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::BNW_INC];
- }
- // 不可提现金额类型-支出 + 收入
- if(isset($this->params['type']) && $this->params['type'] == 'bnw') {
- $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBnwChangeType()];
- }
- // 积分
- if(isset($this->params['type']) && $this->params['type'] == 'integral') {
- $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getIntegralChangeType()];
- }
- // 按日期查询
- if(isset($this->params['search_date']) && $this->params['search_date'] <> '') {
- $start_date = strtotime($this->params['search_date'].'-01 00:00:00');
- $end_date = strtotime(date('Y-m-t 23:59:59', $start_date)); // 获取当月最后一天
- $this->searchWhere[] = ['create_time', 'between', [$start_date,$end_date]];
- }
- }
- /**
- * @notes 账户流水列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author Tab
- * @date 2021/8/9 17:37
- */
- public function lists(): array
- {
- // 设置搜索条件
- $this->setWhere();
- $field = 'change_type,change_amount,left_amount,action,create_time,remark';
- $lists = AccountLog::field($field)
- ->where($this->searchWhere)
- ->order('id', 'desc')
- ->limit($this->limitOffset, $this->limitLength)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- foreach($lists as &$item) {
- $item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
- $item['change_amount_desc'] = $item['action'] == AccountLogEnum::DEC ? '-' . $item['change_amount'] : '+' . $item['change_amount'];
- }
- return $lists;
- }
- /**
- * @notes 账户流水记录数
- * @return int
- * @author Tab
- * @date 2021/8/9 17:36
- */
- public function count(): int
- {
- // 设置搜索条件
- $this->setWhere();
- $count = AccountLog::where($this->searchWhere)->count();
- return $count;
- }
- }
|