Account.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\web;
  11. use app\model\BaseModel;
  12. /**
  13. * 系统站账户
  14. */
  15. class Account extends BaseModel
  16. {
  17. public $from_type = [
  18. 'order' => [
  19. 'type_name' => '订单结算',
  20. 'type_url' => '',
  21. ],
  22. 'withdraw' => [
  23. 'type_name' => '提现',
  24. 'type_url' => '',
  25. ],
  26. ];
  27. /**************************************************************店铺账户****************************************************************/
  28. /**
  29. * 添加分站账户数据
  30. * @param int $site_id
  31. * @param int $account_type 账户类型 默认account
  32. * @param float $account_data
  33. * @param string $relate_url
  34. * @param string $remark
  35. */
  36. public function addAccount($site_id, $account_type, $account_data, $from_type, $relate_tag, $remark)
  37. {
  38. $data = array (
  39. 'account_no' => date('YmdHi') . rand(1000, 9999),
  40. 'site_id' => $site_id,
  41. 'account_type' => $account_type,
  42. 'account_data' => $account_data,
  43. 'from_type' => $from_type,
  44. 'relate_tag' => $relate_tag,
  45. 'create_time' => time(),
  46. 'remark' => $remark
  47. );
  48. $account = model('website')->getInfo([
  49. 'site_id' => 0
  50. ], $account_type);
  51. $account_new_data = (float) $account[ $account_type ] + (float) $account_data;
  52. if ((float) $account_new_data < 0) {
  53. return $this->error('', 'RESULT_ERROR');
  54. }
  55. $res = model('account')->add($data);
  56. $res = model('website')->update([
  57. $account_type => $account_new_data
  58. ], [
  59. 'site_id' => 0
  60. ]);
  61. event("AddAccount", $data);
  62. return $this->success($res);
  63. }
  64. /**
  65. * 获取店铺账户流水分页
  66. * @param unknown $condition
  67. * @param number $page
  68. * @param string $page_size
  69. * @param string $order
  70. * @param string $field
  71. * @return multitype:number unknown
  72. */
  73. public function getAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  74. {
  75. $list = model('account')->pageList($condition, $field, $order, $page, $page_size);
  76. return $this->success($list);
  77. }
  78. /**
  79. * 会员金额账户
  80. * @return multitype:
  81. */
  82. public function getMemberBalanceSum($site_id = 0)
  83. {
  84. $field = '
  85. sum(balance) as balance,
  86. sum(balance_money) as balance_money,
  87. sum(balance_withdraw_apply) as balance_withdraw_apply,
  88. sum(balance_withdraw) as balance_withdraw
  89. ';
  90. $info = model("member")->getInfo([ [ 'member_id', '>', 0 ], [ 'site_id', '=', $site_id ] ], $field);
  91. if ($info[ 'balance' ] == null) {
  92. $info[ 'balance' ] = '0.00';
  93. }
  94. if ($info[ 'balance_money' ] == null) {
  95. $info[ 'balance_money' ] = '0.00';
  96. }
  97. if ($info[ 'balance_withdraw_apply' ] == null) {
  98. $info[ 'balance_withdraw_apply' ] = '0.00';
  99. }
  100. if ($info[ 'balance_withdraw' ] == null) {
  101. $info[ 'balance_withdraw' ] = '0.00';
  102. }
  103. return $this->success($info);
  104. }
  105. }