Skip to content

Commit

Permalink
优化程序排序
Browse files Browse the repository at this point in the history
  • Loading branch information
songyongzhan committed Jan 18, 2021
1 parent 39928a0 commit a25fe45
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions src/Core/DatabaseService.php
Expand Up @@ -22,6 +22,15 @@ public function __construct()

}

/**
*
* add
* @param array $data
* @return string
*
* @author songyongzhan <574482856@qq.com>
* @date 2021/1/18 09:32
*/
public function add(array $data)
{
$data = $this->filterField($this->snake($data));
Expand All @@ -30,6 +39,18 @@ public function add(array $data)
return $result ? $result->{$this->primaryId} : '';
}

/**
*
* getOne
* @param $where
* @param array $fields
* @param array $with
* @param string $callback
* @return array
*
* @author songyongzhan <574482856@qq.com>
* @date 2021/1/18 09:32
*/
public function getOne($where, array $fields = [], array $with = [], $callback = 'function')
{
$fields = $this->filterField($this->valueSnake($fields), '', false);
Expand All @@ -47,6 +68,16 @@ public function getOne($where, array $fields = [], array $with = [], $callback =
return $data ?? [];
}

/**
* 更新
* update
* @param $where
* @param array $data
* @return string
*
* @author songyongzhan <574482856@qq.com>
* @date 2021/1/18 09:31
*/
public function update($where, array $data)
{
if (!is_array($where)) {
Expand All @@ -59,6 +90,15 @@ public function update($where, array $data)
return $result ?? '0';
}

/**
* 删除
* del
* @param int $id
* @return string
*
* @author songyongzhan <574482856@qq.com>
* @date 2021/1/18 09:31
*/
public function del(int $id)
{
$affectedNum = $this->getModel()->newQuery()->where($this->primaryId, '=', $id)->delete();
Expand All @@ -83,6 +123,8 @@ protected function filterField(array $data, $table = '', $keyMap = true)
* @param string $callback 回调方法
* @return DefaultPage
* @throws \Songyz\Exceptions\PageValidaException
* @author songyongzhan <574482856@qq.com>
* @date 2020/05/18 09:27
*/
public function getList(
array $where,
Expand Down Expand Up @@ -139,8 +181,11 @@ public function getList(
* @param array $fields
* @param string $order
* @param array $with
* @param string $callback 回调方法
* @return array
* @param string $callback
* @return mixed
*
* @author songyongzhan <574482856@qq.com>
* @date 2020/05/18 09:27
*/
public function getListAll(
array $where,
Expand All @@ -149,7 +194,7 @@ public function getListAll(
array $with = [],
$callback = 'function'
) {
empty($order) && $order = 'gmt_created desc';
empty($order) && $order = $this->primaryId . ' desc';
list($orderField, $orderType) = explode(' ', $order);

$fields = $this->filterField($this->valueSnake($fields), '', false);
Expand Down

0 comments on commit a25fe45

Please sign in to comment.