123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\common\model;
- use app\common\util\AppAuth;
- use app\hander\HelpHander;
- use think\Db;
- class QualityCate extends Base {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'quality_cate';
- protected $validateName = 'QualityCate';
- public function updates(){
- $data = request()->post();
- $data['org_id'] =cur_org_id();
- $result = validate($this->validateName)->check($data,[],'');
- if(true !== $result){
- $this->error = validate($this->validateName)->getError();
- return false;
- }
- $id = $data['id'];
- $this->startTrans();
- try{
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- if(!$ret){
- exception('保存失败');
- }
- }else{
- if(!empty($data['pid'])){
- $pInfo = Db::name('quality_cate')
- ->where('id',$data['pid'])
- ->find();
- if($pInfo['pid']==0){
- $data['level']==2;
- }else{
- $data['level'] = 3;
- }
- }else{
- $data['level']==1;
- }
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->insertGetId($data);
- $id = $ret;
- if(!$id){
- exception('保存失败');
- }
- }
- $this->commit();
- return true;
- }catch (\Exception $e){
- // 回滚事务
- $this->error = $e->getMessage();
- $this->rollback();
- return false;
- }
- }
- public function list($orgId){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['enable','=',1];
- $map[] = ['del','=',0];
- $list = Db::name('quality_cate')
- ->where($map)
- ->where('pid','=',0)
- ->field('id,title')
- ->select();
- foreach ($list as $k=>$v){
- $pList = Db::name('quality_cate')
- ->where('pid',$v['id'])
- ->where($map)
- ->field('id,title')
- ->select();
- $list[$k]['child'] = $pList;
- foreach ($pList as $k1=>$v1){
- $cList = Db::name('quality_cate')
- ->where('pid',$v1['id'])
- ->where($map)
- ->field('id,title')
- ->select();
- $list[$k]['child'][$k1]['child'] = $cList;
- }
- }
- return $list;
- }
- public function getPTitle($id){
- $title = '';
- $info = Db::name('quality_cate')
- ->where('id',$id)
- ->find();
- if($info){
- $pInfo = Db::name('quality_cate')
- ->where('id',$info['pid'])
- ->find();
- $PPInfo = Db::name('quality_cate')
- ->where('id',$pInfo['pid'])
- ->find();
- $title = $PPInfo['title'].'/'.$pInfo['title'].'/'.$info['title'];
- }
- return $title;
- }
- }
|