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 2.9KB

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