Ver Fonte

2.0

## 主题更新
1. 更新至remark5.1.0;
2. 对input中range进行了一些自定义美化;

## 功能添加/重置
1. 支付相关代码重置;
     1.1 对在线&余额处理代码整合;
     1.2 剃离失效的有赞云;
2. 套餐相关代码重置;
*     2.1 重置日从日改为了日期,列6号 改为 xxxx年x月6号;
     2.2 添加预支付套餐功能;
     2.3 套餐逻辑修改;套餐为主,流量包为辅;流量包将会在下一个重置日期时失效;
     2.4 套餐添加 重置流量周期;默认为30天;

## BUG修复和优化
1. 对上版本添加的节点TCP和ICMP检测 功能进行代码简化,已经提示信息显示优化;
2. 对定时任务进行逻辑优化&简化; [自动化任务]消耗时间减半;
3. 对2019年的老代码进行清理;

## 页面添加与修改
1. 管理员界面 用户相关页面添加重置日期修改;
2. 管理员界面 批量添加用户功能现在将不是默认10个而是可自定义添加数额;
3. 用户界面 检测并提示用户预支付套餐;
Bretton há 5 anos atrás
pai
commit
05ad40e92f
100 ficheiros alterados com 2248 adições e 2640 exclusões
  1. 674 21
      LICENSE
  2. 250 0
      app/Components/Callback.php
  3. 39 1
      app/Components/Helpers.php
  4. 0 75
      app/Components/Yzy.php
  5. 0 126
      app/Console/Commands/AutoDecGoodsTraffic.php
  6. 76 446
      app/Console/Commands/AutoJob.php
  7. 0 80
      app/Console/Commands/AutoResetUserTraffic.php
  8. 172 0
      app/Console/Commands/DailyJob.php
  9. 38 143
      app/Console/Commands/NodeBlockedDetection.php
  10. 89 0
      app/Console/Commands/ServiceTimer.php
  11. 0 55
      app/Console/Commands/upgradeUserLabels.php
  12. 0 33
      app/Console/Commands/upgradeUserPassword.php
  13. 64 0
      app/Console/Commands/upgradeUserResetTime.php
  14. 0 36
      app/Console/Commands/upgradeUserSpeedLimit.php
  15. 0 42
      app/Console/Commands/upgradeUserSubscribe.php
  16. 0 33
      app/Console/Commands/upgradeUserVmessId.php
  17. 18 26
      app/Console/Kernel.php
  18. 21 74
      app/Http/Controllers/AdminController.php
  19. 5 218
      app/Http/Controllers/Api/AlipayController.php
  20. 3 217
      app/Http/Controllers/Api/F2fpayController.php
  21. 0 390
      app/Http/Controllers/Api/YzyController.php
  22. 43 64
      app/Http/Controllers/AuthController.php
  23. 101 88
      app/Http/Controllers/PaymentController.php
  24. 4 4
      app/Http/Controllers/SubscribeController.php
  25. 48 218
      app/Http/Controllers/UserController.php
  26. 0 20
      app/Http/Models/Order.php
  27. 2 1
      composer.json
  28. 252 183
      composer.lock
  29. 1 0
      public/assets/custom/range.min.css
  30. 1 0
      public/assets/examples/css/apps/message.css
  31. 0 0
      public/assets/examples/css/apps/message.min.css
  32. 3 1
      public/assets/examples/css/apps/notebook.css
  33. 0 0
      public/assets/examples/css/apps/notebook.min.css
  34. 3 1
      public/assets/examples/css/pages/login-v3.min.css
  35. BIN
      public/assets/examples/images/assemble.png
  36. BIN
      public/assets/examples/images/bootstrap.png
  37. BIN
      public/assets/examples/images/bower.png
  38. BIN
      public/assets/examples/images/browser/chrome-logo.png
  39. BIN
      public/assets/examples/images/browser/firefox-logo.png
  40. BIN
      public/assets/examples/images/browser/internet-logo.png
  41. BIN
      public/assets/examples/images/browser/opera-logo.png
  42. BIN
      public/assets/examples/images/browser/safari-logo.png
  43. BIN
      public/assets/examples/images/coming-soon.jpg
  44. BIN
      public/assets/examples/images/country/australia-icon.png
  45. BIN
      public/assets/examples/images/country/canada-icon.png
  46. BIN
      public/assets/examples/images/country/china-icon.png
  47. BIN
      public/assets/examples/images/country/germany-icon.png
  48. BIN
      public/assets/examples/images/country/uk-icon.png
  49. BIN
      public/assets/examples/images/country/usa-icon.png
  50. BIN
      public/assets/examples/images/dashboard-header.jpg
  51. BIN
      public/assets/examples/images/dashboard2-header.jpg
  52. BIN
      public/assets/examples/images/favicon.ico
  53. BIN
      public/assets/examples/images/grunt.png
  54. BIN
      public/assets/examples/images/less.png
  55. BIN
      public/assets/examples/images/lockscreen.jpg
  56. BIN
      public/assets/examples/images/login.jpg
  57. BIN
      public/assets/examples/images/modal/accordion-modal.png
  58. BIN
      public/assets/examples/images/modal/fillin-modal.png
  59. BIN
      public/assets/examples/images/modal/form-modal.png
  60. BIN
      public/assets/examples/images/modal/grid-modal.png
  61. BIN
      public/assets/examples/images/modal/modal-position-sidebar.png
  62. BIN
      public/assets/examples/images/modal/modal-position-top.png
  63. BIN
      public/assets/examples/images/modal/modal-position.png
  64. BIN
      public/assets/examples/images/modal/multiple-modal.png
  65. BIN
      public/assets/examples/images/modal/size-modal.png
  66. BIN
      public/assets/examples/images/modal/style-modal.png
  67. BIN
      public/assets/examples/images/modal/sweet-alert.png
  68. BIN
      public/assets/examples/images/modal/tab-modal.png
  69. BIN
      public/assets/examples/images/navbar/fixed-to-bottom.png
  70. BIN
      public/assets/examples/images/navbar/fixed-to-top.png
  71. BIN
      public/assets/examples/images/poster.jpg
  72. BIN
      public/assets/examples/images/products/applewatch.png
  73. BIN
      public/assets/examples/images/products/imac.png
  74. BIN
      public/assets/examples/images/products/iphone.png
  75. BIN
      public/assets/examples/images/products/macmouse.png
  76. BIN
      public/assets/examples/images/txt.png
  77. 1 2
      public/assets/examples/js/dashboard/analytics.js
  78. 81 0
      public/assets/examples/js/pages/map-point.js
  79. 183 28
      public/assets/examples/js/tables/bootstrap.js
  80. 5 1
      public/assets/examples/js/tables/datatable.js
  81. 1 1
      public/assets/global/fonts/Roboto/Roboto.min.css
  82. 0 0
      public/assets/global/fonts/brand-icons/brand-icons.min.css
  83. 0 0
      public/assets/global/fonts/font-awesome/font-awesome.min.css
  84. 0 0
      public/assets/global/fonts/foundation/foundation.min.css
  85. 0 0
      public/assets/global/fonts/framework7/framework7.min.css
  86. 0 0
      public/assets/global/fonts/glyphicons/glyphicons.min.css
  87. 0 0
      public/assets/global/fonts/ionicons/ionicons.min.css
  88. 0 0
      public/assets/global/fonts/map-icons/map-icons.min.css
  89. 0 0
      public/assets/global/fonts/material-design/material-design.min.css
  90. 0 0
      public/assets/global/fonts/mfglabs/mfglabs.min.css
  91. 0 0
      public/assets/global/fonts/micon/micon.min.css
  92. 0 0
      public/assets/global/fonts/octicons/octicons.min.css
  93. 0 0
      public/assets/global/fonts/open-iconic/open-iconic.min.css
  94. 0 0
      public/assets/global/fonts/openwebicons/openwebicons.min.css
  95. 0 0
      public/assets/global/fonts/themify/themify.min.css
  96. 0 0
      public/assets/global/fonts/weather-icons/weather-icons.min.css
  97. 0 0
      public/assets/global/fonts/web-icons/web-icons.min.css
  98. 1 1
      public/assets/global/js/Plugin.js
  99. 6 7
      public/assets/global/js/Plugin/editlist.js
  100. 63 4
      public/assets/global/js/Plugin/formatter.js

+ 674 - 21
LICENSE

@@ -1,21 +1,674 @@
-MIT License
-
-Copyright (c) 2017-2019 Bruskyii Panda
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+Copyright (C) 2017-2020 Bretton Ye
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for software
+and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not price.
+Our General Public Licenses are designed to make sure that you have the
+freedom to distribute copies of free software (and charge for them if you
+wish), that you receive source code or can get it if you want it, that you
+can change the software or use pieces of it in new free programs, and that
+you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 250 - 0
app/Components/Callback.php

@@ -0,0 +1,250 @@
+<?php
+
+namespace App\Components;
+
+use App\Http\Models\Goods;
+use App\Http\Models\GoodsLabel;
+use App\Http\Models\Order;
+use App\Http\Models\Payment;
+use App\Http\Models\SsNode;
+use App\Http\Models\SsNodeLabel;
+use App\Http\Models\User;
+use App\Http\Models\UserLabel;
+use App\Mail\sendUserInfo;
+use DB;
+use Exception;
+use Hash;
+use Illuminate\Http\Request;
+use Log;
+use Mail;
+use Response;
+
+trait Callback
+{
+	protected static $systemConfig;
+
+	function __construct()
+	{
+		self::$systemConfig = Helpers::systemConfig();
+	}
+
+	// 交易支付
+	private function tradePaid($msg, $pay_type)
+	{
+		$pay_type_name = $pay_type == 1? '余额支付' : ($pay_type == 4? '支付宝国际' : ($pay_type == 5? '支付宝当面付' : ''));
+		if($pay_type != 1){
+			Log::info('【'.$pay_type_name.'】支付成功,开始处理回调订单');
+			// 获取未完成状态的订单防止重复增加时间
+			$payment = Payment::query()->with(['order', 'order.goods'])->where('status', 0)->where('order_sn', $msg['out_trade_no'])->first();
+			if(!$payment){
+				Log::info('【'.$pay_type_name.'】回调订单【'.$msg['out_trade_no'].'】不存在');
+
+				return FALSE;
+			}
+		}else{
+			Log::info('【'.$pay_type_name.'】订单处理');
+		}
+
+		// 处理订单
+		DB::beginTransaction();
+		try{
+			if($pay_type != 1){
+				// 如果支付单中没有用户信息则创建一个用户
+				if(!$payment->user_id){
+					$uid = Helpers::addUser('自动生成-'.$payment->order->email, Hash::make(makeRandStr()), 1, $payment->order->goods->days);
+
+					if($uid){
+						Order::query()->where('oid', $payment->oid)->update(['user_id' => $uid]);
+					}
+				}
+
+				// 更新支付单
+				$payment->pay_way = $pay_type == 4 || $pay_type == 5? 2 : 1; // 1-微信、2-支付宝
+				$payment->status = 1;
+				$payment->save();
+			}
+
+			// 更新订单
+			$order = Order::query()->where('order_sn', $msg['out_trade_no'])->first();
+			// 提取商品信息
+			$goods = Goods::query()->where('id', $order->goods_id)->first();
+			// 取出用户信息
+			$user = User::query()->where('id', $order->user_id)->first();
+			// 商品为流量或者套餐
+			switch($goods->type){
+				case 1:
+					$order->status = 2;
+					$order->save();
+					Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, $user->transfer_enable+$goods->traffic*1048576, '[在线支付]加上用户购买的套餐流量');
+					$user->increment('transfer_enable', $goods->traffic*1048576);
+					break;
+				case 2:
+					$activePlan = Order::query()
+						->where('user_id', $order->user_id)
+						->with(['goods'])
+						->whereHas('goods', function($q){
+							$q->where('type', 2);
+						})
+						->where('is_expire', 0)
+						->where('status', 2)
+						->exists();
+					// 2为开始生效,3为预支付
+					$order->status = $activePlan? 3 : 2;
+					$order->save();
+					// 预支付不执行
+					if(!$activePlan){
+						// 如果买的是套餐,则先将之前购买的套餐都无效化,重置用户已用、可用流量为0
+						Order::query()
+							->where('user_id', $order->user_id)
+							->with(['goods'])
+							->whereHas('goods', function($q){
+								$q->where('type', '<=', 2);
+							})
+							->where('is_expire', 0)
+							->where('status', 2)
+							->where('oid', '<>', $order->oid)
+							->update(['expire_at' => date('Y-m-d H:i:s'), 'is_expire' => 1]);
+
+						Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, 0, '[在线支付]用户购买新套餐,先清空流量');
+						User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
+
+						$userTraffic = $goods->traffic*1048576;
+						// 添加账号有效期
+						$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
+						//账号下一个重置时间
+						$nextResetTime = date('Y-m-d', strtotime("+".$goods->period." days"));
+						if($nextResetTime >= $expireTime){
+							$nextResetTime = NULL;
+						}
+
+						// 写入用户标签
+						if($goods->label){
+							// 删除用户所有标签
+							UserLabel::query()->where('user_id', $order->user_id)->delete();
+
+							//取出 商品默认标签  & 系统默认标签 去重
+							$newUserLabels = array_values(array_unique(array_merge(GoodsLabel::query()->where('goods_id', $order->goods_id)->pluck('label_id')->toArray(), self::$systemConfig['initial_labels_for_user']? explode(',', self::$systemConfig['initial_labels_for_user']) : [])));
+
+							// 生成标签
+							foreach($newUserLabels as $vo){
+								$obj = new UserLabel();
+								$obj->user_id = $order->user_id;
+								$obj->label_id = $vo;
+								$obj->save();
+							}
+						}
+
+						// 写入返利日志
+						if($order->user->referral_uid){
+							$this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount*self::$systemConfig['referral_percent']);
+							// 邀请注册功能开启时,每成功邀请一名付费用户,返还邀请者邀请名额
+							if(self::$systemConfig['is_invite_register']){
+								User::query()->where('id', $order->user->referral_uid)->increment('invite_num', 1);
+							}
+						}
+
+						Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, $userTraffic, '[在线支付]加上用户购买的套餐流量');
+						User::query()->where('id', $order->user_id)->increment('invite_num', $goods->invite_num? : 0, ['transfer_enable' => $userTraffic, 'reset_time' => $nextResetTime, 'expire_time' => $expireTime, 'enable' => 1]);
+					}else{
+						//预支付订单先给上账号时间用于流量重置判断
+						User::query()->where('id', $order->user_id)->update(['expire_time' => date('Y-m-d', strtotime("+".$goods->days." days", strtotime($user->expire_time)))]);
+					}
+					break;
+				case 3:
+					$order->status = 2;
+					$order->save();
+					$user->increment('balance', $goods->price*100);
+
+					// 余额变动记录日志
+					$this->addUserBalanceLog($order->user_id, $order->oid, $order->user->balance, $order->user->balance+$goods->price, $goods->price, '用户在线充值');
+					break;
+				default:
+					Log::info('【处理订单】出现错误-未知套餐类型');
+			}
+			// 自动提号机:如果order的email值不为空
+			if($order->email){
+				$title = '自动发送账号信息';
+				$content = [
+					'order_sn'      => $order->order_sn,
+					'goods_name'    => $order->goods->name,
+					'goods_traffic' => flowAutoShow($order->goods->traffic*1048576),
+					'port'          => $order->user->port,
+					'passwd'        => $order->user->passwd,
+					'method'        => $order->user->method,
+					//'protocol'       => $order->user->protocol,
+					//'protocol_param' => $order->user->protocol_param,
+					//'obfs'           => $order->user->obfs,
+					//'obfs_param'     => $order->user->obfs_param,
+					'created_at'    => $order->created_at->toDateTimeString(),
+					'expire_at'     => $order->expire_at
+				];
+
+				// 获取可用节点列表
+				$labels = UserLabel::query()->where('user_id', $order->user_id)->get()->pluck('label_id');
+				$nodeIds = SsNodeLabel::query()->whereIn('label_id', $labels)->get()->pluck('node_id');
+				$nodeList = SsNode::query()->whereIn('id', $nodeIds)->orderBy('sort', 'desc')->orderBy('id', 'desc')->get()->toArray();
+				$content['serverList'] = $nodeList;
+
+				$logId = Helpers::addEmailLog($order->email, $title, json_encode($content));
+				Mail::to($order->email)->send(new sendUserInfo($logId, $content));
+			}
+
+			DB::commit();
+			Log::info('【'.$pay_type_name.'】处理成功');
+		} catch(Exception $e){
+			DB::rollBack();
+			Log::info('【'.$pay_type_name.'】回调更新支付单和订单异常:'.$e->getMessage());
+		}
+		return FALSE;
+	}
+
+	private function activePrepaidOrder($oid)
+	{
+		// 取出预支付订单
+		$prepaidOrder = Order::query()->where('oid', $oid)->first();
+		//去除使用中的套餐和 流量包
+		Order::query()->where('user_id', $prepaidOrder->user_id)->where('status', 2)->where('is_expire', 0)->update(['expire_at' => date('Y-m-d H:i:s'), 'is_expire' => 1]);
+		//取出对应套餐信息
+		$prepaidGood = Goods::query()->where('id', $prepaidOrder->goods_id)->first();
+		//激活预支付套餐
+		Order::query()->where('oid', $prepaidOrder->oid)->update(['expire_at' => date("Y-m-d H:i:s", strtotime("+".$prepaidGood->days." days")), 'status' => 2]);
+		//取出用户信息
+		$user = User::query()->where('id', $prepaidOrder->user_id)->first();
+
+		$userTraffic = $prepaidGood->traffic*1048576;
+		//拿出可能存在的其余套餐, 推算 最新的到期时间
+		$expire_time = date('Y-m-d', strtotime("+".$prepaidGood->days." days"));
+		$prepaidOrders = Order::query()->where('user_id', $prepaidOrder->user_id)->where('status', 3)->get();
+		foreach($prepaidOrders as $paidOrder){
+			//取出对应套餐信息
+			$goods = Goods::query()->where('id', $paidOrder->goods_id)->first();
+			$expire_time = date('Y-m-d', strtotime("+".$goods->days." days", strtotime($expire_time)));
+		}
+		//计算账号下一个重置时间
+		$nextResetTime = date('Y-m-d', strtotime("+".$prepaidGood->period." days"));
+		if($nextResetTime >= $expire_time){
+			$nextResetTime = NULL;
+		}
+
+		// 用户默认标签
+		$defaultLabels = self::$systemConfig['initial_labels_for_user']? explode(',', self::$systemConfig['initial_labels_for_user']) : [];
+		//取出 商品默认标签  & 系统默认标签 去重
+		$newUserLabels = array_values(array_unique(array_merge(GoodsLabel::query()->where('goods_id', $prepaidOrder->goods_id)->pluck('label_id')->toArray(), $defaultLabels)));
+
+		// 生成标签
+		foreach($newUserLabels as $vo){
+			$obj = new UserLabel();
+			$obj->user_id = $prepaidOrder->user_id;
+			$obj->label_id = $vo;
+			$obj->save();
+		}
+		Helpers::addUserTrafficModifyLog($prepaidOrder->user_id, $prepaidOrder->oid, $user->transfer_enable, $userTraffic, '[预支付订单激活]加上用户购买的套餐流量');
+
+		User::query()->where('id', $prepaidOrder->user_id)->increment('invite_num', $prepaidOrder->invite_num? : 0, ['transfer_enable' => $userTraffic, 'expire_time' => $expire_time, 'reset_time' => $nextResetTime]);
+	}
+
+	public function show(Request $request)
+	{
+		exit('show');
+	}
+}

+ 39 - 1
app/Components/Helpers.php

@@ -78,7 +78,7 @@ class Helpers
 		$config = self::systemConfig();
 		$port = $config['min_port'];
 
-		$exists_port = User::query()->where('port', '>=', $config['min_port'])->pluck('port')->toArray();
+		$exists_port = User::query()->where('port', '>=', $port)->pluck('port')->toArray();
 		while(in_array($port, $exists_port) || in_array($port, self::$denyPorts)){
 			$port = $port+1;
 		}
@@ -121,6 +121,44 @@ class Helpers
 		return $code;
 	}
 
