18位身份证校验码有效性检查
@param string $idcard 十八位身份证号码
@return bool
348288
private static function idcard_checksum18($idcard) {

        if ( strlen($idcard) != 18 ) return false;

        $idcard_base = substr($idcard, 0, 17);
        if ( self::idcard_verify_number($idcard_base) != strtoupper(substr($idcard, 17, 1)) ) {
            return false;
        } else {
            return true;
        }
    }
1335509
private function _checkIdArgument($id)
    {
        $id = strtoupper($id);
        $length = strlen($id);

        if ($length === 15) {
            return $this->_generateShortType($id);
        } elseif ($length === 18) {
            return $this->_generatelongType($id);
        }

        return false;
    }
207175
public function delCategory($id)
    {
        $where = [];
        if (is_array($id)) {
            $where[] = ['id', 'IN', $id];
        } else {
            $id = (int)$id;
            if (is_numeric($id) && $id > 0) {
                $where[] = ['id', '=', $id];
            } else {
                throw new Exception('删除条件错误');
            }
        }

        if ($this->where($where)->delete() === false) {
            throw new Exception('删除权限分组出错');
        }
        return true;
    }
827404
public function getDepositCount($card_id)
    {
        $url = "https://api.weixin.qq.com/card/code/getdepositcount?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['card_id' => $card_id]);
    }
1021658
public static function cnIdcard($id_card)
    {
        /**
         * 计算身份证校验码，根据国家标准GB 11643-1999
         * @access protected static
         * @param string $idcard_base
         * @return int
         */
        $idcard_verify_number = function () use(&$id_card)
        {
            if (17 !== strlen($id_card))
            {
                return false;
            }
            // 加权因子
            $factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
            // 校验码对应值
            $verify_number_list = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
            $checksum = 0;
            $len = strlen($id_card);
            for ($i = 0; $i < $len; ++ $i)
            {
                $checksum += substr($id_card, $i, 1) * $factor[$i];
            }
            $mod = $checksum % 11;
            $verify_number = $verify_number_list[$mod];
            return $verify_number;
        };
        /**
         * 18位身份证校验码有效性检查
         * @access protected static
         * @param string $idcard
         * @return bool
         */
        $idcard_checksum18 = function () use(&$id_card, $idcard_verify_number)
        {
            if (18 !== strlen($id_card))
            {
                return false;
            }
            $id_card1 = $id_card;
            $id_card = substr($id_card, 0, 17);
            if ($idcard_verify_number() !== strtoupper(substr($id_card1, 17, 1)))
            {
                return false;
            }
            else
            {
                return true;
            }
        };
        /**
         * 将15位身份证升级到18位
         * @access protected static
         * @param string $idcard
         * @return string
         */
        $idcard_15to18 = function () use(&$id_card, $idcard_verify_number)
        {
            if (15 !== strlen($id_card))
            {
                return false;
            }
            else
            {
                // 如果身份证顺序码是996 997 998 999，这些是为百岁以上老人的特殊编码
                if (false !== array_search(substr($id_card, 12, 3), ['996','997','998','999']))
                {
                    $id_card = substr($id_card, 0, 6) . '18' . substr($id_card, 6, 9);
                }
                else
                {
                    $id_card = substr($id_card, 0, 6) . '19' . substr($id_card, 6, 9);
                }
            }
            $id_card = $id_card . $idcard_verify_number();
            return $id_card;
        };
        $len = strlen($id_card);
        if (18 === $len)
        {
            return $idcard_checksum18();
        }
        else if (15 === $len)
        {
            $id_card = $idcard_15to18();
            return $idcard_checksum18();
        }
        else
        {
            return false;
        }
    }
888485
public static int getAge(String idCard) {
        int age;
        // 计算用户年龄
        int year = Integer.parseInt(idCard.substring(6, 10));
        int monthDay = Integer.parseInt(idCard.substring(10, 14));
        Calendar calendar = Calendar.getInstance();
        int nowYear = calendar.get(Calendar.YEAR);
        int nowMonthDay = calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DATE);
        if (nowMonthDay > monthDay) {
            age = nowYear - year;
        } else {
            age = nowYear - year - 1;

        }
        if (age < 0) {
            logger.warn("身份证年龄应该大于等于0，但是实际年龄为{}", age);
        }
        return age;
    }
43046
public static DateTime getBirthDate(String idCard) {
		final String birthByIdCard = getBirthByIdCard(idCard);
		return null == birthByIdCard ? null : DateUtil.parse(birthByIdCard, DatePattern.PURE_DATE_FORMAT);
	}
416909
public function isAncestor(int $id): Bool
    {
        if ( ! is_null($this->getAncestor($id))) {
            return true;
        }

        return false;
    }
