mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 14:01:07 +00:00
【程序目录】更新后台token验证,更新阿里云短信问题
This commit is contained in:
parent
3e47eaab2b
commit
b5fe43c533
@ -48,7 +48,7 @@ abstract class BaseDao
|
||||
* @param array $where
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [])
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
}
|
||||
@ -59,17 +59,22 @@ abstract class BaseDao
|
||||
* @param string $field
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param bool $search
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function selectList(array $where, $field = '*', $page = 0, $limit = 0)
|
||||
public function selectList(array $where, string $field = '*', int $page = 0, int $limit = 0, bool $search = false)
|
||||
{
|
||||
return $this->getModel()->where($where)->field($field)
|
||||
->when($page && $limit, function ($query) use ($page, $limit) {
|
||||
$query->page($page, $limit);
|
||||
})->select();
|
||||
if ($search) {
|
||||
$model = $this->search($where);
|
||||
} else {
|
||||
$model = $this->getModel()->where($where);
|
||||
}
|
||||
return $model->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
|
||||
$query->page($page, $limit);
|
||||
})->select();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +97,7 @@ abstract class BaseDao
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDistinctCount(array $where, $field, $search = true)
|
||||
public function getDistinctCount(array $where, $field, bool $search = true)
|
||||
{
|
||||
if ($search) {
|
||||
return $this->search($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
|
||||
@ -112,7 +117,7 @@ abstract class BaseDao
|
||||
|
||||
/**
|
||||
* 获取主键
|
||||
* @return mixed
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getPk()
|
||||
{
|
||||
@ -121,7 +126,7 @@ abstract class BaseDao
|
||||
|
||||
/**
|
||||
* 获取一条数据
|
||||
* @param int|array $id
|
||||
* @param $id
|
||||
* @param array|null $field
|
||||
* @param array|null $with
|
||||
* @return array|Model|null
|
||||
@ -136,7 +141,7 @@ abstract class BaseDao
|
||||
} else {
|
||||
$where = [$this->getPk() => $id];
|
||||
}
|
||||
return $this->getModel()::where($where)->when(count($with), function ($query) use ($with) {
|
||||
return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
|
||||
$query->with($with);
|
||||
})->field($field ?? ['*'])->find();
|
||||
}
|
||||
@ -179,7 +184,7 @@ abstract class BaseDao
|
||||
public function value(array $where, ?string $field = '')
|
||||
{
|
||||
$pk = $this->getPk();
|
||||
return $this->getModel()::where($where)->value($field ?: $pk);
|
||||
return $this->getModel()->where($where)->value($field ?: $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +196,7 @@ abstract class BaseDao
|
||||
*/
|
||||
public function getColumn(array $where, string $field, string $key = '')
|
||||
{
|
||||
return $this->getModel()::where($where)->column($field, $key);
|
||||
return $this->getModel()->where($where)->column($field, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,7 +211,7 @@ abstract class BaseDao
|
||||
} else {
|
||||
$where = [is_null($key) ? $this->getPk() : $key => $id];
|
||||
}
|
||||
return $this->getModel()::where($where)->delete();
|
||||
return $this->getModel()->where($where)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +219,7 @@ abstract class BaseDao
|
||||
* @param int|string|array $id
|
||||
* @param array $data
|
||||
* @param string|null $key
|
||||
* @return mixed
|
||||
* @return BaseModel
|
||||
*/
|
||||
public function update($id, array $data, ?string $key = null)
|
||||
{
|
||||
@ -235,7 +240,7 @@ abstract class BaseDao
|
||||
*/
|
||||
public function batchUpdate(array $ids, array $data, ?string $key = null)
|
||||
{
|
||||
return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data);
|
||||
return $this->getModel()->whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,7 +256,8 @@ abstract class BaseDao
|
||||
/**
|
||||
* 插入数据
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
* @return \think\Collection
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveAll(array $data)
|
||||
{
|
||||
@ -262,7 +268,7 @@ abstract class BaseDao
|
||||
* 获取某个字段内的值
|
||||
* @param $value
|
||||
* @param string $filed
|
||||
* @param string $valueKey
|
||||
* @param string|null $valueKey
|
||||
* @param array|string[] $where
|
||||
* @return mixed
|
||||
*/
|
||||
@ -281,10 +287,10 @@ abstract class BaseDao
|
||||
{
|
||||
$with = [];
|
||||
$whereKey = [];
|
||||
$respones = new \ReflectionClass($this->setModel());
|
||||
$responses = new \ReflectionClass($this->setModel());
|
||||
foreach ($withSearch as $fieldName) {
|
||||
$method = 'search' . Str::studly($fieldName) . 'Attr';
|
||||
if ($respones->hasMethod($method)) {
|
||||
if ($responses->hasMethod($method)) {
|
||||
$with[] = $fieldName;
|
||||
} else {
|
||||
$whereKey[] = $fieldName;
|
||||
@ -297,7 +303,8 @@ abstract class BaseDao
|
||||
* 根据搜索器获取搜索内容
|
||||
* @param array $withSearch
|
||||
* @param array|null $data
|
||||
* @return Model
|
||||
* @return BaseModel
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function withSearchSelect(array $withSearch, ?array $data = [])
|
||||
{
|
||||
@ -308,7 +315,8 @@ abstract class BaseDao
|
||||
/**
|
||||
* 搜索
|
||||
* @param array $where
|
||||
* @return BaseModel|mixed
|
||||
* @return BaseModel
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function search(array $where = [])
|
||||
{
|
||||
@ -325,27 +333,25 @@ abstract class BaseDao
|
||||
* @param string $field
|
||||
* @param bool $search
|
||||
* @return float
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function sum(array $where, string $field, bool $search = false)
|
||||
{
|
||||
if ($search) {
|
||||
return $this->search($where)->sum($field);
|
||||
} else {
|
||||
return $this->getModel()::where($where)->sum($field);
|
||||
return $this->getModel()->where($where)->sum($field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 高精度加法
|
||||
* @param int|string $key
|
||||
* @param $key
|
||||
* @param string $incField
|
||||
* @param string $inc
|
||||
* @param string|null $keyField
|
||||
* @param int $acc
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function bcInc($key, string $incField, string $inc, string $keyField = null, int $acc = 2)
|
||||
{
|
||||
@ -354,12 +360,11 @@ abstract class BaseDao
|
||||
|
||||
/**
|
||||
* 高精度 减法
|
||||
* @param int|string $uid id
|
||||
* @param string $decField 相减的字段
|
||||
* @param float|int $dec 减的值
|
||||
* @param string $keyField id的字段
|
||||
* @param bool $minus 是否可以为负数
|
||||
* @param int $acc 精度
|
||||
* @param $key
|
||||
* @param string $decField
|
||||
* @param string $dec
|
||||
* @param string|null $keyField
|
||||
* @param int $acc
|
||||
* @return bool
|
||||
*/
|
||||
public function bcDec($key, string $decField, string $dec, string $keyField = null, int $acc = 2)
|
||||
@ -405,7 +410,7 @@ abstract class BaseDao
|
||||
* @param int $num
|
||||
* @param string $stock
|
||||
* @param string $sales
|
||||
* @return mixed
|
||||
* @return false
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
|
||||
@ -66,11 +66,11 @@ abstract class BaseServices
|
||||
* @param $type
|
||||
* @return array
|
||||
*/
|
||||
public function createToken(int $id, $type)
|
||||
public function createToken(int $id, $type, $pwd = '')
|
||||
{
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
return $jwtAuth->createToken($id, $type);
|
||||
return $jwtAuth->createToken($id, $type, ['pwd' => md5($pwd)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -202,7 +202,7 @@ class RoutineTemplateListService extends NoticeService
|
||||
$data['thing1'] = $bargain['title'];
|
||||
$data['amount2'] = $bargain['min_price'];
|
||||
$data['thing3'] = '恭喜您,已经砍到最低价了';
|
||||
return $this->sendTemplate((int)$uid, $data, '/pages/activity/user_goods_bargain_list/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
|
||||
return $this->sendTemplate((int)$uid, $data, '/pages/activity/goods_bargain_details/index?id=' . $bargain['id'] . '&bargain=' . $bargainUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,7 +17,7 @@ use app\services\BaseServices;
|
||||
use app\services\serve\ServeServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\express\storage\AliyunExpress;
|
||||
use crmeb\services\express\Express;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
|
||||
/**
|
||||
@ -211,9 +211,9 @@ class ExpressServices extends BaseServices
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
/** @var AliyunExpress $services */
|
||||
$services = app()->make(AliyunExpress::class);
|
||||
$result = $services->query($expressNum, $com);
|
||||
/** @var Express $services */
|
||||
$services = app()->make(Express::class, ['aliyun_express']);
|
||||
$result = $services->query($expressNum, '', sys_config('system_express_app_code'));
|
||||
if (is_array($result) &&
|
||||
isset($result['result']) &&
|
||||
isset($result['result']['deliverystatus']) &&
|
||||
|
||||
@ -54,7 +54,7 @@ class AdminAuthServices extends BaseServices
|
||||
/** @var JwtAuth $jwtAuth */
|
||||
$jwtAuth = app()->make(JwtAuth::class);
|
||||
//设置解析token
|
||||
[$id, $type] = $jwtAuth->parseToken($token);
|
||||
[$id, $type, $pwd] = $jwtAuth->parseToken($token);
|
||||
|
||||
//检测token是否过期
|
||||
$md5Token = md5($token);
|
||||
@ -96,6 +96,9 @@ class AdminAuthServices extends BaseServices
|
||||
$this->authFailAfter($id, $type);
|
||||
throw new AuthException(110003);
|
||||
}
|
||||
if ($pwd !== md5($adminInfo->pwd)) {
|
||||
throw new AuthException(110003);
|
||||
}
|
||||
|
||||
$adminInfo->type = $type;
|
||||
return $adminInfo->hidden(['pwd', 'is_del', 'status'])->toArray();
|
||||
|
||||
@ -92,7 +92,7 @@ class SystemAdminServices extends BaseServices
|
||||
public function login(string $account, string $password, string $type, string $key = '')
|
||||
{
|
||||
$adminInfo = $this->verifyLogin($account, $password);
|
||||
$tokenInfo = $this->createToken($adminInfo->id, $type);
|
||||
$tokenInfo = $this->createToken($adminInfo->id, $type, $adminInfo->pwd);
|
||||
/** @var SystemMenusServices $services */
|
||||
$services = app()->make(SystemMenusServices::class);
|
||||
[$menus, $uniqueAuth] = $services->getMenusList($adminInfo->roles, (int)$adminInfo['level']);
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
namespace crmeb\services\express\storage;
|
||||
|
||||
use crmeb\services\express\BaseExpress;
|
||||
use crmeb\services\HttpService;
|
||||
|
||||
/**
|
||||
* Class AliyunExpress
|
||||
@ -31,13 +32,11 @@ class AliyunExpress extends BaseExpress
|
||||
* @param string $type
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function query(string $no = '', string $type = '')
|
||||
public function query(string $no = '', string $type = '', string $appCode = '')
|
||||
{
|
||||
$appCode = sys_config('system_express_app_code');
|
||||
if (!$appCode) return false;
|
||||
$res = HttpService::getRequest(self::$api['query'], compact('no', 'type'), ['Authorization:APPCODE ' . $appCode]);
|
||||
$result = json_decode($res, true) ?: false;
|
||||
return $result;
|
||||
return json_decode($res, true) ?: false;
|
||||
}
|
||||
|
||||
public function open()
|
||||
|
||||
@ -43,9 +43,6 @@ class JwtAuth
|
||||
$host = app()->request->host();
|
||||
$time = time();
|
||||
$exp_time = strtotime('+ 30day');
|
||||
// if (app()->request->isApp()) {
|
||||
// $exp_time = strtotime('+ 30day');
|
||||
// }
|
||||
$params += [
|
||||
'iss' => $host,
|
||||
'aud' => $host,
|
||||
@ -69,7 +66,7 @@ class JwtAuth
|
||||
$this->token = $jwt;
|
||||
list($headb64, $bodyb64, $cryptob64) = explode('.', $this->token);
|
||||
$payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64));
|
||||
return [$payload->jti->id, $payload->jti->type];
|
||||
return [$payload->jti->id, $payload->jti->type, $payload->pwd ?? ''];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user