WorkerAccountLogEnum.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\common\enum\worker;
  3. /**
  4. * 师傅账户流水变动表枚举
  5. * Class AccountLogEnum
  6. * @package app\common\enum
  7. */
  8. class WorkerAccountLogEnum
  9. {
  10. /**
  11. * 变动类型命名规则:对象_动作_简洁描述
  12. * 动作 DEC-减少 INC-增加
  13. * 对象 UM-师傅余额
  14. */
  15. /**
  16. * 变动对象
  17. * UM 师傅余额(user_money)
  18. */
  19. const UM = 1;
  20. /**
  21. * 动作
  22. * INC 增加
  23. * DEC 减少
  24. */
  25. const INC = 1;
  26. const DEC = 2;
  27. /**
  28. * 师傅余额减少类型
  29. */
  30. const UM_DEC_ADMIN = 100;
  31. /**
  32. * 师傅余额增加类型
  33. */
  34. const UM_INC_ADMIN = 200;
  35. /**
  36. * 师傅余额(减少类型汇总)
  37. */
  38. const UM_DEC = [
  39. self::UM_DEC_ADMIN,
  40. ];
  41. /**
  42. * 师傅余额(增加类型汇总)
  43. */
  44. const UM_INC = [
  45. self::UM_INC_ADMIN,
  46. ];
  47. /**
  48. * @notes 动作描述
  49. * @param $action
  50. * @param false $flag
  51. * @return string|string[]
  52. */
  53. public static function getActionDesc($action, $flag = false)
  54. {
  55. $desc = [
  56. self::DEC => '减少',
  57. self::INC => '增加',
  58. ];
  59. if ($flag) {
  60. return $desc;
  61. }
  62. return $desc[$action] ?? '';
  63. }
  64. /**
  65. * @notes 变动类型描述
  66. * @param $changeType
  67. * @param false $flag
  68. * @return string|string[]
  69. */
  70. public static function getChangeTypeDesc($changeType, $flag = false)
  71. {
  72. $desc = [
  73. self::UM_DEC_ADMIN => '平台减少余额',
  74. self::UM_INC_ADMIN => '平台增加余额',
  75. ];
  76. if ($flag) {
  77. return $desc;
  78. }
  79. return $desc[$changeType] ?? '';
  80. }
  81. /**
  82. * @notes 获取师傅余额类型描述
  83. * @return string|string[]
  84. */
  85. public static function getUserMoneyChangeTypeDesc()
  86. {
  87. $UMChangeType = self::getUserMoneyChangeType();
  88. $changeTypeDesc = self::getChangeTypeDesc('', true);
  89. return array_filter($changeTypeDesc, function ($key) use ($UMChangeType) {
  90. return in_array($key, $UMChangeType);
  91. }, ARRAY_FILTER_USE_KEY);
  92. }
  93. /**
  94. * @notes 获取师傅余额变动类型
  95. * @return int[]
  96. */
  97. public static function getUserMoneyChangeType() : array
  98. {
  99. return array_merge(self::UM_DEC, self::UM_INC);
  100. }
  101. /**
  102. * @notes 获取变动对象
  103. * @param $changeType
  104. * @return false
  105. */
  106. public static function getChangeObject($changeType)
  107. {
  108. // 师傅余额
  109. $um = self::getUserMoneyChangeType();
  110. if (in_array($changeType, $um)) {
  111. return self::UM;
  112. }
  113. // 其他...
  114. return false;
  115. }
  116. }