+	/**
+	 * 添加用户
+	 *
+	 * @param string $username        用户邮箱
+	 * @param string $password        用户密码
+	 * @param string $transfer_enable 可用流量
+	 * @param int    $data            可使用天数
+	 * @param int    $referral_uid    邀请人
+	 * @return int
+	 */
+	public static function addUser($username, $password, $transfer_enable, $data, $referral_uid = 0)
+	{
+		$user = new User();
+		$user->username = $username;
+		$user->password = $password;
+		// 生成一个可用端口
+		$user->port = self::systemConfig()['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
+		$user->passwd = makeRandStr();
+		$user->vmess_id = createGuid();
+		$user->enable = 1;
+		$user->method = Helpers::getDefaultMethod();
+		$user->protocol = Helpers::getDefaultProtocol();
+		$user->protocol_param = '';
+		$user->obfs = Helpers::getDefaultObfs();
+		$user->obfs_param = '';
+		$user->usage = 1;
+		$user->transfer_enable = $transfer_enable; // 新创建的账号给1,防止定时任务执行时发现u + d >= transfer_enable被判为流量超限而封禁
+		$user->enable_time = date('Y-m-d');
+		$user->expire_time = date('Y-m-d', strtotime("+".$data." days"));
+		$user->reg_ip = getClientIp();
+		$user->referral_uid = $referral_uid;
+		$user->reset_time = NULL;
+		$user->status = 1;
+		$user->save();
+
+		return $user->id;
+	}
+
 	/**
 	 * 添加邮件投递日志
 	 *

+ 0 - 75
app/Components/Yzy.php

@@ -1,75 +0,0 @@
-<?php
-
-namespace App\Components;
-
-use Cache;
-use Log;
-use Youzan\Open\Client;
-use Youzan\Open\Token;
-
-class Yzy
-{
-	protected static $systemConfig;
-	protected static $accessToken;
-
-	function __construct()
-	{
-		self::$systemConfig = Helpers::systemConfig();
-		self::$accessToken = $this->getAccessToken();
-	}
-
-	// 获取accessToken
-	public function getAccessToken()
-	{
-		if(Cache::has('YZY_TOKEN')){
-			$token = Cache::get('YZY_TOKEN');
-			if(!isset($token['error'])){
-				return Cache::get('YZY_TOKEN')['access_token'];
-			}
-
-			Cache::forget('YZY_TOKEN');
-		}
-
-		$token = (new Token(self::$systemConfig['youzan_client_id'], self::$systemConfig['youzan_client_secret']))->getToken('self', ['kdt_id' => self::$systemConfig['kdt_id']]);
-		if(isset($token['error'])){
-			Log::info('获取有赞云支付access_token失败:'.$token['error_description']);
-
-			return '';
-		}else{
-			Cache::put('YZY_TOKEN', $token, 180);
-
-			return $token['access_token'];
-		}
-	}
-
-	// 生成收款二维码
-	public function createQrCode($goodsName, $price, $orderSn)
-	{
-		$client = new Client(self::$accessToken);
-
-		$params = [
-			'qr_name'   => $goodsName, // 商品名
-			'qr_price'  => $price, // 单位分
-			'qr_source' => $orderSn, // 本地订单号
-			'qr_type'   => 'QR_TYPE_DYNAMIC'
-		];
-
-		return $client->get('youzan.pay.qrcode.create', '3.0.0', $params);
-	}
-
-	// 通过tid获取交易信息
-	public function getTradeByTid($tid)
-	{
-		$client = new Client(self::$accessToken);
-
-		return $client->post('youzan.trade.get', '4.0.0', ['tid' => $tid]);
-	}
-
-	// 通过二维码ID获取已支付的交易信息
-	public function getTradeByQrId($qr_id)
-	{
-		$client = new Client(self::$accessToken);
-
-		return $client->post('youzan.trades.qr.get', '3.0.0', ['qr_id' => $qr_id, 'status' => 'TRADE_RECEIVED']);
-	}
-}

+ 0 - 126
app/Console/Commands/AutoDecGoodsTraffic.php

@@ -1,126 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Components\Helpers;
-use App\Http\Models\GoodsLabel;
-use App\Http\Models\Order;
-use App\Http\Models\User;
-use App\Http\Models\UserLabel;
-use DB;
-use Exception;
-use Illuminate\Console\Command;
-use Log;
-
-class AutoDecGoodsTraffic extends Command
-{
-	protected $signature = 'autoDecGoodsTraffic';
-	protected $description = '自动扣减用户到期商品的流量';
-	protected static $systemConfig;
-
-	public function __construct()
-	{
-		parent::__construct();
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
-	public function handle()
-	{
-		$jobStartTime = microtime(TRUE);
-
-		// 扣减用户到期商品的流量
-		$this->decGoodsTraffic();
-
-		$jobEndTime = microtime(TRUE);
-		$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
-
-		Log::info('执行定时任务【'.$this->description.'】,耗时'.$jobUsedTime.'秒');
-	}
-
-	// 扣减用户到期商品的流量
-	private function decGoodsTraffic()
-	{
-		$orderList = Order::query()->with(['user', 'goods'])->where('status', 2)->where('is_expire', 0)->where('expire_at', '<', date('Y-m-d H:i:s'))->get();
-		if(!$orderList->isEmpty()){
-			// 用户默认标签
-			$defaultLabels = [];
-			if(self::$systemConfig['initial_labels_for_user']){
-				$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-			}
-
-			DB::beginTransaction();
-			try{
-				foreach($orderList as $order){
-					// 先过期本订单
-					Order::query()->where('oid', $order->oid)->update(['is_expire' => 1]);
-
-					// 再检查该订单对应用户是否还有套餐(非流量包)存在
-					$haveOrder = Order::query()
-						->with(['user', 'goods'])
-						->where('is_expire', 0)
-						->where('user_id', $order->user_id)
-						->whereHas('goods', function($q){
-							$q->where('type', 2);
-						})
-						->orderBy('oid', 'desc')
-						->first();
-					if(!$haveOrder){
-						// 如果不存在有效套餐(非流量包),则清空用户重置日
-						User::query()->where('id', $order->user_id)->update(['traffic_reset_day' => 0]);
-					}
-
-					if(empty($order->user) || empty($order->goods)){
-						continue;
-					}
-
-					if($order->user->transfer_enable-$order->goods->traffic*1048576 <= 0){
-						// 写入用户流量变动记录
-						Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $order->user->transfer_enable, 0, '[定时任务]用户所购商品到期,扣减商品对应的流量(扣完并重置)');
-
-						User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-					}else{
-						// 写入用户流量变动记录
-						Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $order->user->transfer_enable, ($order->user->transfer_enable-$order->goods->traffic*1048576), '[定时任务]用户所购商品到期,扣减商品对应的流量(没扣完)');
-
-						User::query()->where('id', $order->user_id)->decrement('transfer_enable', $order->goods->traffic*1048576);
-
-						// 处理已用流量
-						if($order->user->u+$order->user->d-$order->goods->traffic*1048576 <= 0){
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
-						}else{
-							// 一般来说d的值远远大于u
-							if($order->user->d-$order->goods->traffic*1048576 >= 0){
-								User::query()->where('id', $order->user_id)->decrement('d', $order->goods->traffic*1048576);
-							}else{ // 如果d不够减,则减u,然后d置0
-								User::query()->where('id', $order->user_id)->decrement('u', $order->goods->traffic*1048576-$order->user->d);
-								User::query()->where('id', $order->user_id)->update(['d' => 0]);
-							}
-						}
-					}
-
-					// 删除该商品对应用户的所有标签
-					UserLabel::query()->where('user_id', $order->user->id)->delete();
-
-					// 取出用户的其他商品带有的标签
-					$goodsIds = Order::query()->where('user_id', $order->user->id)->where('oid', '<>', $order->oid)->where('status', 2)->where('is_expire', 0)->groupBy('goods_id')->pluck('goods_id')->toArray();
-					$goodsLabels = GoodsLabel::query()->whereIn('goods_id', $goodsIds)->groupBy('label_id')->pluck('label_id')->toArray();
-
-					// 生成标签
-					$labels = array_values(array_unique(array_merge($goodsLabels, $defaultLabels))); // 标签去重
-					foreach($labels as $vo){
-						$userLabel = new UserLabel();
-						$userLabel->user_id = $order->user->id;
-						$userLabel->label_id = $vo;
-						$userLabel->save();
-					}
-				}
-
-				DB::commit();
-			} catch(Exception $e){
-				Log::error($this->description.':'.$e);
-
-				DB::rollBack();
-			}
-		}
-	}
-}

+ 76 - 446
app/Console/Commands/AutoJob.php

@@ -4,32 +4,22 @@ namespace App\Console\Commands;
 
 use App\Components\Helpers;
 use App\Components\ServerChan;
-use App\Components\Yzy;
 use App\Http\Models\Coupon;
-use App\Http\Models\Goods;
-use App\Http\Models\GoodsLabel;
 use App\Http\Models\Invite;
 use App\Http\Models\Order;
 use App\Http\Models\Payment;
-use App\Http\Models\ReferralLog;
 use App\Http\Models\SsNode;
 use App\Http\Models\SsNodeInfo;
-use App\Http\Models\SsNodeLabel;
-use App\Http\Models\Ticket;
 use App\Http\Models\User;
-use App\Http\Models\UserBalanceLog;
 use App\Http\Models\UserBanLog;
-use App\Http\Models\UserLabel;
 use App\Http\Models\UserSubscribe;
 use App\Http\Models\UserSubscribeLog;
 use App\Http\Models\UserTrafficHourly;
 use App\Http\Models\VerifyCode;
-use App\Mail\sendUserInfo;
 use DB;
 use Exception;
 use Illuminate\Console\Command;
 use Log;
-use Mail;
 
 class AutoJob extends Command
 {
@@ -50,14 +40,11 @@ class AutoJob extends Command
 	{
 		$jobStartTime = microtime(TRUE);
 
-		// 注册验证码自动置无效
-		$this->expireVerifyCode();
+		// 关闭超时未支付订单
+		$this->closeOrders();
 
-		// 优惠券到期自动置无效
-		$this->expireCoupon();
-
-		// 邀请码到期自动置无效
-		$this->expireInvite();
+		//过期验证码、优惠券、邀请码无效化
+		$this->expireCode();
 
 		// 封禁访问异常的订阅链接
 		$this->blockSubscribe();
@@ -71,61 +58,70 @@ class AutoJob extends Command
 		// 端口回收与分配
 		$this->dispatchPort();
 
-		// 审计待支付的订单
-		$this->detectOrders();
-
-		// 关闭超时未支付订单
-		$this->closeOrders();
-
-		// 关闭超过72小时未处理的工单
-		$this->closeTickets();
-
 		// 检测节点是否离线
 		$this->checkNodeStatus();
 
 		$jobEndTime = microtime(TRUE);
 		$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
 
-		Log::info('执行定时任务【'.$this->description.'】,耗时'.$jobUsedTime.'秒');
+		Log::info('【'.$this->description.'】执行定时任务,耗时'.$jobUsedTime.'秒');
 	}
 
-	// 注册验证码自动置无效
-	private function expireVerifyCode()
+	// 关闭超时未支付订单
+	private function closeOrders()
 	{
-		VerifyCode::query()->where('status', 0)->where('created_at', '<=', date('Y-m-d H:i:s', strtotime("-10 minutes")))->update(['status' => 2]);
-	}
+		// 关闭超时未支付的在线支付订单(在线支付收款二维码超过30分钟自动关闭,关闭后无法再支付,所以我们限制15分钟内必须付款)
+		$paymentList = Payment::query()->with(['order', 'order.coupon'])->where('status', 0)->where('created_at', '<=', date("Y-m-d H:i:s", strtotime("-15 minutes")))->get();
+		if($paymentList->isNotEmpty()){
+			DB::beginTransaction();
+			try{
+				foreach($paymentList as $payment){
+					// 关闭支付单
+					Payment::query()->where('id', $payment->id)->update(['status' => -1]);
 
-	// 优惠券到期自动置无效
-	private function expireCoupon()
-	{
-		$couponList = Coupon::query()->where('status', 0)->where('available_end', '<=', time())->get();
-		if(!$couponList->isEmpty()){
-			foreach($couponList as $coupon){
-				Coupon::query()->where('id', $coupon->id)->update(['status' => 2]);
+					// 关闭订单
+					Order::query()->where('oid', $payment->oid)->update(['status' => -1]);
+
+					// 退回优惠券
+					if($payment->order->coupon_id){
+						Coupon::query()->where('id', $payment->order->coupon_id)->update(['status' => 0]);
+
+						Helpers::addCouponLog($payment->order->coupon_id, $payment->order->goods_id, $payment->oid, '订单超时未支付,自动退回');
+					}
+				}
+
+				DB::commit();
+			} catch(Exception $e){
+				Log::info('【异常】自动关闭超时未支付订单:'.$e);
+
+				DB::rollBack();
 			}
 		}
 	}
 
-	// 邀请码到期自动置无效
-	private function expireInvite()
+	// 注册验证码自动置无效
+	private function expireCode()
 	{
-		$inviteList = Invite::query()->where('status', 0)->where('dateline', '<=', date('Y-m-d H:i:s'))->get();
-		if(!$inviteList->isEmpty()){
-			foreach($inviteList as $invite){
-				Invite::query()->where('id', $invite->id)->update(['status' => 2]);
-			}
-		}
+		// 注册验证码自动置无效
+		VerifyCode::query()->where('status', 0)->where('created_at', '<=', date('Y-m-d H:i:s', strtotime("-10 minutes")))->update(['status' => 2]);
+
+		// 优惠券到期自动置无效
+		Coupon::query()->where('status', 0)->where('available_end', '<=', time())->update(['status' => 2]);
+
+		// 邀请码到期自动置无效
+		Invite::query()->where('status', 0)->where('dateline', '<=', date('Y-m-d H:i:s'))->update(['status' => 2]);
 	}
 
 	// 封禁访问异常的订阅链接
 	private function blockSubscribe()
 	{
 		if(self::$systemConfig['is_subscribe_ban']){
-			$subscribeList = UserSubscribe::query()->where('status', 1)->get();
-			if(!$subscribeList->isEmpty()){
-				foreach($subscribeList as $subscribe){
+			$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->get();
+			foreach($userList as $user){
+				$subscribe = UserSubscribe::query()->where('user_id', $user->id)->first();
+				if($subscribe){
 					// 24小时内不同IP的请求次数
-					$request_times = UserSubscribeLog::query()->where('sid', $subscribe->id)->where('request_time', '>=', date("Y-m-d H:i:s", strtotime("-24 hours")))->distinct('request_ip')->count('request_ip');
+					$request_times = UserSubscribeLog::query()->where('sid', $subscribe->id)->where('request_time', '>=', date("Y-m-d H:i:s", strtotime("-24 hours")))->distinct()->count('request_ip');
 					if($request_times >= self::$systemConfig['subscribe_ban_times']){
 						UserSubscribe::query()->where('id', $subscribe->id)->update(['status' => 0, 'ban_time' => time(), 'ban_desc' => '存在异常,自动封禁']);
 
@@ -140,82 +136,33 @@ class AutoJob extends Command
 	// 封禁账号
 	private function blockUsers()
 	{
-		// 过期用户处理
-		$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('expire_time', '<', date('Y-m-d'))->get();
-		if(!$userList->isEmpty()){
-			foreach($userList as $user){
-				if(self::$systemConfig['is_ban_status']){
-					User::query()->where('id', $user->id)->update([
-						'u'                 => 0,
-						'd'                 => 0,
-						'transfer_enable'   => 0,
-						'enable'            => 0,
-						'traffic_reset_day' => 0,
-						'ban_time'          => 0,
-						'status'            => -1
-					]);
-
-					$this->addUserBanLog($user->id, 0, '【禁止登录,清空账户】-账号已过期');
-
-					// 如果注册就有初始流量,则废除其名下邀请码
-					if(self::$systemConfig['default_traffic']){
-						Invite::query()->where('uid', $user->id)->where('status', 0)->update(['status' => 2]);
-					}
-
-					// 写入用户流量变动记录
-					Helpers::addUserTrafficModifyLog($user->id, 0, $user->transfer_enable, 0, '[定时任务]账号已过期(禁止登录,清空账户)');
-				}else{
-					User::query()->where('id', $user->id)->update([
-						'u'                 => 0,
-						'd'                 => 0,
-						'transfer_enable'   => 0,
-						'enable'            => 0,
-						'traffic_reset_day' => 0,
-						'ban_time'          => 0
-					]);
-
-					$this->addUserBanLog($user->id, 0, '【封禁代理,清空账户】-账号已过期');
-
-					// 写入用户流量变动记录
-					Helpers::addUserTrafficModifyLog($user->id, 0, $user->transfer_enable, 0, '[定时任务]账号已过期(封禁代理,清空账户)');
-				}
-
-				// 移除标签
-				UserLabel::query()->where('user_id', $user->id)->delete();
-			}
-		}
-
 		// 封禁1小时内流量异常账号
 		if(self::$systemConfig['is_traffic_ban']){
-			$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('ban_time', 0)->get();
-			if(!$userList->isEmpty()){
-				foreach($userList as $user){
-					// 对管理员豁免
-					if($user->is_admin){
-						continue;
-					}
+			$userList = User::query()->where('enable', 1)->where('status', '>=', 0)->where('ban_time', 0)->get();
+			foreach($userList as $user){
+				// 对管理员豁免
+				if($user->is_admin){
+					continue;
+				}
 
-					// 多往前取5分钟,防止数据统计任务执行时间过长导致没有数据
-					$totalTraffic = UserTrafficHourly::query()->where('user_id', $user->id)->where('node_id', 0)->where('created_at', '>=', date('Y-m-d H:i:s', time()-3900))->sum('total');
-					if($totalTraffic >= (self::$systemConfig['traffic_ban_value']*1073741824)){
-						User::query()->where('id', $user->id)->update(['enable' => 0, 'ban_time' => strtotime(date('Y-m-d H:i:s', strtotime("+".self::$systemConfig['traffic_ban_time']." minutes")))]);
+				// 多往前取5分钟,防止数据统计任务执行时间过长导致没有数据
+				$totalTraffic = UserTrafficHourly::query()->where('user_id', $user->id)->where('node_id', 0)->where('created_at', '>=', date('Y-m-d H:i:s', time()-3900))->sum('total');
+				if($totalTraffic >= (self::$systemConfig['traffic_ban_value']*1073741824)){
+					User::query()->where('id', $user->id)->update(['enable' => 0, 'ban_time' => strtotime(date('Y-m-d H:i:s', strtotime("+".self::$systemConfig['traffic_ban_time']." minutes")))]);
 
-						// 写入日志
-						$this->addUserBanLog($user->id, self::$systemConfig['traffic_ban_time'], '【临时封禁代理】-1小时内流量异常');
-					}
+					// 写入日志
+					$this->addUserBanLog($user->id, self::$systemConfig['traffic_ban_time'], '【临时封禁代理】-1小时内流量异常');
 				}
 			}
 		}
 
 		// 禁用流量超限用户
-		$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('ban_time', 0)->whereRaw("u + d >= transfer_enable")->get();
-		if(!$userList->isEmpty()){
-			foreach($userList as $user){
-				User::query()->where('id', $user->id)->update(['enable' => 0]);
+		$userList = User::query()->where('enable', 1)->where('status', '>=', 0)->where('ban_time', 0)->whereRaw("u + d >= transfer_enable")->get();
+		foreach($userList as $user){
+			User::query()->where('id', $user->id)->update(['enable' => 0]);
 
-				// 写入日志
-				$this->addUserBanLog($user->id, 0, '【封禁代理】-流量已用完');
-			}
+			// 写入日志
+			$this->addUserBanLog($user->id, 0, '【封禁代理】-流量已用完');
 		}
 	}
 
@@ -223,7 +170,7 @@ class AutoJob extends Command
 	private function unblockUsers()
 	{
 		// 解封被临时封禁的账号
-		$userList = User::query()->where('status', '>=', 0)->where('enable', 0)->where('ban_time', '>', 0)->get();
+		$userList = User::query()->where('enable', 0)->where('status', '>=', 0)->where('ban_time', '>', 0)->get();
 		foreach($userList as $user){
 			if($user->ban_time < time()){
 				User::query()->where('id', $user->id)->update(['enable' => 1, 'ban_time' => 0]);
@@ -234,14 +181,12 @@ class AutoJob extends Command
 		}
 
 		// 可用流量大于已用流量也解封(比如:邀请返利自动加了流量)
-		$userList = User::query()->where('status', '>=', 0)->where('enable', 0)->where('ban_time', 0)->where('expire_time', '>=', date('Y-m-d'))->whereRaw("u + d < transfer_enable")->get();
-		if(!$userList->isEmpty()){
-			foreach($userList as $user){
-				User::query()->where('id', $user->id)->update(['enable' => 1]);
+		$userList = User::query()->where('enable', 0)->where('status', '>=', 0)->where('ban_time', 0)->where('expire_time', '>=', date('Y-m-d'))->whereRaw("u + d < transfer_enable")->get();
+		foreach($userList as $user){
+			User::query()->where('id', $user->id)->update(['enable' => 1]);
 
-				// 写入操作日志
-				$this->addUserBanLog($user->id, 0, '【自动解封】-有流量解封');
-			}
+			// 写入操作日志
+			$this->addUserBanLog($user->id, 0, '【自动解封】-有流量解封');
 		}
 	}
 
@@ -250,283 +195,18 @@ class AutoJob extends Command
 	{
 		if(self::$systemConfig['auto_release_port']){
 			## 自动分配端口
-			$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('port', 0)->get();
-			if(!$userList->isEmpty()){
-				foreach($userList as $user){
-					$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
+			$userList = User::query()->where('enable', 1)->where('status', '>=', 0)->where('port', 0)->get();
+			foreach($userList as $user){
+				$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
 
-					User::query()->where('id', $user->id)->update(['port' => $port]);
-				}
+				User::query()->where('id', $user->id)->update(['port' => $port]);
 			}
 
 			## 被封禁的账号自动释放端口
-			$userList = User::query()->where('status', -1)->where('enable', 0)->get();
-			if(!$userList->isEmpty()){
-				foreach($userList as $user){
-					if($user->port){
-						User::query()->where('id', $user->id)->update(['port' => 0]);
-					}
-				}
-			}
+			User::query()->where('enable', 0)->where('status', -1)->where('port', '!=', 0)->update(['port' => 0]);
 
 			## 过期一个月的账户自动释放端口
-			$userList = User::query()->where('enable', 0)->get();
-			if(!$userList->isEmpty()){
-				foreach($userList as $user){
-					if($user->port){
-						$overdueDays = floor((strtotime(date('Y-m-d H:i:s'))-strtotime($user->expire_time))/86400);
-						if($overdueDays > 30){
-							User::query()->where('id', $user->id)->update(['port' => 0]);
-						}
-					}
-				}
-			}
-		}
-	}
-
-	// 审计待支付的订单
-	private function detectOrders()
-	{
-		/*
-		 * 因为订单在15分钟未支付则会被自动关闭
-		 * 当有赞没有正常推送消息或者其他原因导致用户已付款但是订单不生效从而导致用户无法正常加流量、置状态
-		 * 故需要每分钟请求一次未支付订单,审计一下其支付状态
-		 */
-		$paymentList = Payment::query()->with(['order', 'user'])->where('status', 0)->where('qr_id', '>', 0)->get();
-		if(!$paymentList->isEmpty()){
-			foreach($paymentList as $payment){
-				// 跳过order丢失的订单
-				if(!isset($payment->order)){
-					continue;
-				}
-
-				$yzy = new yzy();
-				$trade = $yzy->getTradeByQrId($payment->qr_id);
-				if($trade['response']['total_results']){
-					// 再判断一遍当前要操作的订单的状态是否被改变了(可能请求延迟的时候已经回调处理完了)
-					$payment = Payment::query()->where('id', $payment->id)->first();
-					if($payment->status != '0'){
-						continue;
-					}
-
-					// 处理订单
-					DB::beginTransaction();
-					try{
-						// 如果支付单中没有用户信息则创建一个用户
-						if(!$payment->user_id){
-							// 生成一个可用端口
-							$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
-
-							$user = new User();
-							$user->username = '自动生成-'.$payment->order->email;
-							$user->password = md5(makeRandStr());
-							$user->port = $port;
-							$user->passwd = makeRandStr();
-							$user->vmess_id = createGuid();
-							$user->enable = 1;
-							$user->method = Helpers::getDefaultMethod();
-							$user->protocol = Helpers::getDefaultProtocol();
-							$user->obfs = Helpers::getDefaultObfs();
-							$user->usage = 1;
-							$user->transfer_enable = 1; // 新创建的账号给1,防止定时任务执行时发现u + d >= transfer_enable被判为流量超限而封禁
-							$user->enable_time = date('Y-m-d');
-							$user->expire_time = date('Y-m-d', strtotime("+".$payment->order->goods->days." days"));
-							$user->reg_ip = getClientIp();
-							$user->referral_uid = 0;
-							$user->traffic_reset_day = 0;
-							$user->status = 1;
-							$user->save();
-
-							if($user->id){
-								Order::query()->where('oid', $payment->oid)->update(['user_id' => $user->id]);
-							}
-						}
-
-						// 更新支付单
-						$payment->pay_way = $trade['response']['pay_type'] == 'WXPAY_BIGUNSIGN'? 1 : 2; // 1-微信、2-支付宝
-						$payment->status = 1;
-						$payment->save();
-
-						// 更新订单
-						$order = Order::query()->with(['user'])->where('oid', $payment->oid)->first();
-						$order->status = 2;
-						$order->save();
-
-						$goods = Goods::query()->where('id', $order->goods_id)->first();
-
-						// 商品为流量或者套餐
-						if($goods->type <= 2){
-							// 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
-							if($goods->type == 2){
-								$existOrderList = Order::query()
-									->with(['goods'])
-									->whereHas('goods', function($q){
-										$q->where('type', 2);
-									})
-									->where('user_id', $order->user_id)
-									->where('oid', '<>', $order->oid)
-									->where('is_expire', 0)
-									->where('status', 2)
-									->get();
-
-								foreach($existOrderList as $vo){
-									Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
-
-									// 先判断,防止手动扣减过流量的用户流量被扣成负数
-									if($order->user->transfer_enable-$vo->goods->traffic*1048576 <= 0){
-										// 写入用户流量变动记录
-										Helpers::addUserTrafficModifyLog($order->user_id, 0, $order->user->transfer_enable, 0, '[定时任务]审计待支付的订单(扣完)');
-
-										User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-									}else{
-										// 写入用户流量变动记录
-										Helpers::addUserTrafficModifyLog($order->user_id, 0, $order->user->transfer_enable, ($order->user->transfer_enable-$vo->goods->traffic*1048576), '[定时任务]审计待支付的订单');
-
-										User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
-										User::query()->where('id', $order->user_id)->decrement('transfer_enable', $vo->goods->traffic*1048576);
-									}
-								}
-							}
-
-							// 计算账号过期时间
-							if($order->user->expire_time < date('Y-m-d', strtotime("+".$goods->days." days"))){
-								$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
-							}else{
-								$expireTime = $order->user->expire_time;
-							}
-
-							// 把商品的流量加到账号上
-							User::query()->where('id', $order->user_id)->increment('transfer_enable', $goods->traffic*1048576);
-
-							// 套餐就改流量重置日,流量包不改
-							if($goods->type == 2){
-								User::query()->where('id', $order->user_id)->update(['traffic_reset_day' =>  date('d'), 'expire_time' => $expireTime, 'enable' => 1]);
-							}else{
-								User::query()->where('id', $order->user_id)->update(['expire_time' => $expireTime, 'enable' => 1]);
-							}
-
-							// 写入用户标签
-							if($goods->label){
-								// 用户默认标签
-								$defaultLabels = [];
-								if(self::$systemConfig['initial_labels_for_user']){
-									$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-								}
-
-								// 取出现有的标签
-								$userLabels = UserLabel::query()->where('user_id', $order->user_id)->pluck('label_id')->toArray();
-								$goodsLabels = GoodsLabel::query()->where('goods_id', $order->goods_id)->pluck('label_id')->toArray();
-
-								// 标签去重
-								$newUserLabels = array_values(array_unique(array_merge($userLabels, $goodsLabels, $defaultLabels)));
-
-								// 删除用户所有标签
-								UserLabel::query()->where('user_id', $order->user_id)->delete();
-
-								// 生成标签
-								foreach($newUserLabels as $vo){
-									$obj = new UserLabel();
-									$obj->user_id = $order->user_id;
-									$obj->label_id = $vo;
-									$obj->save();
-								}
-							}
-
-							// 写入返利日志
-							if($order->user->referral_uid){
-								$this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount*self::$systemConfig['referral_percent']);
-							}
-
-							// 取消重复返利
-							User::query()->where('id', $order->user_id)->update(['referral_uid' => 0]);
-
-						}elseif($goods->type == 3){ // 商品为在线充值
-							User::query()->where('id', $order->user_id)->increment('balance', $goods->price*100);
-
-							// 余额变动记录日志
-							$this->addUserBalanceLog($order->user_id, $order->oid, $order->user->balance, $order->user->balance+$goods->price, $goods->price, '用户在线充值');
-						}
-
-						// 自动提号机:如果order的email值不为空
-						if($order->email){
-							$title = '【'.self::$systemConfig['website_name'].'】您的账号信息';
-							$content = [
-								'order_sn'      => $order->order_sn,
-								'goods_name'    => $order->goods->name,
-								'goods_traffic' => flowAutoShow($order->goods->traffic*1048576),
-								'port'          => $order->user->port,
-								'passwd'        => $order->user->passwd,
-								'method'        => $order->user->method,
-								//'protocol'       => $order->user->protocol,
-								//'protocol_param' => $order->user->protocol_param,
-								//'obfs'           => $order->user->obfs,
-								//'obfs_param'     => $order->user->obfs_param,
-								'created_at'    => $order->created_at->toDateTimeString(),
-								'expire_at'     => $order->expire_at
-							];
-
-							// 获取可用节点列表
-							$labels = UserLabel::query()->where('user_id', $order->user_id)->get()->pluck('label_id');
-							$nodeIds = SsNodeLabel::query()->whereIn('label_id', $labels)->get()->pluck('node_id');
-							$nodeList = SsNode::query()->whereIn('id', $nodeIds)->orderBy('sort', 'desc')->orderBy('id', 'desc')->get()->toArray();
-							$content['serverList'] = $nodeList;
-
-							$logId = Helpers::addEmailLog($order->email, $title, json_encode($content));
-							Mail::to($order->email)->send(new sendUserInfo($logId, $content));
-						}
-
-						DB::commit();
-					} catch(Exception $e){
-						DB::rollBack();
-
-						Log::info('【有赞云】审计订单时更新支付单和订单异常:'.$e);
-					}
-				}
-			}
-		}
-	}
-
-	// 关闭超时未支付订单
-	private function closeOrders()
-	{
-		// 关闭超时未支付的有赞云订单(有赞云收款二维码超过30分钟自动关闭,关闭后无法再支付,所以我们限制15分钟内必须付款)
-		$paymentList = Payment::query()->with(['order', 'order.coupon'])->where('status', 0)->where('created_at', '<=', date("Y-m-d H:i:s", strtotime("-15 minutes")))->get();
-		if(!$paymentList->isEmpty()){
-			DB::beginTransaction();
-			try{
-				foreach($paymentList as $payment){
-					// 关闭支付单
-					Payment::query()->where('id', $payment->id)->update(['status' => -1]);
-
-					// 关闭订单
-					Order::query()->where('oid', $payment->oid)->update(['status' => -1]);
-
-					// 退回优惠券
-					if($payment->order->coupon_id){
-						Coupon::query()->where('id', $payment->order->coupon_id)->update(['status' => 0]);
-
-						Helpers::addCouponLog($payment->order->coupon_id, $payment->order->goods_id, $payment->oid, '订单超时未支付,自动退回');
-					}
-				}
-
-				DB::commit();
-			} catch(Exception $e){
-				Log::info('【异常】自动关闭超时未支付订单:'.$e);
-
-				DB::rollBack();
-			}
-		}
-	}
-
-	// 关闭超过72小时未处理的工单
-	private function closeTickets()
-	{
-		$ticketList = Ticket::query()->where('updated_at', '<=', date('Y-m-d H:i:s', strtotime("-72 hours")))->where('status', 1)->get();
-		foreach($ticketList as $ticket){
-			$ret = Ticket::query()->where('id', $ticket->id)->update(['status' => 2]);
-			if($ret){
-				ServerChan::send('工单关闭提醒', '工单:ID'.$ticket->id.'超过72小时未处理,系统已自动关闭');
-			}
+			User::query()->where('enable', 0)->where('port', '!=', 0)->where('expire_time', '<=', date("Y-m-d", strtotime("-30 days")))->update(['port' => 0]);
 		}
 	}
 
