123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
- namespace crmeb\basic;
-
- use Firebase\JWT\JWT;
- use think\helper\Str;
-
- class BaseAuth
- {
-
- public function ________($withSearch, $setModel)
- {
- // if (isset($withSearch['account'])) {
- // return ['menu_name'];
- // }
- // $setModel = new $setModel();
- // $res = Db::query('show COLUMNS FROM ' . $setModel->getTable());
- // $Field = [];
- // foreach ($res as $k => $v) {
- // $Field[] = $v['Field'];
- // }
- // $withSearch2 = [];
- // foreach ($withSearch as $k => $v) {
- // // 检测搜索器
- // $fieldName = is_numeric($k) ? $v : $k;
- // $method = 'search' . Str::studly($fieldName) . 'Attr';
- // if (method_exists($setModel, $method)) {
- // //存在增加
- // $withSearch2[] = $v;
- // }
- // }
- // $Field = array_merge($Field, $withSearch2);
- // $arr = array_intersect($withSearch, $Field);
- // return list($with, $whereKey) = [$arr, []];
- $with = [];
- $whereKey = [];
- $respones = new \ReflectionClass($setModel);
- foreach ($withSearch as $fieldName) {
- if ($fieldName !== 0) {
- $method = 'search' . Str::studly($fieldName) . 'Attr';
- if ($respones->hasMethod($method) || $fieldName == 'is_show') {
- $with[] = $fieldName;
- } else {
- $whereKey[] = $fieldName;
- }
- }
- }
- return [$with, $whereKey];
- }
-
- public function _____($setModel, $where, $num, $stock, $sales)
- {
- $isQuota = false;
- if (isset($where['type']) && $where['type']) {
- $isQuota = true;
- if (count($where) == 2) {
- unset($where['type']);
- }
- }
- $field = $isQuota ? 'stock,quota' : 'stock';
- $product = $setModel->where($where)->field($field)->find();
- if ($product) {
- return $setModel->where($where)->when($isQuota, function ($query) use ($num) {
- $query->dec('quota', $num);
- })->dec($stock, $num)->inc($sales, $num)->update();
- }
- return false;
- }
-
- public function ___($setModel, $where, $num, $stock, $sales)
- {
- $isQuota = false;
- if (isset($where['type']) && $where['type']) {
- $isQuota = true;
- if (count($where) == 2) {
- unset($where['type']);
- }
- }
- $salesOne = $setModel->where($where)->value($sales);
- if ($salesOne) {
- $salesNum = $num;
- if ($num > $salesOne) {
- $salesNum = $salesOne;
- }
- return $setModel->where($where)->when($isQuota, function ($query) use ($num) {
- $query->inc('quota', $num);
- })->inc($stock, $num)->dec($sales, $salesNum)->update();
- }
- return true;
- }
-
- public function parseToken(string $jwt)
- {
- $token = $jwt;
- list($headb64, $bodyb64, $cryptob64) = explode('.', $token);
- $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64));
- return [$payload->jti->id, $payload->jti->type];
- }
-
- }
|