$phone = $this->input_data['phone'];
// 成员数
$member_count = $user_customer_village->where(['house_id' => $house_id])->count();
if ($role === RoleEnum::HOST) { // 业主
// 业主必须传手机号
if (!$phone) {
$this->json->err('请填写手机号');
}
if (!Verify::checkMobile($phone)) {
$this->json->err('请填写正确的手机号');
}
} else { // 成员
if (!$phone) {
// 自动生成手机号
$host_info = $user_customer_village->where(['house_id' => $house_id, 'role' => RoleEnum::HOST])->find();
if (!$host_info) {
$this->json->err('当前房屋未设置业主');
}
$host_id = $host_info['customer_id'];
$user_customer_info = $user_customer->where(['id' => $host_id])->find();
if (!$user_customer_info) {
$this->json->err('业主对应用户不存在');
}
if ($id) {
$member_ids = $user_customer_village->where(['house_id' => $house_id])->order('role asc,id asc')->getField('id',true);
$member_ids = array_flip($member_ids);
$pos_val = $member_ids[$id];
// 获取当前成员在家庭中的位置
$phone = $user_customer_info['phone'] . '-' . ($pos_val + 1);
} else {
$phone = $user_customer_info['phone'] . '-' . ($member_count + 1);
}
}
}
$member_ids = $user_customer_village->where(['house_id' => $house_id])->order('role asc,id asc')->getField('id',true);
$member_ids = array_flip($member_ids);
$pos_val = $member_ids[$id];
// 获取当前成员在家庭中的位置
$phone = $user_customer_info['phone'] . '-' . ($pos_val + 1);