@@ -536,7 +216,7 @@ class AutoJob extends Command
 		if(Helpers::systemConfig()['is_node_crash_warning']){
 			$nodeList = SsNode::query()->where('is_transit', 0)->where('status', 1)->get();
 			foreach($nodeList as $node){
-				// 10分钟内无节点负载信息且TCP检测认为不是离线则认为是后端炸了
+				// 10分钟内无节点负载信息则认为是后端炸了
 				$nodeTTL = SsNodeInfo::query()->where('node_id', $node->id)->where('log_time', '>=', strtotime("-10 minutes"))->orderBy('id', 'desc')->first();
 				if(!$nodeTTL){
 					ServerChan::send('节点异常警告', "节点**{$node->name}【{$node->ip}】**异常:**心跳异常,可能离线了**");
@@ -560,54 +240,4 @@ class AutoJob extends Command
 		$log->desc = $desc;
 		$log->save();
 	}
-
-	/**
-	 * 添加返利日志
-	 *
-	 * @param int $userId    用户ID
-	 * @param int $refUserId 返利用户ID
-	 * @param int $oid       订单ID
-	 * @param int $amount    发生金额
-	 * @param int $refAmount 返利金额
-	 *
-	 * @return int
-	 */
-	public function addReferralLog($userId, $refUserId, $oid, $amount, $refAmount)
-	{
-		$log = new ReferralLog();
-		$log->user_id = $userId;
-		$log->ref_user_id = $refUserId;
-		$log->order_id = $oid;
-		$log->amount = $amount;
-		$log->ref_amount = $refAmount;
-		$log->status = 0;
-
-		return $log->save();
-	}
-
-	/**
-	 * 记录余额操作日志
-	 *
-	 * @param int    $userId 用户ID
-	 * @param string $oid    订单ID
-	 * @param int    $before 记录前余额
-	 * @param int    $after  记录后余额
-	 * @param int    $amount 发生金额
-	 * @param string $desc   描述
-	 *
-	 * @return int
-	 */
-	public function addUserBalanceLog($userId, $oid, $before, $after, $amount, $desc = '')
-	{
-		$log = new UserBalanceLog();
-		$log->user_id = $userId;
-		$log->order_id = $oid;
-		$log->before = $before;
-		$log->after = $after;
-		$log->amount = $amount;
-		$log->desc = $desc;
-		$log->created_at = date('Y-m-d H:i:s');
-
-		return $log->save();
-	}
 }

+ 0 - 80
app/Console/Commands/AutoResetUserTraffic.php

@@ -1,80 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Components\Helpers;
-use App\Http\Models\Order;
-use App\Http\Models\User;
-use Illuminate\Console\Command;
-use Log;
-
-class AutoResetUserTraffic extends Command
-{
-	protected $signature = 'autoResetUserTraffic';
-	protected $description = '自动重置用户可用流量';
-	protected static $systemConfig;
-
-	public function __construct()
-	{
-		parent::__construct();
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
-	public function handle()
-	{
-		$jobStartTime = microtime(TRUE);
-
-		// 重置用户流量
-		if(self::$systemConfig['reset_traffic']){
-			$this->resetUserTraffic();
-		}
-
-		$jobEndTime = microtime(TRUE);
-		$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
-
-		Log::info('执行定时任务【'.$this->description.'】,耗时'.$jobUsedTime.'秒');
-	}
-
-	// 重置用户流量
-	private function resetUserTraffic()
-	{
-		$userList = User::query()->where('status', '>=', 0)->where('expire_time', '>=', date('Y-m-d'))->get();
-		if(!$userList->isEmpty()){
-			foreach($userList as $user){
-				if(!$user->traffic_reset_day){
-					continue;
-				}
-
-				// 取出用户购买的有效套餐
-				$order = Order::query()
-					->with(['user', 'goods'])
-					->whereHas('goods', function($q){
-						$q->where('type', 2);
-					})
-					->where('user_id', $user->id)
-					->where('is_expire', 0)
-					->orderBy('oid', 'desc')
-					->first();
-
-				if(!$order){
-					continue;
-				}
-
-				$month = date('m');
-				$today = date('d');
-				$last_day = date('t');
-				$resetDay = $order->user->traffic_reset_day;
-				if($resetDay == $today || ($today == $last_day && $resetDay > $last_day)){
-					// 跳过本月,防止异常重置
-					if($month == date('m', strtotime($order->expire_at))){
-						continue;
-					}elseif($month == date('m', strtotime($order->created_at))){
-						continue;
-					}
-					// 重置流量
-					User::query()->where('id', $user->id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => $order->goods->traffic*1048576]);
-				}
-			}
-		}
-	}
-}

+ 172 - 0
app/Console/Commands/DailyJob.php

@@ -0,0 +1,172 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Components\Helpers;
+use App\Components\ServerChan;
+use App\Http\Models\Invite;
+use App\Http\Models\Order;
+use App\Http\Models\Ticket;
+use App\Http\Models\User;
+use App\Http\Models\UserBanLog;
+use App\Http\Models\UserLabel;
+use Illuminate\Console\Command;
+use Log;
+
+class DailyJob extends Command
+{
+	protected $signature = 'dailyJob';
+	protected $description = '每日任务';
+	protected static $systemConfig;
+
+	public function __construct()
+	{
+		parent::__construct();
+		self::$systemConfig = Helpers::systemConfig();
+	}
+
+	public function handle()
+	{
+		$jobStartTime = microtime(TRUE);
+
+		// 过期用户处理
+		$this->expireUser();
+
+		// 关闭超过72小时未处理的工单
+		$this->closeTickets();
+
+		// 重置用户流量
+		if(self::$systemConfig['reset_traffic']){
+			$this->resetUserTraffic();
+		}
+
+
+		$jobEndTime = microtime(TRUE);
+		$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
+
+		Log::info('【'.$this->description.'】执行定时任务,耗时'.$jobUsedTime.'秒');
+	}
+
+	private function expireUser()
+	{
+		// 过期用户处理
+		$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('expire_time', '<', date('Y-m-d'))->get();
+		foreach($userList as $user){
+			if(self::$systemConfig['is_ban_status']){
+				User::query()->where('id', $user->id)->update([
+					'u'               => 0,
+					'd'               => 0,
+					'transfer_enable' => 0,
+					'enable'          => 0,
+					'reset_time'      => NULL,
+					'ban_time'        => 0,
+					'status'          => -1
+				]);
+
+				$this->addUserBanLog($user->id, 0, '【禁止登录,清空账户】-账号已过期');
+
+				// 废除其名下邀请码
+				Invite::query()->where('uid', $user->id)->where('status', 0)->update(['status' => 2]);
+
+				// 写入用户流量变动记录
+				Helpers::addUserTrafficModifyLog($user->id, 0, $user->transfer_enable, 0, '[定时任务]账号已过期(禁止登录,清空账户)');
+			}else{
+				User::query()->where('id', $user->id)->update([
+					'u'               => 0,
+					'd'               => 0,
+					'transfer_enable' => 0,
+					'enable'          => 0,
+					'reset_time'      => NULL,
+					'ban_time'        => 0
+				]);
+
+				$this->addUserBanLog($user->id, 0, '【封禁代理,清空账户】-账号已过期');
+
+				// 写入用户流量变动记录
+				Helpers::addUserTrafficModifyLog($user->id, 0, $user->transfer_enable, 0, '[定时任务]账号已过期(封禁代理,清空账户)');
+			}
+
+			// 移除标签
+			UserLabel::query()->where('user_id', $user->id)->delete();
+		}
+	}
+
+	// 关闭超过72小时未处理的工单
+	private function closeTickets()
+	{
+		$ticketList = Ticket::query()->where('updated_at', '<=', date('Y-m-d', strtotime("-3 days")))->where('status', 1)->get();
+		foreach($ticketList as $ticket){
+			$ret = Ticket::query()->where('id', $ticket->id)->update(['status' => 2]);
+			if($ret){
+				ServerChan::send('工单关闭提醒', '工单:ID'.$ticket->id.'超过72小时未处理,系统已自动关闭');
+			}
+		}
+	}
+
+	// 重置用户流量
+	private function resetUserTraffic()
+	{
+		$userList = User::query()->where('status', '>=', 0)->where('expire_time', '>', date('Y-m-d'))->where('reset_time', '<=', date('Y-m-d'))->get();
+		foreach($userList as $user){
+			// 跳过 没有重置日期的账号
+			if(!$user->reset_time){
+				continue;
+			}
+
+			// 取出用户正在使用的套餐
+			$order = Order::query()
+				->with(['goods'])
+				->where('user_id', $user->id)
+				->where('status', 2)
+				->where('is_expire', 0)
+				->whereHas('goods', function($q){
+					$q->where('type', 2);
+				})
+				->first();
+
+			// 无订单的免费/特殊用户跳过
+			if(!$order){
+				continue;
+			}
+
+			// 过期生效中的加油包
+			Order::query()
+				->with(['goods'])
+				->where('user_id', $user->id)
+				->where('status', 2)
+				->where('is_expire', 0)
+				->whereHas('goods', function($q){
+					$q->where('type', 1);
+				})->update(['is_expire' => 1]);
+
+			//账号下一个重置时间
+			$nextResetTime = date('Y-m-d', strtotime("+".$order->goods->period." days"));
+			if($nextResetTime >= $user->expire_time){
+				$nextResetTime = NULL;
+			}
+			// 可用流量 变动日志
+			if($user->transfer_enable != $order->goods->traffic*1048576){
+				Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, $order->goods->traffic*1048576, '【流量重置】重置可用流量');
+			}
+			// 重置流量
+			User::query()->where('id', $user->id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => $order->goods->traffic*1048576, 'reset_time' => $nextResetTime]);
+			Log::info('用户[ID:'.$user->id.'  邮箱: '.$user->username.'] 流量重置为 '.($order->goods->traffic*1048576).'. 重置日期为 '.$nextResetTime? : '【无】');
+		}
+	}
+
+	/**
+	 * 添加用户封禁日志
+	 *
+	 * @param int    $userId  用户ID
+	 * @param int    $minutes 封禁时长,单位分钟
+	 * @param string $desc    封禁理由
+	 */
+	private function addUserBanLog($userId, $minutes, $desc)
+	{
+		$log = new UserBanLog();
+		$log->user_id = $userId;
+		$log->minutes = $minutes;
+		$log->desc = $desc;
+		$log->save();
+	}
+}

+ 38 - 143
app/Console/Commands/NodeBlockedDetection.php

@@ -8,14 +8,13 @@ use App\Http\Models\SsNode;
 use App\Mail\nodeCrashWarning;
 use Cache;
 use Exception;
