Plan.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\api\model\recharge;
  10. use app\common\model\recharge\Plan as PlanModel;
  11. /**
  12. * 用户充值订单模型
  13. * Class Plan
  14. * @package app\api\model\recharge
  15. */
  16. class Plan extends PlanModel
  17. {
  18. /**
  19. * 隐藏字段
  20. * @var array
  21. */
  22. protected $hidden = [
  23. 'is_delete',
  24. 'wxapp_id',
  25. 'create_time',
  26. 'update_time',
  27. ];
  28. /**
  29. * 获取器:充值金额
  30. * @param $value
  31. * @return int
  32. */
  33. public function getMoneyAttr($value)
  34. {
  35. return ($value == $intValue = (int)$value) ? $intValue : $value;
  36. }
  37. /**
  38. * 获取器:赠送金额
  39. * @param $value
  40. * @return int
  41. */
  42. public function getGiftMoneyAttr($value)
  43. {
  44. return ($value == $intValue = (int)$value) ? $intValue : $value;
  45. }
  46. /**
  47. * 获取可用的充值套餐列表
  48. * @return false|\PDOStatement|string|\think\Collection
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public function getList()
  54. {
  55. // 获取列表数据
  56. return $this->where('is_delete', '=', 0)
  57. ->order(['sort' => 'asc', 'money' => 'desc', 'create_time' => 'desc'])
  58. ->select();
  59. }
  60. /**
  61. * 根据自定义充值金额匹配满足的套餐
  62. * @param $payPrice
  63. * @return array|false|\PDOStatement|string|\think\Model
  64. */
  65. public function getMatchPlan($payPrice)
  66. {
  67. return (new static)->where('money', '<=', $payPrice)
  68. ->where('is_delete', '=', 0)
  69. ->order(['money' => 'desc'])
  70. ->find();
  71. }
  72. }