You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseAuth.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace crmeb\basic;
  3. use Firebase\JWT\JWT;
  4. use think\helper\Str;
  5. class BaseAuth
  6. {
  7. public function ________($withSearch, $setModel)
  8. {
  9. // if (isset($withSearch['account'])) {
  10. // return ['menu_name'];
  11. // }
  12. // $setModel = new $setModel();
  13. // $res = Db::query('show COLUMNS FROM ' . $setModel->getTable());
  14. // $Field = [];
  15. // foreach ($res as $k => $v) {
  16. // $Field[] = $v['Field'];
  17. // }
  18. // $withSearch2 = [];
  19. // foreach ($withSearch as $k => $v) {
  20. // // 检测搜索器
  21. // $fieldName = is_numeric($k) ? $v : $k;
  22. // $method = 'search' . Str::studly($fieldName) . 'Attr';
  23. // if (method_exists($setModel, $method)) {
  24. // //存在增加
  25. // $withSearch2[] = $v;
  26. // }
  27. // }
  28. // $Field = array_merge($Field, $withSearch2);
  29. // $arr = array_intersect($withSearch, $Field);
  30. // return list($with, $whereKey) = [$arr, []];
  31. $with = [];
  32. $whereKey = [];
  33. $respones = new \ReflectionClass($setModel);
  34. foreach ($withSearch as $fieldName) {
  35. if ($fieldName !== 0) {
  36. $method = 'search' . Str::studly($fieldName) . 'Attr';
  37. if ($respones->hasMethod($method) || $fieldName == 'is_show') {
  38. $with[] = $fieldName;
  39. } else {
  40. $whereKey[] = $fieldName;
  41. }
  42. }
  43. }
  44. return [$with, $whereKey];
  45. }
  46. public function _____($setModel, $where, $num, $stock, $sales)
  47. {
  48. $isQuota = false;
  49. if (isset($where['type']) && $where['type']) {
  50. $isQuota = true;
  51. if (count($where) == 2) {
  52. unset($where['type']);
  53. }
  54. }
  55. $field = $isQuota ? 'stock,quota' : 'stock';
  56. $product = $setModel->where($where)->field($field)->find();
  57. if ($product) {
  58. return $setModel->where($where)->when($isQuota, function ($query) use ($num) {
  59. $query->dec('quota', $num);
  60. })->dec($stock, $num)->inc($sales, $num)->update();
  61. }
  62. return false;
  63. }
  64. public function ___($setModel, $where, $num, $stock, $sales)
  65. {
  66. $isQuota = false;
  67. if (isset($where['type']) && $where['type']) {
  68. $isQuota = true;
  69. if (count($where) == 2) {
  70. unset($where['type']);
  71. }
  72. }
  73. $salesOne = $setModel->where($where)->value($sales);
  74. if ($salesOne) {
  75. $salesNum = $num;
  76. if ($num > $salesOne) {
  77. $salesNum = $salesOne;
  78. }
  79. return $setModel->where($where)->when($isQuota, function ($query) use ($num) {
  80. $query->inc('quota', $num);
  81. })->inc($stock, $num)->dec($sales, $salesNum)->update();
  82. }
  83. return true;
  84. }
  85. public function parseToken(string $jwt)
  86. {
  87. $token = $jwt;
  88. list($headb64, $bodyb64, $cryptob64) = explode('.', $token);
  89. $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64));
  90. return [$payload->jti->id, $payload->jti->type];
  91. }
  92. }