-use GuzzleHttp\Exception\GuzzleException;
 use Illuminate\Console\Command;
 use Log;
 use Mail;
 
 class NodeBlockedDetection extends Command
 {
-	protected $signature = 'NodeBlockedDetection';
+	protected $signature = 'nodeBlockedDetection';
 	protected $description = '节点阻断检测';
 	protected static $systemConfig;
 
@@ -28,14 +27,13 @@ class NodeBlockedDetection extends Command
 	public function handle()
 	{
 		$jobStartTime = microtime(TRUE);
-
 		if(self::$systemConfig['nodes_detection']){
 			if(!Cache::has('LastCheckTime')){
 				$this->checkNodes();
 			}elseif(Cache::get('LastCheckTime') <= time()){
 				$this->checkNodes();
 			}else{
-				Log::info('下次节点TCP阻断检测时间:'.date('Y-m-d H:i:s', Cache::get('LastCheckTime')));
+				Log::info('下次节点阻断检测时间:'.date('Y-m-d H:i:s', Cache::get('LastCheckTime')));
 			}
 		}
 
@@ -48,9 +46,12 @@ class NodeBlockedDetection extends Command
 	// 监测节点状态
 	private function checkNodes()
 	{
-		$title = "节点异常警告";
 		$nodeList = SsNode::query()->where('is_transit', 0)->where('status', 1)->where('detectionType', '>', 0)->get();
 		foreach($nodeList as $node){
+			$title = "【{$node->name}】阻断警告";
+			if($node->detectionType == 0){
+				continue;
+			}
 			// 使用DDNS的node先通过gethostbyname获取ipv4地址
 			if($node->is_ddns){
 				$ip = gethostbyname($node->server);
@@ -61,58 +62,27 @@ class NodeBlockedDetection extends Command
 					$this->notifyMaster($title, "节点**{$node->name}**:** IP获取失败 **", $node->name, $node->server);
 				}
 			}
-			$text = '| 协议 | 状态 |'.PHP_EOL.'| ------ | ------ |'.PHP_EOL;
 			$sendText = FALSE;
-			if($node->detectionType == 1 || $node->detectionType == 3){
-				$tcpCheck = $this->tcpCheck($node->ip, $node->single? $node->port : NULL);
-				if($tcpCheck != FALSE){
-					$text .= '| TCP |';
-					switch($tcpCheck){
-						case 1:
-							$text .= ' 海外阻断 |'.PHP_EOL;
-							break;
-						case 2:
-							$text .= ' 国内阻断 |'.PHP_EOL;
-							break;
-						case 3:
-							$text .= ' 机器宕机 |'.PHP_EOL;
-							break;
-						case 0:
-							$text .= ' 检测正常 |'.PHP_EOL;
-							break;
-						default:
-							$text .= ' 未知 |'.PHP_EOL;
-					}
-					if($tcpCheck > 0){
+			$text = "| 协议 | 状态 |\r\n| :------ | :------ |\r\n";
+			if($node->detectionType != 1){
+				$icmpCheck = $this->networkCheck($node->ip, TRUE, FALSE);
+				if($icmpCheck != FALSE){
+					$text .= "| ICMP | ".$icmpCheck."|\r\n";
+					if($icmpCheck != '通讯正常'){
 						$sendText = TRUE;
 					}
 				}
 			}
-			if($node->detectionType == 2 || $node->detectionType == 3){
-				$icmpCheck = $this->icmpCheck($node->ip);
-				if($icmpCheck != FALSE){
-					$text .= '| ICMP |';
-					switch($icmpCheck){
-						case 1:
-							$text .= ' 海外阻断 |'.PHP_EOL;
-							break;
-						case 2:
-							$text .= ' 国内阻断 |'.PHP_EOL;
-							break;
-						case 3:
-							$text .= ' 机器宕机 |'.PHP_EOL;
-							break;
-						case 0:
-							$text .= ' 检测正常 |'.PHP_EOL;
-							break;
-						default:
-							$text .= ' 未知 |'.PHP_EOL;
-					}
-					if($icmpCheck > 0){
+			if($node->detectionType != 2){
+				$tcpCheck = $this->networkCheck($node->ip, FALSE, $node->single? $node->port : FALSE);
+				if($tcpCheck != FALSE){
+					$text .= "| TCP | ".$tcpCheck."|\r\n";
+					if($tcpCheck != '通讯正常'){
 						$sendText = TRUE;
 					}
 				}
 			}
+
 			// 异常才发通知消息
 			if($sendText){
 				if(self::$systemConfig['numberOfWarningTimes']){
@@ -127,18 +97,14 @@ class NodeBlockedDetection extends Command
 
 					if($times < self::$systemConfig['numberOfWarningTimes']){
 						Cache::increment($cacheKey);
-
-						$this->notifyMaster($title, "**{$node->name} - 【{$node->ip}】**:".PHP_EOL.$text, $node->name, $node->server);
-					}elseif($times >= self::$systemConfig['numberOfWarningTimes']){
+					}else{
 						Cache::forget($cacheKey);
 						SsNode::query()->where('id', $node->id)->update(['status' => 0]);
-
-						$this->notifyMaster($title, "**{$node->name} - 【{$node->ip}】**:".PHP_EOL.$text."节点自动进入维护状态".PHP_EOL, $node->name, $node->server);
+						$text .= "\r\n**节点自动进入维护状态**\r\n";
 					}
-				}else{
-					$this->notifyMaster($title, "**{$node->name} - 【{$node->ip}】**:".PHP_EOL.$text, $node->name, $node->server);
 				}
-				Log::info("【节点阻断检测】{$node->name} - 【{$node->ip}】: ".PHP_EOL.$text);
+				$this->notifyMaster($title, "**{$node->name} - 【{$node->ip}】**: \r\n\r\n".$text, $node->name, $node->server);
+				Log::info("【节点阻断检测】{$node->name} - 【{$node->ip}】: \r\n".$text);
 			}
 		}
 
@@ -150,81 +116,42 @@ class NodeBlockedDetection extends Command
 	/**
 	 * 用api.50network.com进行节点阻断检测
 	 *
-	 * @param string $ip   被检测的IP
-	 * @param int    $port 检测端口
+	 * @param string  $ip   被检测的IP
+	 * @param boolean $type true 为ICMP,false 为tcp
+	 * @param int     $port 检测端口
 	 *
-	 * @return bool|int
+	 * @return bool|string
 	 */
-	private function tcpCheck($ip, $port)
+	private function networkCheck($ip, $type, $port)
 	{
-		try{
-			if(isset($port)){
-				$url = 'https://api.50network.com/china-firewall/check/ip/tcp_port/'.$ip.'/'.$port;
-			}else{
-				$url = 'https://api.50network.com/china-firewall/check/ip/tcp_ack/'.$ip;
-			}
-			$ret = json_decode($this->curlRequest($url), TRUE);
-			if(!$ret){
-				Log::warning("【TCP阻断检测】检测".$ip."时,接口返回异常访问链接:");
-
-				return FALSE;
-			}elseif(!$ret['success']){
-				Log::warning("【TCP阻断检测】检测".$ip."时,返回".$ret->error);
-
-				return FALSE;
-			}
-		} catch(Exception $e){
-			Log::warning("【TCP阻断检测】检测".$ip."时,接口请求超时");
+		$url = 'https://api.50network.com/china-firewall/check/ip/'.($type? 'icmp/' : ($port? 'tcp_port/' : 'tcp_ack/')).$ip.($port? '/'.$port : '');
+		$checkName = $type? 'ICMP' : 'TCP';
 
-			return FALSE;
-		}
-
-		if($ret['firewall-enable'] && $ret['firewall-disable']){
-			return 0; // 正常
-		}elseif($ret['firewall-enable'] && !$ret['firewall-disable']){
-			return 1; // 国外访问异常
-		}elseif(!$ret['firewall-enable'] && $ret['firewall-disable']){
-			return 2; // 被墙
-		}else{
-			return 3; // 服务器宕机
-		}
-	}
-
-	/**
-	 * 用api.50network.com进行ICMP阻断检测
-	 *
-	 * @param string $ip 被检测的IP
-	 *
-	 * @return bool|int
-	 */
-	private function icmpCheck($ip)
-	{
 		try{
-			$url = 'https://api.50network.com/china-firewall/check/ip/icmp/'.$ip;
 			$ret = json_decode($this->curlRequest($url), TRUE);
 			if(!$ret){
-				Log::warning("【ICMP阻断检测】检测".$ip."时,接口返回异常访问链接:");
+				Log::warning("【".$checkName."阻断检测】检测".$ip."时,接口返回异常访问链接:");
 
 				return FALSE;
 			}elseif(!$ret['success']){
-				Log::warning("【ICMP阻断检测】检测".$ip."时,返回".$ret->error);
+				Log::warning("【".$checkName."阻断检测】检测".$ip."时,返回".json_encode($ret));
 
 				return FALSE;
 			}
 		} catch(Exception $e){
-			Log::warning("【ICMP阻断检测】检测".$ip."时,接口请求超时");
+			Log::warning("【".$checkName."阻断检测】检测".$ip."时,接口请求超时".$e);
 
 			return FALSE;
 		}
 
 		if($ret['firewall-enable'] && $ret['firewall-disable']){
-			return 0; // 正常
+			return '通讯正常'; // 正常
 		}elseif($ret['firewall-enable'] && !$ret['firewall-disable']){
-			return 1; // 国外访问异常
+			return '海外阻断'; // 国外访问异常
 		}elseif(!$ret['firewall-enable'] && $ret['firewall-disable']){
-			return 2; // 被墙
+			return '国内阻断'; // 被墙
 		}else{
-			return 3; // 服务器宕机
+			return '机器宕机'; // 服务器宕机
 		}
 	}
 
@@ -236,49 +163,17 @@ class NodeBlockedDetection extends Command
 	 * @param string $nodeName   节点名称
 	 * @param string $nodeServer 节点域名
 	 *
-	 * @throws GuzzleException
 	 */
 	private function notifyMaster($title, $content, $nodeName, $nodeServer)
-	{
-		$this->notifyMasterByEmail($title, $content, $nodeName, $nodeServer);
-		ServerChan::send($title, $content);
-	}
-
-	/**
-	 * 发邮件通知管理员
-	 *
-	 * @param string $title      消息标题
-	 * @param string $content    消息内容
-	 * @param string $nodeName   节点名称
-	 * @param string $nodeServer 节点域名
-	 */
-	private function notifyMasterByEmail($title, $content, $nodeName, $nodeServer)
 	{
 		if(self::$systemConfig['webmaster_email']){
 			$logId = Helpers::addEmailLog(self::$systemConfig['webmaster_email'], $title, $content);
 			Mail::to(self::$systemConfig['webmaster_email'])->send(new nodeCrashWarning($logId, $nodeName, $nodeServer));
 		}
+		ServerChan::send($title, $content);
 	}
 
-	/**
-	 * 发起一个CURL请求
-	 *
-	 * @param string $url  请求地址
-	 * @param array  $data POST数据,留空则为GET
-	 *
-	 * @return mixed
-	 */
-	private function curlRequest($url)
+	private function curlRequest(string $url)
 	{
-		$ch = curl_init();
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
-		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-		curl_setopt($ch, CURLOPT_URL, $url);
-		$result = curl_exec($ch);
-		curl_close($ch);
-
-		return $result;
 	}
 }

+ 89 - 0
app/Console/Commands/ServiceTimer.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Components\Callback;
+use App\Components\Helpers;
+use App\Http\Models\Order;
+use App\Http\Models\User;
+use App\Http\Models\UserLabel;
+use DB;
+use Exception;
+use Illuminate\Console\Command;
+use Log;
+
+class ServiceTimer extends Command
+{
+	use Callback;
+	protected $signature = 'serviceTimer';
+	protected $description = '服务计时器';
+	protected static $systemConfig;
+
+	public function __construct()
+	{
+		parent::__construct();
+		self::$systemConfig = Helpers::systemConfig();
+	}
+
+	public function handle()
+	{
+		$jobStartTime = microtime(TRUE);
+
+		// 扣减用户到期商品的流量
+		$this->decGoodsTraffic();
+
+		$jobEndTime = microtime(TRUE);
+		$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
+
+		Log::info('执行定时任务【'.$this->description.'】,耗时'.$jobUsedTime.'秒');
+	}
+
+	// 扣减用户到期商品的流量
+	private function decGoodsTraffic()
+	{
+		$orderList = Order::query()->with(['user', 'goods'])->where('status', 2)->where('is_expire', 0)->where('expire_at', '<=', date('Y-m-d H:i:s'))->get();
+		if($orderList->isNotEmpty()){
+			DB::beginTransaction();
+			try{
+				foreach($orderList as $order){
+					// 过期本订单
+					Order::query()->where('oid', $order->oid)->update(['is_expire' => 1]);
+
+					// 过期生效中的加油包
+					Order::query()
+						->with(['goods'])
+						->where('user_id', $order->user_id)
+						->where('status', 2)
+						->where('is_expire', 0)
+						->whereHas('goods', function($q){
+							$q->where('type', 1);
+						})->update(['is_expire' => 1]);
+
+					if(empty($order->user) || empty($order->goods)){
+						continue;
+					}
+
+					// 清理全部流量
+					Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $order->user->transfer_enable, 0, '[定时任务]用户所购商品到期,扣减商品对应的流量');
+					User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0, 'reset_time' => NULL]);
+
+					// 删除对应用户的所有标签
+					UserLabel::query()->where('user_id', $order->user_id)->delete();
+
+					// 检查该订单对应用户是否有预支付套餐
+					$prepaidOrder = Order::query()->where('user_id', $order->user_id)->where('status', 3)->orderBy('oid', 'asc')->first();
+
+					if($prepaidOrder){
+						$this->activePrepaidOrder($prepaidOrder->oid);
+					}
+				}
+
+				DB::commit();
+			} catch(Exception $e){
+				Log::error($this->description.':'.$e);
+
+				DB::rollBack();
+			}
+		}
+	}
+}

+ 0 - 55
app/Console/Commands/upgradeUserLabels.php

@@ -1,55 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Components\Helpers;
-use App\Http\Models\User;
-use App\Http\Models\UserLabel;
-use Illuminate\Console\Command;
-use Log;
-
-class upgradeUserLabels extends Command
-{
-	protected $signature = 'upgradeUserLabels';
-	protected $description = '初始化用户默认标签';
-	protected static $systemConfig;
-
-	public function __construct()
-	{
-		parent::__construct();
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
-	public function handle()
-	{
-		if(empty(self::$systemConfig['initial_labels_for_user'])){
-			Log::info('初始化用户默认标签失败:系统未设置默认标签');
-			exit();
-		}
-
-		$userList = User::query()->where('status', '>=', 0)->get();
-		foreach($userList as $user){
-			// 跳过已经有标签的用户
-			$count = UserLabel::query()->where('user_id', $user->id)->count();
-			if($count){
-				continue;
-			}
-
-			// 给用户生成默认标签
-			$this->makeUserDefaultLabels($user->id);
-		}
-	}
-
-	// 生成用户默认标签
-	private function makeUserDefaultLabels($userId)
-	{
-		$labels = explode(',', self::$systemConfig['initial_labels_for_user']);
-
-		foreach($labels as $vo){
-			$userLabel = new UserLabel();
-			$userLabel->user_id = $userId;
-			$userLabel->label_id = $vo;
-			$userLabel->save();
-		}
-	}
-}

+ 0 - 33
app/Console/Commands/upgradeUserPassword.php

@@ -1,33 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Http\Models\User;
-use Hash;
-use Illuminate\Console\Command;
-use Log;
-
-class upgradeUserPassword extends Command
-{
-	protected $signature = 'upgradeUserPassword';
-	protected $description = '用户密码升级(MD5->HASH)';
-
-	public function __construct()
-	{
-		parent::__construct();
-	}
-
-	public function handle()
-	{
-		Log::info('----------------------------【升级用户登录密码】开始----------------------------');
-
-		// 将用户的登录密码由原有的md5升级为hash,统一升级为与用户名相同的密码
-		$userList = User::query()->get();
-		foreach($userList as $user){
-			User::query()->where('id', $user->id)->update(['password' => Hash::make($user->username)]);
-			Log::info('----------------------------升级用户['.$user->username.']的登录密码----------------------------');
-		}
-
-		Log::info('----------------------------【升级用户登录密码】结束----------------------------');
-	}
-}

+ 64 - 0
app/Console/Commands/upgradeUserResetTime.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Http\Models\User;
+use Illuminate\Console\Command;
+use Log;
+
+class upgradeUserResetTime extends Command
+{
+	protected $signature = 'upgradeUserResetTime';
+	protected $description = '升级用户重置日期';
+
+	public function __construct()
+	{
+		parent::__construct();
+	}
+
+	public function handle()
+	{
+		Log::info('----------------------------【升级用户重置日期】开始----------------------------');
+
+		$userList = User::query()->get();
+		foreach($userList as $user){
+			$reset_time = NULL;
+			if($user->traffic_reset_day){
+				$today = date('d');// 今天 日期
+				$last_day = date('t'); //本月最后一天
+				$next_last_day = date('t', strtotime("+1 month"));//下个月最后一天
+				$resetDay = $user->traffic_reset_day;// 用户原本的重置日期
+				// 案例:31 29,重置日 大于 本月最后一天
+				if($resetDay > $last_day){
+					//往后推一个月
+					$resetDay = $resetDay-$last_day;
+					$reset_time = date('Y-m-'.$resetDay, strtotime("+1 month"));
+					//案例:20<30<31
+				}elseif($resetDay < $last_day && $resetDay > $today){
+					$reset_time = date('Y-m-'.$resetDay);
+					// 本日为重置日
+				}elseif($resetDay == $today){
+					$reset_time = date('Y-m-d', strtotime("+1 month"));
+					//本月已经重置过了
+				}elseif($resetDay < $today){
+					//类似第一种情况,向后推一月
+					if($resetDay > $next_last_day){
+						$resetDay = $resetDay-$next_last_day;
+						$reset_time = date('Y-m-'.$resetDay, strtotime("+1 month"));
+					}else{
+						$reset_time = date('Y-m-'.$resetDay, strtotime("+1 month"));
+					}
+				}
+				// 用户账号有效期大于重置日期
+				if($reset_time > $user->expire_time){
+					$reset_time = NULL;
+				}
+				User::query()->where('id', $user->id)->update(['reset_time' => $reset_time]);
+			}
+
+			Log::info('---用户[ID:'.$user->id.' - '.$user->username.']的新重置日期为'.($reset_time != NULL? '【'.$reset_time.'】': '【无】').'---');
+		}
+
+		Log::info('----------------------------【升级用户重置日期】结束----------------------------');
+	}
+}

+ 0 - 36
app/Console/Commands/upgradeUserSpeedLimit.php

@@ -1,36 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Http\Models\User;
-use Illuminate\Console\Command;
-use Log;
-
-class upgradeUserSpeedLimit extends Command
-{
-	protected $signature = 'upgradeUserSpeedLimit';
-	protected $description = '升级用户限速字段,重置初始值';
-
-	public function __construct()
-	{
-		parent::__construct();
-	}
-
-	public function handle()
-	{
-		Log::info('----------------------------【重置用户限速字段】开始----------------------------');
-
-		$userList = User::query()->get();
-		foreach($userList as $user){
-			$data = [
-				'speed_limit_per_con'  => 10737418240,
-				'speed_limit_per_user' => 10737418240
-			];
-
-			User::query()->where('id', $user->id)->update($data);
-			Log::info('---用户[ID:'.$user->id.' - '.$user->username.']的限速字段值被重置为10G---');
-		}
-
-		Log::info('----------------------------【重置用户限速字段】结束----------------------------');
-	}
-}

+ 0 - 42
app/Console/Commands/upgradeUserSubscribe.php

@@ -1,42 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Components\Helpers;
-use App\Http\Models\User;
-use App\Http\Models\UserSubscribe;
-use Illuminate\Console\Command;
-use Log;
-
-class upgradeUserSubscribe extends Command
-{
-	protected $signature = 'upgradeUserSubscribe';
-	protected $description = '生成用户的订阅码';
-
-	public function __construct()
-	{
-		parent::__construct();
-	}
-
-	public function handle()
-	{
-		Log::info('----------------------------【生成用户订阅码】开始----------------------------');
-
-		$userList = User::query()->get();
-		foreach($userList as $user){
-			// 如果未生成过订阅码则生成一个
-			$subscribe = UserSubscribe::query()->where('user_id', $user->id)->first();
-			if(!$subscribe){
-				$subscribe = new UserSubscribe();
-				$subscribe->user_id = $user->id;
-				$subscribe->code = Helpers::makeSubscribeCode();
-				$subscribe->times = 0;
-				$subscribe->save();
-
-				Log::info('---生成用户[ID:'.$user->id.' - '.$user->username.']的订阅码---');
-			}
-		}
-
-		Log::info('----------------------------【生成用户订阅码】结束----------------------------');
-	}
-}

+ 0 - 33
app/Console/Commands/upgradeUserVmessId.php

@@ -1,33 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Http\Models\User;
-use Illuminate\Console\Command;
-use Log;
-
-class upgradeUserVmessId extends Command
-{
-	protected $signature = 'upgradeUserVmessId';
-	protected $description = '重新生成用户的vmess_id字段';
-
-	public function __construct()
-	{
-		parent::__construct();
-	}
-
-	public function handle()
-	{
-		$userList = User::query()->get();
-		foreach($userList as $user){
-			if(!isset($user->vmess_id)){
-				Log::error("USER表缺失vmess_id字段,请先维护数据库字典");
-				break;
-			}
-
-			if(!$user->vmess_id){
-				User::query()->where('id', $user->id)->update(['vmess_id' => createGuid()]);
-			}
-		}
-	}
-}

+ 18 - 26
app/Console/Kernel.php

@@ -2,21 +2,17 @@
 
 namespace App\Console;
 
-use App\Console\Commands\NodeBlockedDetection;
 use App\Console\Commands\AutoClearLog;
-use App\Console\Commands\AutoDecGoodsTraffic;
 use App\Console\Commands\AutoJob;
 use App\Console\Commands\AutoReportNode;
-use App\Console\Commands\AutoResetUserTraffic;
 use App\Console\Commands\AutoStatisticsNodeDailyTraffic;
 use App\Console\Commands\AutoStatisticsNodeHourlyTraffic;
 use App\Console\Commands\AutoStatisticsUserDailyTraffic;
 use App\Console\Commands\AutoStatisticsUserHourlyTraffic;
-use App\Console\Commands\upgradeUserLabels;
-use App\Console\Commands\upgradeUserPassword;
-use App\Console\Commands\upgradeUserSpeedLimit;
-use App\Console\Commands\upgradeUserSubscribe;
-use App\Console\Commands\upgradeUserVmessId;
+use App\Console\Commands\DailyJob;
+use App\Console\Commands\NodeBlockedDetection;
+use App\Console\Commands\ServiceTimer;
+use App\Console\Commands\upgradeUserResetTime;
 use App\Console\Commands\UserExpireAutoWarning;
 use App\Console\Commands\UserTrafficAbnormalAutoWarning;
 use App\Console\Commands\UserTrafficAutoWarning;
@@ -31,24 +27,20 @@ class Kernel extends ConsoleKernel
 	 * @var array
 	 */
 	protected $commands = [
-		AutoJob::class,
 		AutoClearLog::class,
-		AutoDecGoodsTraffic::class,
-		AutoResetUserTraffic::class,
-		NodeBlockedDetection::class,
+		AutoJob::class,
+		AutoReportNode::class,
 		AutoStatisticsNodeDailyTraffic::class,
 		AutoStatisticsNodeHourlyTraffic::class,
 		AutoStatisticsUserDailyTraffic::class,
 		AutoStatisticsUserHourlyTraffic::class,
-		UserTrafficAbnormalAutoWarning::class,
+		DailyJob::class,
+		NodeBlockedDetection::class,
+		ServiceTimer::class,
+		upgradeUserResetTime::class,
 		UserExpireAutoWarning::class,
+		UserTrafficAbnormalAutoWarning::class,
 		UserTrafficAutoWarning::class,
-		upgradeUserLabels::class,
-		upgradeUserPassword::class,
-		upgradeUserSpeedLimit::class,
-		upgradeUserSubscribe::class,
-		upgradeUserVmessId::class,
-		AutoReportNode::class,
 	];
 
 	/**
@@ -61,18 +53,18 @@ class Kernel extends ConsoleKernel
 	protected function schedule(Schedule $schedule)
 	{
 		$schedule->command('autoJob')->everyMinute();
+		$schedule->command('serviceTimer')->everyTenMinutes();
 		$schedule->command('autoClearLog')->everyThirtyMinutes();
-		$schedule->command('autoDecGoodsTraffic')->everyTenMinutes();
-		$schedule->command('autoResetUserTraffic')->daily();
-		$schedule->command('NodeBlockedDetection')->everyThirtyMinutes();
-		$schedule->command('autoStatisticsNodeDailyTraffic')->dailyAt('23:55');
+		$schedule->command('nodeBlockedDetection')->everyThirtyMinutes();
 		$schedule->command('autoStatisticsNodeHourlyTraffic')->hourly();
-		$schedule->command('autoStatisticsUserDailyTraffic')->dailyAt('23:50');
 		$schedule->command('autoStatisticsUserHourlyTraffic')->hourly();
 		$schedule->command('userTrafficAbnormalAutoWarning')->hourly();
-		$schedule->command('userExpireAutoWarning')->dailyAt('20:00');
-		$schedule->command('userTrafficAutoWarning')->dailyAt('10:30');
+		$schedule->command('dailyJob')->daily();
 		$schedule->command('autoReportNode')->dailyAt('09:00');
+		$schedule->command('userTrafficAutoWarning')->dailyAt('10:30');
+		$schedule->command('userExpireAutoWarning')->dailyAt('20:00');
+		$schedule->command('autoStatisticsUserDailyTraffic')->dailyAt('23:50');
+		$schedule->command('autoStatisticsNodeDailyTraffic')->dailyAt('23:55');
 	}
 
 	/**

+ 21 - 74
app/Http/Controllers/AdminController.php

@@ -36,7 +36,6 @@ use App\Http\Models\UserTrafficHourly;
 use App\Http\Models\UserTrafficLog;
 use App\Http\Models\UserTrafficModifyLog;
 use Auth;
-use Cache;
 use DB;
 use Exception;
 use Hash;
@@ -89,20 +88,15 @@ class AdminController extends Controller
 			}
 		}
 		$view['flowAbnormalUserCount'] = User::query()->whereIn('id', $tempUsers)->count();
-
-
 		$view['nodeCount'] = SsNode::query()->count();
 		$view['unnormalNodeCount'] = SsNode::query()->where('status', 0)->count();
-
 		$flowCount = SsNodeTrafficDaily::query()->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime("-30 days")))->sum('total');
 		$view['flowCount'] = flowAutoShow($flowCount);
 		$totalFlowCount = SsNodeTrafficDaily::query()->sum('total');
 		$view['totalFlowCount'] = flowAutoShow($totalFlowCount);
-
 		$view['totalBalance'] = User::query()->sum('balance')/100;
 		$view['totalWaitRefAmount'] = ReferralLog::query()->whereIn('status', [0, 1])->sum('ref_amount')/100;
 		$view['totalRefAmount'] = ReferralApply::query()->where('status', 2)->sum('amount')/100;
-
 		$view['totalOrder'] = Order::query()->count();
 		$view['totalOnlinePayOrder'] = Order::query()->where('pay_way', 2)->count();
 		$view['totalSuccessOrder'] = Order::query()->where('status', 2)->count();
@@ -168,7 +162,7 @@ class AdminController extends Controller
 
 		// 临近过期提醒
 		if($expireWarning){
-			$query->where('expire_time', '>=', date('Y-m-d', strtotime("now")))->where('expire_time', '<=', date('Y-m-d', strtotime("+".self::$systemConfig['expire_days']." days")));
+			$query->where('expire_time', '>=', date('Y-m-d'))->where('expire_time', '<=', date('Y-m-d', strtotime("+".self::$systemConfig['expire_days']." days")));
 		}
 
 		// 当前在线
@@ -199,11 +193,11 @@ class AdminController extends Controller
 		foreach($userList as $user){
 			$user->transfer_enable = flowAutoShow($user->transfer_enable);
 			$user->used_flow = flowAutoShow($user->u+$user->d);
-			if($user->expire_time < date('Y-m-d', strtotime("now"))){
+			if($user->expire_time < date('Y-m-d')){
 				$user->expireWarning = -1; // 已过期
-			}elseif($user->expire_time == date('Y-m-d', strtotime("now"))){
+			}elseif($user->expire_time == date('Y-m-d')){
 				$user->expireWarning = 0; // 今天过期
-			}elseif($user->expire_time > date('Y-m-d', strtotime("now")) && $user->expire_time <= date('Y-m-d', strtotime("+30 days"))){
+			}elseif($user->expire_time > date('Y-m-d') && $user->expire_time <= date('Y-m-d', strtotime("+30 days"))){
 				$user->expireWarning = 1; // 最近一个月过期
 			}else{
 				$user->expireWarning = 2; // 大于一个月过期
@@ -264,7 +258,7 @@ class AdminController extends Controller
 			$user->is_admin = 0;
 			$user->reg_ip = getClientIp();
 			$user->referral_uid = 0;
-			$user->traffic_reset_day = 0;
+			$user->reset_time = $request->input('reset_time') > date('Y-m-d')? $request->input('reset_time') : NULL;
 			$user->status = $request->input('status')? : 1;
 			$user->save();
 
@@ -303,39 +297,17 @@ class AdminController extends Controller
 	// 批量生成账号
 	public function batchAddUsers(Request $request)
 	{
+		$amount = $request->input('amount');
 		DB::beginTransaction();
 		try{
-			for($i = 0; $i < 5; $i++){
+			for($i = 0; $i < $amount; $i++){
+				$uid = Helpers::addUser('批量生成-'.makeRandStr(), Hash::make(makeRandStr()), toGB(1024), 365);
 				// 生成一个可用端口
-				$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
-
-				$user = new User();
-				$user->username = '批量生成-'.makeRandStr();
-				$user->password = Hash::make(makeRandStr());
-				$user->port = $port;
-				$user->passwd = makeRandStr();
-				$user->vmess_id = createGuid();
-				$user->enable = 1;
-				$user->method = Helpers::getDefaultMethod();
-				$user->protocol = Helpers::getDefaultProtocol();
-				$user->protocol_param = '';
-				$user->obfs = Helpers::getDefaultObfs();
-				$user->obfs_param = '';
-				$user->usage = 1;
-				$user->transfer_enable = toGB(1024);
-				$user->enable_time = date('Y-m-d');
-				$user->expire_time = date('Y-m-d', strtotime("+365 days"));
-				$user->remark = '';
-				$user->reg_ip = getClientIp();
-				$user->referral_uid = 0;
-				$user->traffic_reset_day = 0;
-				$user->status = 1;
-				$user->save();
-
-				if($user->id){
+
+				if($uid){
 					// 生成订阅码
 					$subscribe = new UserSubscribe();
-					$subscribe->user_id = $user->id;
+					$subscribe->user_id = $uid;
 					$subscribe->code = Helpers::makeSubscribeCode();
 					$subscribe->times = 0;
 					$subscribe->save();
@@ -343,11 +315,11 @@ class AdminController extends Controller
 					// 初始化默认标签
 					if(!empty(self::$systemConfig['initial_labels_for_user'])){
 						$labels = explode(',', self::$systemConfig['initial_labels_for_user']);
-						$this->makeUserLabels($user->id, $labels);
+						$this->makeUserLabels($uid, $labels);
 					}
 
 					// 写入用户流量变动记录
-					Helpers::addUserTrafficModifyLog($user->id, 0, 0, toGB(1024), '后台批量生成用户');
+					Helpers::addUserTrafficModifyLog($uid, 0, 0, toGB(1024), '后台批量生成用户');
 				}
 			}
 
@@ -390,6 +362,7 @@ class AdminController extends Controller
 			$remark = str_replace("eval", "", str_replace("atob", "", $request->input('remark')));
 			$level = $request->input('level');
 			$is_admin = $request->input('is_admin');
+			$reset_time = $request->input('reset_time');
 
 			// 校验username是否已存在
 			$exists = User::query()->where('id', '<>', $id)->where('username', $username)->first();
@@ -408,7 +381,7 @@ class AdminController extends Controller
 				return Response::json(['status' => 'fail', 'data' => '', 'message' => '系统默认管理员不可取消']);
 			}
 
-			if(!$request->input('usage')){
+			if(!$usage){
 				return Response::json(['status' => 'fail', 'data' => '', 'message' => '请至少选择一种用途']);
 			}
 
@@ -419,7 +392,8 @@ class AdminController extends Controller
 			try{
 				$data = [
 					'username'             => $username,
-					'port'                 => $port, 'passwd' => $passwd,
+					'port'                 => $port,
+					'passwd'               => $passwd,
 					'vmess_id'             => $vmess_id,
 					'transfer_enable'      => toGB($transfer_enable),
 					'enable'               => $status < 0? 0 : $enable,
@@ -435,6 +409,7 @@ class AdminController extends Controller
 					'usage'                => $usage,
 					'pay_way'              => $pay_way,
 					'status'               => $status,
+					'reset_time'           => empty($reset_time)? NULL : $reset_time,
 					'enable_time'          => empty($enable_time)? date('Y-m-d') : $enable_time,
 					'expire_time'          => empty($expire_time)? date('Y-m-d', strtotime("+365 days")) : $expire_time,
 					'remark'               => $remark,
@@ -1969,56 +1944,28 @@ EOF;
 
 		// 演示环境禁止修改特定配置项
 		if(env('APP_DEMO')){
-			$denyConfig = ['website_url', 'min_rand_traffic', 'max_rand_traffic', 'push_bear_send_key', 'push_bear_qrcode', 'youzan_client_id', 'youzan_client_secret', 'kdt_id', 'is_forbid_china', 'alipay_partner', 'alipay_key', 'alipay_transport', 'alipay_sign_type', 'alipay_private_key', 'alipay_public_key', 'website_security_code'];
+			$denyConfig = ['website_url', 'min_rand_traffic', 'max_rand_traffic', 'push_bear_send_key', 'push_bear_qrcode', 'is_forbid_china', 'alipay_partner', 'alipay_key', 'alipay_transport', 'alipay_sign_type', 'alipay_private_key', 'alipay_public_key', 'website_security_code'];
 
 			if(in_array($name, $denyConfig)){
 				return Response::json(['status' => 'fail', 'data' => '', 'message' => '演示环境禁止修改该配置']);
 			}
 		}
 
-		// 如果更改了有赞云任何一个配置,则删除有赞云的授权缓存,防止出现client_id错误
-		if(in_array($name, ['youzan_client_id', 'youzan_client_secret', 'kdt_id'])){
-			Cache::forget('YZY_TOKEN');
-		}
-
 		// 如果是返利比例,则需要除100
 		if(in_array($name, ['referral_percent'])){
 			$value = intval($value)/100;
 		}
 
-		// 用有赞云支付则不可用支付宝国际和支付宝当面付
-		if(in_array($name, ['is_youzan'])){
-			$is_alipay = Config::query()->where('name', 'is_alipay')->first();
-			if($is_alipay->value){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【支付宝国际支付】']);
-			}
-
-			$is_f2fpay = Config::query()->where('name', 'is_f2fpay')->first();
-			if($is_f2fpay->value){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【支付宝当面付】']);
-			}
-		}
-
-		// 用支付国际则不可用有赞云支付和支付宝当面付
+		// 用支付国际则不可用支付宝当面付
 		if(in_array($name, ['is_alipay'])){
-			$is_youzan = Config::query()->where('name', 'is_youzan')->first();
-			if($is_youzan->value){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【有赞云支付】']);
-			}
-
 			$is_f2fpay = Config::query()->where('name', 'is_f2fpay')->first();
 			if($is_f2fpay->value){
 				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【支付宝当面付】']);
 			}
 		}
 
-		// 用支付宝当面则不可用有赞云支付和支付宝国际
+		// 用支付宝当面则不可用支付宝国际
 		if(in_array($name, ['is_f2fpay'])){
-			$is_youzan = Config::query()->where('name', 'is_youzan')->first();
-			if($is_youzan->value){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【有赞云支付】']);
-			}
-
 			$is_alipay = Config::query()->where('name', 'is_alipay')->first();
 			if($is_alipay->value){
 				return Response::json(['status' => 'fail', 'data' => '', 'message' => '已经在使用【支付宝国际支付】']);

+ 5 - 218
app/Http/Controllers/Api/AlipayController.php

@@ -3,23 +3,10 @@
 namespace App\Http\Controllers\Api;
 
 use App\Components\AlipayNotify;
-use App\Components\Helpers;
+use App\Components\Callback;
 use App\Http\Controllers\Controller;
-use App\Http\Models\Goods;
-use App\Http\Models\GoodsLabel;
-use App\Http\Models\Order;
-use App\Http\Models\Payment;
-use App\Http\Models\SsNode;
-use App\Http\Models\SsNodeLabel;
-use App\Http\Models\User;
-use App\Http\Models\UserLabel;
-use App\Mail\sendUserInfo;
-use DB;
-use Exception;
-use Hash;
 use Illuminate\Http\Request;
 use Log;
-use Mail;
 
 /**
  * Class AlipayController
@@ -30,12 +17,7 @@ use Mail;
  */
 class AlipayController extends Controller
 {
-	protected static $systemConfig;
-
-	function __construct()
-	{
-		self::$systemConfig = Helpers::systemConfig();
-	}
+	use Callback;
 
 	// 接收GET请求
 	public function index(Request $request)
@@ -67,210 +49,15 @@ class AlipayController extends Controller
 				// 交易金额(这里是按照结算货币汇率的金额,和rmb_fee不相等)
 				$data['total_fee'] = $request->input('total_fee');
 
-				$this->tradePaid($data);
+				$this->tradePaid($data, 4);
 			}else{
-				Log::info('AliPay-POST:交易失败['.getClientIp().']');
+				Log::info('支付宝国际-POST:交易失败['.getClientIp().']');
 			}
 		}else{
-			Log::info('AliPay-POST:验证失败['.getClientIp().']');
+			Log::info('支付宝国际-POST:验证失败['.getClientIp().']');
 		}
 
 		// 返回验证结果
 		exit($result);
 	}
-
-	// 交易支付
-	private function tradePaid($msg)
-	{
-		Log::info('【支付宝国际】回调交易支付');
-
-		// 获取未完成状态的订单防止重复增加时间
-		$payment = Payment::query()->with(['order', 'order.goods'])->where('status', 0)->where('order_sn', $msg['out_trade_no'])->first();
-		if(!$payment){
-			Log::info('【支付宝国际】回调订单不存在');
-
-			return;
-		}
-
-		// 处理订单
-		DB::beginTransaction();
-		try{
-			// 如果支付单中没有用户信息则创建一个用户
-			if(!$payment->user_id){
-				// 生成一个可用端口
-				$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
-
-				$user = new User();
-				$user->username = '自动生成-'.$payment->order->email;
-				$user->password = Hash::make(makeRandStr());
-				$user->port = $port;
-				$user->passwd = makeRandStr();
-				$user->vmess_id = createGuid();
-				$user->enable = 1;
-				$user->method = Helpers::getDefaultMethod();
-				$user->protocol = Helpers::getDefaultProtocol();
-				$user->obfs = Helpers::getDefaultObfs();
-				$user->usage = 1;
-				$user->transfer_enable = 1; // 新创建的账号给1,防止定时任务执行时发现u + d >= transfer_enable被判为流量超限而封禁
-				$user->enable_time = date('Y-m-d');
-				$user->expire_time = date('Y-m-d', strtotime("+".$payment->order->goods->days." days"));
-				$user->reg_ip = getClientIp();
-				$user->referral_uid = 0;
-				$user->traffic_reset_day = 0;
-				$user->status = 1;
-				$user->save();
-
-				if($user->id){
-					Order::query()->where('oid', $payment->oid)->update(['user_id' => $user->id]);
-				}
-			}
-
-			// 更新支付单
-			$payment->pay_way = 2; // 1-微信、2-支付宝
-			$payment->status = 1;
-			$payment->save();
-
-			// 更新订单
-			$order = Order::query()->with(['user'])->where('oid', $payment->oid)->first();
-			$order->status = 2;
-			$order->save();
-
-			$goods = Goods::query()->where('id', $order->goods_id)->first();
-
-			// 商品为流量或者套餐
-			if($goods->type <= 2){
-				// 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
-				if($goods->type == 2){
-					$existOrderList = Order::query()
-						->with(['goods'])
-						->whereHas('goods', function($q){
-							$q->where('type', 2);
-						})
-						->where('user_id', $order->user_id)
-						->where('oid', '<>', $order->oid)
-						->where('is_expire', 0)
-						->where('status', 2)
-						->get();
-
-					foreach($existOrderList as $vo){
-						Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
-
-						// 先判断,防止手动扣减过流量的用户流量被扣成负数
-						if($order->user->transfer_enable-$vo->goods->traffic*1048576 <= 0){
-							// 写入用户流量变动记录
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, 0, 0, '[在线支付]用户购买套餐,先扣减之前套餐的流量(扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-						}else{
-							// 写入用户流量变动记录
-							$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable-$vo->goods->traffic*1048576), '[在线支付]用户购买套餐,先扣减之前套餐的流量(未扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
-							User::query()->where('id', $order->user_id)->decrement('transfer_enable', $vo->goods->traffic*1048576);
-						}
-					}
-				}
-
-				// 写入用户流量变动记录
-				$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-				Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable+$goods->traffic*1048576), '[在线支付]用户购买商品,加上流量');
-
-				// 把商品的流量加到账号上
-				User::query()->where('id', $order->user_id)->increment('transfer_enable', $goods->traffic*1048576);
-
-				// 计算账号过期时间
-				if($order->user->expire_time < date('Y-m-d', strtotime("+".$goods->days." days"))){
-					$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
-				}else{
-					$expireTime = $order->user->expire_time;
-				}
-
-				// 套餐就改流量重置日,流量包不改
-				if($goods->type == 2){
-					User::query()->where('id', $order->user_id)->update(['traffic_reset_day' =>  date('d'), 'expire_time' => $expireTime, 'enable' => 1]);
-				}else{
-					User::query()->where('id', $order->user_id)->update(['expire_time' => $expireTime, 'enable' => 1]);
-				}
-
-				// 写入用户标签
-				if($goods->label){
-					// 用户默认标签
-					$defaultLabels = [];
-					if(self::$systemConfig['initial_labels_for_user']){
-						$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-					}
-
-					// 取出现有的标签
-					$userLabels = UserLabel::query()->where('user_id', $order->user_id)->pluck('label_id')->toArray();
-					$goodsLabels = GoodsLabel::query()->where('goods_id', $order->goods_id)->pluck('label_id')->toArray();
-
-					// 标签去重
-					$newUserLabels = array_values(array_unique(array_merge($userLabels, $goodsLabels, $defaultLabels)));
-
-					// 删除用户所有标签
-					UserLabel::query()->where('user_id', $order->user_id)->delete();
-
-					// 生成标签
-					foreach($newUserLabels as $vo){
-						$obj = new UserLabel();
-						$obj->user_id = $order->user_id;
-						$obj->label_id = $vo;
-						$obj->save();
-					}
-				}
-
-				// 写入返利日志
-				if($order->user->referral_uid){
-					$this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount*self::$systemConfig['referral_percent']);
-				}
-
-				// 取消重复返利
-				User::query()->where('id', $order->user_id)->update(['referral_uid' => 0]);
-			}elseif($goods->type == 3){ // 商品为在线充值
-				User::query()->where('id', $order->user_id)->increment('balance', $goods->price*100);
-
-				// 余额变动记录日志
-				$this->addUserBalanceLog($order->user_id, $order->oid, $order->user->balance, $order->user->balance+$goods->price, $goods->price, '用户在线充值');
-			}
-
-			// 自动提号机:如果order的email值不为空
-			if($order->email){
-				$title = '自动发送账号信息';
-				$content = [
-					'order_sn'      => $order->order_sn,
-					'goods_name'    => $order->goods->name,
-					'goods_traffic' => flowAutoShow($order->goods->traffic*1048576),
-					'port'          => $order->user->port,
-					'passwd'        => $order->user->passwd,
-					'method'        => $order->user->method,
-					//'protocol'       => $order->user->protocol,
-					//'protocol_param' => $order->user->protocol_param,
-					//'obfs'           => $order->user->obfs,
-					//'obfs_param'     => $order->user->obfs_param,
-					'created_at'    => $order->created_at->toDateTimeString(),
-					'expire_at'     => $order->expire_at
-				];
-
-				// 获取可用节点列表
-				$labels = UserLabel::query()->where('user_id', $order->user_id)->get()->pluck('label_id');
-				$nodeIds = SsNodeLabel::query()->whereIn('label_id', $labels)->get()->pluck('node_id');
-				$nodeList = SsNode::query()->whereIn('id', $nodeIds)->orderBy('sort', 'desc')->orderBy('id', 'desc')->get()->toArray();
-				$content['serverList'] = $nodeList;
-
-				$logId = Helpers::addEmailLog($order->email, $title, json_encode($content));
-				Mail::to($order->email)->send(new sendUserInfo($logId, $content));
-			}
-
-			DB::commit();
-		} catch(Exception $e){
-			DB::rollBack();
-			Log::info('【支付宝国际】回调更新支付单和订单异常:'.$e->getMessage());
-		}
-	}
-
-	public function show(Request $request)
-	{
-		exit('show');
-	}
 }

