作者 郭盛
1 个管道 的构建 通过 耗费 6 秒

修改后台删除农场时候对应用户的身份

@@ -86,4 +86,71 @@ class Farm extends Backend @@ -86,4 +86,71 @@ class Farm extends Backend
86 $this->assign('data',$data); 86 $this->assign('data',$data);
87 return $this->view->fetch(); 87 return $this->view->fetch();
88 } 88 }
  89 +
  90 + /**
  91 + * 删除
  92 + */
  93 + public function del($ids = "")
  94 + {
  95 + if ($ids) {
  96 + $pk = $this->model->getPk();
  97 + $adminIds = $this->getDataLimitAdminIds();
  98 + if (is_array($adminIds)) {
  99 + $this->model->where($this->dataLimitField, 'in', $adminIds);
  100 + }
  101 + $list = $this->model->where($pk, 'in', $ids)->select();
  102 +
  103 + $count = 0;
  104 +
  105 + //将传递过来的农场ID信息转为数组
  106 + $project_id = explode(',',$ids);
  107 + //如果农场已经认证则删除认证信息
  108 + foreach ($project_id as $v_ren){
  109 + $is_ren = Db::name('attestation')->where('farm_id',$v_ren)->find();
  110 + if(!empty($is_ren)){
  111 + Db::name('attestation')->where('farm_id',$v_ren)->delete();
  112 + }else{
  113 + true;
  114 + }
  115 + }
  116 + //查询出该农场对应的用户ID
  117 + $user_id = Db::name('farm')->whereIn('id',$project_id)->column('user_id');
  118 + //删除该农场下的所有项目
  119 + Db::name('project')->whereIn('farm_id',$project_id)->delete();
  120 + //删除关注该农场的所有记录
  121 + Db::name('guanzhu')->whereIn('farm_id',$project_id)->delete();
  122 + //删除用户的入驻信息
  123 + foreach ($user_id as $v){
  124 + $info = Db::name('user')->where('id',$v)->column('identity');
  125 + if($info[0] == 2){
  126 + Db::name('personage')->where('user_id',$v)->delete();
  127 + }elseif ($info[0] == 3){
  128 + Db::name('company')->where('user_id',$v)->delete();
  129 + }else{
  130 + true;
  131 + }
  132 + }
  133 + //修改用户的身份为 游客
  134 + Db::name('user')->whereIn('id',$user_id)->update(['identity'=>1]);
  135 + Db::startTrans();
  136 + try {
  137 + foreach ($list as $k => $v) {
  138 + $count += $v->delete();
  139 + }
  140 + Db::commit();
  141 + } catch (PDOException $e) {
  142 + Db::rollback();
  143 + $this->error($e->getMessage());
  144 + } catch (Exception $e) {
  145 + Db::rollback();
  146 + $this->error($e->getMessage());
  147 + }
  148 + if ($count) {
  149 + $this->success();
  150 + } else {
  151 + $this->error(__('No rows were deleted'));
  152 + }
  153 + }
  154 + $this->error(__('Parameter %s can not be empty', 'ids'));
  155 + }
89 } 156 }
@@ -347,6 +347,7 @@ class Attestation extends Api @@ -347,6 +347,7 @@ class Attestation extends Api
347 "address":"address",//详细地址 347 "address":"address",//详细地址
348 "project_num"://创建项目 348 "project_num"://创建项目
349 "createtime"://入驻时间 349 "createtime"://入驻时间
  350 + "is_ti"://是否已经提交(1提交过2没有提交过)
350 } 351 }
351 }) 352 })
352 */ 353 */
@@ -357,6 +358,14 @@ class Attestation extends Api @@ -357,6 +358,14 @@ class Attestation extends Api
357 ->where('id',$user_id) 358 ->where('id',$user_id)
358 ->find(); 359 ->find();
359 if($data['identity'] == 2){ 360 if($data['identity'] == 2){
  361 +
  362 + $info = Db::name('attestation')->where('user_id',$user_id)->find();
  363 + if(!empty($info)){
  364 + $list['is_ti'] = 1;
  365 + }else{
  366 + $list['is_ti'] = 2;
  367 + }
  368 +
360 //查询入驻消息 拿出 申请人名字 369 //查询入驻消息 拿出 申请人名字
361 $res = Db::name('personage') 370 $res = Db::name('personage')
362 ->where('user_id',$user_id) 371 ->where('user_id',$user_id)
@@ -380,6 +389,13 @@ class Attestation extends Api @@ -380,6 +389,13 @@ class Attestation extends Api
380 $list['createtime'] = date('Y-m-d H:i:s',$farm['createtime']); 389 $list['createtime'] = date('Y-m-d H:i:s',$farm['createtime']);
381 $this->success('success',$list); 390 $this->success('success',$list);
382 }elseif ($data['identity'] == 3){ 391 }elseif ($data['identity'] == 3){
  392 + //查询是否已经提交认证信息
  393 + $info = Db::name('attestation')->where('user_id',$user_id)->find();
  394 + if(!empty($info)){
  395 + $list['is_ti'] = 1;
  396 + }else{
  397 + $list['is_ti'] = 2;
  398 + }
383 //查询入驻消息 拿出 申请人名字 399 //查询入驻消息 拿出 申请人名字
384 $res = Db::name('company') 400 $res = Db::name('company')
385 ->where('user_id',$user_id) 401 ->where('user_id',$user_id)
@@ -433,14 +449,15 @@ class Attestation extends Api @@ -433,14 +449,15 @@ class Attestation extends Api
433 { 449 {
434 $user_id = $this->getUserId(); 450 $user_id = $this->getUserId();
435 $param = $this->request->param(); 451 $param = $this->request->param();
436 - if(empty($param['province'])){  
437 - $this->error('缺少必要信息'); 452 + if(!empty($param['province'])){
  453 + $where['province'] = ['Like',"$param[province]%"];
  454 + }
  455 + if(!empty($param['city'])){
  456 + $where['city'] = ['eq',$param['city']] ;
438 } 457 }
439 - if(empty($param['city'])){  
440 - $this->error('缺少必要信息'); 458 + if(!empty($param['county'])){
  459 + $where['county'] = ['eq',$param['county']];
441 } 460 }
442 - $where['province'] = ['Like',"$param[province]%"];  
443 - $where['city'] = ['eq',$param['city']] ;  
444 $where['status'] = ['eq',1]; 461 $where['status'] = ['eq',1];
445 $data = Db::name('government') 462 $data = Db::name('government')
446 ->where($where) 463 ->where($where)
@@ -489,6 +506,7 @@ class Attestation extends Api @@ -489,6 +506,7 @@ class Attestation extends Api
489 'institution' => 'require', 506 'institution' => 'require',
490 'name'=>'require', 507 'name'=>'require',
491 'identity'=>'require', 508 'identity'=>'require',
  509 + 'institution_id'=>'require',
492 'farm_name'=>'require', 510 'farm_name'=>'require',
493 'project_num'=>'require', 511 'project_num'=>'require',
494 'address' => 'require', 512 'address' => 'require',