GmBackLogic.php 3.8 KB

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