businessserver.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-12-31 16:08:48
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-31 17:57:06
  7. */
  8. namespace app\index\server;
  9. use app\index\model\businesstypemodel;
  10. class businessserver
  11. {
  12. public function getserverobj($kind, $type)
  13. {
  14. $m_b = new businesstypemodel();
  15. $where = [
  16. 'kind' => $kind,
  17. 'type' => $type,
  18. ];
  19. $info = $m_b->getInfo($where);
  20. if (empty($info)) {
  21. return backarr(0, '业务处理请求错误');
  22. }
  23. $classpath = str_replace("\\", "/", __CLASS__);
  24. $classpatharray = array_filter(explode('/', $classpath));
  25. $classname = $classpatharray[count($classpatharray) - 1];
  26. $serverclass = str_replace($classname, $type . $classname, __CLASS__);
  27. $parentclass = str_replace($classname, $kind . $classname, __CLASS__);
  28. if (!class_exists($parentclass)) {
  29. throw new \Exception("无对应业务");
  30. }
  31. $parentobj = new $parentclass();
  32. if (!class_exists($serverclass)) {
  33. throw new \Exception("无对应服务");
  34. }
  35. $obj = new $serverclass();
  36. if ($obj instanceof $parentobj) {
  37. return $obj;
  38. }
  39. throw new \Exception("无对应服务");
  40. }
  41. /**
  42. * 校验业务是否可用
  43. * 20211231
  44. * wj
  45. */
  46. protected function checkactive($info)
  47. {
  48. $time = time();
  49. $isactive = $info['isactive'];
  50. $starttime = strtotime($info['starttime']);
  51. $endtime = strtotime($info['endtime']);
  52. if (!$isactive) {
  53. return false;
  54. }
  55. if ($time > $endtime) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. /**
  61. * 校验业务是否开始
  62. * 20220112
  63. * wj
  64. */
  65. protected function checkstart($info)
  66. {
  67. $time = time();
  68. $isactive = $info['isactive'];
  69. $starttime = strtotime($info['starttime']);
  70. $endtime = strtotime($info['endtime']);
  71. if (!$isactive) {
  72. return false;
  73. }
  74. if ($time < $starttime) {
  75. return false;
  76. }
  77. return true;
  78. }
  79. }