PtbBackLogic.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * PtbBackLogic.php UTF-8
  4. *
  5. *
  6. * @date : 5/19/2018 3:54 PM
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\finance;
  13. use huo\logic\agent\AgentLogic;
  14. use huo\logic\member\MemberLogic;
  15. use huo\model\common\CommonModel;
  16. use huo\model\finance\PtbBackModel;
  17. use huolib\constant\CommonConst;
  18. use huolib\tool\StrUtils;
  19. class PtbBackLogic extends CommonModel {
  20. /**
  21. * @param array $param
  22. *
  23. * @return array
  24. */
  25. protected function getWhere($param = []) {
  26. $_map = [];
  27. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  28. $_map['ptb_back_model.create_time'] = ['between', [strtotime($param['start_time']),
  29. CommonConst::CONST_DAY_SECONDS + strtotime(
  30. $param['end_time']
  31. )]];
  32. } else if (!empty($param['start_time'])) {
  33. $_map['ptb_back_model.create_time'] = ['gt', strtotime($param['start_time'])];
  34. } else if (!empty($param['end_time'])) {
  35. $_map['ptb_back_model.create_time'] = ['lt',
  36. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  37. }
  38. if (!empty($param['order_id'])) {
  39. $_map['back_order_id'] = $param['order_id'];
  40. }
  41. if (!empty($param['mem_id'])) {
  42. $_map['mem_id'] = $param['mem_id'];
  43. }
  44. if (!empty($param['app_id'])) {
  45. $_map['app_id'] = $param['app_id'];
  46. }
  47. if (!empty($param['status'])) {
  48. $_map['status'] = $param['status'];
  49. }
  50. if (!empty($param['user_type'])) {
  51. $_map['user_type'] = $param['user_type'];
  52. }
  53. if (!empty($param['agent_id'])) {
  54. $_map['agent_id'] = $param['agent_id'];
  55. }
  56. if (!empty($param['belong_agent_id'])) {
  57. $_mem_ids = (new MemberLogic())->getIdsByAgentId($param['belong_agent_id']);
  58. $_map['ptb_back_model.mem_id'] = ['in', $_mem_ids];
  59. }
  60. if (!empty($param['username'])) {
  61. $_mem_ids = (new MemberLogic())->getIdsByUsername($param['username']);
  62. $_map['ptb_back_model.mem_id'] = ['in', $_mem_ids];
  63. }
  64. if (!empty($param['parent_id'])) {
  65. $_agent_ids = (new AgentLogic())->getAgentIds($param['parent_id']);
  66. $_map['ptb_back_model.agent_id'] = ['in', $_agent_ids];
  67. }
  68. return $_map;
  69. }
  70. public function getBackList($where = [], $page = '1,10', $order = '-create_time') {
  71. $_where = $this->getWhere($where);
  72. $_field = [];
  73. return $this->getlist($_field, $_where, $page, $order);
  74. }
  75. public function getList($field = [], $where = [], $page = '1,10', $order = '-create_time') {
  76. $_map = $where;
  77. $_model = new PtbBackModel();
  78. $_count = $_model->alias('ptb_back_model')->where($_map)->count();
  79. if (empty($_count)) {
  80. return [
  81. 'count' => 0,
  82. 'sum' => [],
  83. 'list' => []
  84. ];
  85. }
  86. $_sum_field = [
  87. 'sum(ptb_cnt)' => 'sum_ptb_cnt',
  88. 'sum(back_ptb_cnt)' => 'sum_back_ptb_cnt',
  89. ];
  90. $_sum_data = $_model
  91. ->alias('ptb_back_model')
  92. ->field($_sum_field)
  93. ->where($where)
  94. ->find();
  95. if (is_object($_sum_data)) {
  96. $_sum_data = $_sum_data->toArray();
  97. }
  98. $_sum = [];
  99. foreach ($_sum_data as $_k => $_v) {
  100. $_sum[$_k] = StrUtils::formatNumber($_v);
  101. }
  102. $_field = $field;
  103. if (empty($field)) {
  104. $_field = [];
  105. }
  106. $_order = $_model->orderFilter($order);
  107. $_datas = $_model
  108. ->alias('ptb_back_model')
  109. ->with('mem,agent')
  110. ->where($where)
  111. ->field($_field)
  112. ->order($_order)
  113. ->page($page)
  114. ->select();
  115. if (is_object($_datas)) {
  116. $_datas = $_datas->toArray();
  117. }
  118. if (empty($_datas)) {
  119. return [
  120. 'count' => $_count,
  121. 'sum' => $_sum,
  122. 'list' => []
  123. ];
  124. }
  125. return [
  126. 'count' => $_count,
  127. 'sum' => $_sum,
  128. 'list' => $_datas
  129. ];
  130. }
  131. }