SpecialPayService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Created by: PhpStorm
  4. * User: lytian
  5. * Date: 2019/9/19
  6. * Time: 17:47
  7. */
  8. namespace app\main\service;
  9. use app\common\model\SpecialRechargeUrl;
  10. class SpecialPayService extends BaseService
  11. {
  12. /**
  13. * 定义属性
  14. *
  15. * @var SpecialPayService
  16. */
  17. protected static $self = null;
  18. /**
  19. * 返回实例
  20. *
  21. * @return SpecialPayService
  22. */
  23. public static function instance()
  24. {
  25. if (self::$self == null) {
  26. self::$self = new self();
  27. }
  28. return self::$self;
  29. }
  30. /**
  31. * @return SpecialRechargeUrl
  32. */
  33. public function getUrlModel()
  34. {
  35. return model("SpecialRechargeUrl");
  36. }
  37. /**
  38. * 我能下单吗
  39. * @param $id
  40. * @param $user_id
  41. * @return array
  42. * @throws \think\exception\DbException
  43. */
  44. public function canPay($id, $user_id)
  45. {
  46. $result = ['code' => 200, 'msg' => ''];
  47. $row = $this->getUrlModel()->get($id);
  48. if ($row['status'] == 'hidden') {
  49. $result['code'] = 201;
  50. $result['msg'] = '链接不存在';
  51. } else {
  52. if ($row['order_status'] == '1') {
  53. $result['code'] = 202;
  54. $result['msg'] = '链接已支付';
  55. } else {
  56. if ($row['user_id']) {
  57. if ($row['user_id'] != $user_id) {
  58. $result['code'] = 202;
  59. $result['msg'] = '该链接为专属福利链接,请您联系私人助理获取';
  60. }
  61. }
  62. }
  63. }
  64. return $result;
  65. }
  66. /**
  67. * 更新
  68. * @param $id
  69. * @param $params
  70. * @return false|int
  71. * @throws \think\exception\DbException
  72. */
  73. public function updateUrl($id, $params)
  74. {
  75. $row = $this->getUrlModel()->get($id);
  76. return $row->save($params);
  77. }
  78. }