Plan.php 1.7 KB

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