188 行
4.9 KiB
PHP
可执行文件
188 行
4.9 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Model;
|
|
use Think\Model;
|
|
/*
|
|
* 进销存的公共model
|
|
*/
|
|
//[1.4.98]
|
|
class JBaseModel extends Model
|
|
{
|
|
/*
|
|
* 查询信息
|
|
* @param $where 查询条件
|
|
*/
|
|
public function getFind($where,$order=null)
|
|
{
|
|
$order = $order?$order:"id desc";
|
|
$success = $this->where($where)->order($order)->find();
|
|
return $success;
|
|
}
|
|
public function basisOrderFind($where,$fields='*',$order='id desc')
|
|
{
|
|
if(empty($where)){
|
|
return [];
|
|
}
|
|
$success = $this->field($fields)->where($where)->order($order)->find();
|
|
return $success;
|
|
}
|
|
/*
|
|
* 查询某个字段
|
|
* @param $where 条件
|
|
* @param $field 查询的字段
|
|
* @param $state 单个还是数组
|
|
*/
|
|
public function getFindField($where,$field,$state=false)
|
|
{
|
|
$field = $field?$field:'id';
|
|
$res = $this->where($where)->getField($field,$state);
|
|
return $res;
|
|
}
|
|
|
|
/*
|
|
* 查询某个字段
|
|
* @param $where 条件
|
|
* @param $field 查询的字段
|
|
* @param $state 单个还是数组
|
|
*/
|
|
public function basisOrderGetFindField($where,$field,$order='',$state=false)
|
|
{
|
|
$field = $field?$field:'id';
|
|
$order = $order?$order:'id desc';
|
|
$res = $this->where($where)->order($order)->getField($field,$state);
|
|
return $res;
|
|
}
|
|
/*
|
|
* 查询某些字段
|
|
* @param $where 条件
|
|
* @param $fields 查询的字段
|
|
*/
|
|
public function getFindFields($where,$fields)
|
|
{
|
|
$fields = $fields?$fields:'*';
|
|
$res = $this->field($fields)->where($where)->select();
|
|
return $res;
|
|
}
|
|
/*
|
|
* 查询某些字段
|
|
* @param $where 条件
|
|
* @param $fields 查询的字段
|
|
*/
|
|
public function getFieldInfo($where,$fields)
|
|
{
|
|
$fields = $fields?$fields:'*';
|
|
$res = $this->field($fields)->where($where)->find();
|
|
return $res;
|
|
}
|
|
/*
|
|
* 查询
|
|
*/
|
|
public function getSelect($where,$page=null,$limit=null,$field=null,$order=null)
|
|
{
|
|
$field = $field?$field:"*";
|
|
$order = $order?$order:'id desc';
|
|
if(!$page || !$limit || $page == '' || $limit == ''){
|
|
$success = $this->field($field)->where($where)->order($order)->select();
|
|
}else{
|
|
$success = $this->field($field)->where($where)->page($page,$limit)->order($order)->select();
|
|
}
|
|
return $success;
|
|
}
|
|
/**
|
|
* 统计数量(count)
|
|
* @param $where 查询条件
|
|
*
|
|
*/
|
|
public function getCount($where)
|
|
{
|
|
$success = $this->where($where)->count();
|
|
return $success;
|
|
}
|
|
/*
|
|
* 添加
|
|
* @param $data 添加的信息
|
|
*/
|
|
public function addData($data)
|
|
{
|
|
if(!$data){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '添加信息缺失';
|
|
}else{
|
|
$success = $this->add($data);
|
|
if($success){
|
|
$res['status'] = 1;
|
|
$res['data'] = $success;
|
|
$res['msg'] = '操作成功';
|
|
}else{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
/*编辑
|
|
* @param $where 条件
|
|
* @param $content 编辑的信息
|
|
*/
|
|
public function updateData($where,$data)
|
|
{
|
|
if(!$where || !$data){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数有误';
|
|
}else{
|
|
$success = $this->where($where)->save($data);
|
|
if($success){
|
|
$res['status'] = 1;
|
|
$res['msg'] = '操作成功';
|
|
}else{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
/*
|
|
* 字段值统计
|
|
*/
|
|
public function getSum($where,$field)
|
|
{
|
|
$success = $this->where($where)->sum($field);
|
|
$success = $success?$success:0;
|
|
return $success;
|
|
}
|
|
/*
|
|
* 字段值减少
|
|
*/
|
|
public function updateSetDec($where,$filed,$data)
|
|
{
|
|
$success = $this->where($where)->setDec($filed,$data);
|
|
return $success;
|
|
}
|
|
/*
|
|
* 字段值增加
|
|
*/
|
|
public function updateSetInc($where,$filed,$data)
|
|
{
|
|
$success = $this->where($where)->setInc($filed,$data);
|
|
return $success;
|
|
}
|
|
/*
|
|
* 删除数据
|
|
*/
|
|
public function deleteData($where)
|
|
{
|
|
$success = $this->where($where)->delete();
|
|
return $success;
|
|
}
|
|
|
|
/**
|
|
* 删除记录
|
|
* @param $map
|
|
* @return mixed
|
|
*/
|
|
public function deleteOrder($map)
|
|
{
|
|
$res = $this->where($map)->delete();
|
|
return $res;
|
|
}
|
|
} |