123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class DinnerCate extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'start' => input('start','','trim'),
- 'end' => input('end','','trim'),
- 'remark' => input('remark','','trim'),
- 'syesterday' => input('syesterday/d',0),
- 'eyesterday' => input('eyesterday/d',0),
- 'enable' => input('enable/d',1),
- 'color' => input('color','','trim'),
- 'show_start' => input('showStart','','trim'),
- 'show_end' => input('showEnd','','trim'),
- ];
- $logdata = json_encode($data);
- $result = validate('DinnerCate')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('DinnerCate')->getError());
- }
- if($data['syesterday'] > $data['eyesterday']){
- HelpHander::error('开始日期不能大于结束日期');
- }
- if($data['start'] > $data['end'] && $data['syesterday']==$data['eyesterday']){
- HelpHander::error('开始日期不能大于结束日期');
- }
- $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('操作失败');
- }
- if($id > 0){
- $content = '修改点餐分类';
- }else{
- $content = '添加点餐分类';
- }
- model('ActionLog')->add(20,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$title,$enable){
- $map[] = ['del','=',0];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if($enable >= 0){
- $map[] = ['enable','=',$enable];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function getList(){
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $lists = $this
- ->where($map)
- ->field('id,title')
- ->order('id desc')
- ->select();
- return $lists?$lists->toArray():[];
- }
- public function allLists(){
- $lists = Db::name('dinner_cate')->where('del',0)->order('id asc')->select();
- return $lists?$lists:[];
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(20,'删除点餐分类',0,$logdata);
- return true;
- }
- }
|