12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserSubsidies extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'name' => input('name','','trim'),
- 'type' => input('type/d',1),
- 'cate' => input('cate/d',1),
- 'values' => input('values','','trim'),
- 'money' => input('money/f',0),
- 'remark' => input('remark','','trim'),
- 'pay_type' => input('payType/d',1),
- 'gender' => input('gender/d',0),
- 'sorts' => input('sorts/d',0),
- 'prop' => input('prop/d',1),
- 'sbtype' => input('sbtype/d',0)
- ];
- $result = validate('UserSubsidies')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserSubsidies')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- return $data;
- }
- public function lists($page,$size,$title,$payType){
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $map[] = ['pay_type','=',$payType];
- $map[] = ['del','=',0];
- $lists = Db::name('user_subsidies')
- ->where($map)
- ->page($page,$size)
- ->select();
- $total = Db::name('user_subsidies')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function all(){
- $map[] = ['del','=',0];
- $lists = Db::name('user_subsidies')
- ->where($map)
- ->order('sorts asc,id asc')
- ->select();
- return $lists?$lists:[];
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- }
|