123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Subsidiary extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'org_id' => input('orgId/d',0),
- 'count' => input('count'),
- ];
- $result = validate('Subsidiary')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('Subsidiary')->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 del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($orgId){
- $lists = $this
- ->where('org_id',$orgId)
- ->order('id asc')
- ->select();
- $data = $lists?$lists->toArray():[];
- return $data;
- }
- }
|