• php 获取当前成员在数组中的位置


    $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);
    
  • 相关阅读:
    day25 初始面向对象
    JavaScript中的apply()和call()
    JavaScript中的arguments详解
    测试使用MarkDown在博客园发布博客
    《Spring实战》 1-2
    总结: 《jQuery基础教程》 5-完结
    总结: 《jQuery基础教程》 1-4章
    做个计划
    Nginx与tomcat组合的简单使用
    利用 Dijit 组件框架打造丰富的用户界面
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/15188757.html
Copyright © 2020-2023  润新知