截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FinanceLogic.php 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace app\admin\logic\finance;
  3. use app\common\basics\Logic;
  4. use app\common\model\AccountLog;
  5. use app\common\model\order\Order;
  6. use app\common\enum\PayEnum;
  7. use app\common\enum\OrderEnum;
  8. use app\common\enum\OrderRefundEnum;
  9. use app\common\enum\AfterSaleEnum;
  10. use app\common\enum\WithdrawalEnum;
  11. use app\common\enum\DistributionOrderGoodsEnum;
  12. use app\common\enum\WithdrawEnum;
  13. use app\common\model\user\User;
  14. use app\common\model\shop\Shop;
  15. use app\common\model\shop\ShopWithdrawal;
  16. use app\common\model\shop\ShopSettlement;
  17. use app\common\model\WithdrawApply;
  18. class FinanceLogic extends Logic
  19. {
  20. /**
  21. * @Notes: 商家汇总
  22. */
  23. public static function shop()
  24. {
  25. $model = new Order();
  26. $modelShopSettlement = new ShopSettlement();
  27. $modelShopWithdrawal = new ShopWithdrawal();
  28. $modelWithdrawApply = new WithdrawApply();
  29. //已结算交易服务费(平台收入)、(商家)已结算交易服务费
  30. $shopAmount = $settlePoundageAmount = $modelShopSettlement
  31. ->sum('trade_service_fee');
  32. //会员提现手续费(平台收入
  33. $userPoundage = $modelWithdrawApply
  34. ->where([
  35. ['status', '=', WithdrawEnum::STATUS_SUCCESS]
  36. ])
  37. ->sum('poundage');
  38. //商家提现手续费(平台收入)
  39. $commissionAmount = $modelShopWithdrawal
  40. ->sum('poundage_amount');
  41. //成交订单笔数
  42. $orderNum = $model
  43. ->where([
  44. ['pay_status', '>', PayEnum::UNPAID]
  45. ])
  46. ->count('id');
  47. //营业额
  48. $orderAmount = $model
  49. ->where([
  50. ['pay_status', '>', PayEnum::UNPAID]
  51. ])
  52. ->sum('order_amount');
  53. //退款订单金额
  54. $refundAmount = $model
  55. ->where([
  56. ['shipping_status', '=', OrderEnum::SHIPPING_NO],
  57. ['pay_status', '=', PayEnum::REFUNDED],
  58. ['refund_status', 'in', [OrderEnum::REFUND_STATUS_PART_REFUND, OrderEnum::REFUND_STATUS_ALL_REFUND]],
  59. ])
  60. ->sum('refund_amount');
  61. //待退款订单金额
  62. $refundAmountIng = $model->alias('o')
  63. ->join('order_refund or', 'or.order_id = o.id')
  64. ->where([
  65. ['o.shipping_status', '=', OrderEnum::SHIPPING_NO],
  66. ['or.refund_status', '<>', OrderRefundEnum::REFUND_STATUS_COMPLETE]
  67. ])
  68. ->sum('or.refund_amount');
  69. //售后退款金额
  70. $salesRefundAmount = $model->alias('o')
  71. ->join('after_sale as', 'as.order_id = o.id')
  72. ->where([
  73. ['o.shipping_status', '=', OrderEnum::SHIPPING_FINISH],
  74. ['as.status', '=', AfterSaleEnum::STATUS_COMPLETE]
  75. ])
  76. ->sum('as.refund_price');
  77. //待售后退款金额
  78. $salesRefundAmountIng = $model->alias('o')
  79. ->join('after_sale as', 'as.order_id = o.id')
  80. ->where([
  81. ['o.shipping_status', '=', OrderEnum::SHIPPING_FINISH],
  82. ['as.status', '=', AfterSaleEnum::STATUS_WAITING]
  83. ])
  84. ->sum('as.refund_price');
  85. //已结算成交订单数
  86. $settleOrederNum = $modelShopSettlement
  87. ->sum('deal_order_count');
  88. //已结算营业额
  89. $settleOrederAmount = $modelShopSettlement
  90. ->sum('business_money');
  91. //待结算营业额
  92. $settleOrederAmountWait = $model
  93. ->where([
  94. ['refund_status', '=', 0 ],
  95. ['settle_id', '=', OrderEnum::SETTLE_WAIT]
  96. ])
  97. ->sum('order_amount');
  98. //已结算分销佣金金额
  99. $settleDistributionAmount = $modelShopSettlement
  100. ->sum('distribution_money');
  101. //已结算入账金额
  102. $settleWithdrawalAmount = $modelShopSettlement
  103. ->sum('entry_account_money');
  104. //已提现金额
  105. $withdrawaLeftamount = $modelShopWithdrawal
  106. ->where([
  107. ['status', '=', WithdrawalEnum::SUCCESS_STATUS]
  108. ])
  109. ->sum('apply_amount');
  110. //提现中金额
  111. $withdrawaLeftamountIng = $modelShopWithdrawal
  112. ->where([
  113. ['status', '=', WithdrawalEnum::HANDLE_STATUS]
  114. ])
  115. ->sum('apply_amount');
  116. //可提现金额
  117. $modelShop = new Shop();
  118. $shopWallet = $modelShop->sum('wallet');
  119. //会员余额
  120. $modelUser = new User();
  121. $userMoney = $modelUser
  122. ->where([
  123. ['del', '=', 0]
  124. ])
  125. ->sum('user_money');
  126. //会员已结算分销佣金金额
  127. $userSettleDistributionAmount = $model->alias('o')
  128. ->join('order_goods og', 'og.order_id = o.id')
  129. ->join('distribution_order_goods dog', 'dog.order_goods_id = og.id')
  130. ->where([
  131. ['o.settle_id', '=', OrderEnum::SETTLE_FINISH],
  132. ['dog.status', '=', DistributionOrderGoodsEnum::STATUS_SUCCESS]
  133. ])
  134. ->sum('dog.money');
  135. //已提现佣金金额
  136. $userDistributionMoney = $modelWithdrawApply
  137. ->where([
  138. ['status', '=', WithdrawEnum::STATUS_SUCCESS]
  139. ])
  140. ->sum('money');
  141. //提现中佣金金额
  142. $userDistributionMoneyIng = $modelWithdrawApply
  143. ->where([
  144. ['status', '=', WithdrawEnum::STATUS_ING]
  145. ])
  146. ->sum('money');
  147. //可提现佣金金额
  148. $userDistributionMoneyWait = $modelUser
  149. ->where([
  150. ['del', '=', 0]
  151. ])
  152. ->sum('earnings');
  153. //总积分
  154. $all_integral = AccountLog::where(['change_type'=>1,'source_type'=>AccountLog::integral_change])->sum('change_amount');
  155. //签到送出积分
  156. $sign_in_integral = AccountLog::where(['source_type'=>AccountLog::sign_in_integral])->sum('change_amount');
  157. //使用积分
  158. $use_integral = AccountLog::where(['change_type'=>2,'source_type'=>AccountLog::integral_change])->sum('change_amount');
  159. //下单赠送积分
  160. $consume_award_integral = AccountLog::where(['source_type'=>AccountLog::consume_award_integral])->sum('change_amount');
  161. return [
  162. 'shopAmount' => $shopAmount, //已结算交易服务费(平台收入)
  163. 'userPoundage' => $userPoundage, //会员提现手续费(平台收入)
  164. 'commissionAmount' => $commissionAmount, //提现中佣金金额
  165. 'orderNum' => $orderNum, //成交订单笔数
  166. 'orderAmount' => $orderAmount, //营业额
  167. 'refundAmount' => $refundAmount, //退款订单金额
  168. 'refundAmountIng' => $refundAmountIng, //待退款订单金额
  169. 'salesRefundAmount' => $salesRefundAmount, //售后退款金额
  170. 'salesRefundAmountIng' => $salesRefundAmountIng, //待售后退款金额
  171. 'settleOrederNum' => $settleOrederNum, //已结算成交订单数
  172. 'settleOrederAmount' => $settleOrederAmount, //已结算营业额
  173. 'settleOrederAmountWait' => $settleOrederAmountWait, //待结算营业额
  174. 'settleDistributionAmount' => $settleDistributionAmount, //已结算分销佣金金额
  175. 'settleWithdrawalAmount' => $settleWithdrawalAmount, //已结算入账金额
  176. 'settlePoundageAmount' => $settlePoundageAmount, //已结算交易服务费
  177. 'withdrawaLeftamount' => $withdrawaLeftamount, //已提现金额
  178. 'withdrawaLeftamountIng' => $withdrawaLeftamountIng, //提现中金额
  179. 'shopWallet' => $shopWallet, //可提现金额
  180. 'userMoney' => $userMoney, //会员余额
  181. 'userSettleDistributionAmount' => $userSettleDistributionAmount, //会员已结算分销佣金金额
  182. 'userDistributionMoney' => $userDistributionMoney, //已提现佣金金额
  183. 'userDistributionMoneyIng' => $userDistributionMoneyIng, //提现中佣金金额
  184. 'userDistributionMoneyWait' => $userDistributionMoneyWait, //可提现佣金金额
  185. 'all_integral' => $all_integral, //总积分
  186. 'sign_in_integral' => $sign_in_integral, //签到送出积分
  187. 'use_integral' => $use_integral, //使用积分
  188. 'consume_award_integral' => $consume_award_integral, //下单赠送积分
  189. ];
  190. }
  191. }