+ 3 - 217
app/Http/Controllers/Api/F2fpayController.php

@@ -2,23 +2,10 @@
 
 namespace App\Http\Controllers\Api;
 
-use App\Components\Helpers;
+use App\Components\Callback;
 use App\Http\Controllers\Controller;
-use App\Http\Models\Goods;
-use App\Http\Models\GoodsLabel;
-use App\Http\Models\Order;
-use App\Http\Models\Payment;
-use App\Http\Models\SsNode;
-use App\Http\Models\SsNodeLabel;
-use App\Http\Models\User;
-use App\Http\Models\UserLabel;
-use App\Mail\sendUserInfo;
-use DB;
-use Exception;
-use Hash;
 use Illuminate\Http\Request;
 use Log;
-use Mail;
 use Payment\Client\Query;
 use Payment\Common\PayException;
 
@@ -31,13 +18,7 @@ use Payment\Common\PayException;
  */
 class F2fpayController extends Controller
 {
-	protected static $systemConfig;
-
-	function __construct()
-	{
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
+	use Callback;
 	// 接收GET请求
 	public function index(Request $request)
 	{
@@ -87,7 +68,7 @@ class F2fpayController extends Controller
 				// 交易金额(这里是按照结算货币汇率的金额,和rmb_fee不相等)
 				$data['total_amount'] = $request->input('total_amount');
 
-				$this->tradePaid($data);
+				$this->tradePaid($data, 5);
 			}else{
 				Log::info('支付宝当面付-POST:交易失败['.getClientIp().']');
 			}
@@ -98,199 +79,4 @@ class F2fpayController extends Controller
 		// 返回验证结果
 		exit($result);
 	}
-
-	// 交易支付
-	private function tradePaid($msg)
-	{
-		Log::info('【支付宝当面付】回调交易支付');
-
-		// 获取未完成状态的订单防止重复增加时间
-		$payment = Payment::query()->with(['order', 'order.goods'])->where('status', 0)->where('order_sn', $msg['out_trade_no'])->first();
-		if(!$payment){
-			Log::info('【支付宝当面付】回调订单不存在');
-
-			return;
-		}
-
-		// 处理订单
-		DB::beginTransaction();
-		try{
-			// 如果支付单中没有用户信息则创建一个用户
-			if(!$payment->user_id){
-				// 生成一个可用端口
-				$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
-
-				$user = new User();
-				$user->username = '自动生成-'.$payment->order->email;
-				$user->password = Hash::make(makeRandStr());
-				$user->port = $port;
-				$user->passwd = makeRandStr();
-				$user->vmess_id = createGuid();
-				$user->enable = 1;
-				$user->method = Helpers::getDefaultMethod();
-				$user->protocol = Helpers::getDefaultProtocol();
-				$user->obfs = Helpers::getDefaultObfs();
-				$user->usage = 1;
-				$user->transfer_enable = 1; // 新创建的账号给1,防止定时任务执行时发现u + d >= transfer_enable被判为流量超限而封禁
-				$user->enable_time = date('Y-m-d');
-				$user->expire_time = date('Y-m-d', strtotime("+".$payment->order->goods->days." days"));
-				$user->reg_ip = getClientIp();
-				$user->referral_uid = 0;
-				$user->traffic_reset_day = 0;
-				$user->status = 1;
-				$user->save();
-
-				if($user->id){
-					Order::query()->where('oid', $payment->oid)->update(['user_id' => $user->id]);
-				}
-			}
-
-			// 更新支付单
-			$payment->pay_way = 2; // 1-微信、2-支付宝
-			$payment->status = 1;
-			$payment->save();
-
-			// 更新订单
-			$order = Order::query()->with(['user'])->where('oid', $payment->oid)->first();
-			$order->status = 2;
-			$order->save();
-
-			$goods = Goods::query()->where('id', $order->goods_id)->first();
-
-			// 商品为流量或者套餐
-			if($goods->type <= 2){
-				// 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
-				if($goods->type == 2){
-					$existOrderList = Order::query()
-						->with(['goods'])
-						->whereHas('goods', function($q){
-							$q->where('type', 2);
-						})
-						->where('user_id', $order->user_id)
-						->where('oid', '<>', $order->oid)
-						->where('is_expire', 0)
-						->where('status', 2)
-						->get();
-
-					foreach($existOrderList as $vo){
-						Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
-
-						// 先判断,防止手动扣减过流量的用户流量被扣成负数
-						if($order->user->transfer_enable-$vo->goods->traffic*1048576 <= 0){
-							// 写入用户流量变动记录
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, 0, 0, '[在线支付]用户购买套餐,先扣减之前套餐的流量(扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-						}else{
-							// 写入用户流量变动记录
-							$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable-$vo->goods->traffic*1048576), '[在线支付]用户购买套餐,先扣减之前套餐的流量(未扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
-							User::query()->where('id', $order->user_id)->decrement('transfer_enable', $vo->goods->traffic*1048576);
-						}
-					}
-				}
-
-				// 写入用户流量变动记录
-				$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-				Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable+$goods->traffic*1048576), '[在线支付]用户购买商品,加上流量');
-
-				// 把商品的流量加到账号上
-				User::query()->where('id', $order->user_id)->increment('transfer_enable', $goods->traffic*1048576);
-
-				// 计算账号过期时间
-				if($order->user->expire_time < date('Y-m-d', strtotime("+".$goods->days." days"))){
-					$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
-				}else{
-					$expireTime = $order->user->expire_time;
-				}
-
-				// 套餐就改流量重置日,流量包不改
-				if($goods->type == 2){
-					User::query()->where('id', $order->user_id)->update(['traffic_reset_day' =>  date('d'), 'expire_time' => $expireTime, 'enable' => 1]);
-				}else{
-					User::query()->where('id', $order->user_id)->update(['expire_time' => $expireTime, 'enable' => 1]);
-				}
-
-				// 写入用户标签
-				if($goods->label){
-					// 用户默认标签
-					$defaultLabels = [];
-					if(self::$systemConfig['initial_labels_for_user']){
-						$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-					}
-
-					// 取出现有的标签
-					$userLabels = UserLabel::query()->where('user_id', $order->user_id)->pluck('label_id')->toArray();
-					$goodsLabels = GoodsLabel::query()->where('goods_id', $order->goods_id)->pluck('label_id')->toArray();
-
-					// 标签去重
-					$newUserLabels = array_values(array_unique(array_merge($userLabels, $goodsLabels, $defaultLabels)));
-
-					// 删除用户所有标签
-					UserLabel::query()->where('user_id', $order->user_id)->delete();
-
-					// 生成标签
-					foreach($newUserLabels as $vo){
-						$obj = new UserLabel();
-						$obj->user_id = $order->user_id;
-						$obj->label_id = $vo;
-						$obj->save();
-					}
-				}
-
-				// 写入返利日志
-				if($order->user->referral_uid){
-					$this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount*self::$systemConfig['referral_percent']);
-				}
-
-				// 取消重复返利
-				User::query()->where('id', $order->user_id)->update(['referral_uid' => 0]);
-			}elseif($goods->type == 3){ // 商品为在线充值
-				User::query()->where('id', $order->user_id)->increment('balance', $goods->price*100);
-
-				// 余额变动记录日志
-				$this->addUserBalanceLog($order->user_id, $order->oid, $order->user->balance, $order->user->balance+$goods->price, $goods->price, '用户在线充值');
-			}
-
-			// 自动提号机:如果order的email值不为空
-			if($order->email){
-				$title = '自动发送账号信息';
-				$content = [
-					'order_sn'      => $order->order_sn,
-					'goods_name'    => $order->goods->name,
-					'goods_traffic' => flowAutoShow($order->goods->traffic*1048576),
-					'port'          => $order->user->port,
-					'passwd'        => $order->user->passwd,
-					'method'        => $order->user->method,
-					//'protocol'       => $order->user->protocol,
-					//'protocol_param' => $order->user->protocol_param,
-					//'obfs'           => $order->user->obfs,
-					//'obfs_param'     => $order->user->obfs_param,
-					'created_at'    => $order->created_at->toDateTimeString(),
-					'expire_at'     => $order->expire_at
-				];
-
-				// 获取可用节点列表
-				$labels = UserLabel::query()->where('user_id', $order->user_id)->get()->pluck('label_id');
-				$nodeIds = SsNodeLabel::query()->whereIn('label_id', $labels)->get()->pluck('node_id');
-				$nodeList = SsNode::query()->whereIn('id', $nodeIds)->orderBy('sort', 'desc')->orderBy('id', 'desc')->get()->toArray();
-				$content['serverList'] = $nodeList;
-
-				$logId = Helpers::addEmailLog($order->email, $title, json_encode($content));
-				Mail::to($order->email)->send(new sendUserInfo($logId, $content));
-			}
-
-			DB::commit();
-		} catch(Exception $e){
-			DB::rollBack();
-			Log::info('【支付宝当面付】回调更新支付单和订单异常:'.$e->getMessage());
-		}
-	}
-
-	public function show(Request $request)
-	{
-		exit('show');
-	}
 }

+ 0 - 390
app/Http/Controllers/Api/YzyController.php

@@ -1,390 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use App\Components\Helpers;
-use App\Http\Controllers\Controller;
-use App\Http\Models\Goods;
-use App\Http\Models\GoodsLabel;
-use App\Http\Models\Order;
-use App\Http\Models\Payment;
-use App\Http\Models\PaymentCallback;
-use App\Http\Models\SsNode;
-use App\Http\Models\SsNodeLabel;
-use App\Http\Models\User;
-use App\Http\Models\UserLabel;
-use App\Mail\sendUserInfo;
-use DB;
-use Exception;
-use Hash;
-use Illuminate\Http\Request;
-use Log;
-use Mail;
-
-/**
- * 有赞云支付消息推送接收
- *
- * Class YzyController
- *
- * @package App\Http\Controllers
- */
-class YzyController extends Controller
-{
-	protected static $systemConfig;
-
-	function __construct()
-	{
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
-	// 接收GET请求
-	public function index(Request $request)
-	{
-		Log::info("【有赞云】回调接口[GET]:".var_export($request->all(), TRUE).'['.getClientIp().']');
-		exit("【有赞云】接口正常");
-	}
-
-	// 接收POST请求
-	public function store(Request $request)
-	{
-		Log::info("【有赞云】回调接口[POST]:".var_export($request->all(), TRUE));
-
-		$json = file_get_contents('php://input');
-		$data = json_decode($json, TRUE);
-		if(!$data){
-			Log::info('YZY-POST:回调数据无法解析,可能是非法请求['.getClientIp().']');
-			exit();
-		}
-
-		// 判断消息是否合法
-		$msg = $data['msg'];
-		$sign_string = self::$systemConfig['youzan_client_id']."".$msg."".self::$systemConfig['youzan_client_secret'];
-		$sign = md5($sign_string);
-		if($sign != $data['sign']){
-			Log::info('本地签名:'.$sign_string.' | 远程签名:'.$data['sign']);
-			Log::info('YZY-POST:回调数据签名错误,可能是非法请求['.getClientIp().']');
-			exit();
-		}else{
-			// 返回请求成功标识给有赞
-			var_dump(["code" => 0, "msg" => "success"]);
-		}
-
-		// 容错
-		if(!isset($data['kdt_name'])){
-			Log::info("【有赞云】回调数据解析错误,请检查有赞支付设置是否与有赞控制台中的信息保持一致。如果还出现此提示,请执行一遍php artisan cache:clear命令");
-			exit();
-		}
-
-		// 先写入回调日志
-		$this->callbackLog($data['client_id'], $data['id'], $data['kdt_id'], $data['kdt_name'], $data['mode'], $data['msg'], $data['sendCount'], $data['sign'], $data['status'], $data['test'], $data['type'], $data['version']);
-
-		// msg内容经过 urlencode 编码,进行解码
-		$msg = json_decode(urldecode($msg), TRUE);
-
-		switch($data['type']){
-			case 'trade_TradePaid':
-				$this->tradePaid($msg);
-				break;
-			case 'trade_TradeCreate':
-				$this->tradeCreate($msg);
-				break;
-			case 'trade_TradeClose':
-				$this->tradeClose($msg);
-				break;
-			case 'trade_TradeSuccess':
-				$this->tradeSuccess($msg);
-				break;
-			case 'trade_TradePartlySellerShip':
-				$this->tradePartlySellerShip($msg);
-				break;
-			case 'trade_TradeSellerShip':
-				$this->tradeSellerShip($msg);
-				break;
-			case 'trade_TradeBuyerPay':
-				$this->tradeBuyerPay($msg);
-				break;
-			case 'trade_TradeMemoModified':
-				$this->tradeMemoModified($msg);
-				break;
-			default:
-				Log::info('【有赞云】回调无法识别,可能是没有启用[交易消息V3]接口,请到有赞云控制台启用消息推送服务');
-				exit();
-		}
-
-		exit();
-	}
-
-	// 交易支付
-	private function tradePaid($msg)
-	{
-		Log::info('【有赞云】回调交易支付');
-
-		$payment = Payment::query()->with(['order', 'order.goods'])->where('qr_id', $msg['qr_info']['qr_id'])->first();
-		if(!$payment){
-			Log::info('【有赞云】回调订单不存在');
-			exit();
-		}
-
-		if($payment->status != '0'){
-			Log::info('【有赞云】回调订单状态不正确');
-			exit();
-		}
-
-		// 处理订单
-		DB::beginTransaction();
-		try{
-			// 如果支付单中没有用户信息则创建一个用户
-			if(!$payment->user_id){
-				// 生成一个可用端口
-				$port = self::$systemConfig['is_rand_port']? Helpers::getRandPort() : Helpers::getOnlyPort();
-
-				$user = new User();
-				$user->username = '自动生成-'.$payment->order->email;
-				$user->password = Hash::make(makeRandStr());
-				$user->port = $port;
-				$user->passwd = makeRandStr();
-				$user->vmess_id = createGuid();
-				$user->enable = 1;
-				$user->method = Helpers::getDefaultMethod();
-				$user->protocol = Helpers::getDefaultProtocol();
-				$user->obfs = Helpers::getDefaultObfs();
-				$user->usage = 1;
-				$user->transfer_enable = 1; // 新创建的账号给1,防止定时任务执行时发现u + d >= transfer_enable被判为流量超限而封禁
-				$user->enable_time = date('Y-m-d');
-				$user->expire_time = date('Y-m-d', strtotime("+".$payment->order->goods->days." days"));
-				$user->reg_ip = getClientIp();
-				$user->referral_uid = 0;
-				$user->traffic_reset_day = 0;
-				$user->status = 1;
-				$user->save();
-
-				if($user->id){
-					Order::query()->where('oid', $payment->oid)->update(['user_id' => $user->id]);
-				}
-			}
-
-			// 更新支付单
-			$payment->pay_way = $msg['full_order_info']['order_info']['pay_type_str'] == 'WEIXIN_DAIXIAO'? 1 : 2; // 1-微信、2-支付宝
-			$payment->status = 1;
-			$payment->save();
-
-			// 更新订单
-			$order = Order::query()->with(['user'])->where('oid', $payment->oid)->first();
-			$order->status = 2;
-			$order->save();
-
-			$goods = Goods::query()->where('id', $order->goods_id)->first();
-
-			// 商品为流量或者套餐
-			if($goods->type <= 2){
-				// 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
-				if($goods->type == 2){
-					$existOrderList = Order::query()
-						->with(['goods'])
-						->whereHas('goods', function($q){
-							$q->where('type', 2);
-						})
-						->where('user_id', $order->user_id)
-						->where('oid', '<>', $order->oid)
-						->where('is_expire', 0)
-						->where('status', 2)
-						->get();
-
-					foreach($existOrderList as $vo){
-						Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
-
-						// 先判断,防止手动扣减过流量的用户流量被扣成负数
-						if($order->user->transfer_enable-$vo->goods->traffic*1048576 <= 0){
-							// 写入用户流量变动记录
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, 0, 0, '[在线支付]用户购买套餐,先扣减之前套餐的流量(扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-						}else{
-							// 写入用户流量变动记录
-							$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-							Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable-$vo->goods->traffic*1048576), '[在线支付]用户购买套餐,先扣减之前套餐的流量(未扣完)');
-
-							User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
-							User::query()->where('id', $order->user_id)->decrement('transfer_enable', $vo->goods->traffic*1048576);
-						}
-					}
-				}
-
-				// 写入用户流量变动记录
-				$user = User::query()->where('id', $order->user_id)->first(); // 重新取出user信息
-				Helpers::addUserTrafficModifyLog($order->user_id, $order->oid, $user->transfer_enable, ($user->transfer_enable+$goods->traffic*1048576), '[在线支付]用户购买商品,加上流量');
-
-				// 计算账号过期时间
-				if($order->user->expire_time < date('Y-m-d', strtotime("+".$goods->days." days"))){
-					$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
-				}else{
-					$expireTime = $order->user->expire_time;
-				}
-
-				// 把商品的流量加到账号上
-				User::query()->where('id', $order->user_id)->increment('transfer_enable', $goods->traffic*1048576);
-
-				// 套餐就改流量重置日,流量包不改
-				if($goods->type == 2){
-
-					User::query()->where('id', $order->user_id)->update(['traffic_reset_day' =>  date('d'), 'expire_time' => $expireTime, 'enable' => 1]);
-				}else{
-					User::query()->where('id', $order->user_id)->update(['expire_time' => $expireTime, 'enable' => 1]);
-				}
-
-				// 写入用户标签
-				if($goods->label){
-					// 用户默认标签
-					$defaultLabels = [];
-					if(self::$systemConfig['initial_labels_for_user']){
-						$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-					}
-
-					// 取出现有的标签
-					$userLabels = UserLabel::query()->where('user_id', $order->user_id)->pluck('label_id')->toArray();
-					$goodsLabels = GoodsLabel::query()->where('goods_id', $order->goods_id)->pluck('label_id')->toArray();
-
-					// 标签去重
-					$newUserLabels = array_values(array_unique(array_merge($userLabels, $goodsLabels, $defaultLabels)));
-
-					// 删除用户所有标签
-					UserLabel::query()->where('user_id', $order->user_id)->delete();
-
-					// 生成标签
-					foreach($newUserLabels as $vo){
-						$obj = new UserLabel();
-						$obj->user_id = $order->user_id;
-						$obj->label_id = $vo;
-						$obj->save();
-					}
-				}
-
-				// 写入返利日志
-				if($order->user->referral_uid){
-					$this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount*self::$systemConfig['referral_percent']);
-				}
-
-				// 取消重复返利
-				User::query()->where('id', $order->user_id)->update(['referral_uid' => 0]);
-			}elseif($goods->type == 3){ // 商品为在线充值
-				User::query()->where('id', $order->user_id)->increment('balance', $goods->price*100);
-
-				// 余额变动记录日志
-				$this->addUserBalanceLog($order->user_id, $order->oid, $order->user->balance, $order->user->balance+$goods->price, $goods->price, '用户在线充值');
-			}
-
-			// 自动提号机:如果order的email值不为空
-			if($order->email){
-				$title = '自动发送账号信息';
-				$content = [
-					'order_sn'      => $order->order_sn,
-					'goods_name'    => $order->goods->name,
-					'goods_traffic' => flowAutoShow($order->goods->traffic*1048576),
-					'port'          => $order->user->port,
-					'passwd'        => $order->user->passwd,
-					'method'        => $order->user->method,
-					//'protocol'       => $order->user->protocol,
-					//'protocol_param' => $order->user->protocol_param,
-					//'obfs'           => $order->user->obfs,
-					//'obfs_param'     => $order->user->obfs_param,
-					'created_at'    => $order->created_at->toDateTimeString(),
-					'expire_at'     => $order->expire_at
-				];
-
-				// 获取可用节点列表
-				$labels = UserLabel::query()->where('user_id', $order->user_id)->get()->pluck('label_id');
-				$nodeIds = SsNodeLabel::query()->whereIn('label_id', $labels)->get()->pluck('node_id');
-				$nodeList = SsNode::query()->whereIn('id', $nodeIds)->orderBy('sort', 'desc')->orderBy('id', 'desc')->get()->toArray();
-				$content['serverList'] = $nodeList;
-
-				$logId = Helpers::addEmailLog($order->email, $title, json_encode($content));
-				Mail::to($order->email)->send(new sendUserInfo($logId, $content));
-			}
-
-			DB::commit();
-		} catch(Exception $e){
-			DB::rollBack();
-
-			Log::info('【有赞云】回调更新支付单和订单异常:'.$e->getMessage());
-		}
-
-		exit();
-	}
-
-	// 创建交易
-	private function tradeCreate($msg)
-	{
-		Log::info('【有赞云】回调创建交易');
-		exit();
-	}
-
-	// 关闭交易(无视,系统自带15分钟自动关闭未支付订单的定时任务)
-	private function tradeClose($msg)
-	{
-		Log::info('【有赞云】回调关闭交易');
-
-		exit();
-	}
-
-	// 交易成功
-	private function tradeSuccess($msg)
-	{
-		Log::info('【有赞云】回调交易成功');
-
-		exit();
-	}
-
-	// 卖家部分发货
-	private function tradePartlySellerShip($msg)
-	{
-		Log::info('【有赞云】回调卖家部分发货');
-		exit();
-	}
-
-	// 卖家发货
-	private function tradeSellerShip($msg)
-	{
-		Log::info('【有赞云】回调卖家发货');
-		exit();
-	}
-
-	// 买家付款
-	private function tradeBuyerPay($msg)
-	{
-		Log::info('【有赞云】回调买家付款');
-		exit();
-	}
-
-	// 卖家修改交易备注
-	private function tradeMemoModified($msg)
-	{
-		Log::info('【有赞云】回调卖家修改交易备注');
-		exit();
-	}
-
-	public function show(Request $request)
-	{
-		exit('show');
-	}
-
-	// 写入回调请求日志
-	private function callbackLog($client_id, $yz_id, $kdt_id, $kdt_name, $mode, $msg, $sendCount, $sign, $status, $test, $type, $version)
-	{
-		$obj = new PaymentCallback();
-		$obj->client_id = $client_id;
-		$obj->yz_id = $yz_id;
-		$obj->kdt_id = $kdt_id;
-		$obj->kdt_name = $kdt_name;
-		$obj->mode = $mode;
-		$obj->msg = urldecode($msg);
-		$obj->sendCount = $sendCount;
-		$obj->sign = $sign;
-		$obj->status = $status;
-		$obj->test = $test;
-		$obj->type = $type;
-		$obj->version = $version;
-		$obj->save();
-
-		return $obj->id;
-	}
-}

