GamePriceLogic.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * GamePriceLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2020/9/15 15:09
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : H5IOS 1.0
  11. */
  12. namespace huosdk\h5ios\core\logic;
  13. use huo\model\common\CommonModel;
  14. use huosdk\h5ios\core\constant\CommonConst;
  15. use huosdk\h5ios\core\model\GamePriceModel;
  16. class GamePriceLogic extends CommonModel {
  17. protected $base_field = [];
  18. /**
  19. * 转换查询条件
  20. *
  21. * @param array $param
  22. *
  23. * @return array
  24. */
  25. public function getWhere($param = []) {
  26. $_map = [];
  27. /* 时间搜索 */
  28. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  29. $_map['create_time']
  30. = [
  31. 'between',
  32. [
  33. strtotime($param['start_time']),
  34. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
  35. ]
  36. ];
  37. } elseif (!empty($param['start_time'])) {
  38. $_map['create_time'] = ['egt', strtotime($param['start_time'])];
  39. } elseif (!empty($param['end_time'])) {
  40. $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  41. }
  42. /* 删除状态搜索 */
  43. if (!empty($param['is_delete'])) {
  44. $_map['is_delete'] = $param['is_delete'];
  45. }
  46. /* 计费点code搜索 */
  47. if (!empty($param['product_code'])) {
  48. $_map['product_code'] = $param['product_code'];
  49. }
  50. /* 应用ID搜索 */
  51. if (!empty($param['app_id'])) {
  52. $_map['app_id'] = $param['app_id'];
  53. }
  54. /* 渠道ID搜索 */
  55. if (!empty($param['agent_id'])) {
  56. $_map['agent_id'] = $param['agent_id'];
  57. if (CommonConst::CONST_ADMIN_SEARCH_ZERO == $param['agent_id']) {
  58. $_map['agent_id'] = CommonConst::CONST_ZERO;
  59. }
  60. }
  61. return $_map;
  62. }
  63. /**
  64. * 获取列表底层函数
  65. *
  66. * @param array $where 搜索条件
  67. * @param string $page 列表个数
  68. * @param string $order 排序
  69. * @param array $field 附加字段
  70. *
  71. * @return array ['count'=>0,'list'=>[]]
  72. */
  73. public function getList($where = [], $page = '1,10', $order = '', $field = []) {
  74. $_map = $where;
  75. $_field = $field;
  76. $_model = new GamePriceModel();
  77. $_count = $_model->where($_map)->count();
  78. if (empty($_count)) {
  79. return [
  80. 'count' => 0,
  81. 'list' => []
  82. ];
  83. }
  84. $_order = $this->orderFilter($order);
  85. $_datas = $_model->field($_field)->where($_map)->order($_order)->page($page)->select();
  86. if (is_object($_datas)) {
  87. $_datas = $_datas->toArray();
  88. }
  89. if (empty($_datas)) {
  90. return [
  91. 'count' => 0,
  92. 'list' => []
  93. ];
  94. }
  95. return [
  96. 'count' => $_count,
  97. 'list' => $_datas
  98. ];
  99. }
  100. /**
  101. * 获取后台列表
  102. *
  103. * @param array $where 搜索条件
  104. * @param string $page 列表个数
  105. * @param string $order 排序
  106. * @param array $field 附加字段
  107. *
  108. * @return array ['count'=>0,'list'=>[]]
  109. */
  110. public function getAdminList($where = [], $page = '1,10', $order = '-product_price,-app_id', $field = []) {
  111. $_map = $this->getWhere($where);
  112. $_field = $this->base_field;
  113. if (!empty($field)) {
  114. $_field = array_merge($_field, $field);/* 获取后台字段 */
  115. }
  116. return $this->getList($_map, $page, $order, $_field);
  117. }
  118. }