Account.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\member;
  12. use app\dict\member\MemberAccountTypeDict;
  13. use app\service\admin\member\MemberAccountService;
  14. use app\service\admin\member\MemberService;
  15. use core\base\BaseAdminController;
  16. use think\Response;
  17. class Account extends BaseAdminController
  18. {
  19. /**
  20. * 积分流水
  21. * @return Response
  22. */
  23. public function point()
  24. {
  25. $data = $this->request->params([
  26. [ 'member_id', '' ],
  27. [ 'from_type', '' ],
  28. [ 'create_time', [] ],
  29. [ 'keywords', '' ],
  30. ]);
  31. $data[ 'account_type' ] = 'point';
  32. return success(( new MemberAccountService() )->getPage($data));
  33. }
  34. /**
  35. * 会员积分统计(用于会员积分统计窗口)
  36. */
  37. public function sumPoint()
  38. {
  39. $data = $this->request->params([
  40. [ 'member_id', '' ],
  41. ]);
  42. $member_account_service = new MemberAccountService();
  43. $member_service = new MemberService();
  44. if (empty($data[ 'member_id' ])) {
  45. $commission_data = [
  46. 'point_get' => $member_service->getSum('point_get'),//累计
  47. 'point_use' => abs($member_account_service->getExpensesSumAccount(MemberAccountTypeDict::POINT)),
  48. ];
  49. return success($commission_data);
  50. } else {
  51. $info = $member_account_service->getMemberAccountInfo($data[ 'member_id' ]);
  52. $commission_data = [
  53. 'point_get' => $info[ 'point_get' ],
  54. 'point_use' => abs($member_account_service->getExpensesSumAccount(MemberAccountTypeDict::POINT, $data[ 'member_id' ])),
  55. ];
  56. return success($commission_data);
  57. }
  58. }
  59. /**
  60. * 余额流水
  61. * @return Response
  62. */
  63. public function balance()
  64. {
  65. $data = $this->request->params([
  66. [ 'member_id', '' ],
  67. [ 'from_type', '' ],
  68. [ 'create_time', [] ],
  69. [ 'keywords', '' ],
  70. ]);
  71. $data[ 'account_type' ] = 'balance';
  72. return success(( new MemberAccountService() )->getPage($data));
  73. }
  74. /**
  75. * 可提现余额流水
  76. * @return Response
  77. */
  78. public function money()
  79. {
  80. $data = $this->request->params([
  81. [ 'member_id', '' ],
  82. [ 'from_type', '' ],
  83. [ 'create_time', [] ],
  84. [ 'keywords', '' ],
  85. ]);
  86. $data[ 'account_type' ] = 'money';
  87. return success(( new MemberAccountService() )->getPage($data));
  88. }
  89. /**
  90. * 查询成长值
  91. * @return Response
  92. */
  93. public function growth() {
  94. $data = $this->request->params([
  95. ['member_id', ''],
  96. ['from_type', ''],
  97. ['create_time', []],
  98. ['keywords', ''],
  99. ]);
  100. $data['account_type'] = 'growth';
  101. return success(( new MemberAccountService() )->getPage($data));
  102. }
  103. /**
  104. * 积分账户调整
  105. */
  106. public function adjustPoint()
  107. {
  108. $data = $this->request->params([
  109. [ 'member_id', '' ],
  110. [ 'account_data', 0 ],
  111. [ 'memo', '' ],
  112. ]);
  113. $res = ( new MemberAccountService() )->adjustPoint($data);
  114. return success('SUCCESS', [ 'id' => $res ]);
  115. }
  116. /**
  117. * 余额账户调整
  118. */
  119. public function adjustBalance()
  120. {
  121. $data = $this->request->params([
  122. [ 'member_id', '' ],
  123. [ 'account_data', 0 ],
  124. [ 'memo', '' ],
  125. ]);
  126. $res = ( new MemberAccountService() )->adjustBalance($data);
  127. return success('SUCCESS', [ 'id' => $res ]);
  128. }
  129. /**
  130. * 零钱调整
  131. * @return Response
  132. */
  133. public function adjustMoney()
  134. {
  135. $data = $this->request->params([
  136. [ 'member_id', '' ],
  137. [ 'account_data', 0 ],
  138. [ 'memo', '' ],
  139. ]);
  140. $res = ( new MemberAccountService() )->adjustMoney($data);
  141. return success('SUCCESS', [ 'id' => $res ]);
  142. }
  143. /**
  144. * 会员佣金
  145. * @return Response
  146. */
  147. public function commission()
  148. {
  149. $data = $this->request->params([
  150. [ 'member_id', '' ],
  151. [ 'from_type', '' ],
  152. [ 'create_time', [] ],
  153. [ 'keywords', '' ],
  154. ]);
  155. $data[ 'account_type' ] = 'commission';
  156. return success(( new MemberAccountService() )->getPage($data));
  157. }
  158. /**
  159. * 会员佣金统计(用于会员账户统计窗口)
  160. */
  161. public function sumCommission()
  162. {
  163. $data = $this->request->params([
  164. [ 'member_id', '' ],
  165. ]);
  166. $member_account_service = new MemberAccountService();
  167. $member_service = new MemberService();
  168. if (empty($data[ 'member_id' ])) {
  169. $commission_data = [
  170. 'total_commission' => $member_service->getSum('commission_get'),//累计
  171. 'commission' => $member_service->getSum('commission'),//未提现
  172. 'withdrawn_commission' => $member_account_service->getWithdrawnCommission(),//已提现
  173. 'commission_cash_outing' => $member_service->getSum('commission_cash_outing'),//提现中
  174. ];
  175. return success($commission_data);
  176. } else {
  177. $info = $member_account_service->getMemberAccountInfo($data[ 'member_id' ]);
  178. $commission_data = [
  179. 'commission' => $info[ 'commission' ],
  180. 'commission_cash_outing' => $info[ 'commission_cash_outing' ],
  181. 'withdrawn_commission' => $member_account_service->getWithdrawnCommission($data[ 'member_id' ]),//已提现
  182. 'total_commission' => $info[ 'commission_get' ],
  183. ];
  184. return success($commission_data);
  185. }
  186. }
  187. /**
  188. * 会员余额统计(用于会员账户统计窗口)
  189. */
  190. public function sumBalance()
  191. {
  192. $data = $this->request->params([
  193. [ 'member_id', '' ],
  194. ]);
  195. $member_account_service = new MemberAccountService();
  196. if (empty($data[ 'member_id' ])) {
  197. $balance_data = [
  198. MemberAccountTypeDict::BALANCE => number_format($member_account_service->getSumAccount(MemberAccountTypeDict::BALANCE), 2, '.', ''),
  199. MemberAccountTypeDict::MONEY => number_format($member_account_service->getSumAccount(MemberAccountTypeDict::MONEY), 2, '.', ''),
  200. ];
  201. return success($balance_data);
  202. } else {
  203. return success($member_account_service->getMemberAccountInfo($data[ 'member_id' ]));
  204. }
  205. }
  206. /**
  207. * 账户变化类型
  208. * @param string $account_type
  209. * @return Response
  210. */
  211. public function changeType(string $account_type)
  212. {
  213. $res = ( new MemberAccountService() )->getFromType($account_type);
  214. return success($res);
  215. }
  216. /**
  217. * 账户类型
  218. */
  219. public function accountType()
  220. {
  221. return success(MemberAccountTypeDict::getType());
  222. }
  223. }