123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\common\model\Roles;
- use app\common\util\AppAuth;
- use app\hander\HelpHander;
- use think\Db;
- class GreenRecord extends Base
- {
- public function addRecord(){
- $addrId = input('addrId');
- $cateId = input('cateId');
- $content = input('content','','trim');
- $imgs = input('imgs','','trim');
- if(!$addrId){
- HelpHander::error('地点不能为空');
- }
- if(!$cateId){
- HelpHander::error('分类不能为空');
- }
- if(!$content){
- HelpHander::error('汇报内容不能为空');
- }
- if(!$imgs){
- HelpHander::error('汇报图片不能为空');
- }
- $data = [
- 'org_id'=>$this->orgId,
- 'user_id'=>$this->userId,
- 'content'=>$content,
- 'images'=>$imgs,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'create_yyyy'=>date('Y'),
- 'create_yyyymm'=>date('Ym'),
- 'create_yyyymmdd'=>date('Ymd'),
- 'green_addr_id'=>$addrId,
- 'green_cate_id'=>$cateId,
- ];
- $add = Db::name('green_record')->insert($data);
- if($add){
- HelpHander::success('操作成功');
- }else{
- HelpHander::error('操作失败');
- }
- }
- public function recordList(){
- $page = input('page',1);
- $size = input('size',10);
- $type = input('type/d',0);
- $addId = input('greenAddrId');
- if(!$addId){
- HelpHander::error('地点不存在');
- }
- if($type == 1){ // 查看全部记录
- $auth = (new Roles())->getAppAuth($this->userId,AppAuth::GREEN_LOOK_ALL_AUTH);
- if(!$auth){ // 无权限
- $m[] = ['user_id','=',-1];
- }
- }else{ // 查看个人记录
- $m[] = ['user_id','=',$this->userId];
- }
- $m[] = ['org_id','=',$this->orgId];
- $m[] = ['green_addr_id','=',$addId];
- $list = Db::name('green_record')
- ->field('id,create_time,user_id,green_cate_id')
- ->where($m)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['user_name'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- $list[$k]['cate_name'] = Db::name('green_cate')
- ->where('id',$v['green_cate_id'])
- ->value('title');
- }
- HelpHander::success($list);
- }
- public function details(){
- $id = input('id',0);
- $info = Db::name('green_record')
- ->where('id',$id)
- ->find();
- if(!$info){
- HelpHander::error('参数错误');
- }
- $addr = Db::name('green_addr')->where('id',$info['green_addr_id'])->find();
- $info['addr_name'] = $addr?$addr['title']:'';
- $info['addr_img'] = $addr?$addr['img']:'';
- $info['addr_content'] =$addr? $addr['content']:'';
- $info['cate_name'] = Db::name('green_cate')
- ->where('id',$info['green_cate_id'])
- ->value('title');
- $info['user_name'] = Db::name('user')
- ->where('id',$info['user_id'])
- ->value('real_name');
- HelpHander::success($info);
- }
- }
|