Plan.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model\recharge;
  13. use app\common\model\recharge\Plan as PlanModel;
  14. /**
  15. * 会员充值套餐模型
  16. * Class Plan
  17. * @package app\store\model\recharge
  18. */
  19. class Plan extends PlanModel
  20. {
  21. /**
  22. * 列表记录
  23. * @param array $param
  24. * @return \think\Paginator
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function getList(array $param = []): \think\Paginator
  28. {
  29. // 检索查询条件
  30. $filter = $this->getFilter($param);
  31. // 查询列表数据
  32. return $this->where($filter)
  33. ->where('is_delete', '=', 0)
  34. ->order(['sort', $this->getPk()])
  35. ->paginate(15);
  36. }
  37. /**
  38. * 检索查询条件
  39. * @param array $param
  40. * @return array
  41. */
  42. private function getFilter(array $param = []): array
  43. {
  44. // 默认查询条件
  45. $params = $this->setQueryDefaultValue($param, ['search' => '']);
  46. // 检索查询条件
  47. $filter = [];
  48. !empty($params['search']) && $filter[] = ['plan_name', 'like', "%{$params['search']}%"];
  49. return $filter;
  50. }
  51. /**
  52. * 新增记录
  53. * @param array $data
  54. * @return false|int
  55. */
  56. public function add(array $data): bool
  57. {
  58. $data['store_id'] = self::$storeId;
  59. return $this->save($data);
  60. }
  61. /**
  62. * 更新记录
  63. * @param array $data
  64. * @return bool|int
  65. */
  66. public function edit(array $data): bool
  67. {
  68. return $this->save($data) !== false;
  69. }
  70. /**
  71. * 删除记录 (软删除)
  72. * @return bool|int
  73. */
  74. public function setDelete(): bool
  75. {
  76. return $this->save(['is_delete' => 1]) !== false;
  77. }
  78. }