Plan.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\api\model\recharge;
  13. use app\common\model\recharge\Plan as PlanModel;
  14. /**
  15. * 用户充值订单模型
  16. * Class Plan
  17. * @package app\api\model\recharge
  18. */
  19. class Plan extends PlanModel
  20. {
  21. /**
  22. * 隐藏字段
  23. * @var array
  24. */
  25. protected $hidden = [
  26. 'sort',
  27. 'is_delete',
  28. 'store_id',
  29. 'create_time',
  30. 'update_time',
  31. ];
  32. /**
  33. * 获取可用的充值套餐列表
  34. * @return \think\Collection
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getList(): \think\Collection
  40. {
  41. // 获取列表数据
  42. return $this->where('is_delete', '=', 0)
  43. ->order(['sort' => 'asc', 'money' => 'desc', 'create_time' => 'desc'])
  44. ->select();
  45. }
  46. /**
  47. * 根据自定义充值金额匹配满足的套餐
  48. * @param $payPrice
  49. * @return array|\think\Model|null
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function getMatchPlan($payPrice)
  55. {
  56. return (new static)->where('money', '<=', $payPrice)
  57. ->where('is_delete', '=', 0)
  58. ->order(['money' => 'desc'])
  59. ->find();
  60. }
  61. }