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

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

... ... @@ -86,4 +86,71 @@ class Farm extends Backend
$this->assign('data',$data);
return $this->view->fetch();
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
//将传递过来的农场ID信息转为数组
$project_id = explode(',',$ids);
//如果农场已经认证则删除认证信息
foreach ($project_id as $v_ren){
$is_ren = Db::name('attestation')->where('farm_id',$v_ren)->find();
if(!empty($is_ren)){
Db::name('attestation')->where('farm_id',$v_ren)->delete();
}else{
true;
}
}
//查询出该农场对应的用户ID
$user_id = Db::name('farm')->whereIn('id',$project_id)->column('user_id');
//删除该农场下的所有项目
Db::name('project')->whereIn('farm_id',$project_id)->delete();
//删除关注该农场的所有记录
Db::name('guanzhu')->whereIn('farm_id',$project_id)->delete();
//删除用户的入驻信息
foreach ($user_id as $v){
$info = Db::name('user')->where('id',$v)->column('identity');
if($info[0] == 2){
Db::name('personage')->where('user_id',$v)->delete();
}elseif ($info[0] == 3){
Db::name('company')->where('user_id',$v)->delete();
}else{
true;
}
}
//修改用户的身份为 游客
Db::name('user')->whereIn('id',$user_id)->update(['identity'=>1]);
Db::startTrans();
try {
foreach ($list as $k => $v) {
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -347,6 +347,7 @@ class Attestation extends Api
"address":"address",//详细地址
"project_num"://创建项目
"createtime"://入驻时间
"is_ti"://是否已经提交(1提交过2没有提交过)
}
})
*/
... ... @@ -357,6 +358,14 @@ class Attestation extends Api
->where('id',$user_id)
->find();
if($data['identity'] == 2){
$info = Db::name('attestation')->where('user_id',$user_id)->find();
if(!empty($info)){
$list['is_ti'] = 1;
}else{
$list['is_ti'] = 2;
}
//查询入驻消息 拿出 申请人名字
$res = Db::name('personage')
->where('user_id',$user_id)
... ... @@ -380,6 +389,13 @@ class Attestation extends Api
$list['createtime'] = date('Y-m-d H:i:s',$farm['createtime']);
$this->success('success',$list);
}elseif ($data['identity'] == 3){
//查询是否已经提交认证信息
$info = Db::name('attestation')->where('user_id',$user_id)->find();
if(!empty($info)){
$list['is_ti'] = 1;
}else{
$list['is_ti'] = 2;
}
//查询入驻消息 拿出 申请人名字
$res = Db::name('company')
->where('user_id',$user_id)
... ... @@ -433,14 +449,15 @@ class Attestation extends Api
{
$user_id = $this->getUserId();
$param = $this->request->param();
if(empty($param['province'])){
$this->error('缺少必要信息');
}
if(empty($param['city'])){
$this->error('缺少必要信息');
}
if(!empty($param['province'])){
$where['province'] = ['Like',"$param[province]%"];
}
if(!empty($param['city'])){
$where['city'] = ['eq',$param['city']] ;
}
if(!empty($param['county'])){
$where['county'] = ['eq',$param['county']];
}
$where['status'] = ['eq',1];
$data = Db::name('government')
->where($where)
... ... @@ -489,6 +506,7 @@ class Attestation extends Api
'institution' => 'require',
'name'=>'require',
'identity'=>'require',
'institution_id'=>'require',
'farm_name'=>'require',
'project_num'=>'require',
'address' => 'require',
... ...