+ 43 - 64
app/Http/Controllers/AuthController.php

@@ -275,30 +275,16 @@ class AuthController extends Controller
 			$transfer_enable = $referral_uid? (self::$systemConfig['default_traffic']+self::$systemConfig['referral_traffic'])*1048576 : self::$systemConfig['default_traffic']*1048576;
 
 			// 创建新用户
-			$user = new User();
-			$user->username = $request->username;
-			$user->password = Hash::make($request->password);
-			$user->port = $port;
-			$user->passwd = makeRandStr();
-			$user->vmess_id = createGuid();
-			$user->transfer_enable = $transfer_enable;
-			$user->method = Helpers::getDefaultMethod();
-			$user->protocol = Helpers::getDefaultProtocol();
-			$user->obfs = Helpers::getDefaultObfs();
-			$user->enable_time = date('Y-m-d H:i:s');
-			$user->expire_time = date('Y-m-d H:i:s', strtotime("+".self::$systemConfig['default_days']." days"));
-			$user->reg_ip = getClientIp();
-			$user->referral_uid = $referral_uid;
-			$user->save();
+			$uid = Helpers::addUser($request->username, Hash::make($request->password), $transfer_enable, self::$systemConfig['default_days'], $referral_uid);
 
 			// 注册失败,抛出异常
-			if(!$user->id){
+			if(!$uid){
 				return Redirect::back()->withInput()->withErrors(trans('auth.register_fail'));
 			}
 
 			// 生成订阅码
 			$subscribe = new UserSubscribe();
-			$subscribe->user_id = $user->id;
+			$subscribe->user_id = $uid;
 			$subscribe->code = Helpers::makeSubscribeCode();
 			$subscribe->times = 0;
 			$subscribe->save();
@@ -315,7 +301,7 @@ class AuthController extends Controller
 				$labels = explode(',', self::$systemConfig['initial_labels_for_user']);
 				foreach($labels as $label){
 					$userLabel = new UserLabel();
-					$userLabel->user_id = $user->id;
+					$userLabel->user_id = $uid;
 					$userLabel->label_id = $label;
 					$userLabel->save();
 				}
@@ -323,48 +309,39 @@ class AuthController extends Controller
 
 			// 更新邀请码
 			if(self::$systemConfig['is_invite_register'] && $affArr['code_id']){
-				Invite::query()->where('id', $affArr['code_id'])->update(['fuid' => $user->id, 'status' => 1]);
+				Invite::query()->where('id', $affArr['code_id'])->update(['fuid' => $uid, 'status' => 1]);
 			}
 
 			// 清除邀请人Cookie
 			Cookie::unqueue('register_aff');
 
-			if(self::$systemConfig['is_verify_register']){
-				if($referral_uid){
-					$transfer_enable = self::$systemConfig['referral_traffic']*1048576;
 
-					User::query()->where('id', $referral_uid)->increment('transfer_enable', $transfer_enable);
-					User::query()->where('id', $referral_uid)->update(['status' => 1, 'enable' => 1]);
-				}
+			// 发送激活邮件
+			if(!self::$systemConfig['is_verify_register'] && self::$systemConfig['is_active_register']){
+				// 生成激活账号的地址
+				$token = md5(self::$systemConfig['website_name'].$request->username.microtime());
+				$activeUserUrl = self::$systemConfig['website_url'].'/active/'.$token;
+				$this->addVerify($uid, $token);
 
-				User::query()->where('id', $user->id)->update(['status' => 1, 'enable' => 1]);
+				$logId = Helpers::addEmailLog($request->username, '注册激活', '请求地址:'.$activeUserUrl);
+				Mail::to($request->username)->send(new activeUser($logId, $activeUserUrl));
 
-				Session::flash('regSuccessMsg', trans('auth.register_success'));
+				Session::flash('regSuccessMsg', trans('auth.register_success_tip'));
 			}else{
-				// 发送激活邮件
-				if(self::$systemConfig['is_active_register']){
-					// 生成激活账号的地址
-					$token = md5(self::$systemConfig['website_name'].$request->username.microtime());
-					$activeUserUrl = self::$systemConfig['website_url'].'/active/'.$token;
-					$this->addVerify($user->id, $token);
-
-					$logId = Helpers::addEmailLog($request->username, '注册激活', '请求地址:'.$activeUserUrl);
-					Mail::to($request->username)->send(new activeUser($logId, $activeUserUrl));
-
-					Session::flash('regSuccessMsg', trans('auth.register_success_tip'));
-				}else{
-					// 如果不需要激活,则直接给推荐人加流量
-					if($referral_uid){
-						$transfer_enable = self::$systemConfig['referral_traffic']*1048576;
-
-						User::query()->where('id', $referral_uid)->increment('transfer_enable', $transfer_enable);
-						User::query()->where('id', $referral_uid)->update(['status' => 1, 'enable' => 1]);
+				// 则直接给推荐人加流量
+				if($referral_uid){
+					$transfer_enable = self::$systemConfig['referral_traffic']*1048576;
+					$referralUser = User::query()->where('id', $referral_uid)->first();
+					if($referralUser){
+						if($referralUser->expire_time >= date('Y-m-d')){
+							User::query()->where('id', $referral_uid)->increment('transfer_enable', $transfer_enable);
+						}
 					}
+				}
 
-					User::query()->where('id', $user->id)->update(['status' => 1, 'enable' => 1]);
+				User::query()->where('id', $uid)->update(['status' => 1, 'enable' => 1]);
 
-					Session::flash('regSuccessMsg', trans('auth.register_success'));
-				}
+				Session::flash('regSuccessMsg', trans('auth.register_success'));
 			}
 
 			return Redirect::to('login')->withInput();
@@ -409,13 +386,7 @@ class AuthController extends Controller
 			}
 
 			// 生成取回密码的地址
-			$token = md5(self::$systemConfig['website_name'].$request->username.microtime());
-			$verify = new Verify();
-			$verify->type = 1;
-			$verify->user_id = $user->id;
-			$verify->token = $token;
-			$verify->status = 0;
-			$verify->save();
+			$token = $this->addVerifyUrl($user->id, $request->username);
 
 			// 发送邮件
 			$resetPasswordUrl = self::$systemConfig['website_url'].'/reset/'.$token;
@@ -459,13 +430,13 @@ class AuthController extends Controller
 			}elseif($verify->user->status < 0){
 				return Redirect::back()->withErrors(trans('auth.email_banned'));
 			}elseif(Hash::check($request->password, $verify->user->password)){
-				return Redirect::back()->withErrors(trans('auth.rest_password_same_fail'));
+				return Redirect::back()->withErrors(trans('auth.reset_password_same_fail'));
 			}
 
 			// 更新密码
 			$ret = User::query()->where('id', $verify->user_id)->update(['password' => Hash::make($request->password)]);
 			if(!$ret){
-				return Redirect::back()->withErrors(trans('auth.rest_password_fail'));
+				return Redirect::back()->withErrors(trans('auth.reset_password_fail'));
 			}
 
 			// 置为已使用
@@ -525,13 +496,7 @@ class AuthController extends Controller
 			}
 
 			// 生成激活账号的地址
-			$token = md5(self::$systemConfig['website_name'].$request->username.microtime());
-			$verify = new Verify();
-			$verify->type = 1;
-			$verify->user_id = $user->id;
-			$verify->token = $token;
-			$verify->status = 0;
-			$verify->save();
+			$token = $this->addVerifyUrl($user->id, $request->username);
 
 			// 发送邮件
 			$activeUserUrl = self::$systemConfig['website_url'].'/active/'.$token;
@@ -785,4 +750,18 @@ class AuthController extends Controller
 		$verify->status = 0;
 		$verify->save();
 	}
+
+	// 生成激活账号的地址
+	private function addVerifyUrl($uid, $username)
+	{
+		$token = md5(self::$systemConfig['website_name'].$username.microtime());
+		$verify = new Verify();
+		$verify->type = 1;
+		$verify->user_id = $uid;
+		$verify->token = $token;
+		$verify->status = 0;
+		$verify->save();
+
+		return $token;
+	}
 }

+ 101 - 88
app/Http/Controllers/PaymentController.php

@@ -3,13 +3,14 @@
 namespace App\Http\Controllers;
 
 use App\Components\AlipaySubmit;
+use App\Components\Callback;
 use App\Components\Helpers;
-use App\Components\Yzy;
 use App\Http\Models\Coupon;
 use App\Http\Models\Goods;
 use App\Http\Models\Order;
 use App\Http\Models\Payment;
 use App\Http\Models\PaymentCallback;
+use App\Http\Models\User;
 use Auth;
 use DB;
 use Exception;
