Account.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shopapi\controller;
  13. use addon\fenxiao\model\FenxiaoData;
  14. use app\model\member\Withdraw;
  15. use app\model\order\Order as OrderModel;
  16. use app\model\order\OrderCommon as OrderCommonModel;
  17. use app\model\order\OrderRefund;
  18. use app\model\shop\Shop as ShopModel;
  19. use app\model\shop\ShopAccount;
  20. use app\model\shop\ShopOpenAccount;
  21. use app\model\shop\ShopReopen as ShopReopenModel;
  22. use app\model\shop\ShopSettlement;
  23. use app\model\web\Account as AccountModel;
  24. use Carbon\Carbon;
  25. class Account extends BaseApi
  26. {
  27. public function __construct()
  28. {
  29. //执行父类构造函数
  30. parent::__construct();
  31. $token = $this->checkToken();
  32. if ($token[ 'code' ] < 0) {
  33. echo $this->response($token);
  34. exit;
  35. }
  36. }
  37. /**
  38. * 资产概况
  39. */
  40. public function index()
  41. {
  42. $shop_model = new ShopModel();
  43. $shop_account_model = new ShopAccount();
  44. $data = [];
  45. //获取商家转账设置
  46. $shop_withdraw_config = $shop_account_model->getShopWithdrawConfig();
  47. $data[ 'shop_withdraw_config' ] = $shop_withdraw_config[ 'data' ][ 'value' ];//商家转账设置
  48. //获取店铺的账户信息
  49. $condition = array (
  50. [ "site_id", "=", $this->site_id ]
  51. );
  52. $shop_info = $shop_model->getShopInfo($condition, 'site_name,logo,account, account_withdraw,account_withdraw_apply,shop_open_fee,shop_baozhrmb')[ 'data' ];
  53. $data[ 'shop_info' ] = $shop_info;
  54. //余额
  55. $account = $shop_info[ 'account' ] - $shop_info[ 'account_withdraw_apply' ];
  56. $data[ 'account' ] = number_format($account, 2, '.', '');
  57. //累计收入
  58. $total = $shop_info[ 'account' ] + $shop_info[ 'account_withdraw' ];
  59. $data[ 'total' ] = number_format($total, 2, '.', '');
  60. //已提现
  61. $data[ 'account_withdraw' ] = number_format($shop_info[ 'account_withdraw' ], 2, '.', '');
  62. //提现中
  63. $data[ 'account_withdraw_apply' ] = number_format($shop_info[ 'account_withdraw_apply' ], 2, '.', '');
  64. //获取店家结算账户信息
  65. $shop_cert_result = $shop_model->getShopCert($condition, 'bank_type, settlement_bank_account_name, settlement_bank_account_number, settlement_bank_name, settlement_bank_address');
  66. $data[ 'shop_cert_info' ] = $shop_cert_result[ 'data' ];//店家结算账户信息
  67. //店铺的待结算金额
  68. $settlement_model = new ShopSettlement();
  69. $settlement_info = $settlement_model->getWaitSettlementInfo($this->site_id);
  70. $order_apply = $settlement_info[ 'shop_money' ] - $settlement_info[ 'refund_shop_money' ] - $settlement_info[ 'commission' ] + $settlement_info[ 'platform_coupon_money' ] - $settlement_info[ 'refund_platform_coupon_money' ];
  71. $data[ 'order_apply' ] = number_format($order_apply, 2, '.', '');
  72. return $this->response($this->success($data));
  73. }
  74. /**
  75. * 店铺账户面板
  76. */
  77. public function dashboard()
  78. {
  79. $start_time = $this->params['start_time'] ?? Carbon::today()->timestamp;
  80. $end_time = $this->params['end_time'] ?? Carbon::tomorrow()->timestamp;
  81. $data = [];
  82. // 收入
  83. $order_money = (new OrderModel())->getOrderMoneySum([ ['site_id', '=', $this->site_id], ['pay_time', 'between', [$start_time, $end_time] ], ['order_scene', '=', 'online'] ], 'pay_money')['data'];
  84. $income_data = [
  85. [
  86. 'title' => '商城订单',
  87. 'value' => $order_money,
  88. 'desc' => '统计时间内,所有付款订单实付金额之和',
  89. 'url' => 'shop/order/lists'
  90. ]
  91. ];
  92. $event = event('IncomeStatistics', ['site_id' => $this->site_id, 'start_time' => $start_time, 'end_time' => $end_time]);
  93. if (!empty($event)) $income_data = array_merge($income_data, ...$event);
  94. $data['total_income'] = array_sum(array_column($income_data, 'value'));
  95. $data['income_data'] = $income_data;
  96. // 支出
  97. $disburse_data = [
  98. [
  99. 'title' => '订单退款',
  100. 'value' => (new OrderRefund())->getRefundSum([ ['site_id', '=', $this->site_id], ['refund_money_type', '=', '1,2'], ['refund_time', 'between', [$start_time, $end_time] ] ], 'refund_pay_money')['data'],
  101. 'desc' => '统计时间内,所有订单退款转账金额之和',
  102. 'url' => 'shop/orderrefund/lists'
  103. ],
  104. [
  105. 'title' => '会员提现',
  106. 'value' => (new Withdraw())->getMemberWithdrawSum([ ['site_id', '=', $this->site_id], ['payment_time', 'between', [$start_time, $end_time] ] ], 'apply_money')['data'],
  107. 'desc' => '统计时间内,所有会员提现转账金额之和',
  108. 'url' => 'shop/memberwithdraw/lists'
  109. ]
  110. ];
  111. $event = event('DisburseStatistics', ['site_id' => $this->site_id, 'start_time' => $start_time, 'end_time' => $end_time]);
  112. if (!empty($event)) $disburse_data = array_merge($disburse_data, ...$event);
  113. $data['total_disburse'] = array_sum(array_column($disburse_data, 'value'));
  114. $data['disburse_data'] = $disburse_data;
  115. return $this->response($this->success($data));
  116. }
  117. /**
  118. * 账户交易记录
  119. */
  120. public function orderList()
  121. {
  122. $order_model = new OrderCommonModel();
  123. $condition[] = [ 'site_id', '=', $this->site_id ];
  124. //下单时间
  125. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
  126. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
  127. if (!empty($start_time) && empty($end_time)) {
  128. $condition[] = [ "finish_time", ">=", $start_time ];
  129. } elseif (empty($start_time) && !empty($end_time)) {
  130. $condition[] = [ "finish_time", "<=", $end_time ];
  131. } elseif (!empty($start_time) && !empty($end_time)) {
  132. $condition[] = [ 'finish_time', 'between', [ $start_time, $end_time ] ];
  133. }
  134. //订单状态
  135. $order_status = isset($this->params[ 'order_status' ]) ? $this->params[ 'order_status' ] : '';
  136. if ($order_status != "") {
  137. switch ( $order_status ) {
  138. case 1://进行中
  139. $condition[] = [ "order_status", "not in", [ 0, -1, 10 ] ];
  140. $order = 'pay_time desc';
  141. break;
  142. case 2://待结算
  143. $condition[] = [ "order_status", "=", 10 ];
  144. $condition[] = [ "is_settlement", "=", 0 ];
  145. $order = 'finish_time desc';
  146. break;
  147. case 3://已结算
  148. $condition[] = [ "order_status", "=", 10 ];
  149. $condition[] = [ "settlement_id", ">", 0 ];
  150. $order = 'finish_time desc';
  151. break;
  152. case 4://全部
  153. $condition[] = [ "order_status", "not in", [ 0, -1 ] ];
  154. $order = 'pay_time desc';
  155. break;
  156. }
  157. } else {
  158. $condition[] = [ "order_status", "=", 10 ];
  159. $condition[] = [ "settlement_id", "=", 0 ];
  160. $order = 'finish_time desc';
  161. }
  162. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  163. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  164. $field = 'order_id,order_no,order_money,order_status_name,shop_money,platform_money,refund_money,refund_shop_money,refund_platform_money,commission,finish_time,settlement_id';
  165. $list = $order_model->getOrderPageList($condition, $page, $page_size, $order, $field);
  166. return $this->response($list);
  167. }
  168. /**
  169. * 订单统计
  170. * @return false|string
  171. */
  172. public function orderStat()
  173. {
  174. $data = [];
  175. //店铺的待结算金额
  176. $settlement_model = new ShopSettlement();
  177. $settlement_info = $settlement_model->getWaitSettlementInfo($this->site_id);
  178. $wait_settlement = $settlement_info[ 'shop_money' ] - $settlement_info[ 'refund_shop_money' ] - $settlement_info[ 'commission' ];
  179. $data[ 'wait_settlement' ] = number_format($wait_settlement, 2, '.', '');
  180. //店铺的已结算金额
  181. $finish_condition = [
  182. [ 'site_id', '=', $this->site_id ],
  183. [ 'order_status', '=', 10 ],
  184. [ 'settlement_id', '>', 0 ]
  185. ];
  186. $settlement_info = $settlement_model->getShopSettlementData($finish_condition);
  187. $finish_settlement = $settlement_info[ 'shop_money' ] - $settlement_info[ 'refund_shop_money' ] - $settlement_info[ 'commission' ];
  188. $data[ 'finish_settlement' ] = number_format($finish_settlement, 2, '.', '');
  189. //店铺的进行中金额
  190. $settlement_condition = [
  191. [ 'site_id', '=', $this->site_id ],
  192. [ 'order_status', "not in", [ 0, -1, 10 ] ]
  193. ];
  194. $settlement_info = $settlement_model->getShopSettlementData($settlement_condition);
  195. $settlement = $settlement_info[ 'shop_money' ] - $settlement_info[ 'refund_shop_money' ] - $settlement_info[ 'commission' ];
  196. $data[ 'settlement' ] = number_format($settlement, 2, '.', '');
  197. return $this->response($this->success($data));
  198. }
  199. }