| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | <?phpnamespace app\api\controller\company;use app\common\controller\Apic;use think\Db;/** * 套餐管理 */class Package extends Apic{    protected $noNeedLogin = [];    protected $noNeedRight = '*';    //列表    public function lists(){        $status = input('status',1);        $keyword = input('keyword','');        $where = [            'p.company_id' => $this->auth->company_id,            'p.status'     => $status,        ];        if(!empty($keyword)){            $where['p.title|p.info'] = ['LIKE','%'.$keyword.'%'];        }        $list = Db::name('package')->alias('p')            ->field('p.*,type.title as servicetype_title')            ->join('servicetype type','p.servicetype_id = type.id','LEFT')            ->where($where)->order('p.id desc')->autopage()->select();        $list = list_domain_image($list,['images','content_images']);        $this->success(1,$list);    }    //新增    public function add(){        $field = ['title','info','servicetype_id','images','days','price','oldprice','content','content_images'];        $data = request_post_hub($field);        $data['company_id'] = $this->auth->company_id;        $data['createtime'] = time();        $data['updatetime'] = time();        $data['status'] = 1;        Db::name('package')->insertGetId($data);        $this->success('添加成功');    }    //上下架    public function changestatus(){        $id = input('id',0);        $status = Db::name('package')->where('id',$id)->value('status');        $new_status = $status == 1 ? 0 : 1;        $info = Db::name('package')->where('id',$id)->update(['status'=>$new_status,'updatetime'=>time()]);        $this->success();    }    //详情    public function info(){        $id = input('id',0);        $info = Db::name('package')->alias('p')            ->field('p.*,type.title as servicetype_title')            ->join('servicetype type','p.servicetype_id = type.id','LEFT')            ->where('p.id',$id)->find();        $info = info_domain_image($info,['images','content_images']);        $this->success(1,$info);    }    //编辑    public function edit(){        $id = input('id','');        $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();        if(empty($check)){            $this->error('不存在的套餐');        }        //        $field = ['title','info','servicetype_id','images','days','price','oldprice','content','content_images'];        $data = request_post_hub($field);        $data['updatetime'] = time();        Db::name('package')->where('id',$id)->update($data);        $this->success('编辑成功');    }    //删除    public function delete(){        $id = input('id','');        $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();        if(empty($check)){            $this->error('不存在的套餐');        }        Db::name('package')->where('id',$id)->delete();        $this->success('删除成功');    }}
 |