@@ -28,33 +29,39 @@ use Validator;
  */
 class PaymentController extends Controller
 {
-	protected static $systemConfig;
+	use Callback;
 
-	function __construct()
-	{
-		self::$systemConfig = Helpers::systemConfig();
-	}
-
-	// 创建支付单
+// 创建支付订单
 	public function create(Request $request)
 	{
 		$goods_id = $request->input('goods_id');
 		$coupon_sn = $request->input('coupon_sn');
+		$pay_type = $request->input('pay_type');
+
 
 		$goods = Goods::query()->where('status', 1)->where('id', $goods_id)->first();
 		if(!$goods){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:商品或服务已下架']);
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:商品或服务已下架']);
 		}
-
-		// 判断是否开启有赞云支付
-		if(!self::$systemConfig['is_youzan'] && !self::$systemConfig['is_alipay'] && !self::$systemConfig['is_f2fpay']){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:系统并未开启在线支付功能']);
+		// 是否有生效的套餐
+		$activePlan = Order::uid()->with(['goods'])->whereHas('goods', function($q){ $q->where('type', 2); })->where('status', 2)->where('is_expire', 0)->doesntExist();
+		//无生效套餐,禁止购买加油包
+		if($goods->type == 1 && $activePlan){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '购买加油包前,请先购买套餐']);
 		}
 
-		// 判断是否存在同个商品的未支付订单
-		$existsOrder = Order::uid()->where('status', 0)->where('goods_id', $goods_id)->exists();
-		if($existsOrder){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:尚有未支付的订单,请先去支付']);
+		//非余额付款下,检查对应的在线支付是否开启
+		if($pay_type != 1){
+			// 判断是否开启在线支付
+			if(!self::$systemConfig['is_alipay'] && !self::$systemConfig['is_f2fpay']){
+				return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:系统并未开启在线支付功能']);
+			}
+
+			// 判断是否存在同个商品的未支付订单
+			$existsOrder = Order::uid()->where('status', 0)->where('goods_id', $goods_id)->exists();
+			if($existsOrder){
+				return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:尚有未支付的订单,请先去支付']);
+			}
 		}
 
 		// 单个商品限购
@@ -69,7 +76,7 @@ class PaymentController extends Controller
 		if($coupon_sn){
 			$coupon = Coupon::query()->where('status', 0)->whereIn('type', [1, 2])->where('sn', $coupon_sn)->first();
 			if(!$coupon){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:优惠券不存在']);
+				return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:优惠券不存在']);
 			}
 
 			// 计算实际应支付总价
@@ -81,37 +88,19 @@ class PaymentController extends Controller
 
 		// 价格异常判断
 		if($amount < 0){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:订单总价异常']);
-		}elseif($amount == 0){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:订单总价为0,无需使用在线支付']);
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:订单总价异常']);
+		}elseif($amount == 0 && $pay_type != 1){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单创建失败:订单总价为0,无需使用在线支付']);
 		}
 
-		// 验证账号是否存在有效期更长的套餐
-		if($goods->type == 2){
-			$existOrderList = Order::uid()->with(['goods'])->whereHas('goods', function($q){
-				$q->where('type', 2);
-			})->where('is_expire', 0)->where('status', 2)->get();
-
-			foreach($existOrderList as $vo){
-				if($vo->goods->days > $goods->days){
-					return Response::json(['status' => 'info', 'title' => '套餐冲突', 'message' => '是否将本次套餐存为 【预支付】?套餐会在已有套餐失效后生效,或者您可以手动激活套餐']);
-				}
-			}
+		// 验证账号余额是否充足
+		if($pay_type == 1 && Auth::user()->balance < $amount){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '您的余额不足,请先充值']);
 		}
 
 		DB::beginTransaction();
 		try{
 			$orderSn = date('ymdHis').mt_rand(100000, 999999);
-			$sn = makeRandStr(12);
-
-			// 支付方式
-			if(self::$systemConfig['is_youzan']){
-				$pay_way = 2;
-			}elseif(self::$systemConfig['is_alipay']){
-				$pay_way = 4;
-			}elseif(self::$systemConfig['is_f2fpay']){
-				$pay_way = 5;
-			}
 
 			// 生成订单
 			$order = new Order();
@@ -123,77 +112,100 @@ class PaymentController extends Controller
 			$order->amount = $amount;
 			$order->expire_at = date("Y-m-d H:i:s", strtotime("+".$goods->days." days"));
 			$order->is_expire = 0;
-			$order->pay_way = $pay_way;
+			$order->pay_way = $pay_type;
 			$order->status = 0;
 			$order->save();
-
 			// 生成支付单
-			if(self::$systemConfig['is_youzan']){
-				$yzy = new Yzy();
-				$result = $yzy->createQrCode($goods->name, $amount*100, $orderSn);
-				if(isset($result['error_response'])){
-					Log::error('【有赞云】创建二维码失败:'.$result['error_response']['msg']);
+			if($pay_type == 1){
+				// 扣余额
+				User::query()->where('id', Auth::user()->id)->decrement('balance', $amount*100);
 
-					throw new Exception($result['error_response']['msg']);
-				}
-			}elseif(self::$systemConfig['is_alipay']){
-				$parameter = ["service"      => "create_forex_trade", // WAP:create_forex_trade_wap ,即时到帐:create_forex_trade
-				              "partner"      => self::$systemConfig['alipay_partner'], "notify_url" => self::$systemConfig['website_url']."/api/alipay", // 异步回调接口
-				              "return_url"   => self::$systemConfig['website_url'], "out_trade_no" => $orderSn,  // 订单号
-				              "subject"      => "Package", // 订单名称
-					//"total_fee"      => $amount, // 金额
-					          "rmb_fee"      => $amount,   // 使用RMB标价,不再使用总金额
-					          "body"         => "",        // 商品描述,可为空
-					          "currency"     => self::$systemConfig['alipay_currency'], // 结算币种
-					          "product_code" => "NEW_OVERSEAS_SELLER", "_input_charset" => "utf-8"];
-
-				// 建立请求
-				$alipaySubmit = new AlipaySubmit(self::$systemConfig['alipay_sign_type'], self::$systemConfig['alipay_partner'], self::$systemConfig['alipay_key'], self::$systemConfig['alipay_private_key']);
-				$result = $alipaySubmit->buildRequestForm($parameter, "post", "确认");
-			}elseif(self::$systemConfig['is_f2fpay']){
-				// TODO:goods表里增加一个字段用于自定义商品付款时展示的商品名称,
-				// TODO:这里增加一个随机商品列表,根据goods的价格随机取值
-					$result = Charge::run("ali_qr", ['use_sandbox' => FALSE, "partner" => self::$systemConfig['f2fpay_app_id'], 'app_id' => self::$systemConfig['f2fpay_app_id'], 'sign_type' => 'RSA2', 'ali_public_key' => self::$systemConfig['f2fpay_public_key'], 'rsa_private_key' => self::$systemConfig['f2fpay_private_key'], 'notify_url' => self::$systemConfig['website_url']."/api/f2fpay", // 异步回调接口
-					                                 'return_url'  => self::$systemConfig['website_url'], 'return_raw' => FALSE], ['body' => '', 'subject' => self::$systemConfig['f2fpay_subject_name'], 'order_no' => $orderSn, 'amount' => $amount,]);
-				}
+				// 记录余额操作日志
+				$this->addUserBalanceLog(Auth::user()->id, $order->oid, Auth::user()->balance, Auth::user()->balance-$amount, -1*$amount, '购买商品:'.$goods->name);
 
+				$data = [];
+				$data['out_trade_no'] = $orderSn;
+				$this->tradePaid($data, 1);
+			}else{
+				if(self::$systemConfig['is_alipay'] && $pay_type == 4){
+					$pay_way = 2;
+					$parameter = [
+						"service"        => "create_forex_trade", // WAP:create_forex_trade_wap ,即时到帐:create_forex_trade
+						"partner"        => self::$systemConfig['alipay_partner'],
+						"notify_url"     => self::$systemConfig['website_url']."/api/alipay", // 异步回调接口
+						"return_url"     => self::$systemConfig['website_url'],
+						"out_trade_no"   => $orderSn,  // 订单号
+						"subject"        => "Package", // 订单名称
+						//"total_fee"      => $amount, // 金额
+						"rmb_fee"        => $amount,   // 使用RMB标价,不再使用总金额
+						"body"           => "",        // 商品描述,可为空
+						"currency"       => self::$systemConfig['alipay_currency'], // 结算币种
+						"product_code"   => "NEW_OVERSEAS_SELLER",
+						"_input_charset" => "utf-8"
+					];
+
+					// 建立请求
+					$alipaySubmit = new AlipaySubmit(self::$systemConfig['alipay_sign_type'], self::$systemConfig['alipay_partner'], self::$systemConfig['alipay_key'], self::$systemConfig['alipay_private_key']);
+					$result = $alipaySubmit->buildRequestForm($parameter, "post", "确认");
+				}elseif(self::$systemConfig['is_f2fpay'] && $pay_type == 5){
+					$pay_way = 2;
+					// TODO:goods表里增加一个字段用于自定义商品付款时展示的商品名称,
+					// TODO:这里增加一个随机商品列表,根据goods的价格随机取值
+					$result = Charge::run("ali_qr", [
+						'use_sandbox'     => FALSE,
+						"partner"         => self::$systemConfig['f2fpay_app_id'],
+						'app_id'          => self::$systemConfig['f2fpay_app_id'],
+						'sign_type'       => 'RSA2',
+						'ali_public_key'  => self::$systemConfig['f2fpay_public_key'],
+						'rsa_private_key' => self::$systemConfig['f2fpay_private_key'],
+						'notify_url'      => self::$systemConfig['website_url']."/api/f2fpay", // 异步回调接口
+						'return_url'      => self::$systemConfig['website_url'],
+						'return_raw'      => FALSE
+					],
+						[
+							'body'     => '',
+							'subject'  => self::$systemConfig['f2fpay_subject_name'],
+							'order_no' => $orderSn,
+							'amount'   => $amount,
+						]);
+				}else{
+					return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建支付单失败:未知支付类型']);
+				}
+				$sn = makeRandStr(12);
 				$payment = new Payment();
 				$payment->sn = $sn;
 				$payment->user_id = Auth::user()->id;
 				$payment->oid = $order->oid;
 				$payment->order_sn = $orderSn;
-				$payment->pay_way = 1;
+				$payment->pay_way = $pay_way? : 1;
 				$payment->amount = $amount;
-				if(self::$systemConfig['is_youzan']){
-					$payment->qr_id = $result['response']['qr_id'];
-					$payment->qr_url = $result['response']['qr_url'];
-					$payment->qr_code = $result['response']['qr_code'];
-					$payment->qr_local_url = $this->base64ImageSaver($result['response']['qr_code']);
-				}elseif(self::$systemConfig['is_alipay']){
+				if(self::$systemConfig['is_alipay'] && $pay_type == 4){
 					$payment->qr_code = $result;
-				}elseif(self::$systemConfig['is_f2fpay']){
+				}elseif(self::$systemConfig['is_f2fpay'] && $pay_type == 5){
 					$payment->qr_code = $result;
 					$payment->qr_url = 'http://qr.topscan.com/api.php?text='.$result.'&bg=ffffff&fg=000000&pt=1c73bd&m=10&w=400&el=1&inpt=1eabfc&logo=https://t.alipayobjects.com/tfscom/T1Z5XfXdxmXXXXXXXX.png';
 					$payment->qr_local_url = $payment->qr_url;
 				}
 				$payment->status = 0;
 				$payment->save();
+			}
 
-				// 优惠券置为已使用
-				if(!empty($coupon)){
-					if($coupon->usage == 1){
-						$coupon->status = 1;
-						$coupon->save();
+			// 优惠券置为已使用
+			if(!empty($coupon)){
+				if($coupon->usage == 1){
+					$coupon->status = 1;
+					$coupon->save();
 				}
 
-				Helpers::addCouponLog($coupon->id, $goods_id, $order->oid, '在线支付使用');
+				Helpers::addCouponLog($coupon->id, $goods_id, $order->oid, '订单支付使用');
 			}
 
 			DB::commit();
-
-			if(self::$systemConfig['is_alipay']){ // Alipay返回支付信息
+			if($pay_type == 1){
+				return Response::json(['status' => 'success', 'data' => '', 'message' => '支付成功']);
+			}elseif($pay_type == 4){ // Alipay返回支付信息
 				return Response::json(['status' => 'success', 'data' => $result, 'message' => '创建订单成功,正在转到付款页面,请稍后']);
-			}else{
+			}elseif($pay_type == 5){
 				return Response::json(['status' => 'success', 'data' => $sn, 'message' => '创建订单成功,正在转到付款页面,请稍后']);
 			}
 		} catch(Exception $e){
@@ -203,6 +215,7 @@ class PaymentController extends Controller
 
 			return Response::json(['status' => 'fail', 'data' => '', 'message' => '创建订单失败:'.$e->getMessage()]);
 		}
+		return Response::json(['status' => 'fail', 'data' => '', 'message' => '未知错误']);
 	}
 
 	// 支付单详情

+ 4 - 4
app/Http/Controllers/SubscribeController.php

@@ -65,7 +65,7 @@ class SubscribeController extends Controller
 		$query = UserSubscribeLog::with('user:username');
 
 		if(isset($id)){
-			$query->where('sid',$id);
+			$query->where('sid', $id);
 		}
 
 		$view['subscribeLog'] = $query->orderBy('id', 'desc')->paginate(20)->appends($request->except('page'));
@@ -185,7 +185,6 @@ class SubscribeController extends Controller
 			shuffle($nodeList);
 		}
 
-		// 控制客户端最多获取节点数
 		$scheme = '';
 
 		// 展示到期时间和剩余流量
@@ -193,6 +192,7 @@ class SubscribeController extends Controller
 			$scheme .= $this->expireDate($user).$this->lastTraffic($user);
 		}
 
+		// 控制客户端最多获取节点数
 		foreach($nodeList as $key => $node){
 			// 控制显示的节点数
 			if(self::$systemConfig['subscribe_max'] && $key >= self::$systemConfig['subscribe_max']){
@@ -283,7 +283,7 @@ class SubscribeController extends Controller
 	 */
 	private function expireDate($user)
 	{
-		$text = '到期时间'.$user->expire_time;
+		$text = '到期时间: '.$user->expire_time;
 
 		return 'ssr://'.base64url_encode('0.0.0.1:1:origin:none:plain:'.base64url_encode('0000').'/?obfsparam=&protoparam=&remarks='.base64url_encode($text).'&group='.base64url_encode(Helpers::systemConfig()['website_name']).'&udpport=0&uot=0')."\n";
 	}
@@ -297,7 +297,7 @@ class SubscribeController extends Controller
 	 */
 	private function lastTraffic($user)
 	{
-		$text = '剩余流量'.flowAutoShow($user->transfer_enable-$user->u-$user->d);
+		$text = '剩余流量: '.flowAutoShow($user->transfer_enable-$user->u-$user->d);
 
 		return 'ssr://'.base64url_encode('0.0.0.2:1:origin:none:plain:'.base64url_encode('0000').'/?obfsparam=&protoparam=&remarks='.base64url_encode($text).'&group='.base64url_encode(Helpers::systemConfig()['website_name']).'&udpport=0&uot=0')."\n";
 	}

+ 48 - 218
app/Http/Controllers/UserController.php

@@ -2,12 +2,12 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\Callback;
 use App\Components\Helpers;
 use App\Components\ServerChan;
 use App\Http\Models\Article;
 use App\Http\Models\Coupon;
 use App\Http\Models\Goods;
-use App\Http\Models\GoodsLabel;
 use App\Http\Models\Invite;
 use App\Http\Models\Order;
 use App\Http\Models\ReferralApply;
@@ -48,6 +48,7 @@ use Validator;
  */
 class UserController extends Controller
 {
+	use Callback;
 	protected static $systemConfig;
 
 	function __construct()
@@ -60,31 +61,21 @@ class UserController extends Controller
 		$totalTransfer = Auth::user()->transfer_enable;
 		$usedTransfer = Auth::user()->u+Auth::user()->d;
 		$unusedTransfer = $totalTransfer-$usedTransfer > 0? $totalTransfer-$usedTransfer : 0;
-		$userRestDay = Auth::user()->traffic_reset_day;
 		$expireTime = Auth::user()->expire_time;
-		$last_day = date('t');
-		$today = date('d');
-		if($userRestDay > $today){
-			$resetDays = $userRestDay > $last_day? $last_day-$today : $userRestDay-$today;
-		}else{
-			$next_last_day = date('t', strtotime('next month'));
-			$resetDays = $userRestDay > $next_last_day? $last_day-$today+$next_last_day : $last_day-$today+$userRestDay;
-		}
-		$view['remainDays'] = date('Y-m-d') < $expireTime? (strtotime($expireTime)-strtotime(date('Y-m-d')))/86400 : 0;
-		$view['resetDays'] = $resetDays;
+		$view['remainDays'] = $expireTime < date('Y-m-d') ? -1 : (strtotime($expireTime)-strtotime(date('Y-m-d')))/86400;
+		$view['resetDays'] = Auth::user()->reset_time? round((strtotime(Auth::user()->reset_time)-strtotime(date('Y-m-d')))/86400) : 0;
 		$view['unusedTransfer'] = $unusedTransfer;
 		$view['expireTime'] = $expireTime;
-		$view['banedTime'] = Auth::user()->ban_time != 0? date('Y-m-d H:i:s', Auth::user()->ban_time) : 0;;
+		$view['banedTime'] = Auth::user()->ban_time? date('Y-m-d H:i:s', Auth::user()->ban_time) : 0;
 		$view['unusedPercent'] = $totalTransfer > 0? round($unusedTransfer/$totalTransfer, 2) : 0;
 		$view['noticeList'] = Article::type(2)->orderBy('id', 'desc')->Paginate(1); // 公告
 		//流量异常判断
 		$hourlyTraffic = UserTrafficHourly::query()->where('user_id', Auth::user()->id)->where('node_id', 0)->where('created_at', '>=', date('Y-m-d H:i:s', time()-3900))->sum('total');
-		$view['isTrafficWarning'] = $hourlyTraffic < (self::$systemConfig['traffic_ban_value']*1073741824)? 0 : 1;
+		$view['isTrafficWarning'] = $hourlyTraffic >= (self::$systemConfig['traffic_ban_value']*1073741824)? : 0;
 		//付费用户判断
-		$view['not_paying_user'] = Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->get()->isEmpty();
+		$view['not_paying_user'] = Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->doesntExist();
 		$view['userLoginLog'] = UserLoginLog::query()->where('user_id', Auth::user()->id)->orderBy('id', 'desc')->first(); // 近期登录日志
 
-
 		$dailyData = [];
 		$hourlyData = [];
 
@@ -103,7 +94,7 @@ class UserController extends Controller
 
 		// 节点一天内的流量
 		$userTrafficHourly = UserTrafficHourly::query()->where('user_id', Auth::user()->id)->where('node_id', 0)->where('created_at', '>=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-		$hourlyTotal = date('H', time());
+		$hourlyTotal = date('H');
 		$hourlyCount = count($userTrafficHourly);
 		for($x = 0; $x < $hourlyTotal-$hourlyCount; $x++){
 			$hourlyData[$x] = 0;
@@ -324,15 +315,17 @@ class UserController extends Controller
 		// 余额充值商品,只取10个
 		$view['chargeGoodsList'] = Goods::type(3)->where('status', 1)->orderBy('price', 'asc')->orderBy('price', 'asc')->limit(10)->get();
 		$view['goodsList'] = Goods::query()->where('status', 1)->where('type', '<=', '2')->orderBy('type', 'desc')->orderBy('sort', 'desc')->paginate(10)->appends($request->except('page'));
-		$temp = Order::uid()->where('status', 2)->where('is_expire', 0)->first();
-		$view['renewTraffic'] = $temp? Goods::query()->where('id', $temp->goods_id)->first()->renew : 0;
-
+		$renewPrice = Order::uid()->where('status', 2)->where('is_expire', 0)->first();
+		$view['renewTraffic'] = $renewPrice? $renewPrice->renew : 0;
+		// 有重置日时按照重置日为标准,否者就以过期日为标准
+		$dataPlusDays = Auth::user()->reset_time? Auth::user()->reset_time : Auth::user()->expire_time;
+		$view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays)-strtotime(date('Y-m-d')))/86400) : 0;
 
 		return Response::view('user.services', $view);
 	}
 
 	//重置流量
-	public function resetUserTraffic(Request $request)
+	public function resetUserTraffic()
 	{
 		$temp = Order::uid()->where('status', 2)->where('is_expire', 0)->first();
 		$renewCost = Goods::query()->where('id', $temp->goods_id)->first()->renew;
@@ -367,8 +360,23 @@ class UserController extends Controller
 		return Response::view('user.invoices', $view);
 	}
 
+	public function activeOrder(Request $request)
+	{
+		$oid = $request->input('oid');
+		$prepaidOrder = Order::query()->where('oid', $oid)->first();
+		if(!$prepaidOrder){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '查无此单!']);
+		}
+		if($prepaidOrder->status != 3){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '非预支付订单,无需再次启动!']);
+		}
+		$this->activePrepaidOrder($oid);
+
+		return Response::json(['status' => 'success', 'data' => '', 'message' => '激活成功']);
+	}
+
 	// 订单明细
-	public function invoiceDetail(Request $request, $sn)
+	public function invoiceDetail($sn)
 	{
 		$view['order'] = Order::uid()->with(['goods', 'coupon', 'payment'])->where('order_sn', $sn)->firstOrFail();
 
@@ -483,13 +491,11 @@ class UserController extends Controller
 	// 邀请码
 	public function invite(Request $request)
 	{
-		if(Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->get()->isEmpty()){
+		if(Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->doesntExist()){
 			return Response::view('auth.error', ['message' => '本功能对非付费用户禁用!请 <a class="btn btn-sm btn-danger" href="/">返 回</a>']);
 		}
-		// 已生成的邀请码数量
-		$num = Invite::uid()->count();
 
-		$view['num'] = self::$systemConfig['invite_num']-$num <= 0? 0 : self::$systemConfig['invite_num']-$num; // 还可以生成的邀请码数量
+		$view['num'] = Auth::user()->invite_num; // 还可以生成的邀请码数量
 		$view['inviteList'] = Invite::uid()->with(['generator', 'user'])->paginate(10); // 邀请码列表
 		$view['referral_traffic'] = flowAutoShow(self::$systemConfig['referral_traffic']*1048576);
 		$view['referral_percent'] = self::$systemConfig['referral_percent'];
@@ -500,10 +506,8 @@ class UserController extends Controller
 	// 生成邀请码
 	public function makeInvite(Request $request)
 	{
-		// 已生成的邀请码数量
-		$num = Invite::uid()->count();
-		if($num >= self::$systemConfig['invite_num']){
-			return Response::json(['status' => 'fail', 'data' => '', 'message' => '生成失败:最多只能生成'.self::$systemConfig['invite_num'].'个邀请码']);
+		if(Auth::user()->invite_num <= 0){
+			return Response::json(['status' => 'fail', 'data' => '', 'message' => '生成失败:已无邀请码生成名额']);
 		}
 
 		$obj = new Invite();
@@ -514,6 +518,8 @@ class UserController extends Controller
 		$obj->dateline = date('Y-m-d H:i:s', strtotime("+".self::$systemConfig['user_invite_days']." days"));
 		$obj->save();
 
+		User::uid()->decrement('invite_num', 1);
+
 		return Response::json(['status' => 'success', 'data' => '', 'message' => '生成成功']);
 	}
 
@@ -553,200 +559,24 @@ class UserController extends Controller
 	// 购买服务
 	public function buy(Request $request, $goods_id)
 	{
-		$coupon_sn = $request->input('coupon_sn');
-		// 余额支付
-		if($request->isMethod('POST')){
-			$goods = Goods::query()->with(['label'])->where('status', 1)->where('id', $goods_id)->first();
-			if(!$goods){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '支付失败:商品或服务已下架']);
-			}
-
-			// 商品限购
-			if($goods->limit_num){
-				$count = Order::uid()->where('status', '>=', 0)->where('goods_id', $goods_id)->count();
-				if($count >= $goods->limit_num){
-					return Response::json(['status' => 'fail', 'data' => '', 'message' => '此商品/服务限购'.$goods->limit_num.'次,您已购买'.$count.'次']);
-				}
-			}
-
-			// 使用优惠券
-			if(!empty($coupon_sn)){
-				$coupon = Coupon::query()->where('status', 0)->whereIn('type', [1, 2])->where('sn', $coupon_sn)->first();
-				if(!$coupon){
-					return Response::json(['status' => 'fail', 'data' => '', 'message' => '优惠券不存在']);
-				}
-
-				// 计算实际应支付总价
-				$amount = $coupon->type == 2? $goods->price*$coupon->discount/10 : $goods->price-$coupon->amount;
-				$amount = $amount > 0? $amount : 0;
-			}else{
-				$amount = $goods->price;
-			}
-
-			// 价格异常判断
-			if($amount < 0){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '订单总价异常']);
-			}
-
-			// 验证账号余额是否充足
-			if(Auth::user()->balance < $amount){
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '您的余额不足,请先充值']);
-			}
-
-			// 验证账号是否存在有效期更长的套餐
-			if($goods->type == 2){
-				$existOrderList = Order::uid()->with('goods')->whereHas('goods', function($q){
-					$q->where('type', 2);
-				})->where('is_expire', 0)->where('status', 2)->get();
-
-				foreach($existOrderList as $vo){
-					if($vo->goods->days > $goods->days){
-						return Response::json(['status' => 'info', 'title' => '套餐冲突', 'message' => '是否将本次套餐存为 【预支付】?套餐会在已有套餐失效后生效,或者您可以手动激活套餐']);
-					}
-				}
-			}
-
-			DB::beginTransaction();
-			try{
-				// 生成订单
-				$order = new Order();
-				$order->order_sn = date('ymdHis').mt_rand(100000, 999999);
-				$order->user_id = Auth::user()->id;
-				$order->goods_id = $goods_id;
-				$order->coupon_id = !empty($coupon)? $coupon->id : 0;
-				$order->origin_amount = $goods->price;
-				$order->amount = $amount;
-				$order->expire_at = date("Y-m-d H:i:s", strtotime("+".$goods->days." days"));
-				$order->is_expire = 0;
-				$order->pay_way = 1;
-				$order->status = 2;
-				$order->save();
-
-				// 扣余额
-				User::query()->where('id', Auth::user()->id)->decrement('balance', $amount*100);
-
-				// 记录余额操作日志
-				$this->addUserBalanceLog(Auth::user()->id, $order->oid, Auth::user()->balance, Auth::user()->balance-$amount, -1*$amount, '购买商品:'.$goods->name);
-
-				// 优惠券置为已使用
-				if(!empty($coupon)){
-					if($coupon->usage == 1){
-						$coupon->status = 1;
-						$coupon->save();
-					}
-
-					// 写入日志
-					Helpers::addCouponLog($coupon->id, $goods_id, $order->oid, '余额支付订单使用');
-				}
-
-				// 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
-				if($goods->type == 2){
-					$existOrderList = Order::query()->with('goods')->whereHas('goods', function($q){
-						$q->where('type', 2);
-					})->where('user_id', Auth::user()->id)->where('oid', '<>', $order->oid)->where('is_expire', 0)->where('status', 2)->get();
-
-					foreach($existOrderList as $vo){
-						Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
-
-						// 先判断,防止手动扣减过流量的用户流量被扣成负数
-						if($order->user->transfer_enable-$vo->goods->traffic*1048576 <= 0){
-							// 写入用户流量变动记录
-							Helpers::addUserTrafficModifyLog(Auth::user()->id, $order->oid, 0, 0, '[余额支付]用户购买套餐,先扣减之前套餐的流量(扣完)');
-
-							User::query()->where('id', Auth::user()->id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
-						}else{
-							// 写入用户流量变动记录
-							$user = User::query()->uid()->first(); // 重新取出user信息
-							Helpers::addUserTrafficModifyLog(Auth::user()->id, $order->oid, $user->transfer_enable, ($user->transfer_enable-$vo->goods->traffic*1048576), '[余额支付]用户购买套餐,先扣减之前套餐的流量(未扣完)');
-
-							User::query()->uid()->update(['u' => 0, 'd' => 0]);
-							User::query()->uid()->decrement('transfer_enable', $vo->goods->traffic*1048576);
-						}
-					}
-				}
-
-				// 写入用户流量变动记录
-				$user = User::query()->uid()->first(); // 重新取出user信息
-				Helpers::addUserTrafficModifyLog($user->id, $order->oid, $user->transfer_enable, ($user->transfer_enable+$goods->traffic*1048576), '[余额支付]用户购买商品,加上流量');
-
-				// 把商品的流量加到账号上
-				User::query()->where('id', $user->id)->increment('transfer_enable', $goods->traffic*1048576);
-
-				// 计算账号过期时间
-				if($user->expire_time < date('Y-m-d', strtotime("+".$goods->days." days"))){
-					$expireTime = date('Y-m-d', strtotime("+".$goods->days." days"));
-				}else{
-					$expireTime = $user->expire_time;
-				}
-
-				// 套餐就改流量重置日,流量包不改
-				if($goods->type == 2){
-					User::query()->uid()->update(['traffic_reset_day' => date('d'), 'expire_time' => $expireTime, 'enable' => 1]);
-				}else{
-					User::query()->uid()->update(['expire_time' => $expireTime, 'enable' => 1]);
-				}
-
-				// 写入用户标签
-				if($goods->label){
-					// 用户默认标签
-					$defaultLabels = [];
-					if(self::$systemConfig['initial_labels_for_user']){
-						$defaultLabels = explode(',', self::$systemConfig['initial_labels_for_user']);
-					}
-
-					// 取出现有的标签
-					$userLabels = UserLabel::query()->where('user_id', Auth::user()->id)->pluck('label_id')->toArray();
-					$goodsLabels = GoodsLabel::query()->where('goods_id', $goods_id)->pluck('label_id')->toArray();
-
-					// 标签去重
-					$newUserLabels = array_values(array_unique(array_merge($userLabels, $goodsLabels, $defaultLabels)));
-
-					// 删除用户所有标签
-					UserLabel::query()->where('user_id', Auth::user()->id)->delete();
-
-					// 生成标签
-					foreach($newUserLabels as $vo){
-						$obj = new UserLabel();
-						$obj->user_id = Auth::user()->id;
-						$obj->label_id = $vo;
-						$obj->save();
-					}
-				}
-
-				// 写入返利日志
-				if($user->referral_uid){
-					$this->addReferralLog($user->id, $user->referral_uid, $order->oid, $amount, $amount*self::$systemConfig['referral_percent']);
-				}
-
-				// 取消重复返利
-				User::query()->where('id', $order->user_id)->update(['referral_uid' => 0]);
-
-				DB::commit();
-
-				return Response::json(['status' => 'success', 'data' => '', 'message' => '支付成功']);
-			} catch(Exception $e){
-				Log::error('支付订单失败:'.$e);
-
-				DB::rollBack();
-
-				return Response::json(['status' => 'fail', 'data' => '', 'message' => '支付失败:'.$e->getMessage()]);
-			}
-		}else{
-			$goods = Goods::query()->where('id', $goods_id)->where('status', 1)->first();
-			if(empty($goods)){
-				return Redirect::to('services');
-			}
+		$goods = Goods::query()->where('id', $goods_id)->where('status', 1)->first();
+		if(empty($goods)){
+			return Redirect::to('services');
+		}
+		// 有重置日时按照重置日为标准,否者就以过期日为标准
+		$dataPlusDays = Auth::user()->reset_time? Auth::user()->reset_time : Auth::user()->expire_time;
+		$view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays)-strtotime(date('Y-m-d')))/86400) : 0;
+		$view['activePlan'] = Order::uid()->with(['goods'])->where('is_expire', 0)->where('status', 2)->whereHas('goods', function($q){ $q->where('type', 2); })->exists();
 
-			$view['goods'] = $goods;
+		$view['goods'] = $goods;
 
