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]; } }