RechargeConfig.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\model\api;
  4. use library\basic\BaseModel;
  5. use think\Model;
  6. /**
  7. * @mixin \think\Model
  8. */
  9. class RechargeConfig extends BaseModel
  10. {
  11. /**
  12. * 获取充值配置列表
  13. * @param array $where 查询条件
  14. * @param string $field 查询字段
  15. * @param int $page 页码
  16. * @param int $pageCount 每页数量
  17. * @param string $order 排序
  18. * @return array
  19. */
  20. public function getList($where = [], $field = '*', $page = 1, $pageCount = 20, $order = 'sort asc,id asc')
  21. {
  22. $data = $this
  23. ->where($where)
  24. ->field($field)
  25. ->order($order)
  26. ->paginate(['list_rows' => $pageCount, 'page' => $page])
  27. ->toArray();
  28. return [$data['total'], $data['data']];
  29. }
  30. /**
  31. * 获取显示的充值配置
  32. * @return array
  33. */
  34. public function getShowList()
  35. {
  36. return $this
  37. ->where('is_show', 1)
  38. ->order('sort asc,id asc')
  39. ->select()
  40. ->toArray();
  41. }
  42. /**
  43. * 获取默认充值配置
  44. * @return array|null
  45. */
  46. public function getDefault()
  47. {
  48. return $this
  49. ->where('is_default', 1)
  50. ->where('is_show', 1)
  51. ->find();
  52. }
  53. /**
  54. * 根据ID获取充值配置
  55. * @param int $id 配置ID
  56. * @return array|null
  57. */
  58. public function getById($id)
  59. {
  60. return $this->where('id', $id)->find();
  61. }
  62. /**
  63. * 保存充值配置
  64. * @param array $data 数据
  65. * @return bool|int
  66. */
  67. public function saveData($data)
  68. {
  69. return $this->insert($data);
  70. }
  71. /**
  72. * 更新充值配置
  73. * @param int $id 配置ID
  74. * @param array $data 数据
  75. * @return bool
  76. */
  77. public function updateConfig($id, $data): bool
  78. {
  79. return $this->where('id', $id)->update($data) !== false;
  80. }
  81. /**
  82. * 删除充值配置
  83. * @param int $id 配置ID
  84. * @return bool
  85. */
  86. public function deleteData($id)
  87. {
  88. return $this->where('id', $id)->delete();
  89. }
  90. }