-			return Response::view('user.buy', $view);
-		}
+		return Response::view('user.buy', $view);
 	}
 
 	// 推广返利
 	public function referral(Request $request)
 	{
-		if(Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->get()->isEmpty()){
+		if(Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->doesntExist()){
 			return Response::view('auth.error', ['message' => '本功能对非付费用户禁用!请 <a class="btn btn-sm btn-danger" href="/">返 回</a>']);
 		}
 		$view['referral_traffic'] = flowAutoShow(self::$systemConfig['referral_traffic']*1048576);
@@ -809,7 +639,7 @@ class UserController extends Controller
 		$view['articleList'] = Article::type(1)->orderBy('sort', 'desc')->orderBy('id', 'desc')->limit(10)->paginate(5);
 
 		//付费用户判断
-		$view['not_paying_user'] = Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->get()->isEmpty();
+		$view['not_paying_user'] = Order::uid()->where('status', 2)->where('is_expire', 0)->where('origin_amount', '>', 0)->doesntExist();
 		//客户端安装
 		$view['Shadowrocket_install'] = 'itms-services://?action=download-manifest&url='.self::$systemConfig['website_url'].'/clients/ipa.plist';
 		$view['Quantumult_install'] = 'itms-services://?action=download-manifest&url='.self::$systemConfig['website_url'].'/ipa.plist';

+ 0 - 20
app/Http/Models/Order.php

@@ -64,24 +64,4 @@ class Order extends Model
 	{
 		return $this->attributes['amount'] = $value*100;
 	}
-
-	function getStatusLabelAttribute()
-	{
-		switch($this->attributes['status']){
-			case -1:
-				$status_label = '已关闭';
-				break;
-			case 1:
-				$status_label = '已支付待确认';
-				break;
-			case 2:
-				$status_label = '已完成';
-				break;
-			case 0:
-			default:
-				$status_label = '待支付';
-		}
-
-		return $status_label;
-	}
 }

+ 2 - 1
composer.json

@@ -25,7 +25,8 @@
     "riverslei/payment": "*",
     "spatie/laravel-permission": "^2.29",
     "youzanyun/open-sdk": "^2.0",
-    "ext-json": "*"
+    "ext-json": "*",
+    "ext-curl": "*"
   },
   "require-dev": {
     "barryvdh/laravel-debugbar": "^3.2",

Diff do ficheiro suprimidas por serem muito extensas
+ 252 - 183
composer.lock


+ 1 - 0
public/assets/custom/range.min.css

@@ -0,0 +1 @@
+input[type=range]{height: 26px;-webkit-appearance:none}input[type=range]:focus{outline:0}input[type=range]::-webkit-slider-runnable-track{cursor:pointer;animate:.2s;background:#deecff;border-radius:14px}input[type=range]::-webkit-slider-thumb{height:20px;width:40px;border-radius:12px;background:#44ace1;cursor:pointer;-webkit-appearance:none;margin-top:-3px}input[type=range]:focus::-webkit-slider-runnable-track{background:#deecff}input[type=range]::-moz-range-track{cursor:pointer;animate:.2s;background:#deecff;border-radius:14px}input[type=range]::-moz-range-thumb{border-radius:12px;background:#44ace1;cursor:pointer}input[type=range]::-ms-track{cursor:pointer;animate:.2s;background:0 0;border-color:transparent;color:transparent}input[type=range]::-ms-fill-lower{background:#deecff;border-radius:28px}input[type=range]::-ms-fill-upper{background:#deecff;border-radius:28px}input[type=range]::-ms-thumb{margin-top:1px;border-radius:12px;background:#44ace1;cursor:pointer}

+ 1 - 0
public/assets/examples/css/apps/message.css

@@ -23,6 +23,7 @@
   .app-message-list .list-group .list-group-item {
     border-bottom: 0;
     border-radius: 0;
+    width: 100%;
     padding: 16px 30px;
     white-space: nowrap;
     z-index: 0; }

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/examples/css/apps/message.min.css


+ 3 - 1
public/assets/examples/css/apps/notebook.css

@@ -25,6 +25,7 @@
     border-radius: 0;
     margin-bottom: 0;
     white-space: normal;
+    width: 100%;
     z-index: 0; }
     .app-notebook-list .list-group .list-group-item:hover {
       color: #76838f;
@@ -47,7 +48,8 @@
       overflow: hidden;
       text-overflow: ellipsis;
       display: -webkit-box;
-      -webkit-line-clamp: 2; }
+      -webkit-line-clamp: 2;
+      -webkit-box-orient: vertical; }
     .app-notebook-list .list-group .list-group-item::-moz-selection,
     .app-notebook-list .list-group .list-group-item .list-group-item-heading::-moz-selection,
     .app-notebook-list .list-group .list-group-item .list-group-item-text::-moz-selection {

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/examples/css/apps/notebook.min.css


+ 3 - 1
public/assets/examples/css/pages/login-v3.min.css

@@ -1 +1,3 @@
-.page-login-v3:before{position:fixed;top:0;left:0;content:'';width:100%;height:100%;background-position:center top;background-size:cover;z-index:-1;background:#3e8ef7;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzYyYThlYSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMxNTcxYjEiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);background-image:linear-gradient(to bottom,#3e8ef7 0,#0b69e3 100%);background-repeat:repeat-x}.page-login-v3 .panel{width:400px;margin-bottom:45px;background:#fff;border-radius:.286rem}.page-login-v3 .panel .panel-body{padding:50px 40px 40px}.page-login-v3 .panel .brand-text{margin-top:8px}.page-login-v3 form{margin:45px 0 30px}.page-login-v3 form a{margin-left:20px}.page-login-v3 form .form-material.floating+.page-login-v3 form .form-material.floating{margin-top:30px}.page-login-v3 form .form-material label{color:#a3afb7;font-weight:300}@media (max-width:479.98px){.page-login-v3 .page-content{padding:30px 20px}.page-login-v3 .panel{width:auto;padding:10px}.page-login-v3 .panel .panel-body{padding:35px 25px 35px}}
+.page-login-v3:before{position:fixed;top:0;left:0;content:'';width:100%;height:100%;background-position:center top;background-size:cover;z-index:-1;background:#3e8ef7;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzYyYThlYSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMxNTcxYjEiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);background-image:linear-gradient(to bottom,#3e8ef7 0%,#0b69e3 100%);background-repeat:repeat-x}.page-login-v3 .panel{width:400px;margin-bottom:45px;background:#fff;border-radius:0.286rem}.page-login-v3 .panel.brand-text{margin-top:12px}.page-login-v3 form{margin:0 0 30px}.page-login-v3 form.form-material.floating+.page-login-v3 form.form-material.floating{margin-top:30px}.page-login-v3 form.form-material label{color:#a3afb7;font-weight:300}
+@media(max-width:479.98px){.page-login-v3 .panel{width:330px;padding:10px}}
+@media screen and(max-height:575px){.g-recaptcha{-webkit-transform:scale(0.81);transform:scale(0.81);-webkit-transform-origin:0 0;transform-origin:0 0}}.geetest_holder.geetest_wind{min-width:245px!important}

BIN
public/assets/examples/images/assemble.png


BIN
public/assets/examples/images/bootstrap.png


BIN
public/assets/examples/images/bower.png


BIN
public/assets/examples/images/browser/chrome-logo.png


BIN
public/assets/examples/images/browser/firefox-logo.png


BIN
public/assets/examples/images/browser/internet-logo.png


BIN
public/assets/examples/images/browser/opera-logo.png


BIN
public/assets/examples/images/browser/safari-logo.png


BIN
public/assets/examples/images/coming-soon.jpg


BIN
public/assets/examples/images/country/australia-icon.png


BIN
public/assets/examples/images/country/canada-icon.png


BIN
public/assets/examples/images/country/china-icon.png


BIN
public/assets/examples/images/country/germany-icon.png


BIN
public/assets/examples/images/country/uk-icon.png


BIN
public/assets/examples/images/country/usa-icon.png


BIN
public/assets/examples/images/dashboard-header.jpg


BIN
public/assets/examples/images/dashboard2-header.jpg


BIN
public/assets/examples/images/favicon.ico


BIN
public/assets/examples/images/grunt.png


BIN
public/assets/examples/images/less.png


BIN
public/assets/examples/images/lockscreen.jpg


BIN
public/assets/examples/images/login.jpg


BIN
public/assets/examples/images/modal/accordion-modal.png


BIN
public/assets/examples/images/modal/fillin-modal.png


BIN
public/assets/examples/images/modal/form-modal.png


BIN
public/assets/examples/images/modal/grid-modal.png


BIN
public/assets/examples/images/modal/modal-position-sidebar.png


BIN
public/assets/examples/images/modal/modal-position-top.png


BIN
public/assets/examples/images/modal/modal-position.png


BIN
public/assets/examples/images/modal/multiple-modal.png


BIN
public/assets/examples/images/modal/size-modal.png


BIN
public/assets/examples/images/modal/style-modal.png


BIN
public/assets/examples/images/modal/sweet-alert.png


BIN
public/assets/examples/images/modal/tab-modal.png


BIN
public/assets/examples/images/navbar/fixed-to-bottom.png


BIN
public/assets/examples/images/navbar/fixed-to-top.png


BIN
public/assets/examples/images/poster.jpg


BIN
public/assets/examples/images/products/applewatch.png


BIN
public/assets/examples/images/products/imac.png


BIN
public/assets/examples/images/products/iphone.png


BIN
public/assets/examples/images/products/macmouse.png


BIN
public/assets/examples/images/txt.png


+ 1 - 2
public/assets/examples/js/dashboard/analytics.js

@@ -140,8 +140,7 @@
     var overlappingBarsDataThree = {
       labels: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
       series: [[5, 2, 6, 7, 10, 8, 6, 5], [4, 3, 5, 6, 8, 6, 4, 3]]
-    }; //define an array contains four bar's data
-
+    };
     var barsData = [overlappingBarsDataOne, overlappingBarsDataTwo, overlappingBarsDataThree, overlappingBarsDataThree]; //Common OverlappingBarsOptions
 
     var overlappingBarsOptions = {

+ 81 - 0
public/assets/examples/js/pages/map-point.js

@@ -35,4 +35,85 @@
     zoom: 8,
     icon: 'http://maps.google.com/mapfiles/markerC.png'
   }];
+  var LocsAv2 = [{
+    lat: 45.9,
+    lon: 10.9,
+    title: 'Zone A1',
+    html: '<h3>Content A1</h3>',
+    type: 'circle',
+    circle_options: {
+      radius: 200000
+    },
+    draggable: true
+  }, {
+    lat: 44.8,
+    lon: 1.7,
+    title: 'Draggable',
+    html: '<h3>Content B1</h3>',
+    show_infowindow: false,
+    visible: true,
+    draggable: true
+  }, {
+    lat: 51.5,
+    lon: -1.1,
+    title: 'Title C1',
+    html: ['<h3>Content C1</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 8,
+    visible: true
+  }];
+  var LocsB = [{
+    lat: 52.1,
+    lon: 11.3,
+    title: 'Title A2',
+    html: ['<h3>Content A2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 8
+  }, {
+    lat: 51.2,
+    lon: 22.2,
+    title: 'Title B2',
+    html: ['<h3>Content B2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 8
+  }, {
+    lat: 49.4,
+    lon: 35.9,
+    title: 'Title C2',
+    html: ['<h3>Content C2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 4
+  }, {
+    lat: 47.8,
+    lon: 15.6,
+    title: 'Title D2',
+    html: ['<h3>Content D2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 6
+  }];
+  var LocsBv2 = [{
+    lat: 52.1,
+    lon: 11.3,
+    title: 'Title A2',
+    html: ['<h3>Content A2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 8
+  }, {
+    lat: 51.2,
+    lon: 22.2,
+    title: 'Title B2',
+    html: ['<h3>Content B2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 8,
+    type: 'circle',
+    circle_options: {
+      radius: 100000
+    }
+  }, {
+    lat: 49.4,
+    lon: 35.9,
+    title: 'Title C2',
+    html: ['<h3>Content C2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 4
+  }, {
+    lat: 47.8,
+    lon: 15.6,
+    title: 'Title D2',
+    html: ['<h3>Content D2</h3>', '<p>Lorem Ipsum..</p>'].join(''),
+    zoom: 6
+  }];
+  var LocsAB = LocsA.concat(LocsB);
 });

+ 183 - 28
public/assets/examples/js/tables/bootstrap.js

@@ -1,31 +1,186 @@
 (function (global, factory) {
-    if (typeof define === "function" && define.amd) {
-        define("/tables/bootstrap", ["jquery", "Site"], factory);
-    } else if (typeof exports !== "undefined") {
-        factory(require("jquery"), require("Site"));
-    } else {
-        var mod = {
-            exports: {}
-        };
-        factory(global.jQuery, global.Site);
-        global.tablesBootstrap = mod.exports;
-    }
+  if (typeof define === "function" && define.amd) {
+    define("/tables/bootstrap", ["jquery", "Site"], factory);
+  } else if (typeof exports !== "undefined") {
+    factory(require("jquery"), require("Site"));
+  } else {
+    var mod = {
+      exports: {}
+    };
+    factory(global.jQuery, global.Site);
+    global.tablesBootstrap = mod.exports;
+  }
 })(this, function (_jquery, _Site) {
-    "use strict";
-
-    _jquery = babelHelpers.interopRequireDefault(_jquery);
-
-    (function () {
-        (0, _jquery.default)('#exampleTableToolbar').bootstrapTable({
-            showToggle: true,
-            showColumns: true,
-            toolbar: '#exampleToolbar',
-            iconSize: 'outline',
-            icons: {
-                toggle: 'wb-order',
-                columns: 'wb-list-bulleted'
-            }
-        });
-    })(); // Example Bootstrap Table Events
-    // ------------------------------
+  "use strict";
+
+  _jquery = babelHelpers.interopRequireDefault(_jquery);
+
+  function buildTable($el, cells, rows) {
+    var i,
+        j,
+        row,
+        columns = [],
+        data = [];
+
+    for (i = 0; i < cells; i++) {
+      columns.push({
+        field: 'field' + i,
+        title: 'Cell' + i
+      });
+    }
+
+    for (i = 0; i < rows; i++) {
+      row = {};
+
+      for (j = 0; j < cells; j++) {
+        row['field' + j] = 'Row-' + i + '-' + j;
+      }
+
+      data.push(row);
+    }
+
+    $el.bootstrapTable('destroy').bootstrapTable({
+      columns: columns,
+      data: data,
+      iconSize: 'outline',
+      icons: {
+        columns: 'wb-list-bulleted'
+      }
+    });
+  }
+
+  (0, _jquery.default)(document).ready(function ($$$1) {
+    (0, _Site.run)();
+  }); // Example Bootstrap Table From Data
+  // ---------------------------------
+
+  (function () {
+    var bt_data = [{
+      "Tid": "1",
+      "First": "Jill",
+      "Last": "Smith",
+      "Score": "50"
+    }, {
+      "Tid": "2",
+      "First": "Eve",
+      "Last": "Jackson",
+      "Score": "94"
+    }, {
+      "Tid": "3",
+      "First": "John",
+      "Last": "Doe",
+      "Score": "80"
+    }, {
+      "Tid": "4",
+      "First": "Adam",
+      "Last": "Johnson",
+      "Score": "67"
+    }, {
+      "Tid": "5",
+      "First": "Fish",
+      "Last": "Johnson",
+      "Score": "100"
+    }, {
+      "Tid": "6",
+      "First": "CC",
+      "Last": "Joson",
+      "Score": "77"
+    }, {
+      "Tid": "7",
+      "First": "Piger",
+      "Last": "Yoson",
+      "Score": "87"
+    }];
+    (0, _jquery.default)('#exampleTableFromData').bootstrapTable({
+      data: bt_data,
+      // mobileResponsive: true,
+      height: "250"
+    });
+  })(); // Example Bootstrap Table Columns
+  // -------------------------------
+
+
+  (function () {
+    (0, _jquery.default)('#exampleTableColumns').bootstrapTable({
+      url: "../../assets/data/bootstrap_table_test.json",
+      height: "400",
+      iconSize: 'outline',
+      showColumns: true,
+      icons: {
+        refresh: 'wb-refresh',
+        toggle: 'wb-order',
+        columns: 'wb-list-bulleted'
+      }
+    });
+  })(); // Example Bootstrap Table Large Columns
+  // -------------------------------------
+
+
+  buildTable((0, _jquery.default)('#exampleTableLargeColumns'), 50, 50); // Example Bootstrap Table Toolbar
+  // -------------------------------
+
+  (function () {
+    (0, _jquery.default)('#exampleTableToolbar').bootstrapTable({
+      url: "../../assets/data/bootstrap_table_test2.json",
+      search: true,
+      showRefresh: true,
+      showToggle: true,
+      showColumns: true,
+      toolbar: '#exampleToolbar',
+      iconSize: 'outline',
+      icons: {
+        refresh: 'wb-refresh',
+        toggle: 'wb-order',
+        columns: 'wb-list-bulleted'
+      }
+    });
+  })(); // Example Bootstrap Table Events
+  // ------------------------------
+
+
+  (function () {
+    (0, _jquery.default)('#exampleTableEvents').bootstrapTable({
+      url: "../../assets/data/bootstrap_table_test.json",
+      search: true,
+      pagination: true,
+      showRefresh: true,
+      showToggle: true,
+      showColumns: true,
+      iconSize: 'outline',
+      toolbar: '#exampleTableEventsToolbar',
+      icons: {
+        refresh: 'wb-refresh',
+        toggle: 'wb-order',
+        columns: 'wb-list-bulleted'
+      }
+    });
+    var $result = (0, _jquery.default)('#examplebtTableEventsResult');
+    (0, _jquery.default)('#exampleTableEvents').on('all.bs.table', function (e, name, args) {
+      console.log('Event:', name, ', data:', args);
+    }).on('click-row.bs.table', function (e, row, $element) {
+      $result.text('Event: click-row.bs.table');
+    }).on('dbl-click-row.bs.table', function (e, row, $element) {
+      $result.text('Event: dbl-click-row.bs.table');
+    }).on('sort.bs.table', function (e, name, order) {
+      $result.text('Event: sort.bs.table');
+    }).on('check.bs.table', function (e, row) {
+      $result.text('Event: check.bs.table');
+    }).on('uncheck.bs.table', function (e, row) {
+      $result.text('Event: uncheck.bs.table');
+    }).on('check-all.bs.table', function (e) {
+      $result.text('Event: check-all.bs.table');
+    }).on('uncheck-all.bs.table', function (e) {
+      $result.text('Event: uncheck-all.bs.table');
+    }).on('load-success.bs.table', function (e, data) {
+      $result.text('Event: load-success.bs.table');
+    }).on('load-error.bs.table', function (e, status) {
+      $result.text('Event: load-error.bs.table');
+    }).on('column-switch.bs.table', function (e, field, checked) {
+      $result.text('Event: column-switch.bs.table');
+    }).on('page-change.bs.table', function (e, size, number) {
+      $result.text('Event: page-change.bs.table');
+    }).on('search.bs.table', function (e, text) {
+      $result.text('Event: search.bs.table');
+    });
+  })();
 });

+ 5 - 1
public/assets/examples/js/tables/datatable.js

@@ -194,7 +194,11 @@
         this.datatable.order([0, 'asc']).draw(); // always show fields
       },
       rowCancel: function rowCancel($row) {
-        var $actions, data, $cancel;
+        var _self = this,
+            $actions,
+            i,
+            data,
+            $cancel;
 
         if ($row.hasClass('adding')) {
           this.rowRemove($row);

+ 1 - 1
public/assets/global/fonts/Roboto/Roboto.min.css

@@ -1 +1 @@
-@font-face{font-family:Roboto;font-weight:300;font-style:normal;src:url(../Roboto/Roboto-300.eot);src:url(../Roboto/Roboto-300.eot?#iefix) format("embedded-opentype"),local("Roboto Light"),local("Roboto-300"),url(../Roboto/Roboto-300.woff2) format("woff2"),url(../Roboto/Roboto-300.woff) format("woff"),url(../Roboto/Roboto-300.ttf) format("truetype"),url(../Roboto/Roboto-300.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:400;font-style:normal;src:url(../Roboto/Roboto-regular.eot);src:url(../Roboto/Roboto-regular.eot?#iefix) format("embedded-opentype"),local("Roboto"),local("Roboto-regular"),url(../Roboto/Roboto-regular.woff2) format("woff2"),url(../Roboto/Roboto-regular.woff) format("woff"),url(../Roboto/Roboto-regular.ttf) format("truetype"),url(../Roboto/Roboto-regular.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:500;font-style:normal;src:url(../Roboto/Roboto-500.eot);src:url(../Roboto/Roboto-500.eot?#iefix) format("embedded-opentype"),local("Roboto Medium"),local("Roboto-500"),url(../Roboto/Roboto-500.woff2) format("woff2"),url(../Roboto/Roboto-500.woff) format("woff"),url(../Roboto/Roboto-500.ttf) format("truetype"),url(../Roboto/Roboto-500.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:300;font-style:italic;src:url(../Roboto/Roboto-300italic.eot);src:url(../Roboto/Roboto-300italic.eot?#iefix) format("embedded-opentype"),local("Roboto Light Italic"),local("Roboto-300italic"),url(../Roboto/Roboto-300italic.woff2) format("woff2"),url(../Roboto/Roboto-300italic.woff) format("woff"),url(../Roboto/Roboto-300italic.ttf) format("truetype"),url(../Roboto/Roboto-300italic.svg#Roboto) format("svg")}
+@font-face{font-family:Roboto;font-weight:300;font-style:normal;src:url(Roboto-300.eot);src:url(Roboto-300.eot?#iefix) format("embedded-opentype"),local("Roboto Light"),local("Roboto-300"),url(Roboto-300.woff2) format("woff2"),url(Roboto-300.woff) format("woff"),url(Roboto-300.ttf) format("truetype"),url(Roboto-300.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:400;font-style:normal;src:url(Roboto-regular.eot);src:url(Roboto-regular.eot?#iefix) format("embedded-opentype"),local("Roboto"),local("Roboto-regular"),url(Roboto-regular.woff2) format("woff2"),url(Roboto-regular.woff) format("woff"),url(Roboto-regular.ttf) format("truetype"),url(Roboto-regular.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:500;font-style:normal;src:url(Roboto-500.eot);src:url(Roboto-500.eot?#iefix) format("embedded-opentype"),local("Roboto Medium"),local("Roboto-500"),url(Roboto-500.woff2) format("woff2"),url(Roboto-500.woff) format("woff"),url(Roboto-500.ttf) format("truetype"),url(Roboto-500.svg#Roboto) format("svg")}@font-face{font-family:Roboto;font-weight:300;font-style:italic;src:url(Roboto-300italic.eot);src:url(Roboto-300italic.eot?#iefix) format("embedded-opentype"),local("Roboto Light Italic"),local("Roboto-300italic"),url(Roboto-300italic.woff2) format("woff2"),url(Roboto-300italic.woff) format("woff"),url(Roboto-300italic.ttf) format("truetype"),url(Roboto-300italic.svg#Roboto) format("svg")}

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/brand-icons/brand-icons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/font-awesome/font-awesome.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/foundation/foundation.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/framework7/framework7.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/glyphicons/glyphicons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/ionicons/ionicons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/map-icons/map-icons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/material-design/material-design.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/mfglabs/mfglabs.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/micon/micon.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/octicons/octicons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/open-iconic/open-iconic.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/openwebicons/openwebicons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/themify/themify.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/weather-icons/weather-icons.min.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
public/assets/global/fonts/web-icons/web-icons.min.css


+ 1 - 1
public/assets/global/js/Plugin.js

@@ -20,7 +20,7 @@
   _exports.getPlugin = getPlugin;
   _exports.getDefaults = getDefaults;
   _exports.pluginFactory = pluginFactory;
-  _exports.Plugin = _exports.default = void 0;
+  _exports.default = _exports.Plugin = void 0;
   _jquery = babelHelpers.interopRequireDefault(_jquery);
   var plugins = {};
   var apis = {};

+ 6 - 7
public/assets/global/js/Plugin/editlist.js

@@ -1,16 +1,16 @@
 (function (global, factory) {
   if (typeof define === "function" && define.amd) {
-    define("/Plugin/editlist", ["exports", "jquery", "bootbox", "Plugin"], factory);
+    define("/Plugin/editlist", ["exports", "jquery", "Plugin"], factory);
   } else if (typeof exports !== "undefined") {
-    factory(exports, require("jquery"), require("bootbox"), require("Plugin"));
+    factory(exports, require("jquery"), require("Plugin"));
   } else {
     var mod = {
       exports: {}
     };
-    factory(mod.exports, global.jQuery, global.bootbox, global.Plugin);
+    factory(mod.exports, global.jQuery, global.Plugin);
     global.PluginEditlist = mod.exports;
   }
-})(this, function (_exports, _jquery, _bootbox, _Plugin2) {
+})(this, function (_exports, _jquery, _Plugin2) {
   "use strict";
 
   Object.defineProperty(_exports, "__esModule", {
@@ -18,7 +18,6 @@
   });
   _exports.default = void 0;
   _jquery = babelHelpers.interopRequireDefault(_jquery);
-  _bootbox = babelHelpers.interopRequireDefault(_bootbox);
   _Plugin2 = babelHelpers.interopRequireDefault(_Plugin2);
   var pluginName = 'editlist';
   var defaults = {};
@@ -57,11 +56,11 @@
           self.disable();
         });
         this.$delBtn.on('click', function () {
-          if (typeof _bootbox.default === 'undefined') {
+          if (typeof bootbox === 'undefined') {
             return;
           }
 
-          _bootbox.default.dialog({
+          bootbox.dialog({
             message: 'Do you want to delete the contact?',
             buttons: {
               success: {

+ 63 - 4
public/assets/global/js/Plugin/formatter.js

@@ -1,15 +1,74 @@
 (function (global, factory) {
   if (typeof define === "function" && define.amd) {
-    define("/Plugin/formatter", [], factory);
+    define("/Plugin/formatter", ["exports", "jquery", "Plugin"], factory);
   } else if (typeof exports !== "undefined") {
-    factory();
+    factory(exports, require("jquery"), require("Plugin"));
   } else {
     var mod = {
       exports: {}
     };
-    factory();
+    factory(mod.exports, global.jQuery, global.Plugin);
     global.PluginFormatter = mod.exports;
   }
-})(this, function () {
+})(this, function (_exports, _jquery, _Plugin2) {
   "use strict";
+
+  Object.defineProperty(_exports, "__esModule", {
+    value: true
+  });
+  _exports.default = void 0;
+  _jquery = babelHelpers.interopRequireDefault(_jquery);
+  _Plugin2 = babelHelpers.interopRequireDefault(_Plugin2);
+  var NAME = 'formatter';
+
+  var Formatter =
+  /*#__PURE__*/
+  function (_Plugin) {
+    babelHelpers.inherits(Formatter, _Plugin);
+
+    function Formatter() {
+      babelHelpers.classCallCheck(this, Formatter);
+      return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Formatter).apply(this, arguments));
+    }
+
+    babelHelpers.createClass(Formatter, [{
+      key: "getName",
+      value: function getName() {
+        return NAME;
+      }
+    }, {
+      key: "render",
+      value: function render() {
+        if (!_jquery.default.fn.formatter) {
+          return;
+        }
+
+        var browserName = navigator.userAgent.toLowerCase();
+
+        if (/msie/i.test(browserName) && !/opera/.test(browserName)) {} else {}
+
+        var $el = this.$el,
+            options = this.options;
+
+        if (options.pattern) {
+          options.pattern = options.pattern.replace(/\[\[/g, '{{').replace(/\]\]/g, '}}');
+        }
+
+        $el.formatter(options);
+      }
+    }], [{
+      key: "getDefaults",
+      value: function getDefaults() {
+        return {
+          persistent: true
+        };
+      }
+    }]);
+    return Formatter;
+  }(_Plugin2.default);
+
+  _Plugin2.default.register(NAME, Formatter);
+
+  var _default = Formatter;
+  _exports.default = _default;
 });

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff