Memberaccount.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: https://www.niushop.com
  9. * =========================================================
  10. * @author : niuteam
  11. * @date : 2022.8.8
  12. * @version : v5.0.0.1
  13. */
  14. namespace app\api\controller;
  15. use app\model\member\MemberAccount as MemberAccountModel;
  16. use app\model\member\Member as MemberModel;
  17. class Memberaccount extends BaseApi
  18. {
  19. /**
  20. * 基础信息
  21. */
  22. public function info()
  23. {
  24. $token = $this->checkToken();
  25. if ($token[ 'code' ] < 0) return $this->response($token);
  26. $account_type = isset($this->params[ 'account_type' ]) ? $this->params[ 'account_type' ] : 'balance,balance_money'; //账户类型 余额:balance,积分:point
  27. if (!in_array($account_type, [ 'point', 'balance', 'balance,balance_money' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
  28. $member_model = new MemberModel();
  29. $info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], $account_type);
  30. return $this->response($info);
  31. }
  32. /**
  33. * 列表信息
  34. */
  35. public function page()
  36. {
  37. $token = $this->checkToken();
  38. if ($token[ 'code' ] < 0) return $this->response($token);
  39. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  40. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  41. $account_type = isset($this->params[ 'account_type' ]) ? $this->params[ 'account_type' ] : 'balance,balance_money';//账户类型 余额:balance,积分:point
  42. $start_time = empty($this->params[ 'date' ]) ? strtotime(date('Y-m', strtotime("today"))) : strtotime($this->params[ 'date' ]);
  43. $end_time = strtotime("+1 month", $start_time);
  44. $from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : '';
  45. $related_id = isset($this->params[ 'related_id' ]) ? $this->params[ 'related_id' ] : 0;
  46. if (!in_array($account_type, [ 'point', 'balance', 'balance,balance_money' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
  47. $condition[] = [ 'account_type', 'in', $account_type ];
  48. $condition[] = [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ];
  49. if ($this->params['app_type'] != 'pc') {
  50. $condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
  51. }
  52. if (!empty($from_type)) {
  53. $condition[] = [ 'from_type', '=', $from_type ];
  54. }
  55. if (!empty($related_id)) {
  56. $condition[] = [ 'related_id', '=', $related_id ];
  57. }
  58. $member_account_model = new MemberAccountModel();
  59. $list = $member_account_model->getMemberAccountPageList($condition, $page, $page_size);
  60. return $this->response($list);
  61. }
  62. /**
  63. * 获取类型
  64. * @return false|string
  65. */
  66. public function fromType()
  67. {
  68. $member_account_model = new MemberAccountModel();
  69. $lists = $member_account_model->getFromType();
  70. return $this->response($lists);
  71. }
  72. /**
  73. * 获取账户总额
  74. */
  75. public function sum()
  76. {
  77. $token = $this->checkToken();
  78. if ($token[ 'code' ] < 0) return $this->response($token);
  79. $account_type = $this->params[ 'account_type' ] ?? 'point'; // 账户类型 余额:balance,积分:point
  80. $from_type = $this->params[ 'from_type' ] ?? '';
  81. $query_type = $this->params[ 'query_type' ] ?? ''; // 查询类型 收入:income 支出:pay
  82. $start_time = $this->params[ 'start_time' ] ?? 0;
  83. $end_time = $this->params[ 'end_time' ] ?? 0;
  84. if (!in_array($account_type, [ 'point', 'balance', 'balance_money', 'growth' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
  85. $member_account_model = new MemberAccountModel();
  86. $condition = [
  87. [ 'member_id', '=', $this->member_id ],
  88. [ 'site_id', '=', $this->site_id ],
  89. [ 'account_type', '=', $account_type ]
  90. ];
  91. if (!empty($from_type)) $condition[] = [ 'from_type', '=', $from_type ];
  92. if ($query_type == 'income') $condition[] = [ 'account_data', '>', 0 ];
  93. if ($query_type == 'pay') $condition[] = [ 'account_data', '<', 0 ];
  94. if ($start_time && $end_time) $condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
  95. $data = $member_account_model->getMemberAccountSum($condition, 'account_data');
  96. return $this->response($data);
  97. }
  98. /**
  99. * 获取用户可用余额
  100. * @return false|string
  101. */
  102. public function usableBalance()
  103. {
  104. $token = $this->checkToken();
  105. if ($token[ 'code' ] < 0) return $this->response($token);
  106. $store_id = $this->params[ 'store_id' ];
  107. $data = ( new MemberModel() )->getMemberUsableBalancenew($this->site_id, $this->member_id,$store_id);
  108. return $this->response($data);
  109. }
  110. }