diff --git a/app/api/controller/BaseApiController.php b/app/api/controller/BaseApiController.php index 3651058..f263c40 100755 --- a/app/api/controller/BaseApiController.php +++ b/app/api/controller/BaseApiController.php @@ -20,6 +20,8 @@ class BaseApiController extends BaseLikeAdminController { protected int $userId = 0; protected array $userInfo = []; + protected int $page_no = 1; + protected int $page_size = 15; public function initialize() { diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index 07e785c..b9f4f0b 100755 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -83,6 +83,20 @@ class UserController extends BaseApiController $info = UserLogic::myWallet($this->userId); return $this->success('获取成功', $info); } + /** + * Notes:账户流水 + * @author: 2021/3/10 10:13 + */ + public function accountLog() + { + $source = $this->request->get('source'); + $type = $this->request->get('type', 0); + $list = []; + if ($source) { + $list = UserLogic::accountLog($this->userId, $source, $type, $this->page_no, $this->page_size); + } + return $this->success('获取成功', $list); + } /** * @notes 修改密码 diff --git a/app/api/logic/UserLogic.php b/app/api/logic/UserLogic.php index c8059d4..76e3711 100755 --- a/app/api/logic/UserLogic.php +++ b/app/api/logic/UserLogic.php @@ -19,6 +19,7 @@ use app\common\{enum\notice\NoticeEnum, enum\user\UserTerminalEnum, enum\YesNoEnum, logic\BaseLogic, + model\account\AccountLog, model\user\User, model\user\UserAuth, service\ConfigServer, @@ -92,6 +93,46 @@ class UserLogic extends BaseLogic return $info; + } + public static function accountLog($user_id, $source, $type, $page, $size) + { + $source_type = ''; + $where[] = ['user_id', '=', $user_id]; + switch ($source) { + case 1: + $source_type = AccountLog::money_change; + break; + case 2: + $source_type = AccountLog::integral_change; + break; + case 3: + $source_type = AccountLog::growth_change; + + } + $where[] = ['source_type', 'in', $source_type]; + if ($type) { + $where[] = ['change_type', '=', $type]; + } + $accountLog = new AccountLog(); + $count = $accountLog + ->where($where) + ->count(); + $list = $accountLog + ->where($where) + ->page($page, $size) + ->order('id desc') + ->field('id,change_amount,source_type,change_type,create_time,remark') + ->select(); + $more = is_more($count, $page, $size); //是否有下一页 + + $data = [ + 'list' => $list, + 'page_no' => $page, + 'page_size' => $size, + 'count' => $count, + 'more' => $more + ]; + return $data; } /** * @notes 设置用户信息 diff --git a/app/common.php b/app/common.php index d3baa03..f8cfead 100755 --- a/app/common.php +++ b/app/common.php @@ -30,7 +30,26 @@ function create_token(string $extra = '') : string $encryptSalt = md5( $salt . uniqid()); return md5($salt . $extra . time() . $encryptSalt); } +/** + * User: 意象信息科技 cjh + * Desc: 返回是否有下一页 + * @param $count 总记录数 + * @param $page 当前页码 + * @param $size 每页记录数 + * @return int + */ +function is_more($count, $page, $size) +{ + $more = 0; + + $last_page = ceil($count / $size); //总页数、也是最后一页 + + if ($last_page && $last_page > $page) { + $more = 1; + } + return $more; +} /** * @notes 截取某字符字符串