503014
public function isValid($id)
    {
        // 基础验证
        $code = $this->_checkIdArgument($id);
        if (empty($code)) {
            return false;
        }

        // 分别验证：*地址码*、*出生日期码*和*顺序码*
        if (!$this->_checkAddressCode($code['addressCode'], $code['birthdayCode']) || !$this->_checkBirthdayCode($code['birthdayCode']) || !$this->_checkOrderCode($code['order'])) {
            return false;
        }

        // 15位身份证不含校验码
        if ($code['type'] === 15) {
            return true;
        }

        // 验证：校验码
        $checkBit = $this->_generatorCheckBit($code['body']);

        // 检查校验码
        return $checkBit == $code['checkBit'];
    }
907486
public function getdepositcount($card_id)
    {
        if (!is_string($card_id)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr            = [];
        $queryStr['card_id'] = $card_id;

        $this->apitype = 'card';
        $this->module  = 'code';
        $res           = $this->_post('getdepositcount', $queryStr);

        return $res;
    }
1113252
private static function checkForStraight(CardCollection $cards)
    {
        // check 2-6
        $cardsToCheck = static::isStraight($cards->only(range(2, 6)));
        if ($cardsToCheck !== false) {
            return $cardsToCheck;
        }

        // check 1-5
        $cardsToCheck = static::isStraight($cards->only(range(1, 5)));
        if ($cardsToCheck !== false) {
            return $cardsToCheck;
        }

        // check 0-4
        $cardsToCheck = static::isStraight($cards->only(range(0, 4)));
        if ($cardsToCheck !== false) {
            return $cardsToCheck;
        }

        return false;
    }
204006
static public function getBirthday($id)
    {
        if (empty($id) || strlen($id) !== 18)
            return null;

        $birthdayStr = substr($id, 6, 8);
        $year = substr($birthdayStr, 0, 4);
        $month = substr($birthdayStr, 4, 2);
        $day = substr($birthdayStr, 6, 2);

        return sprintf('%s-%s-%s', $year, $month, $day);
    }
412036
public function hasRights($id, $self = 1)
	{
		//允许本人
		if($self === 0){
			if($this->selfId == $id) {
				return true;
				
			}
		}

		$target = Member::find($id);

		if($this->isRoot()){
			return true;
		}elseif(!$this->isRoot() && $this->isAdmin()){
			if($this->isRoot($target->work_id)){
				return false;
			}elseif($target->admin === 0){
				return false;
			}else{
				return true;
			}
			
		}else{

			if($this->isRoot($target->work_id)){
				return false;
			}elseif($target->admin === 0){
				return false;
			}

			$departmentList = $this->getDepartments();
			$positionList = $this->getPositions();

			$targetDepartment = $target->department;
			$targetPosition = $target->position;

			if (array_key_exists($targetDepartment,$departmentList) && array_key_exists($targetPosition, $positionList)){
			  	return true;
			}else{
			  	return false;
			}
		}

	}
315506
public static boolean isMasterCard(String cc) {
        int firstdig = Integer.parseInt(cc.substring(0, 1));
        int seconddig = Integer.parseInt(cc.substring(1, 2));

        if ((cc.length() == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
            return isCreditCard(cc);
        return false;

    }
654326
public function getCard($card_id)
    {
        $url = "https://api.weixin.qq.com/card/get?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['card_id' => $card_id]);
    }
176270
public function deleteCard($cardId)
    {
        $result = $this->wechat->httpPost(self::WECHAT_DELETE_CARD_URL, [
            'card_id' => $cardId
        ], [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? true : false;
    }
1272338
public function actionIndex($id)
    {
        // TODO 群发事件推送群发处理
        // TODO 模板消息事件推送处理
        // TODO 用户上报地理位置事件推送处理
        // TODO 自定义菜单事件推送处理
        // TODO 微信小店订单付款通知处理
        // TODO 微信卡卷(卡券通过审核、卡券被用户领取、卡券被用户删除)通知处理
        // TODO 智能设备接口
        // TODO 多客服转发处理
        $request = Yii::$app->request;
        $wechat = $this->findWechat($id);
        if (!$wechat->getSdk()->checkSignature()) {
            return 'Sign check fail!';
        }
        switch ($request->getMethod()) {
            case 'GET':
                if ($wechat->status == Wechat::STATUS_INACTIVE) { // 激活公众号
                    $wechat->updateAttributes(['status' => Wechat::STATUS_ACTIVE]);
                }
                return $request->get('echostr');
            case 'POST':
                $this->setWechat($wechat);
                $this->message = $this->parseRequest();
                $result = null;
                if($this->beforeProcess()) {
                    $result = $this->resolveProcess(); // 处理请求
                    $this->afterProcess($result);
                }
                return is_array($result) ? $this->createResponse($result) : $result;
            default:
                throw new NotFoundHttpException('The requested page does not exist.');
        }
    }