Plan.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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. * @param $value
  35. * @return int
  36. */
  37. public function getMoneyAttr($value)
  38. {
  39. return ($value == $intValue = (int)$value) ? $intValue : $value;
  40. }
  41. /**
  42. * 获取器:赠送金额
  43. * @param $value
  44. * @return int
  45. */
  46. public function getGiftMoneyAttr($value)
  47. {
  48. return ($value == $intValue = (int)$value) ? $intValue : $value;
  49. }
  50. /**
  51. * 获取可用的充值套餐列表
  52. * @return \think\Collection
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function getList()
  58. {
  59. // 获取列表数据
  60. return $this->where('is_delete', '=', 0)
  61. ->order(['sort' => 'asc', 'money' => 'desc', 'create_time' => 'desc'])
  62. ->select();
  63. }
  64. /**
  65. * 根据自定义充值金额匹配满足的套餐
  66. * @param $payPrice
  67. * @return array|\think\Model|null
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function getMatchPlan($payPrice)
  73. {
  74. return (new static)->where('money', '<=', $payPrice)
  75. ->where('is_delete', '=', 0)
  76. ->order(['money' => 'desc'])
  77. ->find();
  78. }
  79. }